Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
xbee_dl.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 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 
28 #include "mcu.h"
29 #include "mcu_periph/sys_time.h"
30 #include "mcu_periph/uart.h"
31 #include "generated/airframe.h"
32 
33 #define STR_(s) #s
34 #define STR(s) STR_(s)
35 
36 #ifndef XBEE_TYPE
37 #define XBEE_TYPE XBEE_24
38 #endif
39 #ifndef XBEE_INIT
40 #define XBEE_INIT ""
41 #endif
42 
43 #ifdef XBEE_CHANNEL
44 #define XBEE_CHANNEL_CONF "ATCH" STR(XBEE_CHANNEL) "\r"
45 INFO("XBEE channel configured : " XBEE_CHANNEL_CONF)
46 #else
47 #define XBEE_CHANNEL_CONF ""
48 #endif
49 
50 #define CONCAT(a, b) a b
51 
52 #ifndef XBEE_UPDATE_DL
53 #define XBEE_UPDATE_DL TRUE
54 #endif
55 
56 struct xbee_transport xbee_tp;
57 
58 void xbee_dl_init(void)
59 {
60 #if USE_HARD_FAULT_RECOVERY
61  if (recovering_from_hard_fault)
62  // in case of hardfault recovery, we want to skip xbee init which as an active wait
63  xbee_transport_init(&xbee_tp, &((XBEE_UART).device), AC_ID, XBEE_TYPE, XBEE_BAUD, NULL, CONCAT(XBEE_INIT, XBEE_CHANNEL_CONF));
64  else
65 #endif
66  xbee_transport_init(&xbee_tp, &((XBEE_UART).device), AC_ID, XBEE_TYPE, XBEE_BAUD, sys_time_usleep, CONCAT(XBEE_INIT, XBEE_CHANNEL_CONF));
67 }
68 
69 void xbee_dl_event(void)
70 {
71  xbee_check_and_parse(&(XBEE_UART).device, &xbee_tp, dl_buffer, &dl_msg_available);
72  DlCheckAndParse(&(XBEE_UART).device, &xbee_tp.trans_tx, dl_buffer, &dl_msg_available, XBEE_UPDATE_DL);
73 }
74 
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
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
Arch independent mcu ( Micro Controller Unit ) utilities.
Architecture independent timing functions.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define XBEE_CHANNEL_CONF
Definition: xbee_dl.c:47
#define XBEE_TYPE
Definition: xbee_dl.c:37
struct xbee_transport xbee_tp
XBEE transport structure.
Definition: xbee_dl.c:56
#define CONCAT(a, b)
Definition: xbee_dl.c:50
#define XBEE_INIT
Definition: xbee_dl.c:40
#define XBEE_UPDATE_DL
Definition: xbee_dl.c:53
void xbee_dl_init(void)
Init function.
Definition: xbee_dl.c:58
void xbee_dl_event(void)
Datalink Event.
Definition: xbee_dl.c:69
Datalink using XBEE protocol.