Firmware for the mbed in the BlueSync Sensor platform. Intended to communicate with a BlueGiga BLE112 Bluetooth LE module over UART.

Dependencies:   TimerCapture mbed

main.cpp

Committer:
dishbreak
Date:
2015-05-24
Revision:
1:cb941edd7bce
Parent:
0:2bc22bc992ac
Child:
2:ac474fccf29b

File content as of revision 1:cb941edd7bce:

#include "mbed.h"
#include "TimerCapture.h"
#include "bluesync_types.h"

/** @file main.cpp
@brief Main for the BlueSync mbed application. */

Serial ble112(p9, p10); ///< Serial connection for communicating with the BLE112.
TimerCapture * capPin; ///< Capture pin, wired to GPIO pin on BLE112.
DigitalOut bleScanningLed(LED1);

void on_serial_rcv() {
    ble112.getc();
    uint8_t hw_addr[6];
    for (int i = 5; i >=0; i--) {
        hw_addr[i] = ble112.getc();
    }
    
    printf("***************\r\n");
    printf("HW Addr: %02x:%02x:%02x:%02x:%02x:%02x ", 
        hw_addr[0], 
        hw_addr[1], 
        hw_addr[2], 
        hw_addr[3], 
        hw_addr[4], 
        hw_addr[5]);
    printf("Obs At: %d\r\n", capPin->getTime());
    
    intByteArray bitArray;
    bitArray.integer = capPin->getTime();
    
    for (int i = 3; i >= 0; i--) {
        ble112.putc(bitArray.byte[i]);
    }
}

int main() {
    TimerCapture::startTimer();
    capPin = new TimerCapture(p30);
    ble112.baud(115200);
    ble112.set_flow_control(SerialBase::RTSCTS, p7, p8);
    ble112.attach(&on_serial_rcv);
}