Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: main.cpp
- Revision:
- 46:6398237672a0
- Parent:
- 45:01a33363bc21
- Child:
- 47:b6120c152ad1
--- a/main.cpp Sun Mar 08 15:59:14 2015 +0000 +++ b/main.cpp Tue Mar 10 12:11:13 2015 +0000 @@ -72,10 +72,20 @@ else myprintf("%f\r\n", node.distances[destination]); - } + } + +} -} +struct __attribute__((packed, aligned(1))) DistancesFrame { + uint8_t source; + uint8_t destination; + uint8_t type; + float dist[4]; + }; + + +void altCallbackRX(); // ----------------------------------------------------------------------------------------------- int main() { @@ -85,16 +95,20 @@ pc.printf("EUI register: %016llX\r\n", dw.getEUI()); pc.printf("Voltage: %fV\r\n", dw.getVoltage()); - node.isAnchor = false; + node.isAnchor = true; // declare as anchor or beacon if (node.isAnchor) { - node.address = 1; + node.address = 5; myprintf("This node is Anchor node %d \r\n", node.address); } else { node.address = 0; myprintf("This node is a Beacon. "); } + if (node.address == 5){ + dw.setCallbacks(&altCallbackRX, NULL); + } + while(1) { if (!node.isAnchor){ rangeAndDisplayAll(); @@ -102,9 +116,33 @@ + + }else - myprintf(".\r"); + //myprintf(".\r"); - wait(0.3); + wait(0.5); } -} \ No newline at end of file +} + + +void altCallbackRX(){ + + DistancesFrame distFrame; + float distances[4]; + dw.readRegister(DW1000_RX_BUFFER, 0, (uint8_t*)&distFrame, dw.getFramelength()); + + if (distFrame.destination == 5){ + for (int i = 0; i<4; i++){ + distances[i] = distFrame.dist[i]; + } + + for (int i = 0; i < 4; i++) { // Output Results + myprintf("%f, ", distances[i]); + + } + + myprintf("\r\n"); + } + dw.startRX(); +}