iCub-main
EsdCan.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2008 RobotCub Consortium.
5  *
6  * Author: Lorenzo Natale
7  *
8  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
9  *
10  * This file can be edited at src/modules/esdCan/EsdCan.h
11  *
12  */
13 
14 //
15 // $Id: EsdCan.h,v 1.4 2008/06/25 22:33:53 nat Exp $
16 //
17 //
18 
19 #ifndef __ESDCANH__
20 #define __ESDCANH__
21 
22 #include <yarp/dev/DeviceDriver.h>
23 #include <yarp/dev/CanBusInterface.h>
24 
25 #include "ntcan.h"
26 #include "memory.h"
27 
28 #ifdef WIN32
29 #ifndef NTCAN_HANDLE
30 #define NTCAN_HANDLE HANDLE
31 #endif
32 #endif
33 
34 namespace yarp{
35  namespace dev{
36  class EsdCan;
37  class EsdCanMessage;
38  }
39 }
40 
41 class yarp::dev::EsdCanMessage:public yarp::dev::CanMessage
42 {
43 public:
44  CMSG *msg;
45 
46 public:
48  {
49  msg=0;
50  }
51 
52  virtual ~EsdCanMessage()
53  {
54  }
55 
56  virtual CanMessage &operator=(const CanMessage &l)
57  {
58  const EsdCanMessage &tmp=dynamic_cast<const EsdCanMessage &>(l);
59  memcpy(msg, tmp.msg, sizeof(CMSG));
60  return *this;
61  }
62 
63  virtual unsigned int getId() const
64  { return msg->id;}
65 
66  virtual unsigned char getLen() const
67  { return msg->len;}
68 
69  virtual void setLen(unsigned char len)
70  { msg->len=len;}
71 
72  virtual void setId(unsigned int id)
73  { msg->id=id;}
74 
75  virtual const unsigned char *getData() const
76  { return msg->data; }
77 
78  virtual unsigned char *getData()
79  { return msg->data; }
80 
81  virtual unsigned char *getPointer()
82  { return (unsigned char *) msg; }
83 
84  virtual const unsigned char *getPointer() const
85  { return (const unsigned char *) msg; }
86 
87  virtual void setBuffer(unsigned char *b)
88  {
89  if (b!=0)
90  msg=(CMSG *)(b);
91  }
92 };
93 
102 class yarp::dev::EsdCan: public ImplementCanBufferFactory<EsdCanMessage, CMSG>,
103  public ICanBus,
104  public DeviceDriver
105 {
106 private:
107  NTCAN_HANDLE *handle;
108 public:
109  EsdCan();
110  ~EsdCan();
111 
112  /* ICanBus */
113  virtual bool canSetBaudRate(unsigned int rate);
114  virtual bool canGetBaudRate(unsigned int *rate);
115  virtual bool canIdAdd(unsigned int id);
116  virtual bool canIdDelete(unsigned int id);
117 
118  virtual bool canRead(CanBuffer &msgs,
119  unsigned int size,
120  unsigned int *read,
121  bool wait=false);
122 
123  virtual bool canWrite(const CanBuffer &msgs,
124  unsigned int size,
125  unsigned int *sent,
126  bool wait=false);
127 
128  /*Device Driver*/
129  virtual bool open(yarp::os::Searchable &par);
130  virtual bool close();
131 
132 };
133 
134 #endif
virtual void setBuffer(unsigned char *b)
Definition: EsdCan.h:87
virtual const unsigned char * getPointer() const
Definition: EsdCan.h:84
virtual void setLen(unsigned char len)
Definition: EsdCan.h:69
virtual unsigned char getLen() const
Definition: EsdCan.h:66
virtual ~EsdCanMessage()
Definition: EsdCan.h:52
virtual unsigned char * getPointer()
Definition: EsdCan.h:81
virtual unsigned int getId() const
Definition: EsdCan.h:63
virtual CanMessage & operator=(const CanMessage &l)
Definition: EsdCan.h:56
virtual unsigned char * getData()
Definition: EsdCan.h:78
virtual const unsigned char * getData() const
Definition: EsdCan.h:75
virtual void setId(unsigned int id)
Definition: EsdCan.h:72
ecan : implements yarp::dev::ICanBus for a esd can bus board.
Definition: EsdCan.h:105
virtual bool close()
Definition: EsdCan.cpp:183
virtual bool canGetBaudRate(unsigned int *rate)
Definition: EsdCan.cpp:52
virtual bool canIdDelete(unsigned int id)
Definition: EsdCan.cpp:79
virtual bool canWrite(const CanBuffer &msgs, unsigned int size, unsigned int *sent, bool wait=false)
Definition: EsdCan.cpp:116
virtual bool open(yarp::os::Searchable &par)
Definition: EsdCan.cpp:148
virtual bool canSetBaudRate(unsigned int rate)
Definition: EsdCan.cpp:35
virtual bool canIdAdd(unsigned int id)
Definition: EsdCan.cpp:70
virtual bool canRead(CanBuffer &msgs, unsigned int size, unsigned int *read, bool wait=false)
Definition: EsdCan.cpp:88
bool read(yarp::os::Searchable &cfgtotal, pc104Data &pc104data)
Definition: ethParser.cpp:92
Copyright (C) 2008 RobotCub Consortium.