Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pprz_transport.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 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 #include <inttypes.h>
43 #ifndef PPRZ_DATALINK_EXPORT
45 #else /* PPRZ_DATALINK_EXPORT defined */
46 #include "pprz_transport.h"
47 #endif
48 
50 
51 static void put_1byte(struct pprz_transport *trans, struct link_device *dev, const uint8_t byte)
52 {
53  trans->ck_a_tx += byte;
54  trans->ck_b_tx += trans->ck_a_tx;
55  dev->put_byte(dev->periph, byte);
56 }
57 
58 static void put_bytes(struct pprz_transport *trans, struct link_device *dev,
59  enum TransportDataType type __attribute__((unused)), enum TransportDataFormat format __attribute__((unused)),
60  uint8_t len, const void *bytes)
61 {
62  const uint8_t *b = (const uint8_t *) bytes;
63  int i;
64  for (i = 0; i < len; i++) {
65  put_1byte(trans, dev, b[i]);
66  }
67 }
68 
69 static void put_named_byte(struct pprz_transport *trans, struct link_device *dev,
70  enum TransportDataType type __attribute__((unused)), enum TransportDataFormat format __attribute__((unused)),
71  uint8_t byte, const char *name __attribute__((unused)))
72 {
73  put_1byte(trans, dev, byte);
74 }
75 
76 static uint8_t size_of(struct pprz_transport *trans __attribute__((unused)), uint8_t len)
77 {
78  // message length: payload + protocol overhead (STX + len + ck_a + ck_b = 4)
79  return len + 4;
80 }
81 
82 static void start_message(struct pprz_transport *trans, struct link_device *dev, uint8_t payload_len)
83 {
84  dev->put_byte(dev->periph, STX);
85  const uint8_t msg_len = size_of(trans, payload_len);
86  dev->put_byte(dev->periph, msg_len);
87  trans->ck_a_tx = msg_len;
88  trans->ck_b_tx = msg_len;
89  dev->nb_msgs++;
90 }
91 
92 static void end_message(struct pprz_transport *trans, struct link_device *dev)
93 {
94  dev->put_byte(dev->periph, trans->ck_a_tx);
95  dev->put_byte(dev->periph, trans->ck_b_tx);
96  dev->send_message(dev->periph);
97 }
98 
99 static void overrun(struct pprz_transport *trans __attribute__((unused)),
100  struct link_device *dev)
101 {
102  dev->nb_ovrn++;
103 }
104 
105 static void count_bytes(struct pprz_transport *trans __attribute__((unused)),
106  struct link_device *dev, uint8_t bytes)
107 {
108  dev->nb_bytes += bytes;
109 }
110 
111 static int check_available_space(struct pprz_transport *trans __attribute__((unused)), struct link_device *dev,
112  uint8_t bytes)
113 {
114  return dev->check_free_space(dev->periph, bytes);
115 }
116 
118 {
119  t->status = UNINIT;
129  t->trans_tx.impl = (void *)(t);
130 }
131 
volatile bool_t msg_received
message received flag
Definition: transport.h:42
TransportDataFormat
Data format (scalar or array)
Definition: transport.h:66
end_message_t end_message
transport trailer
Definition: transport.h:95
static void end_message(struct pprz_transport *trans, struct link_device *dev)
static void put_1byte(struct pprz_transport *trans, struct link_device *dev, const uint8_t byte)
uint8_t(* size_of_t)(void *, uint8_t)
Function pointers definition.
Definition: transport.h:76
void(* end_message_t)(void *, struct link_device *)
Definition: transport.h:83
static void put_bytes(struct pprz_transport *trans, struct link_device *dev, enum TransportDataType type, enum TransportDataFormat format, uint8_t len, const void *bytes)
size_of_t size_of
get size of payload with transport header and trailer
Definition: transport.h:90
Building and parsing Paparazzi frames.
overrun_t overrun
overrun
Definition: transport.h:96
void(* overrun_t)(void *, struct link_device *)
Definition: transport.h:84
TransportDataType
Data type.
Definition: transport.h:48
count_bytes_t count_bytes
count bytes to send
Definition: transport.h:97
#define FALSE
Definition: std.h:5
void pprz_transport_init(struct pprz_transport *t)
struct transport_tx trans_tx
void(* start_message_t)(void *, struct link_device *, uint8_t)
Definition: transport.h:82
static int check_available_space(struct pprz_transport *trans, struct link_device *dev, uint8_t bytes)
void(* put_named_byte_t)(void *, struct link_device *, enum TransportDataType, enum TransportDataFormat, uint8_t, const char *)
Definition: transport.h:80
start_message_t start_message
transport header
Definition: transport.h:94
#define STX
Definition: protocol.h:98
put_named_byte_t put_named_byte
send a single byte or its name
Definition: transport.h:93
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
int(* check_available_space_t)(void *, struct link_device *, uint8_t)
Definition: transport.h:77
void(* put_bytes_t)(void *, struct link_device *, enum TransportDataType, enum TransportDataFormat, uint8_t, const void *)
Definition: transport.h:78
unsigned char uint8_t
Definition: types.h:14
void * impl
pointer to parent implementation
Definition: transport.h:98
static void put_named_byte(struct pprz_transport *trans, struct link_device *dev, enum TransportDataType type, enum TransportDataFormat format, uint8_t byte, const char *name)
static void overrun(struct pprz_transport *trans, struct link_device *dev)
struct transport_rx trans_rx
check_available_space_t check_available_space
check if transmit buffer is not full
Definition: transport.h:91
static uint8_t size_of(struct pprz_transport *trans, uint8_t len)
put_bytes_t put_bytes
send bytes
Definition: transport.h:92
static void count_bytes(struct pprz_transport *trans, struct link_device *dev, uint8_t bytes)
void(* count_bytes_t)(void *, struct link_device *, uint8_t)
Definition: transport.h:85
struct pprz_transport pprz_tp
static void start_message(struct pprz_transport *trans, struct link_device *dev, uint8_t payload_len)
#define UNINIT
Receiving pprz messages.
Definition: protocol.c:11