Paparazzi UAS
v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
protocol.c
Go to the documentation of this file.
1
2
3
#include "
protocol.h
"
4
5
uint8_t
mora_ck_a
,
mora_ck_b
;
6
7
10
// PPRZ parsing state machine
11
#define UNINIT 0
12
#define GOT_STX 1
13
#define GOT_LENGTH 2
14
#define GOT_MSGID 3
15
#define GOT_PAYLOAD 4
16
#define GOT_CRC1 5
17
18
struct
mora_transport
mora_protocol
;
19
20
void
parse_mora
(
struct
mora_transport
*t,
uint8_t
c)
21
{
22
//printf("%02X %d %d\n",c, t->status, t->error);
23
24
switch
(t->
status
) {
25
case
UNINIT
:
26
if
(c ==
STX
) {
27
t->
status
++;
28
}
29
break
;
30
case
GOT_STX
:
31
if
(t->
msg_received
) {
32
t->
error
++;
33
goto
error
;
34
}
35
t->
payload_len
= c - 5;
/* Counting STX, LENGTH and CRC1 and CRC2 */
36
t->
ck_a
= t->
ck_b
= c;
37
t->
status
++;
38
t->
payload_idx
= 0;
39
break
;
40
case
GOT_LENGTH
:
41
t->
msg_id
= c;
42
t->
ck_a
+= c; t->
ck_b
+= t->
ck_a
;
43
t->
status
++;
44
if
(t->
payload_len
== 0) {
45
t->
status
++;
46
}
47
break
;
48
case
GOT_MSGID
:
49
t->
payload
[t->
payload_idx
] = c;
50
t->
ck_a
+= c; t->
ck_b
+= t->
ck_a
;
51
t->
payload_idx
++;
52
if
(t->
payload_idx
== t->
payload_len
) {
53
t->
status
++;
54
}
55
break
;
56
case
GOT_PAYLOAD
:
57
if
(c != t->
ck_a
) {
58
goto
error
;
59
}
60
t->
status
++;
61
break
;
62
case
GOT_CRC1
:
63
if
(c != t->
ck_b
) {
64
goto
error
;
65
}
66
t->
msg_received
=
true
;
67
goto
restart;
68
default
:
69
goto
error
;
70
}
71
return
;
72
error
:
73
t->
error
++;
74
restart:
75
t->
status
=
UNINIT
;
76
return
;
77
}
mora_transport::payload_len
uint8_t payload_len
Definition:
protocol.h:136
GOT_LENGTH
#define GOT_LENGTH
Definition:
protocol.c:13
mora_transport
Definition:
protocol.h:130
mora_transport::error
uint8_t error
Definition:
protocol.h:133
mora_protocol
struct mora_transport mora_protocol
Definition:
protocol.c:18
protocol.h
|STX|length|...
mora_transport::msg_id
uint8_t msg_id
Definition:
protocol.h:134
mora_transport::ck_b
uint8_t ck_b
Definition:
protocol.h:140
mora_transport::payload
uint8_t payload[256]
Definition:
protocol.h:132
GOT_MSGID
#define GOT_MSGID
Definition:
protocol.c:14
GOT_PAYLOAD
#define GOT_PAYLOAD
Definition:
protocol.c:15
mora_transport::msg_received
bool msg_received
Definition:
protocol.h:135
GOT_STX
#define GOT_STX
Definition:
protocol.c:12
STX
#define STX
Definition:
protocol.h:99
mora_transport::payload_idx
uint8_t payload_idx
Definition:
protocol.h:139
uint8_t
unsigned char uint8_t
Definition:
types.h:14
mora_transport::ck_a
uint8_t ck_a
Definition:
protocol.h:140
mora_ck_b
uint8_t mora_ck_b
Definition:
protocol.c:5
mora_ck_a
uint8_t mora_ck_a
Definition:
protocol.c:5
GOT_CRC1
#define GOT_CRC1
Definition:
protocol.c:16
parse_mora
void parse_mora(struct mora_transport *t, uint8_t c)
Definition:
protocol.c:20
UNINIT
#define UNINIT
Receiving pprz messages.
Definition:
protocol.c:11
mora_transport::status
uint8_t status
Definition:
protocol.h:138
sw
airborne
modules
digital_cam
catia
protocol.c
Generated on Wed Aug 28 2019 16:29:03 for Paparazzi UAS by
1.8.8