iCub-main
Cfw2Can.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) 2010 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/cfw2can/Cfw2Can.h
11  *
12  */
13 
14 //
15 // $Id: Cfw2Can.h,v 1.5 2008/06/25 22:33:53 nat Exp $
16 //
17 //
18 
19 #ifndef __Cfw2Canh__
20 #define __Cfw2Canh__
21 
22 #include <yarp/dev/DeviceDriver.h>
23 #include <yarp/dev/CanBusInterface.h>
24 
25 namespace yarp{
26  namespace dev{
27  class Cfw2Can;
28  class Cfw2CanMessage;
29  }
30 }
31 
32 #include "libcfw002.h"
33 
34 class yarp::dev::Cfw2CanMessage:public yarp::dev::CanMessage
35 {
36  public:
37  CFWCAN_MSG *msg;
38 
39  public:
41  {
42  msg=0;
43  }
44 
45  virtual ~Cfw2CanMessage()
46  {
47  }
48 
54  virtual CanMessage &operator=(const CanMessage &l);
55 
56  virtual unsigned int getId() const
57  { return msg->id;}
58 
59  virtual unsigned char getLen() const
60  { return msg->len;}
61 
62  virtual void setLen(unsigned char len)
63  { msg->len=len;}
64 
65  virtual void setId(unsigned int id)
66  { msg->id=id;}
67 
68  virtual const unsigned char *getData() const
69  { return msg->data; }
70 
71  virtual unsigned char *getData()
72  { return msg->data; }
73 
74  virtual unsigned char *getPointer()
75  { return (unsigned char *) msg; }
76 
77  virtual const unsigned char *getPointer() const
78  { return (const unsigned char *) msg; }
79 
80  virtual void setBuffer(unsigned char *b)
81  {
82  if (b!=0)
83  msg=(CFWCAN_MSG *)(b);
84  }
85 };
86 
95 class yarp::dev::Cfw2Can: public ImplementCanBufferFactory<Cfw2CanMessage, CFWCAN_MSG>,
96  public ICanBus,
97  /* public ICanBusErrors, */
98  public DeviceDriver
99 {
100 private:
101  CFWCAN_HANDLE *handle;
102 public:
103  Cfw2Can();
104  ~Cfw2Can();
105 
106  /* ICanBus */
107  virtual bool canSetBaudRate(unsigned int rate);
108  virtual bool canGetBaudRate(unsigned int *rate);
109  virtual bool canIdAdd(unsigned int id);
110  virtual bool canIdDelete(unsigned int id);
111 
112  virtual bool canRead(CanBuffer &msgs,
113  unsigned int size,
114  unsigned int *read,
115  bool wait=false);
116 
117  virtual bool canWrite(const CanBuffer &msgs,
118  unsigned int size,
119  unsigned int *sent,
120  bool wait=false);
121 
122  /*ICanBusErrors*/
123  // virtual bool canGetErrors(CanErrors &errs);
124 
125 
126  /*Device Driver*/
127  virtual bool open(yarp::os::Searchable &par);
128  virtual bool close();
129 };
130 
131 #endif
virtual const unsigned char * getData() const
Definition: Cfw2Can.h:68
virtual void setBuffer(unsigned char *b)
Definition: Cfw2Can.h:80
virtual ~Cfw2CanMessage()
Definition: Cfw2Can.h:45
virtual unsigned char * getData()
Definition: Cfw2Can.h:71
virtual void setId(unsigned int id)
Definition: Cfw2Can.h:65
virtual unsigned int getId() const
Definition: Cfw2Can.h:56
CFWCAN_MSG * msg
Definition: Cfw2Can.h:37
virtual const unsigned char * getPointer() const
Definition: Cfw2Can.h:77
virtual unsigned char getLen() const
Definition: Cfw2Can.h:59
virtual unsigned char * getPointer()
Definition: Cfw2Can.h:74
virtual CanMessage & operator=(const CanMessage &l)
This operator is defined in a general way, but it will crash if you try to assign to a Cfw2CanMessage...
Definition: Cfw2Can.cpp:173
virtual void setLen(unsigned char len)
Definition: Cfw2Can.h:62
cfw2can : driver implementing the yarp::dev::ICanBus interface for a cfw2 can bus device (cfw2 pc104 ...
Definition: Cfw2Can.h:99
virtual bool canRead(CanBuffer &msgs, unsigned int size, unsigned int *read, bool wait=false)
Definition: Cfw2Can.cpp:66
virtual bool close()
Definition: Cfw2Can.cpp:141
virtual bool canWrite(const CanBuffer &msgs, unsigned int size, unsigned int *sent, bool wait=false)
Definition: Cfw2Can.cpp:85
virtual bool open(yarp::os::Searchable &par)
Definition: Cfw2Can.cpp:107
virtual bool canIdAdd(unsigned int id)
Definition: Cfw2Can.cpp:46
virtual bool canGetBaudRate(unsigned int *rate)
Definition: Cfw2Can.cpp:39
virtual bool canIdDelete(unsigned int id)
Definition: Cfw2Can.cpp:56
virtual bool canSetBaudRate(unsigned int rate)
Definition: Cfw2Can.cpp:33
bool read(yarp::os::Searchable &cfgtotal, pc104Data &pc104data)
Definition: ethParser.cpp:92
Copyright (C) 2008 RobotCub Consortium.