Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
manumaet
Date:
Sun Feb 22 17:40:38 2015 +0000
Revision:
39:bb57aa77b015
Parent:
37:40f94c634c3e
Child:
40:5ce51b7e3118
setup to find the 40 bit overflow in the timestamps, seems to be fixed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manumaet 27:71178fdb78e1 1 // by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
manumaet 27:71178fdb78e1 2
manumaet 27:71178fdb78e1 3 #ifndef MMRANGING_H
manumaet 27:71178fdb78e1 4 #define MMRANGING_H
manumaet 27:71178fdb78e1 5
manumaet 27:71178fdb78e1 6 #include "mbed.h"
manumaet 27:71178fdb78e1 7 #include "DW1000.h"
manumaet 27:71178fdb78e1 8
manumaet 39:bb57aa77b015 9 #define MMRANGING_TIMEUNIT_US 1/(128*499.2) // conversion between LSB of TX and RX timestamps and microseconds
manumaet 39:bb57aa77b015 10 #define MMRANGING_TIMEUNIT_NS 1000/(128*499.2) // conversion between LSB of TX and RX timestamps and nanoseconds
manumaet 39:bb57aa77b015 11
manumaet 39:bb57aa77b015 12 #define MMRANGING_2POWER40 1099511627776 // decimal value of 2^40 to correct timeroverflow between timestamps
manumaet 27:71178fdb78e1 13
manumaet 27:71178fdb78e1 14 class MMRanging {
manumaet 28:a830131560e8 15 public:
manumaet 28:a830131560e8 16 MMRanging(DW1000& DW);
manumaet 36:883de6f9a73b 17 void requestRanging(uint8_t destination);
manumaet 28:a830131560e8 18 //private:
manumaet 28:a830131560e8 19 DW1000& dw;
manumaet 28:a830131560e8 20
manumaet 30:4ecc69d3cf8d 21 void callbackRX();
manumaet 30:4ecc69d3cf8d 22 void callbackTX();
manumaet 36:883de6f9a73b 23 void sendRangingframe(uint8_t destination, uint8_t sequence_number, uint8_t type, uint64_t time_difference_receiver);
manumaet 39:bb57aa77b015 24 uint64_t timeDifference40Bit(uint64_t early, uint64_t late); // Method to calculate the difference between two 40-Bit timestamps correcting timer overflow reset between the timestamps
manumaet 30:4ecc69d3cf8d 25
manumaet 39:bb57aa77b015 26 uint8_t address; // Identifies the node, source and destination in rangingframes
manumaet 34:f56962030c5c 27 struct rangingframe {
manumaet 36:883de6f9a73b 28 uint8_t source;
manumaet 36:883de6f9a73b 29 uint8_t destination;
manumaet 36:883de6f9a73b 30 uint8_t sequence_number;
manumaet 36:883de6f9a73b 31 uint8_t type;
manumaet 31:6f76f3d518ac 32 uint64_t time_difference_receiver;
manumaet 36:883de6f9a73b 33 };
manumaet 36:883de6f9a73b 34
manumaet 39:bb57aa77b015 35 rangingframe TX; // buffer in class for sending a frame (not made locally because then we can recall in the interrupt what was sent)
manumaet 31:6f76f3d518ac 36 uint64_t rangingtimingsSender[10][2];
manumaet 31:6f76f3d518ac 37 uint64_t rangingtimingsReceiver[10][2];
manumaet 39:bb57aa77b015 38 uint64_t tofs[10]; // Array containing time of flights for each node (index is address of node)
manumaet 31:6f76f3d518ac 39
manumaet 28:a830131560e8 40 // draft for first test
manumaet 28:a830131560e8 41 bool receiver;
manumaet 28:a830131560e8 42 int event_i;
manumaet 28:a830131560e8 43 char event[10][20];
manumaet 28:a830131560e8 44 uint8_t counter;
manumaet 27:71178fdb78e1 45 };
manumaet 27:71178fdb78e1 46
manumaet 27:71178fdb78e1 47 #endif