source: trunk/MagicSoft/Cosy/candrv/nodedrv.h@ 6724

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