/
canbus_frame.h
119 lines (97 loc) · 2.58 KB
/
canbus_frame.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef VITROIO_SDK_CANBUS_FRAME_H
#define VITROIO_SDK_CANBUS_FRAME_H
#include <mbed.h>
namespace vitroio
{
namespace sdk
{
/**
* @addtogroup communication
* @{
*/
/**
* @brief Class is a wrapper for
* <a href="https://os.mbed.com/docs/v5.10/mbed-os-api-doxy/classmbed_1_1_c_a_n_message.html">mbed::CANMessage</a>.
* It provides interface allowing creation of frames complied with vitroio
* protocol.
*/
class CanbusFrame
{
public:
CanbusFrame();
~CanbusFrame();
/**
* @brief Function allows to set node ID for the frame.
*
* @param id Node ID to set
*/
void setNodeId(uint32_t id);
/**
* @brief Function allows to set parameter ID for the frame.
*
* @param id Parameter ID to set
*/
void setParameterId(uint32_t id);
/**
* @brief Function allows to set data length of the frame.
*
* @param length Data length in bytes
*
* @return Function returns true on success or false otherwise.
*/
bool setDataLength(uint32_t length);
/**
* @brief Function allows to obtain node ID from the frame.
*
* @return Function returns node ID of the frame.
*/
uint32_t nodeId() const;
/**
* @brief Function allows to obtain parameter ID from the frame.
*
* @return Function returns parameter ID of the frame.
*/
uint32_t parameterId() const;
/**
* @brief Function allows to obtain data length of the frame.
*
* @return Function returns length of the frame data.
*/
uint32_t dataLength() const;
/**
* @brief Function allows to obtain maximum data length of the frame.
*
* @return Function returns maximum size of frame data.
*/
uint32_t maxDataLength() const;
/**
* @brief Function allows a direct access to the frame data for
* modifications.
*
* @note This function should be used with dataLength() function to avoid
* exceeding address range.
*
* @return Function returns pointer to buffer of frame data.
*/
char* data();
/**
* @brief Function allows to get frame data for reading.
*
* @note This function should be used with dataLength() function to avoid
* exceeding address range.
*
* @return Function returns constant pointer to buffer of frame data.
*/
const char* data() const;
private:
friend class Canbus;
CANMessage message_;
CANMessage* message();
const CANMessage* message() const;
};
/**
* @}
*/
} // namespace sdk
} // namespace vitroio
#endif // VITROIO_SDK_CANBUS_FRAME_H