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
pprzlog_transport.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  *
20  */
21 
44 #include <inttypes.h>
46 
48 
49 #define STX_LOG 0x99
50 
51 static void put_1byte(struct pprzlog_transport *trans, struct link_device *dev, const uint8_t byte)
52 {
53  trans->ck += byte;
54  dev->put_byte(dev->periph, byte);
55 }
56 
57 static void put_bytes(struct pprzlog_transport *trans, struct link_device *dev,
58  enum TransportDataType type __attribute__((unused)), enum TransportDataFormat format __attribute__((unused)),
59  uint8_t len, const void *bytes)
60 {
61  const uint8_t *b = (const uint8_t *) bytes;
62  int i;
63  for (i = 0; i < len; i++) {
64  put_1byte(trans, dev, b[i]);
65  }
66 }
67 
68 static void put_named_byte(struct pprzlog_transport *trans, struct link_device *dev,
69  enum TransportDataType type __attribute__((unused)), enum TransportDataFormat format __attribute__((unused)),
70  uint8_t byte, const char *name __attribute__((unused)))
71 {
72  put_1byte(trans, dev, byte);
73 }
74 
75 static uint8_t size_of(struct pprzlog_transport *trans __attribute__((unused)), uint8_t len)
76 {
77  return len;
78 }
79 
80 static void start_message(struct pprzlog_transport *trans, struct link_device *dev, uint8_t payload_len)
81 {
82  dev->put_byte(dev->periph, STX_LOG);
83  const uint8_t msg_len = size_of(trans, payload_len);
84  trans->ck = 0;
85  put_1byte(trans, dev, msg_len);
86  put_1byte(trans, dev, 0); // TODO use correct source ID
87  uint32_t ts = get_sys_time_usec() / 100;
88  put_bytes(trans, dev, DL_TYPE_TIMESTAMP, DL_FORMAT_SCALAR, 4, (uint8_t *)(&ts));
89 }
90 
91 static void end_message(struct pprzlog_transport *trans, struct link_device *dev)
92 {
93  dev->put_byte(dev->periph, trans->ck);
94  dev->send_message(dev->periph);
95 }
96 
97 static void overrun(struct pprzlog_transport *trans __attribute__((unused)),
98  struct link_device *dev __attribute__((unused)))
99 {
100 }
101 
102 static void count_bytes(struct pprzlog_transport *trans __attribute__((unused)),
103  struct link_device *dev __attribute__((unused)), uint8_t bytes __attribute__((unused)))
104 {
105 }
106 
107 static int check_available_space(struct pprzlog_transport *trans __attribute__((unused)), struct link_device *dev,
108  uint8_t bytes)
109 {
110  return dev->check_free_space(dev->periph, bytes);
111 }
112 
114 {
123  pprzlog_tp.trans_tx.impl = (void *)(&pprzlog_tp);
124 }
125 
static void overrun(struct pprzlog_transport *trans, struct link_device *dev)
TransportDataFormat
Data format (scalar or array)
Definition: transport.h:66
end_message_t end_message
transport trailer
Definition: transport.h:95
static void put_bytes(struct pprzlog_transport *trans, struct link_device *dev, enum TransportDataType type, enum TransportDataFormat format, uint8_t len, const void *bytes)
static void count_bytes(struct pprzlog_transport *trans, struct link_device *dev, uint8_t bytes)
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 int check_available_space(struct pprzlog_transport *trans, struct link_device *dev, uint8_t bytes)
size_of_t size_of
get size of payload with transport header and trailer
Definition: transport.h:90
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
static uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.h:39
void pprzlog_transport_init(void)
unsigned long uint32_t
Definition: types.h:18
void(* start_message_t)(void *, struct link_device *, uint8_t)
Definition: transport.h:82
struct pprzlog_transport pprzlog_tp
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
put_named_byte_t put_named_byte
send a single byte or its name
Definition: transport.h:93
Protocol for on-board data logger with timestamp.
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
static void end_message(struct pprzlog_transport *trans, struct link_device *dev)
int(* check_available_space_t)(void *, struct link_device *, uint8_t)
Definition: transport.h:77
#define STX_LOG
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 uint8_t size_of(struct pprzlog_transport *trans, uint8_t len)
static void put_named_byte(struct pprzlog_transport *trans, struct link_device *dev, enum TransportDataType type, enum TransportDataFormat format, uint8_t byte, const char *name)
check_available_space_t check_available_space
check if transmit buffer is not full
Definition: transport.h:91
put_bytes_t put_bytes
send bytes
Definition: transport.h:92
void(* count_bytes_t)(void *, struct link_device *, uint8_t)
Definition: transport.h:85
struct transport_tx trans_tx
static void put_1byte(struct pprzlog_transport *trans, struct link_device *dev, const uint8_t byte)
static void start_message(struct pprzlog_transport *trans, struct link_device *dev, uint8_t payload_len)