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