Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
dw1000_range_arduino.c
Go to the documentation of this file.
1
16
17#include "std.h"
18#include "mcu_periph/uart.h"
19#include "modules/core/abi.h"
22#include "generated/airframe.h"
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26
27
29#define DW_STX 0xFE
30
32#define DW_WAIT_STX 0
33#define DW_GET_DATA 1
34#define DW_GET_CK 2
35#define DW_NB_DATA 6
36
45
47
48
50static inline float float_from_buf(uint8_t* b) {
51 float f;
52 memcpy((uint8_t*)(&f), b, sizeof(float));
53 return f;
54}
55
59 memcpy ((uint8_t*)(&u16), b, sizeof(uint16_t));
60 return u16;
61}
62
65 uint16_t dst_id = uint16_from_buf(dw->buf);
67 float raw_dist = float_from_buf(dw->buf + 2);
69
70 AbiSendMsgUWB_RANGING(UWB_DW1000_ARDUINO_ID, now_ts, src_id, dst_id, raw_dist);
71}
72
75{
76 switch (dw->state) {
77
78 case DW_WAIT_STX:
79 /* Waiting Synchro */
80 if (c == DW_STX) {
81 dw->idx = 0;
82 dw->ck = 0;
83 dw->state = DW_GET_DATA;
84 }
85 break;
86
87 case DW_GET_DATA:
88 /* Read Bytes */
89 dw->buf[dw->idx++] = c;
90 dw->ck += c;
91 if (dw->idx == DW_NB_DATA) {
92 dw->state = DW_GET_CK;
93 }
94 break;
95
96 case DW_GET_CK:
97 /* Checksum */
98 if (dw->ck == c) {
100 }
101 dw->state = DW_WAIT_STX;
102 break;
103
104 default:
105 dw->state = DW_WAIT_STX;
106 }
107}
108
113
115{
116 // Look for data on serial link and send to parser
120 }
121}
Main include for ABI (AirBorneInterface).
Convenience defines for ABI sender IDs.
#define UWB_DW1000_ARDUINO_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
struct uart_periph * dev
#define DW_NB_DATA
void dw1000_range_arduino_init(void)
uint8_t idx
buffer index
static float float_from_buf(uint8_t *b)
Utility function to get float from buffer.
struct DW1000RangeArduino dw1000_range_arduino
#define DW_STX
frame sync byte
#define DW_WAIT_STX
Parsing states.
uint8_t buf[DW_NB_DATA]
incoming data buffer
uint8_t state
parser state
#define DW_GET_DATA
static uint16_t uint16_from_buf(uint8_t *b)
Utility function to get uint16_t from buffer.
#define DW_GET_CK
static void send_anchor_data(struct DW1000RangeArduino *dw)
Send range data decoded from the serial frame.
void dw1000_range_arduino_event(void)
static void dw1000_range_arduino_parse(struct DW1000RangeArduino *dw, uint8_t c)
Data parsing function.
DW1000 Arduino range parser state.
Copyright (C) 2026 Fabien-B fabien-b@github.com This file is part of paparazzi.
uint16_t u16
Unsigned 16-bit integer.
Definition common.h:43
int uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition uart_arch.c:357
uint8_t uart_getch(struct uart_periph *p)
Definition uart_arch.c:348
uint16_t foo
Definition main_demo5.c:58
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
UART peripheral.
Definition uart.h:72
#define UWB_POSITIONING_TAG_ID
My UWB tag id.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
uint16_t f
Camera baseline, in meters (i.e. horizontal distance between the two cameras of the stereo setup)
Definition wedgebug.c:204
float b
Definition wedgebug.c:202