Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
main.cpp@18:bbc7ca7d3a95, 2014-11-24 (annotated)
- Committer:
- manumaet
- Date:
- Mon Nov 24 16:48:03 2014 +0000
- Revision:
- 18:bbc7ca7d3a95
- Parent:
- 17:8afa5f9122da
- Child:
- 19:e94bc88c1eb0
many changes, sadly TX interrupt broken
Who changed what in which revision?
User | Revision | Line number | New 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 | 7:e634eeafc4d2 | 6 | DW1000 dw(D11, D12, D13, D10, D14); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ) |
manumaet | 0:f50e671ffff7 | 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 | 11:c87d37db2c6f | 11 | uint64_t timestamp_old = 0; |
manumaet | 14:8041c9b68406 | 12 | |
manumaet | 18:bbc7ca7d3a95 | 13 | void callbackRX(int framelength) { |
manumaet | 16:96879e1c99f2 | 14 | if(framelength<200) { |
manumaet | 16:96879e1c99f2 | 15 | char* receive = dw.receiveString(); // receive a string |
manumaet | 16:96879e1c99f2 | 16 | pc.printf("Received: \"%s\" %d ", receive, framelength); |
manumaet | 16:96879e1c99f2 | 17 | delete[] receive; |
manumaet | 16:96879e1c99f2 | 18 | } else |
manumaet | 16:96879e1c99f2 | 19 | pc.printf("Received! %d ", framelength); |
manumaet | 10:d077bb12d259 | 20 | |
manumaet | 18:bbc7ca7d3a95 | 21 | pc.printf("Status: %010llX ", dw.getStatus()); |
manumaet | 11:c87d37db2c6f | 22 | |
manumaet | 18:bbc7ca7d3a95 | 23 | uint64_t timestamp = dw.readRegister40(DW1000_RX_TIME, 0); |
manumaet | 11:c87d37db2c6f | 24 | uint64_t difference = timestamp - timestamp_old; |
manumaet | 11:c87d37db2c6f | 25 | timestamp_old = timestamp; |
manumaet | 15:e1fea7e2aff1 | 26 | //pc.printf("Timestamp: %lld\r\n", difference); |
manumaet | 15:e1fea7e2aff1 | 27 | pc.printf("Timestamp: %fs", difference*timeunit); // TODO: gives some wrong values because of timer overflow |
manumaet | 15:e1fea7e2aff1 | 28 | pc.printf("\r\n"); |
manumaet | 17:8afa5f9122da | 29 | dw.startRX(); |
manumaet | 6:d5864a1b9e17 | 30 | } |
manumaet | 6:d5864a1b9e17 | 31 | |
manumaet | 18:bbc7ca7d3a95 | 32 | void callbackTX() { |
manumaet | 18:bbc7ca7d3a95 | 33 | char messagecheck[1200]; |
manumaet | 18:bbc7ca7d3a95 | 34 | dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1); |
manumaet | 18:bbc7ca7d3a95 | 35 | if (i < 200) |
manumaet | 18:bbc7ca7d3a95 | 36 | pc.printf("%d Sent: \"%s\" %d ", i, messagecheck, strlen(message)+1); |
manumaet | 18:bbc7ca7d3a95 | 37 | else |
manumaet | 18:bbc7ca7d3a95 | 38 | pc.printf("%d Sent! %d ", i, strlen(message)+1); |
manumaet | 18:bbc7ca7d3a95 | 39 | pc.printf("Status: %010llX\r\n", dw.getStatus()); |
manumaet | 18:bbc7ca7d3a95 | 40 | } |
manumaet | 18:bbc7ca7d3a95 | 41 | |
manumaet | 0:f50e671ffff7 | 42 | int main() { |
manumaet | 0:f50e671ffff7 | 43 | pc.printf("DecaWave 0.1\r\nup and running!\r\n"); |
manumaet | 0:f50e671ffff7 | 44 | |
manumaet | 14:8041c9b68406 | 45 | dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a slave |
manumaet | 4:6240b9c7a033 | 46 | pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID()); |
manumaet | 4:6240b9c7a033 | 47 | pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI()); |
manumaet | 4:6240b9c7a033 | 48 | pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage()); |
manumaet | 0:f50e671ffff7 | 49 | |
manumaet | 12:985aa9843c3c | 50 | uint32_t conf = 0; // read System Configuration |
manumaet | 4:6240b9c7a033 | 51 | dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4); |
manumaet | 4:6240b9c7a033 | 52 | pc.printf("%d System Configuration: %X\r\n", i, conf); |
manumaet | 4:6240b9c7a033 | 53 | |
manumaet | 18:bbc7ca7d3a95 | 54 | dw.callbackRX = &callbackRX; // TODO: must not jump to NULL & setter |
manumaet | 18:bbc7ca7d3a95 | 55 | dw.callbackTX = &callbackTX; |
manumaet | 14:8041c9b68406 | 56 | |
manumaet | 14:8041c9b68406 | 57 | // Receiver initialisation |
manumaet | 18:bbc7ca7d3a95 | 58 | dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4080); // RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080 |
manumaet | 17:8afa5f9122da | 59 | dw.startRX(); |
manumaet | 5:111f11c95d27 | 60 | |
manumaet | 0:f50e671ffff7 | 61 | while(1) { |
manumaet | 18:bbc7ca7d3a95 | 62 | #if 0 |
manumaet | 17:8afa5f9122da | 63 | if(i < 1200) { |
manumaet | 17:8afa5f9122da | 64 | message[i] = 48+ (i%10); |
manumaet | 17:8afa5f9122da | 65 | message[i+1] = '\0'; |
manumaet | 17:8afa5f9122da | 66 | } |
manumaet | 16:96879e1c99f2 | 67 | |
manumaet | 16:96879e1c99f2 | 68 | //wait(0.1); |
manumaet | 10:d077bb12d259 | 69 | dw.sendString(message); |
manumaet | 15:e1fea7e2aff1 | 70 | |
manumaet | 17:8afa5f9122da | 71 | #endif |
manumaet | 15:e1fea7e2aff1 | 72 | #if 0 |
manumaet | 15:e1fea7e2aff1 | 73 | pc.printf("%d Waiting... ", i); |
manumaet | 18:bbc7ca7d3a95 | 74 | pc.printf("Status: %010llX ", dw.getStatus()); |
manumaet | 15:e1fea7e2aff1 | 75 | wait(5); |
manumaet | 15:e1fea7e2aff1 | 76 | #endif |
manumaet | 15:e1fea7e2aff1 | 77 | i++; |
manumaet | 0:f50e671ffff7 | 78 | } |
manumaet | 0:f50e671ffff7 | 79 | } |