Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Revision:
10:d077bb12d259
Parent:
9:c8839de428ac
Child:
11:c87d37db2c6f
--- a/main.cpp	Thu Nov 20 16:00:34 2014 +0000
+++ b/main.cpp	Fri Nov 21 14:33:23 2014 +0000
@@ -8,19 +8,26 @@
 #define SENDER
 
 void Interrupthandler() {
-    uint8_t frameready = 0;
+    /*uint8_t frameready = 0;
     dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
-    pc.printf("Interrupt status: %X\r\n", frameready);
-    // get data from buffer
-    uint8_t receive[20] = "NOTHING IN!!";
-    dw.readRegister(DW1000_RX_BUFFER, 0, receive, 20);
-    pc.printf("Message received: %s\r\n", receive);
-    dw.resetRX();
+    pc.printf("Interrupt status: %X\r\n", frameready);*/
+    
+    uint16_t framelength = 0;                                       // get framelength
+    dw.readRegister(DW1000_RX_FINFO, 0, (uint8_t*)&framelength, 2);
+    framelength &= 0x03FF;
+    framelength -= 2;
+    
+    char* receive = dw.receiveString();
+    pc.printf("Message Received: %s %d\r\n", receive, framelength);
+    delete[] receive;
+    
+    dw.resetRX();                                                   // TODO: is crucial because otherwise only 1 frame is received correct
     dw.receiveFrame();
 }
 
 int main() {
     int i=0;
+    char message[1024] = "";
     pc.printf("DecaWave 0.1\r\nup and running!\r\n");
     
     dw.setEUI(0xFAEDCD01FAEDCD01);
@@ -37,7 +44,7 @@
     
     dw.callbackRX = &Interrupthandler;
 #ifndef SENDER
-    uint8_t dataframereadyinterrupt = 0x20; // only good frame would be 0x40
+    uint8_t dataframereadyinterrupt = 0x40; // only good frame 0x40 all frames 0x20
     dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1);
     
     // Receive something
@@ -46,24 +53,32 @@
     
     while(1) {
         i++;
-        
 # ifdef SENDER                      // to make one node sender and one receiver
         // Send something
-        char message[20];
-        sprintf((char*)message, "HELLO WORLD! %d", i);
-        dw.sendFrame(message, 20);
+        message[i-1] = 'O';
+        message[i] = '\0';
+        //sprintf((char*)message, "HELLO WORLD! %d", i);
+        if (i < 200)
+            pc.printf("%d Message: \"%s\" %d\r\n", i, message, strlen(message));
+        else
+            pc.printf("%d Message: %d\r\n", i, strlen(message));
+        dw.sendString(message);
         
-        uint8_t messagecheck[20];
-        dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 20);
-        pc.printf("Message in buffer: %s\r\nSending...\r\n", messagecheck);
+        char messagecheck[1024];
+        dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1);
+        messagecheck[1] = '\0';
+        if (i < 200)
+            pc.printf("%d  Buffer: \"%s\" %d\r\n", i, messagecheck, strlen(messagecheck)+1);
+        else
+            pc.printf("%d  Buffer: %d\r\n", i, strlen(messagecheck)+1);
         /*for(int i=0; i<10; i++) {                                 // to control Voltage
             pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
             wait(0.2);
         }*/
-        wait(0.1);
+        wait(1);
 #else
         pc.printf("%d Waiting...\r\n", i);
-        wait(5);
+        wait(1);
 # endif
         
     }