53 for (i = 0x700; i < 0x7FF; i++) iCanBus->canIdAdd (i);
54 for (i = 0x200; i < 0x2FF; i++) iCanBus->canIdAdd (i);
56 iCanBus->canSetBaudRate(0);
58 yarp::os::Time::delay(2.0);
82 maxreadmsg = canpackets.size();
84 if (howMany>maxreadmsg)
87 unsigned int how_many_messages=0;
91 double start=Time::now();
99 ret=iCanBus->canRead(canRXbuffer, maxreadmsg, &how_many_messages,
false);
101 if (read+how_many_messages>maxreadmsg)
103 how_many_messages=(maxreadmsg-read);
106 for(
unsigned int k=0;k<how_many_messages;k++)
109 canpackets[read].setLen(canRXbuffer[k].getLen());
110 canpackets[read].setId(canRXbuffer[k].getId());
111 memcpy(canpackets[read].getData(), canRXbuffer[k].getData(), canRXbuffer[k].getLen());
124 if ( (now-start)>TIMEOUT)
142 if(
n > canpackets.size())
144 n = canpackets.size();
153 for(
int i=0; i<
n; i++)
157 canTXbuffer[i].setId(canpackets[i].getId());
158 canTXbuffer[i].setLen(canpackets[i].getLen());
159 void * src = canpackets[i].getData();
160 void * dst = canTXbuffer[i].getData();
161 memcpy(dst, src, canpackets[i].getLen());
166 bool ret = iCanBus->canWrite(canTXbuffer,
n, &sent);
208 ACE_UINT32 local=(ACE_UINT32)config.find(
"local").asInt32();
214 if (!mSocket->
create(3334,local))
216 yError(
"invalid address\n");
220 mBoardAddr=(ACE_UINT32)config.find(
"remote").asInt32();
225 timestart = yarp::os::Time::now();
239 yarp::os::Time::delay(2.0);
243#if defined(USE_LEGACY_0X20_MESSAGE)
248 static unsigned char cmd_cangtw_start[8] = {0x20, 0, 0, 0, 0, 0, 0, 0};
249 if(_verbose) yDebug() <<
"byte is ...." << cmd_cangtw_start[0];
251 mSocket->
sendTo(cmd_cangtw_start, 1, 3333, mBoardAddr);
258 yarp::os::Time::delay(1.5);
262 if(_verbose) yWarning(
"sending request to start can gateway mode");
264 const uint16_t t_can_stabilisation = 900;
265 const uint8_t b_send_ff_after_can_stabilisation = 0;
266 const uint16_t t_wait_for_can_reply = 0;
267 const uint8_t b_clear_can_buffers_on_start_gtw = 0;
268 const uint8_t b_send_ack = 1;
282 eOuprot_cmd_CANGATEWAY_t command = {0};
283 command.opc = uprot_OPC_LEGACY_CANGATEWAY;
284 command.sendcanbroadcast = b_send_ff_after_can_stabilisation;
285 command.time4canstable = t_can_stabilisation;
286 command.time2waitcanreply = t_wait_for_can_reply;
287 command.rxcanbufferclear = b_clear_can_buffers_on_start_gtw;
288 command.ackrequired = b_send_ack;
291 mSocket->
sendTo(&command,
sizeof(eOuprot_cmd_CANGATEWAY_t), 3333, mBoardAddr);
297 const double waitingTime = 1.5;
302 eOuprot_cmdREPLY_t cmdreply = {0};
304 if(_verbose) yDebug(
"waiting for an ack/nak from board");
308 int mswait = 1000.0f * waitingTime;
309 int nrec = mSocket->
receiveFrom(&cmdreply,
sizeof(cmdreply), address, port, mswait);
313 if(_verbose) yWarning(
"remote board did not sent any ack to command 0x20. it may have a version of eUpdater older than 6.6");
316 else if(
sizeof(cmdreply) == nrec)
318 if((uprot_OPC_CANGATEWAY == cmdreply.opc) && (uprot_RES_OK == cmdreply.res))
320 if(_verbose) yDebug(
"REMOTE BOARD is in CAN gateway now");
323 else if((uprot_OPC_CANGATEWAY == cmdreply.opc) && (uprot_RES_OK != cmdreply.res))
325 if(uprot_RES_ERR_TRYAGAIN == cmdreply.res)
327 if(_verbose) yWarning(
"REMOTE BOARD tells that it cannot go to CAN gateway mode, BUT: The eApplication has jumped to eUpdater. Try connect again.");
332 if(_verbose) yWarning(
"REMOTE BOARD tells that it cannot go to CAN gateway mode.");
338 uint8_t *bb = (uint8_t*) &cmdreply;
339 if(_verbose) yWarning(
"REMOTE BOARD sends an unknown reply[%d] = {%x, %x, %x, %x}.", nrec, bb[0], bb[1], bb[2], bb[3]);
345 uint8_t *bb = (uint8_t*) &cmdreply;
346 if(_verbose) yWarning(
"REMOTE BOARD sends an unknown reply[%d] = {%x, %x, %x, %x}.", nrec, bb[0], bb[1], bb[2], bb[3]);
353 yarp::os::Time::delay(waitingTime);
384 double tstart=yarp::os::Time::now();
397 if (address==mBoardAddr && port==3334)
401 for (
int f=0;
f<nframes; ++
f)
410 canpackets[nread].setCanBus(canbus);
412 canpackets[nread].setLen(canPkt.
frames[
f].
len);
416 if (++nread>=howMany)
return nread;
422 if (yarp::os::Time::now()-tstart>TIMEOUT)
break;
432 static ACE_UINT32 prognumber = 0;
435 for (
int i=0; i<
n; ++i)
445 canPkt.
frames[0].
len = canpackets[i].getLen();
446 memcpy(canPkt.
frames[0].
data, canpackets[i].getData(), canpackets[i].getLen());
456 yarp::os::Time::delay(0.001);
460 yarp::os::Time::delay(0.001);
465 yarp::os::Time::delay(0.001);
611 ACE_UINT32 local=(ACE_UINT32)config.find(
"local").asInt32();
613 if (!mSocket.
create(3334,local))
615 yError(
"invalid address\n");
619 mBoardAddr=(ACE_UINT32)config.find(
"remote").asInt32();
621 mCanBusId=config.check(
"canid")?config.find(
"canid").asInt32():0;
624 timestart = yarp::os::Time::now();
633 yarp::os::Time::delay(1.75);
642 unsigned char CMD_CANGTW_START=0x20;
644 mSocket.
sendTo(&CMD_CANGTW_START,1,3333,mBoardAddr);
652 yarp::os::Time::delay(0.25);
676 double tstart=yarp::os::Time::now();
686 if (address==mBoardAddr && port==3334)
690 for (
int f=0;
f<nframes; ++
f)
702 if (++nread>=howMany)
return nread;
708 if (yarp::os::Time::now()-tstart>TIMEOUT)
break;