![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
This is a basic program that provides the necessary BLE service to allow communications with the UPAS
Dependencies: BLE_API mbed nRF51822 CronoDot EEPROM NCP5623BMUTBG ADS1115 BME280 Calibration_one MCP40D17 SDFileSystem LSM303 SI1145 STC3100
Fork of BLE_Button by
Diff: main.cpp
- Revision:
- 11:1058647c66e8
- Parent:
- 10:66549fa08986
- Child:
- 12:27273e6a50b3
--- a/main.cpp Tue Oct 20 20:38:04 2015 +0000 +++ b/main.cpp Fri Oct 23 02:44:23 2015 +0000 @@ -3,9 +3,49 @@ #include "mbed.h" #include "BLE.h" #include "UPAS_Service.h" +#include "EEPROM.h" +#include "CronoDot.h" +#include "NCP5623BMUTBG.h" BLE ble; -DigitalOut led1(LED1); //Use of leds is important for debugging +//DigitalOut led1(LED1); //Use of leds is important for debugging +DigitalOut blower(p29, 0); +DigitalOut pbKill(p18, 1); +DigitalOut GPS_EN(p4,0); +EEPROM E2PROM(p22, p20); +CronoDot RTC(p22, p20); +NCP5623BMUTBG RGB_LED(p22, p20); +/*EEPROM ADDRESSING: + 0:Status bit-Unused + 1-15:Device Name + 16-19:Flow Rate + 20: Data Log Interval + 21-26: Start Time: ssmmHHddMMyy + 27-32: Stop Time: ssmmHHddMMyy + 33: Duty Up + 34: Duty Down + 35-38: Home Latitude + 39-42: Home Longitude + 43-46: Work Latitude + 47-50: Work Longitude + 51: Runready: Currently useless, should be 0 + 52-53: Device Calibration + 54: Consider RunReady + 55-56: Menu Options + 57+ Nothing*/ +// .write(uint32_t addr, uint8_t dt[], uint16_t length); +// addr -- is where the data in dt[] will be stored, max of 0x3FFFF, 0x00000 to 0x1FFFF on EEPROM 1 and 0x20000 to 0x3FFFF on EEPROM 2 +// dt[] -- is unit8_t array that contains the data to be stored. This can only be uint8_t types, single bytes +// length -- is the number of bytes to save t the EEPROM, starting at dt[0] +// +// returns: +// Ture(1) -- when if has finished saving the data +// False(0) -- when length is to long to fit on the remainder of the page, when this happens it does not save any data in order to avoid over writing past data +// +// .read(uint32_t addr, uint8_t *rt_data, uint16_t length); +// addr -- where the data is requested from, max of 0x3FFFF, 0x00000 to 0x1FFFF on EEPROM 1 and 0x20000 to 0x3FFFF on EEPROM 2 +// rt_data -- a local variable where the data from the EEPROM should be stored, again in uint8_t types +// length -- how much to read from the EERPOM, this may be limited to <256 bytes? const static char DEVICE_NAME[] = "UPAS"; //Will hold the actual name of the whichever UPAS is being connected to static const uint16_t uuid16_list[] = {UPAS_Service::UPAS_SERVICE_UUID}; //Currently a custom 16-bit representation of 128-bit UUID @@ -19,37 +59,46 @@ void periodicCallback(void) { - led1 = !led1; /* Do blinky on LED1 to indicate system aliveness. */ + // led1 = !led1; /* Do blinky on LED1 to indicate system aliveness. */ } - +void readCharCallin(const GattReadCallbackParams *eventDataP) +{ + RTC.get_time(); +} void writeCharCallback(const GattWriteCallbackParams *params) { - led1 = !led1; /* Do blinky on LED1 to indicate system aliveness. */ + // led1 = !led1; /* Do blinky on LED1 to indicate system aliveness. */ // check to see what characteristic was written, by handle if(params->handle == upasServicePtr->writeChar.getValueHandle()) { // toggle LED if only 1 byte is written if(params->len == 1) { - led1 = params->data[0]; + //led1 = params->data[0]; } // update the readChar with the value of writeChar ble.updateCharacteristicValue(upasServicePtr->readChar.getValueHandle(),params->data,params->len); + uint8_t *writeData = const_cast<uint8_t*>(params->data); + + E2PROM.write(0x00015, writeData+6, 12); + RTC.set_time(writeData[0],writeData[1],writeData[2],writeData[3],writeData[3],writeData[4],writeData[5]); } } int main(void) { - led1 = 1; + // led1 = 1; Ticker ticker; ticker.attach(periodicCallback, 1); - - uint8_t readValues[57] = {0x31,0x30,0x2F,0x31,0x38,0x2F,0x31,0x35,0x20,0x31,0x32,0x3A,0x30,0x30,0x3A,0x30,0x30}; //dummy array for testing + RGB_LED.set_led(1,1,1); + RTC.get_time(); + uint8_t newReadValues[20] = {RTC.seconds, RTC.minutes,RTC.hour,RTC.date,RTC.month,RTC.year}; + E2PROM.read(0x00015, newReadValues+6, 12); ble.init(); ble.gap().onDisconnection(disconnectionCallback); ble.gattServer().onDataWritten(writeCharCallback); //add writeCharCallback (custom function) to whenever data is being written to device - - UPAS_Service upasService(ble, false,readValues); //Create a GattService that is defined in UPAS_Service.h + ble.gattServer().onDataRead(readCharCallin); + UPAS_Service upasService(ble, false,newReadValues); //Create a GattService that is defined in UPAS_Service.h upasServicePtr = &upasService; //Create a pointer to the service (Allows advertisement without specifically adding the service /* setup advertising