source: trunk/Cosy/candrv/nodedrv.h@ 19248

Last change on this file since 19248 was 8864, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 3.3 KB
Line 
1#ifndef COSY_NodeDrv
2#define COSY_NodeDrv
3
4#ifndef ROOT_TString
5#include <TString.h>
6#endif
7
8#ifdef __CINT__
9typedef Byte_t BYTE_t;
10typedef UShort_t WORD_t;
11typedef Short_t WORDS_t;
12typedef UInt_t LWORD_t;
13typedef Int_t LWORDS_t;
14#else
15#include "gendef.h"
16#endif
17
18typedef struct timeval timeval_t;
19
20class Network;
21class NodeGuard;
22
23class NodeDrv
24{
25private:
26 Network *fNetwork;
27 BYTE_t fId;
28
29 TString fName;
30
31 int fError;
32
33 Bool_t fIsZombie; // A Zombie node is a node which doesn't answer...
34
35 NodeGuard *fGuard;
36
37 Int_t fGuardTime; // Guardtime [ms]
38 Int_t fLifeTimeFactor;
39
40protected:
41 void SetError(int err) { fError = err; }
42 void DelError() { fError = 0; }
43
44 Int_t GetLifeTimeFactor() const { return fLifeTimeFactor; }
45 Int_t GetGuardTime() const { return fGuardTime; }
46
47public:
48 NodeDrv(BYTE_t nodeid, const char *name=NULL);
49 virtual ~NodeDrv();
50
51 BYTE_t GetId() const { return fId; }
52 const char *GetNodeName() const { return fName; }
53 Network *GetNetwork() { return fNetwork; }
54
55 virtual void Init() = 0;
56 virtual bool InitDevice(Network *net);
57 virtual void StopDevice() = 0;
58 virtual bool Reboot();
59 virtual void CheckConnection() = 0;
60
61 int GetError() const { return fError; }
62 bool HasError() const { return fError!=0; }
63
64 bool IsZombieNode() const { return fIsZombie; }
65 void SetZombie(bool stopguard=true);
66
67 virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv);
68 virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv);
69 virtual void HandleSDOError(WORD_t idx, BYTE_t subidx);
70
71 virtual void HandlePDO1(const BYTE_t *data, const timeval_t &tv) {}
72 virtual void HandlePDO2(const BYTE_t *data, const timeval_t &tv) {}
73 virtual void HandlePDO3(const BYTE_t *data, const timeval_t &tv) {}
74 virtual void HandlePDO4(const BYTE_t *data, const timeval_t &tv) {}
75 virtual void HandleNodeguard(const timeval_t &tv);
76 virtual void HandleEmergency(const timeval_t &tv) {}
77
78 bool SendPDO1(BYTE_t data[8]);
79 bool SendPDO2(BYTE_t data[8]);
80 bool SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
81 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
82 bool SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
83 BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
84
85 bool SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store=true);
86 bool SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store=true);
87 bool SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store=true);
88
89 bool SendSDO(WORD_t idx, BYTE_t val);
90 bool SendSDO(WORD_t idx, WORD_t val);
91 bool SendSDO(WORD_t idx, LWORD_t val=0);
92
93 bool SendNMT(BYTE_t cmd);
94 virtual void SendNodeguard();
95
96 bool RequestSDO(WORD_t idx, BYTE_t subidx=0);
97
98 void WaitForNextPdo1();
99 void WaitForNextPdo2();
100 void WaitForNextPdo3();
101 void WaitForNextPdo4();
102
103 // void WaitForSdos();
104 bool WaitForSdo(WORD_t idx, BYTE_t subidx=0, WORDS_t timeout=500, bool zombie=true);
105
106 void EnableCanMsg(BYTE_t fcode);
107
108 void StartGuarding(Bool_t real=kTRUE);
109 void StartGuarding(Int_t ms, Int_t ltf, Bool_t real=kTRUE);
110 void StopGuarding();
111
112 ClassDef(NodeDrv, 0) // base class for an object describing hardware
113};
114
115#endif
Note: See TracBrowser for help on using the repository browser.