Benjamin Hepp / Mbed 2 deprecated AIT_UWB_Tracker

Dependencies:   DW1000 ait_link BufferedSerial mbed

Committer:
bhepp
Date:
Tue Mar 29 10:00:43 2016 +0000
Revision:
4:1a2c1e5e5516
Parent:
1:c070ca30da80
Fixed bug with delayed transmission (delay was too long for multi-ranging)

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 4:1a2c1e5e5516 37 // With passive multi-ranging the delay usually has to be raised a bit (e.g. 3000 instead of 2500).
bhepp 1:c070ca30da80 38 #ifdef ANSWER_DELAY_US_OVERWRITE
bhepp 1:c070ca30da80 39 const static int ANSWER_DELAY_US = ANSWER_DELAY_US_OVERWRITE;
bhepp 1:c070ca30da80 40 #else
bhepp 0:6d63b6992cbf 41 const static int ANSWER_DELAY_US = 2500;
bhepp 1:c070ca30da80 42 #endif
bhepp 0:6d63b6992cbf 43 const static float ANSWER_DELAY_TIMEUNITS = ANSWER_DELAY_US * DW1000::US_TO_TIMEUNITS;
bhepp 0:6d63b6992cbf 44
bhepp 0:6d63b6992cbf 45 const static int NUM_OF_UWB_ADDRESSES = 256;
bhepp 0:6d63b6992cbf 46
bhepp 0:6d63b6992cbf 47 enum FrameType
bhepp 0:6d63b6992cbf 48 {
bhepp 0:6d63b6992cbf 49 MASTER_REQUEST_1 = 1,
bhepp 0:6d63b6992cbf 50 SLAVE_REPLY,
bhepp 0:6d63b6992cbf 51 MASTER_REQUEST_2,
bhepp 0:6d63b6992cbf 52 SLAVE_REPORT,
bhepp 0:6d63b6992cbf 53 };
bhepp 0:6d63b6992cbf 54
bhepp 0:6d63b6992cbf 55 // Attributes packed and aligned(1) ensure that the structure is not padded and not aligned in memory.
bhepp 0:6d63b6992cbf 56 struct __attribute__((packed, aligned(1))) RangingFrame
bhepp 0:6d63b6992cbf 57 {
bhepp 0:6d63b6992cbf 58 uint8_t address;
bhepp 0:6d63b6992cbf 59 uint8_t remote_address;
bhepp 0:6d63b6992cbf 60 uint8_t type;
bhepp 0:6d63b6992cbf 61 };
bhepp 0:6d63b6992cbf 62
bhepp 0:6d63b6992cbf 63 // Attributes packed and aligned(1) ensure that the structure is not padded and not aligned in memory.
bhepp 0:6d63b6992cbf 64 struct __attribute__((packed, aligned(1))) ReportRangingFrame : RangingFrame
bhepp 0:6d63b6992cbf 65 {
bhepp 0:6d63b6992cbf 66 int64_t timediff_slave;
bhepp 0:6d63b6992cbf 67 int64_t timestamp_master_request_1_recv;
bhepp 0:6d63b6992cbf 68 int64_t timestamp_slave_reply_send;
bhepp 0:6d63b6992cbf 69 int64_t timestamp_master_request_2_recv;
bhepp 0:6d63b6992cbf 70 #if SLAVE_REPLY_WITH_STATS
bhepp 0:6d63b6992cbf 71 ReceptionStats stats1;
bhepp 0:6d63b6992cbf 72 ReceptionStats stats2;
bhepp 0:6d63b6992cbf 73 #endif
bhepp 0:6d63b6992cbf 74 };
bhepp 0:6d63b6992cbf 75
bhepp 0:6d63b6992cbf 76 RangingFrame rangingFrame_;
bhepp 0:6d63b6992cbf 77 ReportRangingFrame receivedFrame_;
bhepp 0:6d63b6992cbf 78 ReportRangingFrame reportFrame_;
bhepp 0:6d63b6992cbf 79
bhepp 0:6d63b6992cbf 80 void sendRangingFrame(DW1000* dw_ptr, uint8_t remote_address, uint8_t type);
bhepp 0:6d63b6992cbf 81 void sendDelayedRangingFrame(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, uint64_t timestamp_send);
bhepp 0:6d63b6992cbf 82 void sendReportFrame(DW1000* dw_ptr, uint8_t remote_address, int64_t timediff_slave,
bhepp 0:6d63b6992cbf 83 uint64_t timestamp_master_request_1_recv,
bhepp 0:6d63b6992cbf 84 uint64_t timestamp_slave_reply_send,
bhepp 0:6d63b6992cbf 85 uint64_t timestamp_master_request_2_recv);
bhepp 0:6d63b6992cbf 86
bhepp 0:6d63b6992cbf 87 bool receiveAnyFrameBlocking(DW1000* dw_ptr, float timeout, uint64_t* timestamp_recv = NULL, ReceptionStats* stats = NULL, bool start_recv = true);
bhepp 0:6d63b6992cbf 88
bhepp 0:6d63b6992cbf 89 bool receiveFrameBlocking(DW1000* dw_ptr, 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 type, float timeout, uint64_t* timestamp_recv = NULL, ReceptionStats* stats = NULL, bool start_recv = true);
bhepp 0:6d63b6992cbf 91 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 92
bhepp 0:6d63b6992cbf 93 bool sendFrameBlocking(DW1000* dw_ptr, uint8_t* frame, int frame_size, float timeout, uint64_t* timestamp_send = NULL);
bhepp 0:6d63b6992cbf 94 bool sendDelayedFrameBlocking(DW1000* dw_ptr, uint8_t* frame, int frame_size, float timeout, uint64_t* timestamp_send);
bhepp 0:6d63b6992cbf 95
bhepp 0:6d63b6992cbf 96 bool sendRangingFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, float timeout, uint64_t* timestamp_send = NULL);
bhepp 0:6d63b6992cbf 97 bool sendReportFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, int64_t timediff_slave, float timeout, uint64_t* timestamp_send = NULL);
bhepp 0:6d63b6992cbf 98 bool sendDelayedRangingFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, float timeout, uint64_t* timestamp_send = NULL);
bhepp 0:6d63b6992cbf 99
bhepp 0:6d63b6992cbf 100 // This function corrects the timestamps if the counter had an overflow between measurements
bhepp 0:6d63b6992cbf 101 bool correctTimestamps(uint64_t* timestamp_master_request_1, uint64_t* timestamp_slave_reply, uint64_t* timestamp_master_request_2) const;
bhepp 0:6d63b6992cbf 102 };
bhepp 0:6d63b6992cbf 103
bhepp 0:6d63b6992cbf 104 }