Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
main_demo5.c
Go to the documentation of this file.
1 #include "std.h"
2 #include "mcu.h"
3 #include "mcu_periph/sys_time.h"
4 #include "led.h"
5 #include "mcu_periph/uart.h"
6 
7 #include "pprzlink/messages.h"
9 
10 static inline void main_init(void);
11 static inline void main_periodic_task(void);
12 static inline void main_event_task(void);
13 
14 static inline void main_dl_parse_msg(void);
15 
16 int main(void)
17 {
18  main_init();
19  while (1) {
22  }
24  }
25  return 0;
26 }
27 
28 static inline void main_init(void)
29 {
30  mcu_init();
31  sys_time_register_timer((1. / PERIODIC_FREQUENCY), NULL);
32  uart0_init_tx();
33 }
34 
35 static inline void main_periodic_task(void)
36 {
37  // LED_TOGGLE(1);
38  uint16_t time_sec = sys_time.nb_sec;
39  DOWNLINK_SEND_TAKEOFF(&time_sec);
40 }
41 
42 static inline void main_event_task(void)
43 {
44  if (PprzBuffer()) {
45  ReadPprzBuffer();
46  if (pprz_msg_received) {
47  pprz_parse_payload();
48  pprz_msg_received = false;
49  }
50  }
51  if (dl_msg_available) {
53  dl_msg_available = false;
54  LED_TOGGLE(1);
55  }
56 }
57 
59 
61 
62 #define MSG_SIZE 256
63 uint8_t dl_buffer[MSG_SIZE] __attribute__((aligned));
64 
65 #include "generated/settings.h"
66 
67 #define IdOfMsg(x) (x[1])
68 
69 static inline void main_dl_parse_msg(void)
70 {
71  uint8_t msg_id = IdOfMsg(dl_buffer);
72  if (msg_id == DL_SETTING) {
73  uint8_t i = DL_SETTING_index(dl_buffer);
74  float var = DL_SETTING_value(dl_buffer);
75  DlSetting(i, var);
76  DOWNLINK_SEND_DL_VALUE(&i, &var);
77  }
78 }
#define LED_TOGGLE(i)
Definition: led_hw.h:53
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:98
arch independent LED (Light Emitting Diodes) API
static void main_event_task(void)
Definition: main_demo5.c:42
static void main_dl_parse_msg(void)
Definition: main_demo5.c:69
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:63
bool dl_msg_available
Flag provided to control calls to dl_parse_msg.
Definition: main_demo5.c:60
static void main_periodic_task(void)
Definition: main_demo5.c:35
int main(void)
Definition: main_demo5.c:16
#define MSG_SIZE
Definition: main_demo5.c:62
uint16_t foo
Definition: main_demo5.c:58
#define IdOfMsg(x)
Definition: main_demo5.c:67
static void main_init(void)
Definition: main_demo5.c:28
Arch independent mcu ( Micro Controller Unit ) utilities.
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:43
Architecture independent timing functions.
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:123
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98