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
xbee.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Pascal Brisset, Antoine Drouin
3  * Copyright (C) 2014 Gautier Hattenberger <gautier.hattenberger@enac.fr>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  */
22 
28 #ifndef XBEE_H
29 #define XBEE_H
30 
32 #include "generated/airframe.h"
34 
35 #ifdef XBEE868
37 #else /* Not 868 */
39 #endif
40 
41 #define XBEE_START 0x7e
42 
45 void xbee_init(void);
46 
48 #define XBEE_UNINIT 0
49 #define XBEE_GOT_START 1
50 #define XBEE_GOT_LENGTH_MSB 2
51 #define XBEE_GOT_LENGTH_LSB 3
52 #define XBEE_GOT_PAYLOAD 4
53 
55  // generic reception interface
57  // specific xbee transport variables
62  // generic transmission interface
64  // specific pprz transport_tx variables
66 };
67 
68 extern struct xbee_transport xbee_tp;
69 
71 static inline void parse_xbee(struct xbee_transport *t, uint8_t c)
72 {
73  switch (t->status) {
74  case XBEE_UNINIT:
75  if (c == XBEE_START) {
76  t->status++;
77  }
78  break;
79  case XBEE_GOT_START:
80  if (t->trans_rx.msg_received) {
81  t->trans_rx.ovrn++;
82  goto error;
83  }
84  t->trans_rx.payload_len = c << 8;
85  t->status++;
86  break;
88  t->trans_rx.payload_len |= c;
89  t->status++;
90  t->payload_idx = 0;
91  t->cs_rx = 0;
92  break;
94  t->trans_rx.payload[t->payload_idx] = c;
95  t->cs_rx += c;
96  t->payload_idx++;
97  if (t->payload_idx == t->trans_rx.payload_len) {
98  t->status++;
99  }
100  break;
101  case XBEE_GOT_PAYLOAD:
102  if (c + t->cs_rx != 0xff) {
103  goto error;
104  }
106  goto restart;
107  break;
108  default:
109  goto error;
110  }
111  return;
112 error:
113  t->trans_rx.error++;
114 restart:
115  t->status = XBEE_UNINIT;
116  return;
117 }
118 
120 static inline void xbee_parse_payload(struct xbee_transport *t)
121 {
122  switch (t->trans_rx.payload[0]) {
123  case XBEE_RX_ID:
124  case XBEE_TX_ID: /* Useful if A/C is connected to the PC with a cable */
126  uint8_t i;
127  for (i = XBEE_RFDATA_OFFSET; i < t->trans_rx.payload_len; i++) {
129  }
131  break;
132  default:
133  return;
134  }
135 }
136 
137 #define XBeeCheckAndParse(_dev, _trans) xbee_check_and_parse(&(_dev).device, &(_trans))
138 
139 static inline void xbee_check_and_parse(struct link_device *dev, struct xbee_transport *trans)
140 {
141  if (dev->char_available(dev->periph)) {
142  while (dev->char_available(dev->periph) && !trans->trans_rx.msg_received) {
143  parse_xbee(trans, dev->get_byte(dev->periph));
144  }
145  if (trans->trans_rx.msg_received) {
146  xbee_parse_payload(trans);
147  trans->trans_rx.msg_received = FALSE;
148  }
149  }
150 }
151 
152 #endif /* XBEE_H */
struct xbee_transport xbee_tp
Definition: xbee.c:43
volatile bool_t msg_received
message received flag
Definition: transport.h:42
Generic reception transport header.
Definition: transport.h:39
Generic transmission transport header.
Definition: transport.h:89
generic transport header
#define XBEE_GOT_START
Definition: xbee.h:49
#define XBEE_TX_ID
Definition: xbee24.h:31
uint8_t payload[TRANSPORT_PAYLOAD_LEN]
payload buffer
Definition: transport.h:40
#define XbeeGetRSSI(_payload)
Definition: xbee24.h:44
Configuration for 2.4GHz "series 1" and 900MHz modules.
#define XBEE_GOT_LENGTH_MSB
Definition: xbee.h:50
volatile uint8_t payload_len
payload buffer length
Definition: transport.h:41
#define FALSE
Definition: std.h:5
#define XBEE_RFDATA_OFFSET
Definition: xbee24.h:33
void xbee_init(void)
Initialisation in API mode and setting of the local address FIXME: busy wait.
Definition: xbee.c:165
bool_t dl_msg_available
Definition: main_demo5.c:61
#define XBEE_GOT_PAYLOAD
Definition: xbee.h:52
#define TRUE
Definition: std.h:4
static void parse_xbee(struct xbee_transport *t, uint8_t c)
Parsing a XBee API frame.
Definition: xbee.h:71
uint8_t status
Definition: xbee.h:58
uint8_t cs_rx
Definition: xbee.h:60
#define XBEE_START
Definition: xbee.h:41
#define XBEE_UNINIT
Status of the API packet receiver automata.
Definition: xbee.h:48
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
unsigned char uint8_t
Definition: types.h:14
static void xbee_check_and_parse(struct link_device *dev, struct xbee_transport *trans)
Definition: xbee.h:139
uint8_t rssi
Definition: xbee.h:61
struct transport_rx trans_rx
Definition: xbee.h:56
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:64
#define XBEE_RX_ID
Definition: xbee24.h:32
static void xbee_parse_payload(struct xbee_transport *t)
Parsing a frame data and copy the payload to the datalink buffer.
Definition: xbee.h:120
#define XBEE_GOT_LENGTH_LSB
Definition: xbee.h:51
uint8_t payload_idx
Definition: xbee.h:59
uint8_t cs_tx
Definition: xbee.h:65
uint8_t error
overrun and error flags
Definition: transport.h:43
Configuration for 868MHz modules.
uint8_t ovrn
Definition: transport.h:43
struct transport_tx trans_tx
Definition: xbee.h:63