Tobi's ubw test branch

Dependencies:   mavlink_bridge mbed

Fork of AIT_UWB_Range by Benjamin Hepp

main.cpp

Committer:
manumaet
Date:
2014-12-27
Revision:
34:f56962030c5c
Parent:
33:6ea4c3dd504d
Child:
35:95d838d33bf5

File content as of revision 34:f56962030c5c:

// by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
#include "mbed.h"
#include "PC.h"                                     // Serial Port via USB for debugging with Terminal
#include "DW1000.h"                                 // our DW1000 device driver
#include "MMRanging.h"                              // our self developed raning application

PC          pc(USBTX, USBRX, 921600);               // USB UART Terminal
DW1000      dw(PA_7, PA_6, PA_5, PB_6, PB_9);       // Device driver instanceSPI pins: (MOSI, MISO, SCLK, CS, IRQ)
MMRanging   r(dw);                                  // Ranging class for getting distances and later positions

char message[100] = "";

int main() {
    pc.printf("DecaWave 0.2\r\nup and running!\r\n");  
    dw.setEUI(0xFAEDCD01FAEDCD01);                                  // basic methods called to check if we have a working SPI connection
    pc.printf("DEVICE_ID register: 0x%X\r\n", dw.getDeviceID());
    pc.printf("EUI register: %016llX\r\n", dw.getEUI());
    pc.printf("Voltage: %f\r\n", dw.getVoltage());
    pc.printf("Size of Frame: %d\r\n", sizeof(r.TX));
    
    uint16_t setdelay = 65500;
    dw.writeRegister16(DW1000_TX_ANTD, 0, setdelay);
    pc.printf("Antenna Delay TX: %d\r\n", dw.readRegister16(DW1000_TX_ANTD, 0));
    pc.printf("Antenna Delay RX: %d\r\n", dw.readRegister16(DW1000_LDE_CTRL, 0x1804));
    r.receiver = true;
    
    bool senderstart = true;
    while(1) {
        for(int j = 0; j < 10; j++)
            pc.printf("%d ", (unsigned int)r.tofs[j]);
        pc.printf("\r\n");
        for(int j = 0; j < 10; j++)
            if(r.event[j][0] == '!') {
                pc.printf("%s Time: %lldus\r\n", r.event[j], r.eventtimes[j]);
                r.event[j][0] = 'X';
            }    
        if (!r.receiver) {
                if(senderstart)
                    r.requestRanging();
                else
                    r.requestTime();
                senderstart = !senderstart;
        }
        pc.printf("Status: %llX\r\n", dw.getStatus());
        wait(2);
    }
}