Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
main.cpp@24:6f25ba679490, 2014-11-27 (annotated)
- Committer:
- manumaet
- Date:
- Thu Nov 27 16:26:42 2014 +0000
- Revision:
- 24:6f25ba679490
- Parent:
- 23:661a79e56208
- Child:
- 25:d58b0595b300
no more printfs and heap in interrupt, ack of every frame works
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
manumaet | 24:6f25ba679490 | 1 | // by Matthias Grob & Manuel Stalder - ETH Zürich - 2015 |
manumaet | 0:f50e671ffff7 | 2 | #include "mbed.h" |
manumaet | 0:f50e671ffff7 | 3 | #include "PC.h" // Serial Port via USB for debugging with Terminal |
manumaet | 0:f50e671ffff7 | 4 | #include "DW1000.h" |
manumaet | 0:f50e671ffff7 | 5 | |
manumaet | 0:f50e671ffff7 | 6 | PC pc(USBTX, USBRX, 921600); // USB UART Terminal |
manumaet | 22:576ee999b004 | 7 | DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ) |
manumaet | 22:576ee999b004 | 8 | |
manumaet | 24:6f25ba679490 | 9 | const float timeunit = 1/(128*499.2); |
manumaet | 14:8041c9b68406 | 10 | int i=0; |
manumaet | 24:6f25ba679490 | 11 | char message[1021] = ""; |
manumaet | 24:6f25ba679490 | 12 | char messageRX[1021] = ""; |
manumaet | 24:6f25ba679490 | 13 | |
manumaet | 24:6f25ba679490 | 14 | uint64_t TX_timestamp; |
manumaet | 24:6f25ba679490 | 15 | uint64_t RX_timestamp; |
manumaet | 24:6f25ba679490 | 16 | |
manumaet | 24:6f25ba679490 | 17 | int event_i = 0; |
manumaet | 24:6f25ba679490 | 18 | char event[10][20]; |
manumaet | 24:6f25ba679490 | 19 | uint64_t eventtimes[10]; |
manumaet | 14:8041c9b68406 | 20 | |
manumaet | 18:bbc7ca7d3a95 | 21 | void callbackRX(int framelength) { |
manumaet | 24:6f25ba679490 | 22 | TX_timestamp = dw.readRegister40(DW1000_TX_TIME, 0); |
manumaet | 21:23bf4399020d | 23 | RX_timestamp = dw.readRegister40(DW1000_RX_TIME, 0); |
manumaet | 24:6f25ba679490 | 24 | dw.receiveString(messageRX); // receive a string |
manumaet | 21:23bf4399020d | 25 | #if 0 |
manumaet | 24:6f25ba679490 | 26 | message[0] = 'A'; |
manumaet | 24:6f25ba679490 | 27 | for(int i = 0; i < 10; i++) |
manumaet | 24:6f25ba679490 | 28 | message[i+1] = messageRX[i]; |
manumaet | 24:6f25ba679490 | 29 | dw.sendString(message); |
manumaet | 21:23bf4399020d | 30 | #endif |
manumaet | 24:6f25ba679490 | 31 | eventtimes[event_i] = RX_timestamp - TX_timestamp; // TODO: gives some wrong values because of timer overflow |
manumaet | 24:6f25ba679490 | 32 | event[event_i][0] = '!'; |
manumaet | 24:6f25ba679490 | 33 | event[event_i][1] = 'R'; |
manumaet | 24:6f25ba679490 | 34 | event[event_i][2] = ' '; |
manumaet | 24:6f25ba679490 | 35 | for(int i = 0; i < 10; i++) |
manumaet | 24:6f25ba679490 | 36 | event[event_i][i+3] = messageRX[i]; |
manumaet | 24:6f25ba679490 | 37 | if (event_i == 8) |
manumaet | 24:6f25ba679490 | 38 | event_i = 0; |
manumaet | 24:6f25ba679490 | 39 | else |
manumaet | 24:6f25ba679490 | 40 | event_i++; |
manumaet | 17:8afa5f9122da | 41 | dw.startRX(); |
manumaet | 6:d5864a1b9e17 | 42 | } |
manumaet | 6:d5864a1b9e17 | 43 | |
manumaet | 18:bbc7ca7d3a95 | 44 | void callbackTX() { |
manumaet | 22:576ee999b004 | 45 | //TX_timestamp = dw.readRegister40(DW1000_TX_TIME, 0); |
manumaet | 24:6f25ba679490 | 46 | //dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, 1021); |
manumaet | 24:6f25ba679490 | 47 | //pc.printf("! %d Sent: \"%s\" %d\r\n", i, message, strlen(message)+1); |
manumaet | 24:6f25ba679490 | 48 | eventtimes[event_i] = 0; |
manumaet | 24:6f25ba679490 | 49 | event[event_i][0] = '!'; |
manumaet | 24:6f25ba679490 | 50 | event[event_i][1] = 'S'; |
manumaet | 24:6f25ba679490 | 51 | event[event_i][2] = ' '; |
manumaet | 24:6f25ba679490 | 52 | for(int i = 0; i < 10; i++) |
manumaet | 24:6f25ba679490 | 53 | event[event_i][i+3] = message[i]; |
manumaet | 24:6f25ba679490 | 54 | if (event_i == 8) |
manumaet | 24:6f25ba679490 | 55 | event_i = 0; |
manumaet | 18:bbc7ca7d3a95 | 56 | else |
manumaet | 24:6f25ba679490 | 57 | event_i++; |
manumaet | 18:bbc7ca7d3a95 | 58 | } |
manumaet | 18:bbc7ca7d3a95 | 59 | |
manumaet | 0:f50e671ffff7 | 60 | int main() { |
manumaet | 20:257d56530ae1 | 61 | pc.printf("DecaWave 0.1\r\nup and running!\r\n"); |
manumaet | 20:257d56530ae1 | 62 | dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection |
manumaet | 4:6240b9c7a033 | 63 | pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID()); |
manumaet | 4:6240b9c7a033 | 64 | pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI()); |
manumaet | 4:6240b9c7a033 | 65 | pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage()); |
manumaet | 0:f50e671ffff7 | 66 | |
manumaet | 18:bbc7ca7d3a95 | 67 | dw.callbackRX = &callbackRX; // TODO: must not jump to NULL & setter |
manumaet | 18:bbc7ca7d3a95 | 68 | dw.callbackTX = &callbackTX; |
manumaet | 14:8041c9b68406 | 69 | |
manumaet | 14:8041c9b68406 | 70 | // Receiver initialisation |
manumaet | 24:6f25ba679490 | 71 | dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4000); //| 0x0080); // TODO: RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080 |
manumaet | 17:8afa5f9122da | 72 | dw.startRX(); |
manumaet | 5:111f11c95d27 | 73 | |
manumaet | 0:f50e671ffff7 | 74 | while(1) { |
manumaet | 24:6f25ba679490 | 75 | for(int i = 0; i < 10; i++) |
manumaet | 24:6f25ba679490 | 76 | if(event[i][0] == '!') { |
manumaet | 24:6f25ba679490 | 77 | pc.printf("%s Time: %fus\r\n", event[i], eventtimes[i]*timeunit); |
manumaet | 24:6f25ba679490 | 78 | event[i][0] = 'X'; |
manumaet | 24:6f25ba679490 | 79 | } |
manumaet | 19:e94bc88c1eb0 | 80 | #if 1 |
manumaet | 24:6f25ba679490 | 81 | sprintf(message, "%d", i); |
manumaet | 24:6f25ba679490 | 82 | //if ((i % 10) > 5) { |
manumaet | 22:576ee999b004 | 83 | dw.sendString(message); |
manumaet | 23:661a79e56208 | 84 | //pc.printf("%d Sent: \"%s\" %d \r\n", i, message, strlen(message)+1); |
manumaet | 24:6f25ba679490 | 85 | //} |
manumaet | 17:8afa5f9122da | 86 | #endif |
manumaet | 15:e1fea7e2aff1 | 87 | #if 0 |
manumaet | 21:23bf4399020d | 88 | pc.printf("%d Waiting... %d %d ", i, dw.receiving, dw.sending); |
manumaet | 15:e1fea7e2aff1 | 89 | wait(5); |
manumaet | 15:e1fea7e2aff1 | 90 | #endif |
manumaet | 24:6f25ba679490 | 91 | wait(1); |
manumaet | 22:576ee999b004 | 92 | //pc.printf("Status: %010llX\r\n", dw.getStatus()); |
manumaet | 24:6f25ba679490 | 93 | //pc.printf("State: %010llX\r\n", dw.readRegister40(DW1000_SYS_STATE, 0)); |
manumaet | 15:e1fea7e2aff1 | 94 | i++; |
manumaet | 0:f50e671ffff7 | 95 | } |
manumaet | 0:f50e671ffff7 | 96 | } |