Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DW1000 ait_link BufferedSerial mbed
UWBProtocol/UWBProtocol.h@0:6d63b6992cbf, 2016-02-05 (annotated)
- Committer:
- bhepp
- Date:
- Fri Feb 05 13:48:52 2016 +0000
- Revision:
- 0:6d63b6992cbf
- Child:
- 1:c070ca30da80
Single module working
Who changed what in which revision?
| User | Revision | Line number | New 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 | 0:6d63b6992cbf | 37 | const static int ANSWER_DELAY_US = 2500; |
| bhepp | 0:6d63b6992cbf | 38 | const static float ANSWER_DELAY_TIMEUNITS = ANSWER_DELAY_US * DW1000::US_TO_TIMEUNITS; |
| bhepp | 0:6d63b6992cbf | 39 | |
| bhepp | 0:6d63b6992cbf | 40 | const static int NUM_OF_UWB_ADDRESSES = 256; |
| bhepp | 0:6d63b6992cbf | 41 | |
| bhepp | 0:6d63b6992cbf | 42 | enum FrameType |
| bhepp | 0:6d63b6992cbf | 43 | { |
| bhepp | 0:6d63b6992cbf | 44 | MASTER_REQUEST_1 = 1, |
| bhepp | 0:6d63b6992cbf | 45 | SLAVE_REPLY, |
| bhepp | 0:6d63b6992cbf | 46 | MASTER_REQUEST_2, |
| bhepp | 0:6d63b6992cbf | 47 | SLAVE_REPORT, |
| bhepp | 0:6d63b6992cbf | 48 | }; |
| bhepp | 0:6d63b6992cbf | 49 | |
| bhepp | 0:6d63b6992cbf | 50 | // Attributes packed and aligned(1) ensure that the structure is not padded and not aligned in memory. |
| bhepp | 0:6d63b6992cbf | 51 | struct __attribute__((packed, aligned(1))) RangingFrame |
| bhepp | 0:6d63b6992cbf | 52 | { |
| bhepp | 0:6d63b6992cbf | 53 | uint8_t address; |
| bhepp | 0:6d63b6992cbf | 54 | uint8_t remote_address; |
| bhepp | 0:6d63b6992cbf | 55 | uint8_t type; |
| bhepp | 0:6d63b6992cbf | 56 | }; |
| bhepp | 0:6d63b6992cbf | 57 | |
| bhepp | 0:6d63b6992cbf | 58 | // Attributes packed and aligned(1) ensure that the structure is not padded and not aligned in memory. |
| bhepp | 0:6d63b6992cbf | 59 | struct __attribute__((packed, aligned(1))) ReportRangingFrame : RangingFrame |
| bhepp | 0:6d63b6992cbf | 60 | { |
| bhepp | 0:6d63b6992cbf | 61 | int64_t timediff_slave; |
| bhepp | 0:6d63b6992cbf | 62 | int64_t timestamp_master_request_1_recv; |
| bhepp | 0:6d63b6992cbf | 63 | int64_t timestamp_slave_reply_send; |
| bhepp | 0:6d63b6992cbf | 64 | int64_t timestamp_master_request_2_recv; |
| bhepp | 0:6d63b6992cbf | 65 | #if SLAVE_REPLY_WITH_STATS |
| bhepp | 0:6d63b6992cbf | 66 | ReceptionStats stats1; |
| bhepp | 0:6d63b6992cbf | 67 | ReceptionStats stats2; |
| bhepp | 0:6d63b6992cbf | 68 | #endif |
| bhepp | 0:6d63b6992cbf | 69 | }; |
| bhepp | 0:6d63b6992cbf | 70 | |
| bhepp | 0:6d63b6992cbf | 71 | RangingFrame rangingFrame_; |
| bhepp | 0:6d63b6992cbf | 72 | ReportRangingFrame receivedFrame_; |
| bhepp | 0:6d63b6992cbf | 73 | ReportRangingFrame reportFrame_; |
| bhepp | 0:6d63b6992cbf | 74 | |
| bhepp | 0:6d63b6992cbf | 75 | void sendRangingFrame(DW1000* dw_ptr, uint8_t remote_address, uint8_t type); |
| bhepp | 0:6d63b6992cbf | 76 | void sendDelayedRangingFrame(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, uint64_t timestamp_send); |
| bhepp | 0:6d63b6992cbf | 77 | void sendReportFrame(DW1000* dw_ptr, uint8_t remote_address, int64_t timediff_slave, |
| bhepp | 0:6d63b6992cbf | 78 | uint64_t timestamp_master_request_1_recv, |
| bhepp | 0:6d63b6992cbf | 79 | uint64_t timestamp_slave_reply_send, |
| bhepp | 0:6d63b6992cbf | 80 | uint64_t timestamp_master_request_2_recv); |
| bhepp | 0:6d63b6992cbf | 81 | |
| bhepp | 0:6d63b6992cbf | 82 | bool receiveAnyFrameBlocking(DW1000* dw_ptr, float timeout, uint64_t* timestamp_recv = NULL, ReceptionStats* stats = NULL, bool start_recv = true); |
| bhepp | 0:6d63b6992cbf | 83 | |
| bhepp | 0:6d63b6992cbf | 84 | bool receiveFrameBlocking(DW1000* dw_ptr, float timeout, uint64_t* timestamp_recv = NULL, ReceptionStats* stats = NULL, bool start_recv = true); |
| bhepp | 0:6d63b6992cbf | 85 | 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 | 86 | 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 | 87 | |
| bhepp | 0:6d63b6992cbf | 88 | bool sendFrameBlocking(DW1000* dw_ptr, uint8_t* frame, int frame_size, float timeout, uint64_t* timestamp_send = NULL); |
| bhepp | 0:6d63b6992cbf | 89 | bool sendDelayedFrameBlocking(DW1000* dw_ptr, uint8_t* frame, int frame_size, float timeout, uint64_t* timestamp_send); |
| bhepp | 0:6d63b6992cbf | 90 | |
| bhepp | 0:6d63b6992cbf | 91 | bool sendRangingFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, float timeout, uint64_t* timestamp_send = NULL); |
| bhepp | 0:6d63b6992cbf | 92 | bool sendReportFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, int64_t timediff_slave, float timeout, uint64_t* timestamp_send = NULL); |
| bhepp | 0:6d63b6992cbf | 93 | bool sendDelayedRangingFrameBlocking(DW1000* dw_ptr, uint8_t remote_address, uint8_t type, float timeout, uint64_t* timestamp_send = NULL); |
| bhepp | 0:6d63b6992cbf | 94 | |
| bhepp | 0:6d63b6992cbf | 95 | // This function corrects the timestamps if the counter had an overflow between measurements |
| bhepp | 0:6d63b6992cbf | 96 | bool correctTimestamps(uint64_t* timestamp_master_request_1, uint64_t* timestamp_slave_reply, uint64_t* timestamp_master_request_2) const; |
| bhepp | 0:6d63b6992cbf | 97 | }; |
| bhepp | 0:6d63b6992cbf | 98 | |
| bhepp | 0:6d63b6992cbf | 99 | } |