1 | #ifndef NODEDRV_H
|
---|
2 | #define NODEDRV_H
|
---|
3 |
|
---|
4 | #include <TString.h>
|
---|
5 |
|
---|
6 | #include "log.h"
|
---|
7 |
|
---|
8 | #ifdef __CINT__
|
---|
9 | typedef Byte_t BYTE_t;
|
---|
10 | typedef UShort_t WORD_t;
|
---|
11 | typedef Short_t WORDS_t;
|
---|
12 | typedef UInt_t LWORD_t;
|
---|
13 | typedef Int_t LWORDS_t;
|
---|
14 | #else
|
---|
15 | #include "gendef.h"
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | typedef struct timeval timeval_t;
|
---|
19 |
|
---|
20 | class Network;
|
---|
21 |
|
---|
22 | class NodeDrv : public Log, public TObject
|
---|
23 | {
|
---|
24 | private:
|
---|
25 | Network *fNetwork;
|
---|
26 | BYTE_t fId;
|
---|
27 |
|
---|
28 | TString fName;
|
---|
29 |
|
---|
30 | int fError;
|
---|
31 |
|
---|
32 | Bool_t fIsZombie; // A Zombie node is a node which doesn't answer...
|
---|
33 |
|
---|
34 | TTimer *fTimeout;
|
---|
35 | Int_t fGuardTime; // Guardtime [ms]
|
---|
36 | Int_t fLifeTimeFactor;
|
---|
37 | Double_t fTimeoutTime;
|
---|
38 | Bool_t fTimerOn;
|
---|
39 |
|
---|
40 | Bool_t HandleTimer(TTimer *t);
|
---|
41 |
|
---|
42 | protected:
|
---|
43 | void SetError(int err) { fError = err; }
|
---|
44 | void DelError() { fError = 0; }
|
---|
45 |
|
---|
46 | Int_t GetLifeTimeFactor() const { return fLifeTimeFactor; }
|
---|
47 | Int_t GetGuardTime() const { return fGuardTime; }
|
---|
48 |
|
---|
49 | virtual void SetZombie();
|
---|
50 |
|
---|
51 | public:
|
---|
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 |
|
---|
70 | virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);
|
---|
71 | virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, timeval_t *tv);
|
---|
72 | virtual void HandleSDOError(LWORD_t data);
|
---|
73 |
|
---|
74 | virtual void HandlePDO1(BYTE_t *data, timeval_t *tv) {}
|
---|
75 | virtual void HandlePDO2(BYTE_t *data, timeval_t *tv) {}
|
---|
76 | virtual void HandlePDO3(BYTE_t *data, timeval_t *tv) {}
|
---|
77 | virtual void HandlePDO4(BYTE_t *data, timeval_t *tv) {}
|
---|
78 | virtual void HandleNodeguard(timeval_t *tv);
|
---|
79 | virtual void HandleEmergency(timeval_t *tv) {}
|
---|
80 |
|
---|
81 | bool SendPDO1(BYTE_t data[8]);
|
---|
82 | bool SendPDO2(BYTE_t data[8]);
|
---|
83 | bool SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
|
---|
84 | BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
|
---|
85 | bool SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
|
---|
86 | BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
|
---|
87 |
|
---|
88 | bool SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store=true);
|
---|
89 | bool SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store=true);
|
---|
90 | bool SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store=true);
|
---|
91 |
|
---|
92 | bool SendSDO(WORD_t idx, BYTE_t val);
|
---|
93 | bool SendSDO(WORD_t idx, WORD_t val);
|
---|
94 | bool SendSDO(WORD_t idx, LWORD_t val=0);
|
---|
95 |
|
---|
96 | bool SendNMT(BYTE_t cmd);
|
---|
97 | virtual void SendNodeguard();
|
---|
98 |
|
---|
99 | bool RequestSDO(WORD_t idx, BYTE_t subidx=0);
|
---|
100 |
|
---|
101 | void WaitForNextPdo1();
|
---|
102 | void WaitForNextPdo2();
|
---|
103 | void WaitForNextPdo3();
|
---|
104 | void WaitForNextPdo4();
|
---|
105 |
|
---|
106 | // void WaitForSdos();
|
---|
107 | bool WaitForSdo(WORD_t idx, BYTE_t subidx=0, WORDS_t timeout=500);
|
---|
108 |
|
---|
109 | void EnableCanMsg(BYTE_t fcode);
|
---|
110 |
|
---|
111 | void StartGuarding(Bool_t real=kTRUE);
|
---|
112 | void StartGuarding(Int_t ms, Int_t ltf, Bool_t real=kTRUE);
|
---|
113 | void StopGuarding();
|
---|
114 |
|
---|
115 | ClassDef(NodeDrv, 0) // base class for an object describing hardware
|
---|
116 | };
|
---|
117 |
|
---|
118 | #endif
|
---|