Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Revision:
28:a830131560e8
Parent:
27:71178fdb78e1
Child:
29:019ff388ed76
--- a/main.cpp	Fri Nov 28 07:44:36 2014 +0000
+++ b/main.cpp	Fri Nov 28 14:40:03 2014 +0000
@@ -4,80 +4,34 @@
 #include "DW1000.h"                                 // our DW1000 device driver
 #include "MMRanging.h"                              // our self developed raning application
 
-//#define RECEIVER
-
 PC          pc(USBTX, USBRX, 921600);               // USB UART Terminal
 DW1000      dw(PA_7, PA_6, PA_5, PB_6, PB_9);       // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
-MMRanging   ranging(&dw);                            // Ranging class for getting distances and later positions
-
-const float timeunit = 1/(128*499.2);               // conversion between LSB of TX and RX timestamps and microseconds
-int i=0;
-char message[1021] = "";
-char messageRX[1021] = "";
-uint64_t TX_timestamp;
-uint64_t RX_timestamp;
-int event_i = 0;
-char event[10][20];
-uint64_t eventtimes[10];
+MMRanging   r(dw);                                  // Ranging class for getting distances and later positions
 
-void callbackRX(int framelength) {
-    RX_timestamp = dw.getRXTimestamp();
-    dw.receiveString(messageRX);
-#ifdef RECEIVER
-    message[0] = 'A';                               // acknowledge messages
-    for(int i = 0; i < 10; i++)
-        message[i+1] = messageRX[i];
-    dw.sendString(message);
-#endif
-    eventtimes[event_i] = RX_timestamp - TX_timestamp;                      // TODO: can give some wrong values because of timer reset after 17 seconds
-    event[event_i][0] = '!';
-    event[event_i][1] = 'R';
-    event[event_i][2] = ' ';
-    for(int i = 0; i < 10; i++)
-        event[event_i][i+3] = messageRX[i];
-    if (event_i == 8)
-        event_i = 0;
-    else
-        event_i++;
-    dw.startRX();
-}
+char message[100] = "";
 
-void callbackTX() {
-    TX_timestamp = dw.getTXTimestamp();
-    eventtimes[event_i] = 0;
-    event[event_i][0] = '!';
-    event[event_i][1] = 'S';
-    event[event_i][2] = ' ';
-    for(int i = 0; i < 10; i++)
-        event[event_i][i+3] = message[i];
-    if (event_i == 8)
-        event_i = 0;
-    else
-        event_i++;
-}
+void callbackRX() {r.callbackRX();}                 // TODO: solve cast from memebr function pointer to function pointer
+void callbackTX() {r.callbackTX();}
 
 int main() {
     pc.printf("DecaWave 0.2\r\nup and running!\r\n");  
     dw.setEUI(0xFAEDCD01FAEDCD01);                  // basic methods called to check if we have a working SPI connection
-    pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID());
-    pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI());
-    pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
-    
+    pc.printf("DEVICE_ID register: 0x%X\r\n", dw.getDeviceID());
+    pc.printf("EUI register: %016llX\r\n", dw.getEUI());
+    pc.printf("Voltage: %f\r\n", dw.getVoltage());
+
+    r.receiver = true;
     dw.setCallbacks(&callbackRX, &callbackTX);
-    dw.setInterrupt(true, true);
-    dw.startRX();
     
     while(1) {
         for(int j = 0; j < 10; j++)
-            if(event[j][0] == '!') {
-                pc.printf("%s Time: %fus\r\n", event[j], eventtimes[j]*timeunit);
-                event[j][0] = 'X';
+            if(r.event[j][0] == '!') {
+                pc.printf("%s Time: %fus\r\n", r.event[j], r.eventtimes[j]*MMRANGING_TIMEUNIT);
+                r.event[j][0] = 'X';
             }    
-#ifndef RECEIVER
-        sprintf(message, "%d", i);                  // send numbers to acknowledge
-        dw.sendString(message);
-        wait(1);
-#endif
-        i++;
+        if (!r.receiver) {
+                r.requestRanging();
+                wait(1);
+        }
     }
 }
\ No newline at end of file