Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
manumaet
Date:
Fri Nov 28 16:45:10 2014 +0000
Revision:
29:019ff388ed76
Parent:
28:a830131560e8
Child:
31:6f76f3d518ac
problem with member function pointers solved!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manumaet 27:71178fdb78e1 1 #include "MMRanging.h"
manumaet 27:71178fdb78e1 2
manumaet 28:a830131560e8 3 MMRanging::MMRanging(DW1000& DW) : dw(DW){
manumaet 27:71178fdb78e1 4 MMRanging::dw = dw;
manumaet 28:a830131560e8 5
manumaet 28:a830131560e8 6 message[0] = '\0';
manumaet 28:a830131560e8 7 messageRX[0] = '\0';
manumaet 28:a830131560e8 8 event_i = 0;
manumaet 28:a830131560e8 9 counter = 0;
manumaet 28:a830131560e8 10
manumaet 29:019ff388ed76 11 dw.setCallbacks(this, &MMRanging::callbackRX, &MMRanging::callbackTX);
manumaet 28:a830131560e8 12 dw.startRX();
manumaet 27:71178fdb78e1 13 }
manumaet 28:a830131560e8 14
manumaet 28:a830131560e8 15 void MMRanging::callbackRX() {
manumaet 28:a830131560e8 16 RX_timestamp = dw.getRXTimestamp();
manumaet 28:a830131560e8 17 dw.receiveString(messageRX);
manumaet 28:a830131560e8 18 if (receiver) {
manumaet 28:a830131560e8 19 message[0] = 'A'; // acknowledge messages
manumaet 28:a830131560e8 20 for(int i = 0; i < 10; i++)
manumaet 28:a830131560e8 21 message[i+1] = messageRX[i];
manumaet 28:a830131560e8 22 dw.sendString(message);
manumaet 28:a830131560e8 23 }
manumaet 28:a830131560e8 24 eventtimes[event_i] = RX_timestamp - TX_timestamp; // TODO: can give some wrong values because of timer reset after 17 seconds
manumaet 28:a830131560e8 25 event[event_i][0] = '!';
manumaet 28:a830131560e8 26 event[event_i][1] = 'R';
manumaet 28:a830131560e8 27 event[event_i][2] = ' ';
manumaet 28:a830131560e8 28 for(int i = 0; i < 10; i++)
manumaet 28:a830131560e8 29 event[event_i][i+3] = messageRX[i];
manumaet 28:a830131560e8 30 if (event_i == 8)
manumaet 28:a830131560e8 31 event_i = 0;
manumaet 28:a830131560e8 32 else
manumaet 28:a830131560e8 33 event_i++;
manumaet 28:a830131560e8 34 dw.startRX();
manumaet 28:a830131560e8 35 }
manumaet 28:a830131560e8 36
manumaet 28:a830131560e8 37 void MMRanging::callbackTX() {
manumaet 28:a830131560e8 38 TX_timestamp = dw.getTXTimestamp();
manumaet 28:a830131560e8 39 eventtimes[event_i] = 0;
manumaet 28:a830131560e8 40 event[event_i][0] = '!';
manumaet 28:a830131560e8 41 event[event_i][1] = 'S';
manumaet 28:a830131560e8 42 event[event_i][2] = ' ';
manumaet 28:a830131560e8 43 for(int i = 0; i < 10; i++)
manumaet 28:a830131560e8 44 event[event_i][i+3] = message[i];
manumaet 28:a830131560e8 45 if (event_i == 8)
manumaet 28:a830131560e8 46 event_i = 0;
manumaet 28:a830131560e8 47 else
manumaet 28:a830131560e8 48 event_i++;
manumaet 28:a830131560e8 49 }
manumaet 28:a830131560e8 50
manumaet 28:a830131560e8 51 void MMRanging::requestRanging() {
manumaet 28:a830131560e8 52 sprintf(message, "%d", counter); // send numbers to acknowledge
manumaet 28:a830131560e8 53 counter++;
manumaet 28:a830131560e8 54 dw.sendString(message);
manumaet 28:a830131560e8 55 }