Paparazzi UAS
v5.8.2_stable-0-g6260b7c
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
pprz_transport.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2003 Pascal Brisset, Antoine Drouin
3
* Copyright (C) 2014 Gautier Hattenberger <gautier.hattenberger@enac.fr>
4
*
5
* This file is part of paparazzi.
6
*
7
* paparazzi is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2, or (at your option)
10
* any later version.
11
*
12
* paparazzi is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with paparazzi; see the file COPYING. If not, see
19
* <http://www.gnu.org/licenses/>.
20
*
21
*/
22
41
#ifndef PPRZ_TRANSPORT_H
42
#define PPRZ_TRANSPORT_H
43
44
#include <
inttypes.h
>
45
#include "
std.h
"
46
#ifndef PPRZ_DATALINK_EXPORT
47
#include "
subsystems/datalink/datalink.h
"
48
#include "
subsystems/datalink/transport.h
"
49
#else
/* PPRZ_DATALINK_EXPORT defined */
50
#include "
datalink.h
"
51
#include "
transport.h
"
52
#endif
53
54
/* PPRZ Transport
55
*/
56
57
#define STX 0x99
58
59
// PPRZ parsing state machine
60
#define UNINIT 0
61
#define GOT_STX 1
62
#define GOT_LENGTH 2
63
#define GOT_PAYLOAD 3
64
#define GOT_CRC1 4
65
66
struct
pprz_transport
{
67
// generic reception interface
68
struct
transport_rx
trans_rx
;
69
// specific pprz transport_rx variables
70
uint8_t
status
;
71
uint8_t
payload_idx
;
72
uint8_t
ck_a_rx
,
ck_b_rx
;
73
// generic transmission interface
74
struct
transport_tx
trans_tx
;
75
// specific pprz transport_tx variables
76
uint8_t
ck_a_tx
,
ck_b_tx
;
77
};
78
79
extern
struct
pprz_transport
pprz_tp
;
80
81
// Init function
82
extern
void
pprz_transport_init
(
struct
pprz_transport
*t);
83
84
static
inline
void
parse_pprz
(
struct
pprz_transport
*t,
uint8_t
c)
85
{
86
switch
(t->
status
) {
87
case
UNINIT
:
88
if
(c ==
STX
) {
89
t->
status
++;
90
}
91
break
;
92
case
GOT_STX
:
93
if
(t->
trans_rx
.
msg_received
) {
94
t->
trans_rx
.
ovrn
++;
95
goto
error;
96
}
97
t->
trans_rx
.
payload_len
= c - 4;
/* Counting STX, LENGTH and CRC1 and CRC2 */
98
t->
ck_a_rx
= t->
ck_b_rx
= c;
99
t->
status
++;
100
t->
payload_idx
= 0;
101
break
;
102
case
GOT_LENGTH
:
103
t->
trans_rx
.
payload
[t->
payload_idx
] = c;
104
t->
ck_a_rx
+= c; t->
ck_b_rx
+= t->
ck_a_rx
;
105
t->
payload_idx
++;
106
if
(t->
payload_idx
== t->
trans_rx
.
payload_len
) {
107
t->
status
++;
108
}
109
break
;
110
case
GOT_PAYLOAD
:
111
if
(c != t->
ck_a_rx
) {
112
goto
error;
113
}
114
t->
status
++;
115
break
;
116
case
GOT_CRC1
:
117
if
(c != t->
ck_b_rx
) {
118
goto
error;
119
}
120
t->
trans_rx
.
msg_received
=
TRUE
;
121
goto
restart;
122
default
:
123
goto
error;
124
}
125
return
;
126
error:
127
t->
trans_rx
.
error
++;
128
restart:
129
t->
status
=
UNINIT
;
130
return
;
131
}
132
133
static
inline
void
pprz_parse_payload
(
struct
pprz_transport
*t)
134
{
135
uint8_t
i;
136
for
(i = 0; i < t->
trans_rx
.
payload_len
; i++) {
137
dl_buffer
[i] = t->
trans_rx
.
payload
[i];
138
}
139
dl_msg_available
=
TRUE
;
140
}
141
142
143
#define PprzCheckAndParse(_dev, _trans) pprz_check_and_parse(&(_dev).device, &(_trans))
144
145
static
inline
void
pprz_check_and_parse
(
struct
link_device
*
dev
,
struct
pprz_transport
*trans)
146
{
147
if
(dev->
char_available
(dev->
periph
)) {
148
while
(dev->
char_available
(dev->
periph
) && !trans->
trans_rx
.
msg_received
) {
149
parse_pprz
(trans, dev->
get_byte
(dev->
periph
));
150
}
151
if
(trans->
trans_rx
.
msg_received
) {
152
pprz_parse_payload
(trans);
153
trans->
trans_rx
.
msg_received
=
FALSE
;
154
}
155
}
156
}
157
158
#endif
/* PPRZ_TRANSPORT_H */
159
transport_rx::msg_received
volatile bool_t msg_received
message received flag
Definition:
transport.h:42
transport_rx
Generic reception transport header.
Definition:
transport.h:39
pprz_transport::status
uint8_t status
Definition:
pprz_transport.h:70
transport_tx
Generic transmission transport header.
Definition:
transport.h:89
transport.h
generic transport header
GOT_PAYLOAD
#define GOT_PAYLOAD
Definition:
pprz_transport.h:63
transport_rx::payload
uint8_t payload[TRANSPORT_PAYLOAD_LEN]
payload buffer
Definition:
transport.h:40
datalink.h
Handling of messages coming from ground and other A/Cs.
parse_pprz
static void parse_pprz(struct pprz_transport *t, uint8_t c)
Definition:
pprz_transport.h:84
pprz_transport
Definition:
pprz_transport.h:66
link_device
Device structure.
Definition:
link_device.h:44
transport_rx::payload_len
volatile uint8_t payload_len
payload buffer length
Definition:
transport.h:41
GOT_STX
#define GOT_STX
Definition:
pprz_transport.h:61
pprz_transport::payload_idx
uint8_t payload_idx
Definition:
pprz_transport.h:71
link_device::periph
void * periph
pointer to parent implementation
Definition:
link_device.h:50
FALSE
#define FALSE
Definition:
std.h:5
dl_msg_available
bool_t dl_msg_available
Definition:
main_demo5.c:61
pprz_check_and_parse
static void pprz_check_and_parse(struct link_device *dev, struct pprz_transport *trans)
Definition:
pprz_transport.h:145
TRUE
#define TRUE
Definition:
std.h:4
pprz_transport::trans_tx
struct transport_tx trans_tx
Definition:
pprz_transport.h:74
link_device::get_byte
get_byte_t get_byte
get a new char
Definition:
link_device.h:49
std.h
pprz_transport::ck_b_rx
uint8_t ck_b_rx
Definition:
pprz_transport.h:72
UNINIT
#define UNINIT
Definition:
pprz_transport.h:60
inttypes.h
pprz_transport_init
void pprz_transport_init(struct pprz_transport *t)
Definition:
pprz_transport.c:117
dev
static const struct usb_device_descriptor dev
Definition:
usb_ser_hw.c:69
uint8_t
unsigned char uint8_t
Definition:
types.h:14
pprz_transport::ck_a_tx
uint8_t ck_a_tx
Definition:
pprz_transport.h:76
STX
#define STX
Definition:
pprz_transport.h:57
GOT_CRC1
#define GOT_CRC1
Definition:
pprz_transport.h:64
pprz_transport::ck_b_tx
uint8_t ck_b_tx
Definition:
pprz_transport.h:76
pprz_transport::trans_rx
struct transport_rx trans_rx
Definition:
pprz_transport.h:68
dl_buffer
uint8_t dl_buffer[MSG_SIZE]
Definition:
main_demo5.c:64
link_device::char_available
char_available_t char_available
check if a new character is available
Definition:
link_device.h:48
pprz_transport::ck_a_rx
uint8_t ck_a_rx
Definition:
pprz_transport.h:72
GOT_LENGTH
#define GOT_LENGTH
Definition:
pprz_transport.h:62
pprz_parse_payload
static void pprz_parse_payload(struct pprz_transport *t)
Definition:
pprz_transport.h:133
transport_rx::error
uint8_t error
overrun and error flags
Definition:
transport.h:43
transport_rx::ovrn
uint8_t ovrn
Definition:
transport.h:43
pprz_tp
struct pprz_transport pprz_tp
Definition:
pprz_transport.c:49
sw
airborne
subsystems
datalink
pprz_transport.h
Generated on Tue Jun 21 2016 14:01:26 for Paparazzi UAS by
1.8.8