1
+ #pragma once
2
+ #ifndef __CANBase_H
3
+ #define __CANBase_H
4
+ #include < functional>
5
+ #include < string>
6
+ #include " CANType.h"
7
+ namespace ZCANBus {
8
+
9
+ class CANBase {
10
+ public:
11
+ CANBase (){};
12
+
13
+ virtual ~CANBase (){};
14
+
15
+ /* *
16
+ * @brief Open a specific channel
17
+ * @param channel the specific number for the CAN device
18
+ * @param baudRate the speed for the communication
19
+ * @param type different CAN devices has differents meanings
20
+ * @return a error code. Generally, 0 means OK. @see CanStatus
21
+ */
22
+ virtual CANStatus OpenChannel (int channel, CANRate baudRate, int type) = 0;
23
+
24
+ /* *
25
+ * @brief Read CAN message continuously with async mode.
26
+ * @param callback the function will be called while received new CAN
27
+ * message the param msg is the received msg and status is the error code
28
+ * which generally 0 means OK
29
+ * @param interval the max interval in milliseconds between two message
30
+ * received
31
+ */
32
+ virtual void ReadLoop (
33
+ std::function<void (const CANMessage* msg, CANStatus status)> callback,
34
+ uint64_t interval) = 0;
35
+
36
+ /* *@brief End read CAN message continuously with async mode.*/
37
+ virtual void EndReadLoop () = 0;
38
+
39
+ /* *
40
+ * @brief Read CAN message once
41
+ * @param msg Modified by received CAN message
42
+ * @param timeout Read CAN message with timeout in milliseconds
43
+ * @return a error code. Generally, 0 means OK. @see CanStatus
44
+ */
45
+ virtual CANStatus ReadOnce (CANMessage& msg, uint64_t timeout = 0 ) = 0;
46
+
47
+ /* *
48
+ * @brief Write CAN message once
49
+ * @param msg the CAN message to be wrote
50
+ * @return a error code. Generally, 0 means OK. @see CanStatus
51
+ */
52
+ virtual CANStatus Write (CANMessage* msg, int count) = 0;
53
+
54
+ /* *
55
+ * @brief Close the channel.
56
+ * @return a error code. Generally, 0 means OK. @see CanStatus
57
+ */
58
+ virtual CANStatus CloseChannel () = 0;
59
+
60
+ /* *
61
+ * @brief Flush the data in queue.
62
+ * @return a error code. Generally, 0 means OK. @see CanStatus
63
+ */
64
+ virtual CANStatus FlushQueue () = 0;
65
+
66
+ /* *
67
+ * @brief Get error message in detail.
68
+ * @param status the error code. Modified by the new error code returned by
69
+ * this operation
70
+ * @return error message
71
+ */
72
+ virtual std::string GetErrorText (CANStatus& status) = 0;
73
+ };
74
+ } // namespace ZCANBus
75
+ #endif
0 commit comments