iCub-main
Loading...
Searching...
No Matches
PlxCan.h
Go to the documentation of this file.
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
14//
15// $Id: PlxCan.h,v 1.5 2008/06/25 22:33:53 nat Exp $
16//
17//
18
19#ifndef __PlxCanh__
20#define __PlxCanh__
21
22#include <yarp/dev/DeviceDriver.h>
23#include <yarp/dev/CanBusInterface.h>
24
25namespace yarp{
26 namespace dev{
27 class PlxCan;
28 class PlxCanMessage;
29 }
30}
31
32//struct __PLXCAN_HANDLE; //fw decl
33//typedef struct __PLXCAN_HANDLE PLXCAN_HANDLE;
34#include "PexApi.h"
35
36class yarp::dev::PlxCanMessage:public yarp::dev::CanMessage
37{
38 public:
39 PLXCAN_MSG *msg;
40
41 public:
43 {
44 msg=0;
45 }
46
48 {
49 }
50
51 virtual CanMessage &operator=(const CanMessage &l)
52 {
53 const PlxCanMessage &tmp=dynamic_cast<const PlxCanMessage &>(l);
54 memcpy(msg, tmp.msg, sizeof(PLXCAN_MSG));
55 return *this;
56 }
57
58 virtual unsigned int getId() const
59 { return msg->id;}
60
61 virtual unsigned char getLen() const
62 { return msg->len;}
63
64 virtual void setLen(unsigned char len)
65 { msg->len=len;}
66
67 virtual void setId(unsigned int id)
68 { msg->id=id;}
69
70 virtual const unsigned char *getData() const
71 { return msg->data; }
72
73 virtual unsigned char *getData()
74 { return msg->data; }
75
76 virtual unsigned char *getPointer()
77 { return (unsigned char *) msg; }
78
79 virtual const unsigned char *getPointer() const
80 { return (const unsigned char *) msg; }
81
82 virtual void setBuffer(unsigned char *b)
83 {
84 if (b!=0)
85 msg=(PLXCAN_MSG *)(b);
86 }
87};
88
97class yarp::dev::PlxCan: public ImplementCanBufferFactory<PlxCanMessage, PLXCAN_MSG>,
98 public ICanBus,
99 public ICanBusErrors,
100 public DeviceDriver
101{
102private:
103 PLXCAN_HANDLE *handle;
104public:
105 PlxCan();
106 ~PlxCan();
107
108 /* ICanBus */
109 virtual bool canSetBaudRate(unsigned int rate);
110 virtual bool canGetBaudRate(unsigned int *rate);
111 virtual bool canIdAdd(unsigned int id);
112 virtual bool canIdDelete(unsigned int id);
113
114 virtual bool canRead(CanBuffer &msgs,
115 unsigned int size,
116 unsigned int *read,
117 bool wait=false);
118
119 virtual bool canWrite(const CanBuffer &msgs,
120 unsigned int size,
121 unsigned int *sent,
122 bool wait=false);
123
124 /*ICanBusErrors*/
125 virtual bool canGetErrors(CanErrors &errs);
126
127 /*Device Driver*/
128 virtual bool open(yarp::os::Searchable &par);
129 virtual bool close();
130
131#if 0
132 virtual CanBuffer createBuffer(int elem)
133 {
134 return CanBufferFactoryImpl<PlxCanMessage, PLXCAN_MSG>::createBuffer(elem);
135 }
136
137 virtual void destroyBuffer(CanBuffer &buffer)
138 {
139
140 CanBufferFactoryImpl<PlxCanMessage, PLXCAN_MSG>::destroyBuffer(buffer);
141 }
142#endif
143};
144
145#endif
PLXCAN_MSG * msg
Definition PlxCan.h:39
virtual unsigned char * getData()
Definition PlxCan.h:73
virtual const unsigned char * getPointer() const
Definition PlxCan.h:79
virtual void setBuffer(unsigned char *b)
Definition PlxCan.h:82
virtual ~PlxCanMessage()
Definition PlxCan.h:47
virtual void setLen(unsigned char len)
Definition PlxCan.h:64
virtual CanMessage & operator=(const CanMessage &l)
Definition PlxCan.h:51
virtual unsigned char getLen() const
Definition PlxCan.h:61
virtual unsigned char * getPointer()
Definition PlxCan.h:76
virtual void setId(unsigned int id)
Definition PlxCan.h:67
virtual const unsigned char * getData() const
Definition PlxCan.h:70
virtual unsigned int getId() const
Definition PlxCan.h:58
pcan : implements yarp::dev::ICanBus for a "plx based" can bus device (cfw pc104 card).
Definition PlxCan.h:101
virtual bool canRead(CanBuffer &msgs, unsigned int size, unsigned int *read, bool wait=false)
Definition PlxCan.cpp:60
virtual bool close()
Definition PlxCan.cpp:128
virtual bool open(yarp::os::Searchable &par)
Definition PlxCan.cpp:101
virtual bool canSetBaudRate(unsigned int rate)
Definition PlxCan.cpp:32
virtual bool canIdDelete(unsigned int id)
Definition PlxCan.cpp:54
virtual bool canGetErrors(CanErrors &errs)
Definition PlxCan.cpp:144
virtual bool canIdAdd(unsigned int id)
Definition PlxCan.cpp:45
virtual bool canGetBaudRate(unsigned int *rate)
Definition PlxCan.cpp:38
virtual bool canWrite(const CanBuffer &msgs, unsigned int size, unsigned int *sent, bool wait=false)
Definition PlxCan.cpp:79
Copyright (C) 2008 RobotCub Consortium.