forked from PSU-AVT/QuadLLFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproto.c
31 lines (27 loc) · 810 Bytes
/
proto.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
/*
* Copyright (c) 2011 Gregory Haynes <greg@greghaynes.net>
*
* Licensed under the BSD license. See LICENSE for more information.
*/
#include "proto.h"
#include "afproto.h"
#include "commands.h"
#include "core/uart.h"
static unsigned char proto_buff[256];
static unsigned char cmd_buff[256];
static uint8_t proto_buff_ndx = 0;
void proto_update(void) {
while(uartRxBufferDataPending()) {
proto_buff[proto_buff_ndx] = uartRxBufferRead();
if(proto_buff[proto_buff_ndx] == AFPROTO_FRAME_END_BYTE &&
(proto_buff_ndx == 0 ||
proto_buff[proto_buff_ndx-1] != AFPROTO_FRAME_ESCAPE_BYTE)) {
// Message end
uint8_t len;
afproto_get_payload(proto_buff, proto_buff_ndx+1, cmd_buff, &len);
commands_handle_message(cmd_buff, len);
proto_buff_ndx = 0;
} else
++proto_buff_ndx;
}
}