14 #include "std_msgs/String.h"
28 printf(
"pcan_transmit - a small node, based on transmitest , which is subscribed to a ROS topic and sends CAN messages.\n");
29 printf(
"usage: pcan_transmit {[-f=devicenode] | {[-b=BTR0BTR1] [-?]}} \n");
30 printf(
"options: -f - devicenode, default=%s\n",
DEFAULT_NODE);
31 printf(
" -b - BTR0BTR1 code in hex, e.g.\n");
32 printf(
" 0x0014 = 1 MBit/s\n");
33 printf(
" 0x001C = 500 kBit/s\n");
34 printf(
" 0x011C = 250 kBit/s\n");
35 printf(
" 0x031C = 125 kBit/s\n");
36 printf(
" 0x432F = 100 kBit/s\n");
37 printf(
" 0x472F = 50 kBit/s\n");
38 printf(
" 0x532F = 20 kBit/s\n");
39 printf(
" 0x672F = 10 kBit/s\n");
40 printf(
" 0x7F7F = 5 kBit/s\n");
41 printf(
" (default: 1 Mbit).\n");
42 printf(
" -? or --help - this help\n");
72 int nExtended = CAN_INIT_TYPE_ST;
77 __u16 wBTR0BTR1 = 0x0014;
90 bool bDevNodeGiven =
false;
91 bool bTypeGiven =
false;
92 char txt[VERSIONSTRING_LEN];
95 for (
int i = 1; i < argc; i++)
119 bDevNodeGiven =
true;
122 wBTR0BTR1 = (__u16)strtoul(ptr, NULL, 16);
131 if ((bDevNodeGiven) || (!bDevNodeGiven && !bTypeGiven))
133 h = LINUX_CAN_Open(szDevNode, O_RDWR);
136 printf(
"pcan_transmit: can't open %s\n", szDevNode);
146 h = CAN_Open(nType, dwPort, wIrq);
156 errno = CAN_VersionInfo(
h, txt);
158 printf(
"pcan_transmit: driver version = %s\n", txt);
160 perror(
"pcan_transmit: CAN_VersionInfo()");
166 errno = CAN_Init(
h, wBTR0BTR1, nExtended);
169 perror(
"pcan_transmit: CAN_Init()");
185 std::string can_message = msg.data;
186 std::stringstream
ss;
187 std::istringstream iss(can_message);
188 std::vector<std::string> tokens;
189 std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(), std::back_inserter<std::vector<std::string> >(tokens));
192 m.ID = (DWORD) std::strtol(tokens.at(0).data(),NULL,0);
193 m.LEN = (BYTE) std::strtol(tokens.at(1).data(),NULL,0);
195 if(tokens.size()>3 && tokens.size()<11)
197 for(
int i = 2; i < tokens.size(); i++)
199 m.DATA[i-2] = (BYTE) std::strtol(tokens.at(i).data(),NULL,0);
220 if ( CAN_Write(
h, &m))
222 perror(
"pcan_transmit: CAN_Write()");
TPCANMsg StringToTPCANRdMsg(std_msgs::String msg)
void do_exit(int error, HANDLE h)
char const * getNameOfInterface(int nType)
void init(int argc, char **argv)
void transmit(const std_msgs::String can_message)