1 | #ifndef VMODICAN_H
|
---|
2 | #define VMODICAN_H
|
---|
3 |
|
---|
4 | #include <pthread.h>
|
---|
5 |
|
---|
6 | #include "unistd.h" // gettimeofday
|
---|
7 |
|
---|
8 | #include "log.h"
|
---|
9 |
|
---|
10 | #ifdef __CINT__
|
---|
11 | //#include <TROOT.h>
|
---|
12 | typedef UShort_t WORD_t;
|
---|
13 | typedef Byte_t BYTE_t;
|
---|
14 | #else
|
---|
15 | #include "gendef.h"
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | #include "MThread.h"
|
---|
19 |
|
---|
20 | class Message;
|
---|
21 | class FastMessage;
|
---|
22 |
|
---|
23 | class VmodIcan : public Log, protected MThread
|
---|
24 | {
|
---|
25 | friend class VmodIcanRX;
|
---|
26 |
|
---|
27 | private:
|
---|
28 | int fd; // file descriptor for can module
|
---|
29 |
|
---|
30 | int Ioctl(int msg, void *arg);
|
---|
31 |
|
---|
32 | void *Thread();
|
---|
33 |
|
---|
34 | void HandleMessage(Message *msg, struct timeval *tv);
|
---|
35 | virtual void HandleCanMessage(WORD_t cobid, BYTE_t *data, struct timeval *tv) {}
|
---|
36 |
|
---|
37 | int Receive(Message *pm);
|
---|
38 | int ReceiveFast(FastMessage *pm);
|
---|
39 |
|
---|
40 | void SetBaudRate(int rate);
|
---|
41 | void EnableCanBusConnection();
|
---|
42 | int EnableFastCan(int rbuffers, int wbuffers);
|
---|
43 | void DisableCanBusConnection();
|
---|
44 | int EnableFifo();
|
---|
45 | int Reset();
|
---|
46 | void SetTermination(int strate=1);
|
---|
47 | int StdHost2NewStyle(int rbuffers, int wbuffers, int wbuffers_hi, int wbuffers_low);
|
---|
48 | void DisableAllCobIds();
|
---|
49 |
|
---|
50 | void PrintMsg(Message *m);
|
---|
51 |
|
---|
52 | int Send(Message *pm);
|
---|
53 | int SendHi(Message *pm);
|
---|
54 | int SendLo(Message *pm);
|
---|
55 | int Send(FastMessage *pm);
|
---|
56 |
|
---|
57 | void Close();
|
---|
58 | int Open(const char *devname); /* pathname of device */
|
---|
59 |
|
---|
60 | WORD_t MsgDescr(const WORD_t cobid, const BYTE_t dlc, const BYTE_t rtr=0)
|
---|
61 | {
|
---|
62 | return (cobid<<5) | ((rtr&0x1)<<4) | (dlc&0xf);
|
---|
63 | }
|
---|
64 |
|
---|
65 | virtual void TerminateApp() { exit(-1); }
|
---|
66 |
|
---|
67 | public:
|
---|
68 | VmodIcan(const char *dev, const int baud, MLog &out=gLog);
|
---|
69 | virtual ~VmodIcan();
|
---|
70 |
|
---|
71 | void EnableCobId(WORD_t cobid, int flag=TRUE);
|
---|
72 |
|
---|
73 | void SendCanFrame(WORD_t cobid, BYTE_t m[8]);
|
---|
74 | void SendCanFrame(WORD_t cobid,
|
---|
75 | BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
|
---|
76 | BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
|
---|
77 |
|
---|
78 | ClassDef(VmodIcan, 0)
|
---|
79 | };
|
---|
80 |
|
---|
81 | #endif
|
---|