16#include <yarp/dev/PolyDriver.h>
17#include <yarp/dev/CanBusInterface.h>
18#include <yarp/os/Searchable.h>
19#include <yarp/os/Time.h>
20#include <yarp/os/Log.h>
21#include <yarp/os/LogStream.h>
24#include <ace/SOCK_Dgram_Bcast.h>
25#include <ace/Time_Value.h>
26#include <ace/OS_NS_sys_socket.h>
37#define DRIVER_KEEP_LEGACY_IDRIVER
40#define MAX_READ_MSG 64
41#define MAX_WRITE_MSG 8
61 unsigned char data[8];
67 CanPacket(){ canpkt.canbus = 0; canpkt.id = 0; canpkt.len = 0; memset(canpkt.data, 0,
sizeof(canpkt.data)); }
74 pkt.canpkt.id = canmsg.getId();
75 pkt.canpkt.len = canmsg.getLen();
76 memcpy(pkt.canpkt.data, canmsg.getData(),
sizeof(pkt.canpkt.data));
81 unsigned int getId()
const {
return canpkt.id; }
82 unsigned char getLen()
const {
return canpkt.len; }
83 void setLen(
unsigned char len) { canpkt.len=len; }
84 void setId(
unsigned int id){ canpkt.id=id; }
85 const unsigned char *
getData()
const {
return canpkt.data; }
86 unsigned char *
getData(){
return canpkt.data; }
88 void setCanBus(
unsigned int bus){ canpkt.canbus=bus; }
100 virtual int init(yarp::os::Searchable &config,
bool verbose =
true)=0;
119 int init(yarp::os::Searchable &config,
bool verbose =
true);
126 yarp::dev::PolyDriver dd;
127 yarp::dev::ICanBus *iCanBus;
128 yarp::dev::ICanBufferFactory *iFactory;
130 yarp::dev::CanBuffer canTXbuffer;
131 yarp::dev::CanBuffer canRXbuffer;
137 yarp::dev::CanBuffer createCanBuffer(
int m);
138 void destroyCanBuffer(yarp::dev::CanBuffer &buff);
152 int init(yarp::os::Searchable &config,
bool verbose =
true);
161 ACE_UINT32 mBoardAddr;
211 ACE_OS::socket_init(2,2);
218 ACE_OS::socket_fini();
221 bool create(ACE_UINT16 port,ACE_UINT32 address)
223 mSocket=
new ACE_SOCK_Dgram_Bcast(ACE_INET_Addr(port,address));
227 void sendTo(
void*
data,
size_t len, ACE_UINT16 port, ACE_UINT32 address)
233 mSocket->send(
data,len,ACE_INET_Addr(port,address));
236 ssize_t
receiveFrom(
void*
data,
size_t len, ACE_UINT32 &address, ACE_UINT16 &port,
int wait_msec)
238 ACE_Time_Value tv(wait_msec/1000,(wait_msec%1000)*1000);
239 ACE_INET_Addr ace_addr;
240 ssize_t nrec=
mSocket->recv(
data,len,ace_addr,0,&tv);
247 address=ace_addr.get_ip_address();
248 port=ace_addr.get_port_number();
278#if defined(DRIVER_KEEP_LEGACY_IDRIVER)
284 virtual int init(yarp::os::Searchable &config)=0;
297 yarp::dev::PolyDriver dd;
298 yarp::dev::ICanBus *iCanBus;
299 yarp::dev::ICanBufferFactory *iFactory;
303 int init(yarp::os::Searchable &config);
333 memcpy(
msg, tmp.msg,
sizeof(
ECMSG));
344 virtual const unsigned char *
getPointer()
const {
return (
const unsigned char *)
msg; }
352class eDriver :
public yarp::dev::ImplementCanBufferFactory<EthCanMessage,ECMSG>,
public iDriver
358 ACE_UINT32 mBoardAddr;
362 yarp::dev::ICanBufferFactory *iFactory;
367 int init(yarp::os::Searchable &config);
unsigned char * getData()
unsigned int getId() const
void setCanBus(unsigned int bus)
const unsigned char * getData() const
void setId(unsigned int id)
unsigned char getLen() const
void setLen(unsigned char len)
CanPacket operator=(const yarp::dev::CanMessage &canmsg)
bool create(ACE_UINT16 port, ACE_UINT32 address)
void sendTo(void *data, size_t len, ACE_UINT16 port, ACE_UINT32 address)
ssize_t receiveFrom(void *data, size_t len, ACE_UINT32 &address, ACE_UINT16 &port, int wait_msec)
ACE_SOCK_Dgram_Bcast * mSocket
unsigned int getCanBus() const
virtual unsigned char getLen() const
virtual CanMessage & operator=(const CanMessage &l)
virtual void setId(unsigned int id)
void setCanBus(unsigned int bus)
virtual unsigned int getId() const
virtual unsigned char * getPointer()
virtual const unsigned char * getPointer() const
virtual void setLen(unsigned char len)
virtual const unsigned char * getData() const
virtual void setBuffer(unsigned char *b)
virtual unsigned char * getData()
int receive_message(vector< CanPacket > &canpackets, int howMany=MAX_READ_MSG, double TIMEOUT=1)
int init(yarp::os::Searchable &config, bool verbose=true)
int send_message(vector< CanPacket > &canpackets, int n)
int receive_message(yarp::dev::CanBuffer &messages, int howMany=MAX_READ_MSG, double TIMEOUT=1)
int send_message(yarp::dev::CanBuffer &message, int n)
int init(yarp::os::Searchable &config)
void destroyBuffer(yarp::dev::CanBuffer &buff)
yarp::dev::CanBuffer createBuffer(int m)
int init(yarp::os::Searchable &config, bool verbose=true)
int receive_message(vector< CanPacket > &canpackets, int howMany=MAX_READ_MSG, double TIMEOUT=1)
int send_message(vector< CanPacket > &canpackets, int n)
int init(yarp::os::Searchable &config)
void destroyBuffer(yarp::dev::CanBuffer &buff)
int receive_message(yarp::dev::CanBuffer &messages, int howMany=MAX_READ_MSG, double TIMEOUT=1.0)
int send_message(yarp::dev::CanBuffer &message, int n)
yarp::dev::CanBuffer createBuffer(int m)
virtual int send_message(vector< CanPacket > &canpackets, int n)=0
virtual iDriver2Type type()=0
virtual int init(yarp::os::Searchable &config, bool verbose=true)=0
virtual int receive_message(vector< CanPacket > &canpackets, int howMany=MAX_READ_MSG, double TIMEOUT=1)=0
virtual void destroyBuffer(yarp::dev::CanBuffer &buff)=0
virtual int send_message(yarp::dev::CanBuffer &message, int n)=0
virtual yarp::dev::CanBuffer createBuffer(int m)=0
virtual int init(yarp::os::Searchable &config)=0
virtual int receive_message(yarp::dev::CanBuffer &messages, int howMany=MAX_READ_MSG, double TIMEOUT=1)=0