CARMA C++
InetCan.h
Go to the documentation of this file.
1 
10 #ifndef CARMA_CANBUS_INETCAN_H
11 #define CARMA_CANBUS_INETCAN_H
12 
13 #include "carma/canbus/CanIo.h"
14 
15 namespace carma {
16 namespace canbus {
17 
22 class InetCan : public carma::canbus::CanIo {
23 public:
24 
37  InetCan(
38  const std::string hostname,
39  unsigned int ac = 0xffffffff,
40  unsigned int am = 0xffffffff,
41  unsigned short busac = 0xffff);
42 
46  ~InetCan();
47 
53  void postMessage(
54  const carma::canbus::Message& msg,
55  carma::canbus::txPriorityType prio = carma::canbus::NORMAL);
56 
63 
70  void addFilter(unsigned int ac, unsigned int am, unsigned short busac);
71 
76  void clearFilters();
77 
78 protected:
79 
80  // There are no protected methods.
81 
82 private:
83 
84  // Message received received from server (contains CAN message).
85  struct MsgFromServer {
86  unsigned int id;
87  unsigned short busId;
88  unsigned char size;
89  unsigned char data[8];
90  }; // 15 Bytes
91 
92  // Message for posting to CANbus or setting filter.
93  struct MsgToServer {
94  unsigned char mode;
99  union {
100  unsigned int id;
101  unsigned int ac;
102  };
108  union {
109  unsigned short busId;
110  unsigned short busFilter;
111  };
112  unsigned char size;
117  union {
118  unsigned char data[8]; // Data
119  unsigned int am; // Acceptance mask
120  };
121  }; // 16 bytes
122 
123  // MsgToServer mode
124  enum mode {
125  SET_READ_FILTER = 0x00,
126  CLEAR_READ_FILTERS = 0x01,
127  WRITE_CAN_MSG = 0x02
128  };
129 
130  // Private data.
131  static const unsigned int READ_PORT = 15000;
132  static const unsigned int WRITE_PORT = 15001;
133 
134  int writeSock_; // Write socket file descriptor.
135  int readSock_; // Read socket file descriptor.
136  const std::string hostname_; // Who are we connected to?
137 
138  // Private methods.
139  void sendToServer(const MsgToServer &msg); // Posts to write socket.
140 
141 }; // End class InetCan
142 }} // End namespace carma::canbus
143 #endif
InetCan class.
Definition: InetCan.h:22
carma::canbus::Message getMessage()
Get a CAN Message.
Class to encapsulate a CAN message.
Definition: Message.h:21
void clearFilters()
Clear all acceptance filters.
Declaration of carma::canbus::CanIo interface.
~InetCan()
Destructor.
void postMessage(const carma::canbus::Message &msg, carma::canbus::txPriorityType prio=carma::canbus::NORMAL)
Post a CAN Message.
void addFilter(unsigned int ac, unsigned int am, unsigned short busac)
Add an additional acceptance filter.
InetCan(const std::string hostname, unsigned int ac=0xffffffff, unsigned int am=0xffffffff, unsigned short busac=0xffff)
Constructor.
txPriorityType
CAN Tx priority type.
Definition: Types.h:194
CanIo interface.
Definition: CanIo.h:22