Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
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 "subsystems/intermcu.h"
30 #include "pprzlink/intermcu_msg.h"
31 #include "pprzlink/short_transport.h"
32 #include "generated/periodic_telemetry.h"
34 
35 /* Default maximum telemetry message size */
36 #ifndef TELEMERTY_INTERMCU_MSG_SIZE
37 #define TELEMERTY_INTERMCU_MSG_SIZE 128
38 #endif
39 
40 /* Structure for handling telemetry over InterMCU */
42  struct link_device dev;
43  struct short_transport trans;
46 };
47 
48 /* Telemetry InterMCU throughput */
50 
51 /* Static functions */
52 static bool telemetry_intermcu_check_free_space(struct telemetry_intermcu_t *p, long *fd __attribute__((unused)), uint16_t len);
53 static void telemetry_intermcu_put_byte(struct telemetry_intermcu_t *p, long fd __attribute__((unused)), uint8_t data);
54 static void telemetry_intermcu_put_buffer(struct telemetry_intermcu_t *p, long fd, uint8_t *data, uint16_t len);
55 static void telemetry_intermcu_send_message(struct telemetry_intermcu_t *p, long fd __attribute__((unused)));
56 
57 /* InterMCU initialization */
59 {
60  // Initialize transport structure
61  short_transport_init(&telemetry_intermcu.trans);
62 
63  // Configure the device
64  telemetry_intermcu.dev.check_free_space = (check_free_space_t)telemetry_intermcu_check_free_space;
65  telemetry_intermcu.dev.put_byte = (put_byte_t)telemetry_intermcu_put_byte;
66  telemetry_intermcu.dev.put_buffer = (put_buffer_t)telemetry_intermcu_put_buffer;
67  telemetry_intermcu.dev.send_message = (send_message_t)telemetry_intermcu_send_message;
68  telemetry_intermcu.dev.periph = (void *)&telemetry_intermcu;
69 }
70 
71 /* InterMCU periodic handling of telemetry */
73 {
74  periodic_telemetry_send_InterMCU(DefaultPeriodic, &telemetry_intermcu.trans.trans_tx, &telemetry_intermcu.dev);
75 }
76 
77 void telemetry_intermcu_on_msg(uint8_t msg_id __attribute__((unused)), uint8_t* msg __attribute__((unused)), uint8_t size __attribute__((unused)))
78 {
79 
80 }
81 
82 static bool telemetry_intermcu_check_free_space(struct telemetry_intermcu_t *p, long *fd __attribute__((unused)), uint16_t len)
83 {
84  return ((p->buf_idx + len) < (TELEMERTY_INTERMCU_MSG_SIZE - 1));
85 }
86 
87 static void telemetry_intermcu_put_byte(struct telemetry_intermcu_t *p, long fd __attribute__((unused)), uint8_t data)
88 {
89  if(p->buf_idx >= (TELEMERTY_INTERMCU_MSG_SIZE - 1))
90  return;
91 
92  p->buf[p->buf_idx++] = data;
93 }
94 
95 static void telemetry_intermcu_put_buffer(struct telemetry_intermcu_t *p, long fd __attribute__((unused)), uint8_t *data, uint16_t len)
96 {
97  int i;
98  for (i = 0; i < len; i++) {
99  p->buf[p->buf_idx++] = data[i];
100  }
101 }
102 
103 static void telemetry_intermcu_send_message(struct telemetry_intermcu_t *p, long fd __attribute__((unused)))
104 {
105  pprz_msg_send_IMCU_TELEMETRY(&(intermcu.transport.trans_tx), intermcu.device,
106  INTERMCU_AP, &p->buf[1], (p->buf_idx - 2), &p->buf[2]);
107  p->buf_idx = 0;
108 }
unsigned short uint16_t
Definition: types.h:16
struct link_device dev
Device structure for communication.
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:69
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).
struct intermcu_t intermcu
Definition: intermcu_ap.c:41
Telemetry through InterMCU.
#define INTERMCU_AP
Definition: intermcu.h:34
void telemetry_intermcu_on_msg(uint8_t msg_id, uint8_t *msg, uint8_t size)
void telemetry_intermcu_init(void)
static 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:70
static void telemetry_intermcu_send_message(struct telemetry_intermcu_t *p, long fd)
void telemetry_intermcu_periodic(void)
unsigned char uint8_t
Definition: types.h:14
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]
#define TELEMERTY_INTERMCU_MSG_SIZE
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)