Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Revision:
18:bbc7ca7d3a95
Parent:
17:8afa5f9122da
Child:
19:e94bc88c1eb0
diff -r 8afa5f9122da -r bbc7ca7d3a95 main.cpp
--- a/main.cpp	Mon Nov 24 14:09:49 2014 +0000
+++ b/main.cpp	Mon Nov 24 16:48:03 2014 +0000
@@ -10,18 +10,7 @@
 char message[1200] = "";
 uint64_t timestamp_old = 0;
 
-//#define PINGPONG
-
-void Interrupthandler() {
-    /*uint8_t frameready = 0;
-    dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
-    pc.printf("Interrupt status: %X\r\n", frameready);*/
-    
-    uint16_t framelength = 0;                                       // get framelength TODO: just for debugging of string
-    dw.readRegister(DW1000_RX_FINFO, 0, (uint8_t*)&framelength, 2);
-    framelength &= 0x03FF;
-    framelength -= 2;
-    
+void callbackRX(int framelength) {
     if(framelength<200) {
         char* receive = dw.receiveString();                             // receive a string
         pc.printf("Received: \"%s\" %d ", receive, framelength);
@@ -29,14 +18,9 @@
     } else
         pc.printf("Received! %d ", framelength);
     
-    uint64_t status;
-    dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5);
-    status &= 0xFFFFFFFFFF;                                      // only 40-Bit
-    pc.printf("Status: %010llX  ", status);
+    pc.printf("Status: %010llX  ", dw.getStatus());
     
-    uint64_t timestamp;
-    dw.readRegister(DW1000_RX_TIME, 0, (uint8_t*)&timestamp, 5);
-    timestamp &= 0xFFFFFFFFFF;                                      // only 40-Bit
+    uint64_t timestamp = dw.readRegister40(DW1000_RX_TIME, 0);
     uint64_t difference = timestamp - timestamp_old;
     timestamp_old = timestamp;
     //pc.printf("Timestamp: %lld\r\n", difference);
@@ -45,6 +29,16 @@
     dw.startRX();
 }
 
+void callbackTX() {
+    char messagecheck[1200];
+    dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1);
+    if (i < 200)
+        pc.printf("%d Sent: \"%s\" %d ", i, messagecheck, strlen(message)+1);
+    else
+        pc.printf("%d Sent! %d ", i, strlen(message)+1);
+    pc.printf("Status: %010llX\r\n", dw.getStatus());
+}
+
 int main() {
     pc.printf("DecaWave 0.1\r\nup and running!\r\n");
     
@@ -57,37 +51,27 @@
     dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4);
     pc.printf("%d System Configuration: %X\r\n", i, conf);
     
-    dw.callbackRX = &Interrupthandler;
+    dw.callbackRX = &callbackRX;        // TODO: must not jump to NULL & setter
+    dw.callbackTX = &callbackTX;
     
     // Receiver initialisation
-    uint8_t dataframereadyinterrupt = 0x40; // only good frame 0x40 all frames 0x20
-    dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1);
+    dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4080); // RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080
     dw.startRX();
     
     while(1) {
-#if 1
+#if 0
         if(i < 1200) {
             message[i] = 48+ (i%10);
             message[i+1] = '\0';
         }
         
         //wait(0.1);
-        char messagecheck[1200];
         dw.sendString(message);
-        wait_us(10000);
-        dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1);
-        if (i < 200)
-            pc.printf("%d Sent: \"%s\" %d\r\n", i, messagecheck, strlen(message)+1);
-        else
-            pc.printf("%d Sent! %d\r\n", i, strlen(message)+1);
         
 #endif
 #if 0
         pc.printf("%d Waiting...  ", i);
-        uint64_t status;
-        dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5);
-        status &= 0xFFFFFFFFFF;                                      // only 40-Bit
-        pc.printf("Status: %010llX\r\n", status);
+        pc.printf("Status: %010llX  ", dw.getStatus());
         wait(5);
 #endif
         i++;