Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

Committer:
manumaet
Date:
Thu Nov 27 13:34:35 2014 +0000
Revision:
23:661a79e56208
Parent:
22:576ee999b004
Child:
24:6f25ba679490
trancieving with interrupt works now, exclusion receive/send not finished

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manumaet 0:f50e671ffff7 1 #include "mbed.h"
manumaet 0:f50e671ffff7 2 #include "PC.h" // Serial Port via USB for debugging with Terminal
manumaet 0:f50e671ffff7 3 #include "DW1000.h"
manumaet 0:f50e671ffff7 4
manumaet 0:f50e671ffff7 5 PC pc(USBTX, USBRX, 921600); // USB UART Terminal
manumaet 22:576ee999b004 6 DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
manumaet 22:576ee999b004 7
manumaet 15:e1fea7e2aff1 8 const float timeunit = 1/(128*499.2e6);
manumaet 14:8041c9b68406 9 int i=0;
manumaet 17:8afa5f9122da 10 char message[1200] = "";
manumaet 21:23bf4399020d 11 uint64_t TX_timestamp = 0;
manumaet 21:23bf4399020d 12 uint64_t RX_timestamp = 0;
manumaet 14:8041c9b68406 13
manumaet 18:bbc7ca7d3a95 14 void callbackRX(int framelength) {
manumaet 21:23bf4399020d 15 RX_timestamp = dw.readRegister40(DW1000_RX_TIME, 0);
manumaet 21:23bf4399020d 16 if (framelength < 200) {
manumaet 16:96879e1c99f2 17 char* receive = dw.receiveString(); // receive a string
manumaet 16:96879e1c99f2 18 pc.printf("Received: \"%s\" %d ", receive, framelength);
manumaet 22:576ee999b004 19 pc.printf("Status: %010llX ", dw.getStatus());
manumaet 21:23bf4399020d 20 #if 0
manumaet 21:23bf4399020d 21 sprintf(message, "ACK \"%s\"", receive);
manumaet 21:23bf4399020d 22 dw.sendString(message);
manumaet 21:23bf4399020d 23 wait(0.1);
manumaet 21:23bf4399020d 24 #endif
manumaet 16:96879e1c99f2 25 delete[] receive;
manumaet 16:96879e1c99f2 26 } else
manumaet 16:96879e1c99f2 27 pc.printf("Received! %d ", framelength);
manumaet 10:d077bb12d259 28
manumaet 21:23bf4399020d 29 uint64_t difference = RX_timestamp - TX_timestamp;
manumaet 15:e1fea7e2aff1 30 //pc.printf("Timestamp: %lld\r\n", difference);
manumaet 21:23bf4399020d 31 pc.printf("Time since TX: %fs\r\n", difference*timeunit); // TODO: gives some wrong values because of timer overflow
manumaet 17:8afa5f9122da 32 dw.startRX();
manumaet 6:d5864a1b9e17 33 }
manumaet 6:d5864a1b9e17 34
manumaet 18:bbc7ca7d3a95 35 void callbackTX() {
manumaet 22:576ee999b004 36 //TX_timestamp = dw.readRegister40(DW1000_TX_TIME, 0);
manumaet 22:576ee999b004 37 /*char messagecheck[1021];
manumaet 21:23bf4399020d 38 dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, 1021);
manumaet 18:bbc7ca7d3a95 39 if (i < 200)
manumaet 21:23bf4399020d 40 pc.printf("%d Sent: \"%s\" %d ", i, messagecheck, strlen(messagecheck)+1);
manumaet 18:bbc7ca7d3a95 41 else
manumaet 22:576ee999b004 42 pc.printf("%d Sent! %d ", i, strlen(messagecheck)+1);*/
manumaet 23:661a79e56208 43 pc.printf("SENT!! Status: %010llX\r\n", dw.getStatus());
manumaet 18:bbc7ca7d3a95 44 }
manumaet 18:bbc7ca7d3a95 45
manumaet 0:f50e671ffff7 46 int main() {
manumaet 20:257d56530ae1 47 pc.printf("DecaWave 0.1\r\nup and running!\r\n");
manumaet 20:257d56530ae1 48 dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection
manumaet 4:6240b9c7a033 49 pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID());
manumaet 4:6240b9c7a033 50 pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI());
manumaet 4:6240b9c7a033 51 pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
manumaet 0:f50e671ffff7 52
manumaet 18:bbc7ca7d3a95 53 dw.callbackRX = &callbackRX; // TODO: must not jump to NULL & setter
manumaet 18:bbc7ca7d3a95 54 dw.callbackTX = &callbackTX;
manumaet 14:8041c9b68406 55
manumaet 14:8041c9b68406 56 // Receiver initialisation
manumaet 22:576ee999b004 57 dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4080); //| 0x0080); // TODO: RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080
manumaet 17:8afa5f9122da 58 dw.startRX();
manumaet 5:111f11c95d27 59
manumaet 0:f50e671ffff7 60 while(1) {
manumaet 19:e94bc88c1eb0 61 #if 1
manumaet 23:661a79e56208 62 sprintf(message, "Hi %d", i);
manumaet 22:576ee999b004 63 if ((i % 10) > 5) {
manumaet 22:576ee999b004 64 dw.sendString(message);
manumaet 23:661a79e56208 65 //pc.printf("%d Sent: \"%s\" %d \r\n", i, message, strlen(message)+1);
manumaet 22:576ee999b004 66 }
manumaet 17:8afa5f9122da 67 #endif
manumaet 15:e1fea7e2aff1 68 #if 0
manumaet 21:23bf4399020d 69 pc.printf("%d Waiting... %d %d ", i, dw.receiving, dw.sending);
manumaet 15:e1fea7e2aff1 70 wait(5);
manumaet 15:e1fea7e2aff1 71 #endif
manumaet 22:576ee999b004 72 wait(0.2);
manumaet 22:576ee999b004 73 //pc.printf("Status: %010llX\r\n", dw.getStatus());
manumaet 15:e1fea7e2aff1 74 i++;
manumaet 0:f50e671ffff7 75 }
manumaet 0:f50e671ffff7 76 }