Benjamin Hepp / Mbed 2 deprecated AIT_UWB_Tracker

Dependencies:   DW1000 ait_link BufferedSerial mbed

Committer:
bhepp
Date:
Thu Feb 11 10:49:49 2016 +0000
Revision:
1:c070ca30da80
Parent:
0:6d63b6992cbf
Child:
4:1a2c1e5e5516
Multi Ranging working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bhepp 0:6d63b6992cbf 1 #pragma once
bhepp 0:6d63b6992cbf 2
bhepp 0:6d63b6992cbf 3 #include "settings.h"
bhepp 0:6d63b6992cbf 4
bhepp 0:6d63b6992cbf 5 #include <mbed.h>
bhepp 0:6d63b6992cbf 6 #include <DW1000.h>
bhepp 0:6d63b6992cbf 7
bhepp 0:6d63b6992cbf 8 namespace ait
bhepp 0:6d63b6992cbf 9 {
bhepp 0:6d63b6992cbf 10
bhepp 0:6d63b6992cbf 11 class UWBProtocol
bhepp 0:6d63b6992cbf 12 {
bhepp 0:6d63b6992cbf 13 public:
bhepp 0:6d63b6992cbf 14 UWBProtocol(uint8_t address);
bhepp 0:6d63b6992cbf 15
bhepp 0:6d63b6992cbf 16 uint8_t getAddress() const;
bhepp 0:6d63b6992cbf 17
bhepp 0:6d63b6992cbf 18 // Attributes packed and aligned(1) ensure that the structure is not padded and not aligned in memory.
bhepp 0:6d63b6992cbf 19 struct __attribute__((packed, aligned(1))) ReceptionStats
bhepp 0:6d63b6992cbf 20 {
bhepp 0:6d63b6992cbf 21 uint16_t std_noise;
bhepp 0:6d63b6992cbf 22 uint16_t preamble_acc_count;
bhepp 0:6d63b6992cbf 23 uint16_t first_path_index;
bhepp 0:6d63b6992cbf 24 uint16_t first_path_amp_1;
bhepp 0:6d63b6992cbf 25 uint16_t first_path_amp_2;
bhepp 0:6d63b6992cbf 26 uint16_t first_path_amp_3;
bhepp 0:6d63b6992cbf 27 uint16_t channel_impulse_response_power;
bhepp 0:6d63b6992cbf 28 uint8_t prf;
bhepp 0:6d63b6992cbf 29 };
bhepp 0:6d63b6992cbf 30
bhepp 0:6d63b6992cbf 31 protected:
bhepp 0:6d63b6992cbf 32 uint8_t address_;
bhepp 0:6d63b6992cbf 33 Timer timer_;
bhepp 0:6d63b6992cbf 34
bhepp 0:6d63b6992cbf 35 // Response delay of the ranging. This should be equal on both sides and has to be bigger than the processing time of the frame on each node.
bhepp 0:6d63b6992cbf 36 // For 110kbps, 2500 is OK. For 6.8Mbps, 900 is OK.
bhepp 1:c070ca30da80 37 #ifdef ANSWER_DELAY_US_OVERWRITE
bhepp 1:c070ca30da80 38 const static int ANSWER_DELAY_US = ANSWER_DELAY_US_OVERWRITE;
bhepp 1:c070ca30da80 39 #else
bhepp 0:6d63b6992cbf 40 const static int ANSWER_DELAY_US = 2500;
bhepp 1:c070ca30da80 41 #endif
bhepp 0:6d63b6992cbf 42 const static float ANSWER_DELAY_TIMEUNITS = ANSWER_DELAY_US * DW1000::US_TO_TIMEUNITS;
bhepp 0:6d63b6992cbf 43
bhepp 0:6d63b6992cbf 44 const static int NUM_OF_UWB_ADDRESSES = 256;
bhepp 0:6d63b6992cbf 45
bhepp 0:6d63b6992cbf 46 enum FrameType
bhepp 0:6d63b6992cbf 47 {
bhepp 0:6d63b6992cbf 48 MASTER_REQUEST_1 = 1,
bhepp 0:6d63b6992cbf 49 SLAVE_REPLY,
bhepp 0:6d63b6992cbf 50 MASTER_REQUEST_2,
bhepp 0:6d63b6992cbf 51 SLAVE_REPORT,
bhepp 0:6d63b6992cbf 52 };
bhepp 0:6d63b6992cbf 53
bhepp 0:6d63b6992cbf 54 // Attributes packed and aligned(1) ensure that the structure is not padded and not aligned in memory.
bhepp 0:6d63b6992cbf 55 struct __attribute__((packed, aligned(1))) RangingFrame
bhepp 0:6d63b6992cbf 56 {
bhepp 0:6d63b6992cbf 57 uint8_t address;
bhepp 0:6d63b6992cbf 58 uint8_t remote_address;
bhepp 0:6d63b6992cbf 59 uint8_t type;
bhepp 0:6d63b6992cbf 60 };
bhepp 0:6d63b6992cbf 61
bhepp 0:6d63b6992cbf 62 // Attributes packed and aligned(1) ensure that the structure is not padded and not aligned in memory.
bhepp 0:6d63b6992cbf 63 struct __attribute__((packed, aligned(1))) ReportRangingFrame : RangingFrame
bhepp 0:6d63b6992cbf 64 {
bhepp 0:6d63b6992cbf 65 int64_t timediff_slave;
bhepp 0:6d63b6992cbf 66 int64_t timestamp_master_request_1_recv;
bhepp 0:6d63b6992cbf 67 int64_t timestamp_slave_reply_send;
bhepp 0:6d63b6992cbf 68 int64_t timestamp_master_request_2_recv;
bhepp 0:6d63b6992cbf 69 #if SLAVE_REPLY_WITH_STATS
bhepp 0:6d63b6992cbf 70 ReceptionStats stats1;
bhepp 0:6d63b6992cbf 71 ReceptionStats stats2;
bhepp 0:6d63b6992cbf 72 #endif
bhepp 0:6d63b6992cbf 73 };
bhepp 0:6d63b6992cbf 74
bhepp 0:6d63b6992cbf 75 RangingFrame rangingFrame_;
bhepp 0:6d63b6992cbf 76 ReportRangingFrame receivedFrame_;
bhepp 0:6d63b6992cbf 77 ReportRangingFrame reportFrame_;
bhepp 0:6d63b6992cbf 78
bhepp 0:6d63b6992cbf 79 void sendRangingFrame(DW1000* dw_ptr, uint8_t remote_address, uint8_t type);
bhepp 0:6d63b6992cbf 80 void sendDelayedRangingFrame(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, uint64_t timestamp_send);
bhepp 0:6d63b6992cbf 81 void sendReportFrame(DW1000* dw_ptr, uint8_t remote_address, int64_t timediff_slave,
bhepp 0:6d63b6992cbf 82 uint64_t timestamp_master_request_1_recv,
bhepp 0:6d63b6992cbf 83 uint64_t timestamp_slave_reply_send,
bhepp 0:6d63b6992cbf 84 uint64_t timestamp_master_request_2_recv);
bhepp 0:6d63b6992cbf 85
bhepp 0:6d63b6992cbf 86 bool receiveAnyFrameBlocking(DW1000* dw_ptr, float timeout, uint64_t* timestamp_recv = NULL, ReceptionStats* stats = NULL, bool start_recv = true);
bhepp 0:6d63b6992cbf 87
bhepp 0:6d63b6992cbf 88 bool receiveFrameBlocking(DW1000* dw_ptr, float timeout, uint64_t* timestamp_recv = NULL, ReceptionStats* stats = NULL, bool start_recv = true);
bhepp 0:6d63b6992cbf 89 bool receiveFrameBlocking(DW1000* dw_ptr, uint8_t type, float timeout, uint64_t* timestamp_recv = NULL, ReceptionStats* stats = NULL, bool start_recv = true);
bhepp 0:6d63b6992cbf 90 bool receiveFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, float timeout, uint64_t* timestamp_recv = NULL, ReceptionStats* stats = NULL, bool start_recv = true);
bhepp 0:6d63b6992cbf 91
bhepp 0:6d63b6992cbf 92 bool sendFrameBlocking(DW1000* dw_ptr, uint8_t* frame, int frame_size, float timeout, uint64_t* timestamp_send = NULL);
bhepp 0:6d63b6992cbf 93 bool sendDelayedFrameBlocking(DW1000* dw_ptr, uint8_t* frame, int frame_size, float timeout, uint64_t* timestamp_send);
bhepp 0:6d63b6992cbf 94
bhepp 0:6d63b6992cbf 95 bool sendRangingFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, float timeout, uint64_t* timestamp_send = NULL);
bhepp 0:6d63b6992cbf 96 bool sendReportFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, int64_t timediff_slave, float timeout, uint64_t* timestamp_send = NULL);
bhepp 0:6d63b6992cbf 97 bool sendDelayedRangingFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, float timeout, uint64_t* timestamp_send = NULL);
bhepp 0:6d63b6992cbf 98
bhepp 0:6d63b6992cbf 99 // This function corrects the timestamps if the counter had an overflow between measurements
bhepp 0:6d63b6992cbf 100 bool correctTimestamps(uint64_t* timestamp_master_request_1, uint64_t* timestamp_slave_reply, uint64_t* timestamp_master_request_2) const;
bhepp 0:6d63b6992cbf 101 };
bhepp 0:6d63b6992cbf 102
bhepp 0:6d63b6992cbf 103 }