cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
osaCANBusFrame.h
Go to the documentation of this file.
1 
2 #ifndef _osaCANBusFrame_h
3 #define _osaCANBusFrame_h
4 
5 #include <cisstVector.h>
7 
9 
17 
18  public:
19 
21 
25  typedef unsigned short ID;
26 
27  typedef unsigned short Mask;
28 
30  typedef unsigned char Data;
31 
33  typedef Data DataField[8];
34 
36  typedef unsigned char DataLength;
37 
38  protected:
39 
41  ID id;
42 
44  DataField data;
45 
48 
49  public:
50 
51 
53 
58 
60 
63  osaCANBusFrame( ID canid, DataField data, DataLength nbytes );
64 
65  osaCANBusFrame( ID canid, const vctDynamicVector<Data>& data );
66 
68  ID GetID() const { return id; }
69 
71  DataLength GetLength() const { return nbytes; }
72 
74  Data* GetData() { return &(data[0]); }
75 
77  const Data* GetData() const { return &(data[0]); }
78 
80 
85  friend std::ostream& operator<<(std::ostream& os, const osaCANBusFrame& frame){
86  os <<"ID: 0x"
87  << std::hex << std::setfill('0') << std::setw(4)
88  << (int)frame.GetID() << std::endl
89  << "Length: " << (int)frame.GetLength() << std::endl
90  << "Data: ";
91  for( DataLength i=0; i<frame.GetLength(); i++ )
92  os << "0x" << std::hex << std::setfill('0') << std::setw(2)
93  << (int)(frame.data[i]) << " ";
94  os << std::dec;
95  return os;
96  }
97 
98 }; // Frame
99 
100 #endif
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
A vector object of dynamic size.
Definition: vctDynamicVector.h:127
ID GetID() const
Return the identifier of the frame.
Definition: osaCANBusFrame.h:68
DataLength nbytes
The lenght of the message in bytes.
Definition: osaCANBusFrame.h:47
DataField data
The message (8 bytes)
Definition: osaCANBusFrame.h:44
unsigned short Mask
Definition: osaCANBusFrame.h:27
unsigned char Data
The data type.
Definition: osaCANBusFrame.h:30
unsigned short ID
The id of a CAN frame.
Definition: osaCANBusFrame.h:25
friend std::ostream & operator<<(std::ostream &os, const osaCANBusFrame &frame)
Output the can frame.
Definition: osaCANBusFrame.h:85
Data * GetData()
Return a pointer to the data.
Definition: osaCANBusFrame.h:74
DataLength GetLength() const
Return the length in bytes of the data.
Definition: osaCANBusFrame.h:71
const Data * GetData() const
Return a const pointer to the data.
Definition: osaCANBusFrame.h:77
unsigned char DataLength
The data length type.
Definition: osaCANBusFrame.h:36
CAN frame implementation.
Definition: osaCANBusFrame.h:16
ID id
The ID of the node origin.
Definition: osaCANBusFrame.h:41