init
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
MM2WayRanging.h
00001 #ifndef MM2WAYRANGING_H 00002 #define MM2WAYRANGING_H 00003 00004 #include "mbed.h" 00005 #include "DW1000.h" 00006 00007 00008 #define TIMEUNITS_TO_US (1/(128*499.2)) // conversion between the decawave timeunits (ca 15.65ps) to microseconds. 00009 #define US_TO_TIMEUNITS (128*499.2) // conversion between microseconds to the decawave timeunits (ca 15.65ps). 00010 #define MMRANGING_2POWER40 1099511627776 // decimal value of 2^40 to correct timeroverflow between timestamps 00011 00012 //Predefined delay for the critical answers in the ranging algorithm 00013 //HAS TO BE BIGGER THAN THE PROCESSING TIME OF THE FRAME ON THE NODE 00014 #define ANSWER_DELAY_US 2500 //2500 works for 110kbps, 900 for 6.8Mbps 00015 #define ANSWER_DELAY_TIMEUNITS ANSWER_DELAY_US * (128*499.2) 00016 00017 class MM2WayRanging { 00018 00019 public: 00020 MM2WayRanging(DW1000& DW); 00021 00022 bool beacon_requestRanging(); 00023 void anchor_standbyToRange(); 00024 00025 bool isBeacon; 00026 uint8_t address; // Identifies the nodes as source and destination in rangingframes 00027 bool overflow; // TRUE if counter overflows while ranging 00028 00029 private: 00030 DW1000& dw; 00031 Timer LocalTimer; 00032 00033 bool waitForFrameTX(float time_before); 00034 bool waitForFrameRX(float time_before); 00035 void callbackRX(); 00036 void callbackTX(); 00037 00038 void beacon_ready_Send(); 00039 void anchor_to_beacon_Send(uint8_t destination); 00040 void beacon_to_anchor_response_Send(uint8_t destination, uint64_t rxTimestamp); 00041 00042 //void correctReceiverTimestamps(uint8_t source); 00043 //void correctSenderTimestamps(uint8_t source); 00044 00045 enum FrameType{ 00046 BEACON_READY=1, 00047 ANCHOR_TO_BEACON_PING, 00048 BEACON_TO_ANCHOR_RESPONSE 00049 }; 00050 00051 //the packed attribute makes sure the types only use their respective size in memory (8 bit for uint8_t), otherwise they would always use 32 bit 00052 //IT IS A GCC SPECIFIC DIRECTIVE 00053 struct __attribute__((packed, aligned(1))) RangingFrame { 00054 uint8_t source; 00055 uint8_t destination; 00056 uint8_t type; 00057 }; 00058 00059 RangingFrame rangingFrame; // buffer in class for sending a frame (not made locally because then we can recall in the interrupt what was sent) 00060 RangingFrame receivedFrame; 00061 00062 uint64_t RxTimestamp; 00063 uint64_t rangingTxTimestamp[5]; 00064 uint64_t rangingRxTimestamp[5]; 00065 uint64_t rangingTOF[5]; 00066 float rangingDistance[5]; 00067 }; 00068 #endif
Generated on Sat Jul 16 2022 03:03:28 by
1.7.2