Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: main.cpp
- Revision:
- 4:6240b9c7a033
- Parent:
- 3:69587fadfa87
- Child:
- 5:111f11c95d27
--- a/main.cpp Mon Nov 17 16:00:28 2014 +0000 +++ b/main.cpp Tue Nov 18 12:44:22 2014 +0000 @@ -11,64 +11,64 @@ }*/ int main() { + int i=0; pc.printf("DecaWave 0.1\r\nup and running!\r\n"); dw.setEUI(0xFAEDCD01FAEDCD01); + 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()); - int i=0; + // read System Configuration + uint32_t conf = 0; + dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4); + pc.printf("%d System Configuration: %X\r\n", i, conf); + + wait(5); while(1) { i++; - 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()); - - // read System Configuration - uint32_t conf = 0; - dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4); - pc.printf("%d System Configuration: %X\r\n", i, conf); # if 0 // to make one node sender and one receiver // Send something - uint8_t message[13] = "HELLO WORLD!"; // fill buffer - //sprintf((char*)message, "Hello: %d!", i); - dw.writeRegister(DW1000_TX_BUFFER, 0, message, 13); - uint8_t messagecheck[13]; - dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 13); - pc.printf("Message in buffer: %s\r\nHex: 0x", messagecheck); - for (int i = 0;i < 13; i++) - pc.printf("%X", messagecheck[i]); - pc.printf("\r\n", messagecheck[i]); + char message[20] = "HELLO WORLD!"; + sprintf((char*)message, "HELLO WORLD! %d", i); + dw.sendFrame(message, 20); - uint16_t framelength = 13; // put length of frame - dw.writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&framelength, 1); + uint8_t messagecheck[20]; + dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 20); + pc.printf("Message in buffer: %s\r\n", messagecheck); + wait(2); +# else - //if (i==4) { - uint8_t txstart = 0x02; // trigger sending process - dw.writeRegister(DW1000_SYS_CTRL, 0, &txstart, 1); - pc.printf("Sending...\r\n"); - //} -# else // Receive something uint8_t rxenable = 0x01; // start listening dw.writeRegister(DW1000_SYS_CTRL, 1, &rxenable, 1); uint8_t frameready = 0; // check if frame received - while ((frameready & 0x20) != 0x20) { // while no frame ready + while (frameready == 0 /*& 0x20) != 0x20*/) { // while no frame ready i++; + pc.printf("%d Waiting for frame... \r\n", i); dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1); pc.printf("Status: %X\r\n", frameready); - /*uint8_t receive[13] = "NOTHING IN!!"; // get data from buffer - dw.readRegister(DW1000_RX_BUFFER, 0, receive, 13); - pc.printf("Message would be: %s\r\n", receive);*/ - wait(0.5); + uint8_t receive[20] = "NOTHING IN!!"; // get data from buffer + dw.readRegister(DW1000_RX_BUFFER, 0, receive, 20); + pc.printf("Message would be: %s\r\n", receive); + wait(0.3); } - uint8_t receive[13] = "NOTHING IN!!"; // get data from buffer - dw.readRegister(DW1000_RX_BUFFER, 0, receive, 13); - pc.printf("Message received: %s\r\n", receive); + uint8_t receive[20] = "NOTHING IN!!"; // get data from buffer + dw.readRegister(DW1000_RX_BUFFER, 0, receive, 20); + pc.printf("Message received: %s -------------------------\r\n", receive); + + dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1); + pc.printf("Status: %X\r\n", frameready); + + dw.resetRX(); + wait(0.5); + continue; + # endif - wait(0.5); - return 0; + } } \ No newline at end of file