-
Notifications
You must be signed in to change notification settings - Fork 3
/
protocol.c
50 lines (39 loc) · 1007 Bytes
/
protocol.c
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
#include "protocol.h"
static void protocol_clear_buffer(uint8_t *buffer);
static void protocol_add_endings(uint8_t *buffer);
static void protocol_add_endings(uint8_t *buffer)
{
buffer[I_START] = MSG_START;
buffer[I_END] = MSG_END;
}
static void protocol_clear_buffer(uint8_t *buffer)
{
for (uint8_t i = 0; i < MSG_SIZE; i++)
{
buffer[i] = BLANK;
}
}
void protocol_build_error_rsp(uint8_t *buffer, uint8_t cmd, uint8_t code)
{
protocol_clear_buffer(buffer);
protocol_add_endings(buffer);
buffer[I_TYPE] = TYPE_RSP;
buffer[I_CMD] = cmd;
buffer[I_RSP_CODE] = code;
}
void protocol_build_ok_rsp(uint8_t *buffer, uint8_t cmd)
{
protocol_clear_buffer(buffer);
protocol_add_endings(buffer);
buffer[I_TYPE] = TYPE_RSP;
buffer[I_CMD] = cmd;
buffer[I_RSP_CODE] = RSP_OK;
}
void protocol_build_complete_rsp(uint8_t *buffer, uint8_t cmd)
{
protocol_clear_buffer(buffer);
protocol_add_endings(buffer);
buffer[I_TYPE] = TYPE_RSP;
buffer[I_CMD] = cmd;
buffer[I_RSP_CODE] = RSP_COMPLETE;
}