Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: main.cpp
- Revision:
- 11:c87d37db2c6f
- Parent:
- 10:d077bb12d259
- Child:
- 12:985aa9843c3c
--- a/main.cpp Fri Nov 21 14:33:23 2014 +0000 +++ b/main.cpp Sun Nov 23 11:20:46 2014 +0000 @@ -5,7 +5,9 @@ PC pc(USBTX, USBRX, 921600); // USB UART Terminal DW1000 dw(D11, D12, D13, D10, D14); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ) -#define SENDER + +uint64_t timestamp_old = 0; +//#define SENDER void Interrupthandler() { /*uint8_t frameready = 0; @@ -18,10 +20,26 @@ framelength -= 2; char* receive = dw.receiveString(); - pc.printf("Message Received: %s %d\r\n", receive, framelength); + pc.printf("Received: %s %d ", receive, framelength); delete[] receive; - dw.resetRX(); // TODO: is crucial because otherwise only 1 frame is received correct + uint64_t status; + dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5); + status &= 0xFFFFFFFFFF; // only 40-Bit + pc.printf("Status: %010llX ", status); + + uint64_t timestamp; + dw.readRegister(DW1000_RX_TIME, 0, (uint8_t*)×tamp, 5); + timestamp &= 0xFFFFFFFFFF; // only 40-Bit + uint64_t difference = timestamp - timestamp_old; + timestamp_old = timestamp; + pc.printf("Timestamp: %lld\r\n", difference); + + /*uint8_t xtalt; // for clock tuning + dw.readRegister(DW1000_FS_CTRL, 0x0E, (uint8_t*)&xtalt, 1); + pc.printf("XTALT: %X\r\n", xtalt);*/ + + //dw.resetRX(); // TODO DONE: reset was crucial because otherwise only 1 frame is received correct, cause: LDE crashing because you have to manually initialize dw.receiveFrame(); } @@ -54,30 +72,37 @@ while(1) { i++; # ifdef SENDER // to make one node sender and one receiver - // Send something - 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)); + //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)+1); + //else + //pc.printf("%d Message: %d\r\n", i, strlen(message)+1); dw.sendString(message); char messagecheck[1024]; dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1); - messagecheck[1] = '\0'; - if (i < 200) + //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); + //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(1); + //if (i<27) + wait(1); + //else + //wait(3); #else - pc.printf("%d Waiting...\r\n", i); + 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); + wait(1); # endif