Paparazzi UAS  v5.15_devel-81-gd13dafb
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
telemetry_intermcu_ap.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freek van Tienen <freek.v.tienen@gmail.com>
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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
27 #define PERIODIC_C_INTERMCU
28 #include "telemetry_intermcu.h"
29 #include "telemetry_intermcu_ap.h"
30 #include "subsystems/intermcu.h"
31 #include "pprzlink/intermcu_msg.h"
32 #include "pprzlink/short_transport.h"
33 #include "generated/periodic_telemetry.h"
36 
37 /* Telemetry InterMCU throughput */
39 
40 /* Static functions */
41 static bool telemetry_intermcu_check_free_space(struct telemetry_intermcu_t *p, long *fd __attribute__((unused)), uint16_t len);
42 static void telemetry_intermcu_put_byte(struct telemetry_intermcu_t *p, long fd __attribute__((unused)), uint8_t data);
43 static void telemetry_intermcu_put_buffer(struct telemetry_intermcu_t *p, long fd, uint8_t *data, uint16_t len);
44 static void telemetry_intermcu_send_message(struct telemetry_intermcu_t *p, long fd __attribute__((unused)));
45 
46 /* InterMCU initialization */
48 {
49  // Initialize transport structure
50  short_transport_init(&telemetry_intermcu.trans);
51 
52  // Configure the device
53  telemetry_intermcu.dev.check_free_space = (check_free_space_t)telemetry_intermcu_check_free_space;
54  telemetry_intermcu.dev.put_byte = (put_byte_t)telemetry_intermcu_put_byte;
55  telemetry_intermcu.dev.put_buffer = (put_buffer_t)telemetry_intermcu_put_buffer;
56  telemetry_intermcu.dev.send_message = (send_message_t)telemetry_intermcu_send_message;
57  telemetry_intermcu.dev.periph = (void *)&telemetry_intermcu;
58 }
59 
60 /* InterMCU periodic handling of telemetry */
62 {
63  periodic_telemetry_send_InterMCU(DefaultPeriodic, &telemetry_intermcu.trans.trans_tx, &telemetry_intermcu.dev);
64 }
65 
66 /* InterMCU event handling of telemetry */
68 {
69 
70 }
71 
72 void telemetry_intermcu_on_msg(uint8_t* msg, uint8_t size __attribute__((unused)))
73 {
74  datalink_time = 0;
77 }
78 
79 static bool telemetry_intermcu_check_free_space(struct telemetry_intermcu_t *p, long *fd __attribute__((unused)), uint16_t len)
80 {
81  return ((p->buf_idx + len) < (TELEMERTY_INTERMCU_MSG_SIZE - 1));
82 }
83 
84 static void telemetry_intermcu_put_byte(struct telemetry_intermcu_t *p, long fd __attribute__((unused)), uint8_t data)
85 {
86  if(p->buf_idx >= (TELEMERTY_INTERMCU_MSG_SIZE - 1))
87  return;
88 
89  p->buf[p->buf_idx++] = data;
90 }
91 
92 static void telemetry_intermcu_put_buffer(struct telemetry_intermcu_t *p, long fd __attribute__((unused)), uint8_t *data, uint16_t len)
93 {
94  int i;
95  for (i = 0; i < len; i++) {
96  p->buf[p->buf_idx++] = data[i];
97  }
98 }
99 
100 static void telemetry_intermcu_send_message(struct telemetry_intermcu_t *p, long fd __attribute__((unused)))
101 {
102  pprz_msg_send_IMCU_TELEMETRY(&(intermcu.transport.trans_tx), intermcu.device,
103  INTERMCU_AP, p->buf_idx, p->buf);
104  p->buf_idx = 0;
105 }
unsigned short uint16_t
Definition: types.h:16
struct link_device dev
Device structure for communication.
Telemetry through InterMCU.
uint8_t buf_idx
Index of the buffer.
struct short_transport trans
Transport without any extra encoding.
struct link_device * device
Device used for communication.
Definition: intermcu.h:71
static void telemetry_intermcu_put_byte(struct telemetry_intermcu_t *p, long fd, uint8_t data)
Periodic telemetry system header (includes downlink utility and generated code).
void telemetry_intermcu_on_msg(uint8_t *msg, uint8_t size)
struct intermcu_t intermcu
Definition: intermcu_ap.c:41
Telemetry through InterMCU.
#define INTERMCU_AP
Definition: intermcu.h:34
void telemetry_intermcu_init(void)
uint16_t datalink_nb_msgs
Definition: sim_ap.c:42
struct telemetry_intermcu_t telemetry_intermcu
Rotorcraft Inter-MCU interface.
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
static void telemetry_intermcu_put_buffer(struct telemetry_intermcu_t *p, long fd, uint8_t *data, uint16_t len)
uint8_t buf[TELEMERTY_INTERMCU_MSG_SIZE]
Buffer for the messages.
struct pprz_transport transport
Transport over communication line (PPRZ)
Definition: intermcu.h:72
static void telemetry_intermcu_send_message(struct telemetry_intermcu_t *p, long fd)
void dl_parse_msg(struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
Should be called when chars are available in dl_buffer.
void telemetry_intermcu_periodic(void)
uint16_t datalink_time
Definition: sim_ap.c:41
void telemetry_intermcu_event(void)
unsigned char uint8_t
Definition: types.h:14
#define TELEMERTY_INTERMCU_MSG_SIZE
int fd
Definition: serial.c:26
static bool telemetry_intermcu_check_free_space(struct telemetry_intermcu_t *p, long *fd, uint16_t len)
static float p[2][2]
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)