iCub-main
Loading...
Searching...
No Matches
fakeCan.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008 RobotCub Consortium
3 * Author: Lorenzo Natale
4 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
5 *
6 */
7
8#ifndef __FAKECAN__
9#define __FAKECAN__
10
11#include "fbCanBusMessage.h"
12#include "fakeBoard.h"
13#include "msgList.h"
14
15#include <yarp/dev/DeviceDriver.h>
16#include <yarp/dev/CanBusInterface.h>
17
18#include <memory.h>
19#include <list>
20
21namespace yarp
22{
23 namespace dev
24 {
25 class FakeCanMessage;
26 class FakeCan;
27 }
28}
29
30class yarp::dev::FakeCanMessage:public yarp::dev::CanMessage
31{
32public:
34
35public:
37 {
38 msg=0;
39 }
40
42 {
43 }
44
45 virtual CanMessage &operator=(const CanMessage &l)
46 {
47 const FakeCanMessage &tmp=dynamic_cast<const FakeCanMessage &>(l);
48 memcpy(msg, tmp.msg, sizeof(FCMSG));
49 return *this;
50 }
51
52 virtual unsigned int getId() const
53 { return msg->id;}
54
55 virtual unsigned char getLen() const
56 { return msg->len;}
57
58 virtual void setLen(unsigned char len)
59 { msg->len=len;}
60
61 virtual void setId(unsigned int id)
62 { msg->id=id;}
63
64 virtual const unsigned char *getData() const
65 { return msg->data; }
66
67 virtual unsigned char *getData()
68 { return msg->data; }
69
70 virtual unsigned char *getPointer()
71 { return (unsigned char *) msg; }
72
73 virtual const unsigned char *getPointer() const
74 { return (const unsigned char *) msg; }
75
76 virtual void setBuffer(unsigned char *b)
77 {
78 if (b!=0)
79 msg=(FCMSG *)(b);
80 }
81};
82
83class Boards: public std::list<FakeBoard *>
84{};
85
86typedef std::list<FakeBoard *>::iterator BoardsIt;
87typedef std::list<FakeBoard *>::const_iterator BoardsConstIt;
88
89
105class yarp::dev::FakeCan: public ImplementCanBufferFactory<FakeCanMessage, FCMSG>,
106 public ICanBus,
107 public DeviceDriver
108{
109private:
110 Boards boardList;
111 MsgList replies;
112public:
113 FakeCan();
114 ~FakeCan();
115
116 /* ICanBus */
117 virtual bool canSetBaudRate(unsigned int rate);
118 virtual bool canGetBaudRate(unsigned int *rate);
119 virtual bool canIdAdd(unsigned int id);
120 virtual bool canIdDelete(unsigned int id);
121
122 virtual bool canRead(CanBuffer &msgs,
123 unsigned int size,
124 unsigned int *read,
125 bool wait=false);
126
127 virtual bool canWrite(const CanBuffer &msgs,
128 unsigned int size,
129 unsigned int *sent,
130 bool wait=false);
131
132 /*Device Driver*/
133 virtual bool open(yarp::os::Searchable &par);
134 virtual bool close();
135
136};
137
138#endif
virtual const unsigned char * getPointer() const
Definition fakeCan.h:73
virtual ~FakeCanMessage()
Definition fakeCan.h:41
virtual const unsigned char * getData() const
Definition fakeCan.h:64
virtual unsigned char getLen() const
Definition fakeCan.h:55
virtual CanMessage & operator=(const CanMessage &l)
Definition fakeCan.h:45
virtual unsigned char * getData()
Definition fakeCan.h:67
virtual unsigned char * getPointer()
Definition fakeCan.h:70
virtual unsigned int getId() const
Definition fakeCan.h:52
virtual void setBuffer(unsigned char *b)
Definition fakeCan.h:76
virtual void setLen(unsigned char len)
Definition fakeCan.h:58
virtual void setId(unsigned int id)
Definition fakeCan.h:61
fakecan : implements yarp::dev::ICanBus for a software (fake) can bus board.
Definition fakeCan.h:108
virtual bool open(yarp::os::Searchable &par)
Definition fakeCan.cpp:98
virtual bool close()
Definition fakeCan.cpp:127
virtual bool canSetBaudRate(unsigned int rate)
Definition fakeCan.cpp:25
virtual bool canWrite(const CanBuffer &msgs, unsigned int size, unsigned int *sent, bool wait=false)
Definition fakeCan.cpp:73
virtual bool canRead(CanBuffer &msgs, unsigned int size, unsigned int *read, bool wait=false)
Definition fakeCan.cpp:45
virtual bool canIdAdd(unsigned int id)
Definition fakeCan.cpp:35
virtual bool canGetBaudRate(unsigned int *rate)
Definition fakeCan.cpp:30
virtual bool canIdDelete(unsigned int id)
Definition fakeCan.cpp:40
std::list< FakeBoard * >::const_iterator BoardsConstIt
Definition fakeCan.h:87
std::list< FakeBoard * >::iterator BoardsIt
Definition fakeCan.h:86
Copyright (C) 2008 RobotCub Consortium.
unsigned char data[8]