CARMA C++
Utilities.h
Go to the documentation of this file.
1 
9 #ifndef CARMA_CANBUS_UTILITIES_H
10 #define CARMA_CANBUS_UTILITIES_H
11 
12 // C++ Standard Library includes
13 #include <vector>
14 
15 // Carma includes
16 #include "carma/canbus/Types.h"
17 
18 namespace carma {
19 
23  namespace canbus {
24 
25  // CAN Id Utilities.
26 
33 
39  bool isToHost(idType id);
40 
45  const bool TO_HOST = true;
46 
51  const bool TO_NODES = false;
52 
62  idType createId(bool host, apiType api, nodeType node, msgType mid);
63 
73  idType createEngId(bool host, boardType board,
74  serialNumberType serialNumber, msgType mid);
75 
83  void fromId(apiType &api, nodeType &node,
84  msgType &mid, idType id);
85 
93  void fromEngId(boardType &bt, serialNumberType &sn,
94  msgType &mid, idType engId);
95 
96  // CAN data utilities...
97  // The toData and dataTo routines correspond to the basic
98  // CAN data types that will be used and are defined in the hardware
99  // APIs... The names reflect the corresponding C basic data types.
100 
114  void uByteToData(std::vector<byteType> &data, unsigned char value);
115 
127  void uShortToData(std::vector<byteType> &data, unsigned short value);
128 
140  void uLongToData(std::vector<byteType> &data, unsigned long value);
141 
153  void sShortToData(std::vector<byteType> &data, short value);
154 
166  void sLongToData(std::vector<byteType> &data, long value);
167 
179  void floatToData(std::vector<byteType> &data, float value);
180 
192  void doubleToData(std::vector<byteType> &data, double value);
193 
203  unsigned char dataToUbyte(std::vector<byteType> &data);
204 
215  unsigned short dataToUshort(std::vector<byteType> &data);
216 
227  unsigned long dataToUlong(std::vector<byteType> &data);
228 
239  short dataToShort(std::vector<byteType> &data);
240 
251  long dataToLong(std::vector<byteType> &data);
252 
263  float dataToFloat(std::vector<byteType> &data);
264 
275  double dataToDouble(std::vector<byteType> &data);
276 
287  void padWithZeros(std::vector<byteType> &data);
288 
289  // Timing routines
290  // Useful for sleeping and waking on 1/2 second boundaries
291  // or Slow monitor boundaries (5 second).
292 
302 
311  timespec calculateTimeToNextHalfSec();
312 
321  busIdType extractBusId(std::string filename);
322 
332  int validateModulbusNo(int modulbusNo);
333 
344  int validateSlotNo(int slotNo);
345 
346  }; // namespace canbus
347 }; // namespace carma
348 #endif // CARMA_CANBUS_UTILITIES_H
void sShortToData(std::vector< byteType > &data, short value)
Convert a signed short integer (2 bytes) into raw CAN bytes.
double dataToDouble(std::vector< byteType > &data)
Convert data vector to IEEE double.
timespec calculateTimeToNextSlowBoundary()
Calculate the time to the next five second boundary.
int validateModulbusNo(int modulbusNo)
Validate a modulbusNo.
int validateSlotNo(int slotNo)
Validate slot number for CANbus slot.
void uShortToData(std::vector< byteType > &data, unsigned short value)
Convert an unsigned short integer (2 bytes) into raw CAN bytes.
unsigned short boardType
Carma Board Type id type.
Definition: Types.h:65
void fromEngId(boardType &bt, serialNumberType &sn, msgType &mid, idType engId)
Convert a raw CAN id to board type, serial number and mid.
Declarations of carma::canbus types.
void floatToData(std::vector< byteType > &data, float value)
Convert a IEEE 754-1990 float (4 bytes) into raw CAN bytes.
unsigned short dataToUshort(std::vector< byteType > &data)
Convert data vector to unsigned short integer.
unsigned char dataToUbyte(std::vector< byteType > &data)
Convert data vector to unsigned byte.
const bool TO_NODES
Constant for bool host parameter of createId indicating that the message is to be addressed to the ca...
Definition: Utilities.h:51
idType createId(bool host, apiType api, nodeType node, msgType mid)
Create a CAN id from api, node and mid.
void fromId(apiType &api, nodeType &node, msgType &mid, idType id)
Convert a raw CAN id to api code, node location and mid.
long dataToLong(std::vector< byteType > &data)
Convert data vector to signed long integer.
short dataToShort(std::vector< byteType > &data)
Convert data vector to signed short integer.
void sLongToData(std::vector< byteType > &data, long value)
Convert a signed long integer (4 bytes) into raw CAN bytes.
modeType getMode(idType id)
Extract the address mode from a 29 bit can id.
enum carma::canbus::modeTypeEnum modeType
Mode type.
float dataToFloat(std::vector< byteType > &data)
Convert data vector to IEEE float.
unsigned short apiType
Carma API id type.
Definition: Types.h:64
unsigned short serialNumberType
Carma Serial Number type.
Definition: Types.h:67
unsigned short nodeType
Carma Node Type id type.
Definition: Types.h:66
unsigned long dataToUlong(std::vector< byteType > &data)
Convert data vector to unsigned long integer.
void uLongToData(std::vector< byteType > &data, unsigned long value)
Convert an unsigned long integer (4 bytes) into raw CAN bytes.
timespec calculateTimeToNextHalfSec()
Calculate the time to the next half second boundary.
void uByteToData(std::vector< byteType > &data, unsigned char value)
Convert a unsigned char into raw CAN bytes.
bool isToHost(idType id)
Extract the host bit from a 29 bit CAN id.
busIdType extractBusId(std::string filename)
Extract the busId from a string containing the device filename.
unsigned int idType
Type for full 29 bit CAN id.
Definition: Types.h:60
const bool TO_HOST
Constant for bool host parameter of createId indicating that the message is to be addressed to the li...
Definition: Utilities.h:45
void padWithZeros(std::vector< byteType > &data)
Pad an input vector with up to 8 bytes of zeros.
unsigned short busIdType
Carma Bus Id type.
Definition: Types.h:70
idType createEngId(bool host, boardType board, serialNumberType serialNumber, msgType mid)
Produce a CAN message from a board type and serial number (engineering message).
unsigned short msgType
Carma Message id type.
Definition: Types.h:69
void doubleToData(std::vector< byteType > &data, double value)
Convert a IEEE 754-1990 double float (8 bytes) into raw CAN bytes.