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 Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
jelord
Date:
Mon Oct 26 21:27:48 2015 +0000
Parent:
11:1058647c66e8
Child:
13:b43ec7e0cc1d
Commit message:
Added characteristic to UPAS_SERVICE.h that advertises the subject label from the EEPROM

Changed in this revision

ADS1115.lib Show annotated file Show diff for this revision Revisions of this file
BME280.lib Show annotated file Show diff for this revision Revisions of this file
Calibration.lib Show annotated file Show diff for this revision Revisions of this file
LSM303.lib Show annotated file Show diff for this revision Revisions of this file
MCP40D17.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
STC3100.lib Show annotated file Show diff for this revision Revisions of this file
UPAS_Service.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADS1115.lib	Mon Oct 26 21:27:48 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Vockens-Group-Sensors/code/ADS1115/#3c1800eec725
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BME280.lib	Mon Oct 26 21:27:48 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/MACRUM/code/BME280/#ddcaa259e65b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Calibration.lib	Mon Oct 26 21:27:48 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/Vockens-Group-Sensors/code/Calibration/#f6493d2aedcf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM303.lib	Mon Oct 26 21:27:48 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Vockens-Group-Sensors/code/LSM303/#b582a3225455
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP40D17.lib	Mon Oct 26 21:27:48 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Vockens-Group-Sensors/code/MCP40D17/#872f6e451bfd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Mon Oct 26 21:27:48 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/neilt6/code/SDFileSystem/#2286a4e7fa31
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/STC3100.lib	Mon Oct 26 21:27:48 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Vockens-Group-Sensors/code/STC3100/#6ef1baca49e6
--- a/UPAS_Service.h	Fri Oct 23 02:44:23 2015 +0000
+++ b/UPAS_Service.h	Mon Oct 26 21:27:48 2015 +0000
@@ -6,19 +6,27 @@
 
 class UPAS_Service {
 public:
-    const static uint16_t UPAS_SERVICE_UUID                     = 0xA000; //UUID of Service.  Following two are read/write characteristics of the service
-    const static uint16_t WRITE_STATE_CHARACTERISTIC_UUID       = 0xA002; //UUID for variable that app will write to
-    const static uint16_t READ_STATE_CHARACTERISTIC_UUID        = 0xA003; //UUID of variable that app will read from
-    GattCharacteristic                readChar;
-    GattCharacteristic                writeChar;
+    //All Characteristics shall have a read/write counterpart protocol.  This should prevent corruption of data.  
+    const static uint16_t UPAS_SERVICE_UUID                     = 0xA000; //UUID of Service.
+    
+    const static uint16_t RTC_CHARACTERISTIC_UUID               = 0xA002; //UUID for characteristic to write the RTC to 
+    GattCharacteristic                rtcCharacteristic;
+    
+    const static uint16_t SAMPLETIME_CHARACTERISTIC_UUID        = 0xA003; //UUID of variable that app will read from
+    GattCharacteristic                sampleTimeCharacteristic;
+    
+    const static uint16_t SUBJECTLABEL_CHARACTERISTIC_UUID      = 0xA004; //UUID of variable that app will read from
+    GattCharacteristic                subjectLabelCharacteristic;
 
 
-    UPAS_Service(BLE &_ble, bool placeholder, uint8_t *tempArray) :
-        ble(_ble), readChar(READ_STATE_CHARACTERISTIC_UUID, tempArray,18,20,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
-        writeChar(WRITE_STATE_CHARACTERISTIC_UUID, tempArray,18,20,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
+    UPAS_Service(BLE &_ble, bool placeholder, uint8_t *rtc, uint8_t *sampleTime, uint8_t *subjectLabel) :
+        ble(_ble), 
+        rtcCharacteristic(RTC_CHARACTERISTIC_UUID, rtc,6,20, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        sampleTimeCharacteristic(SAMPLETIME_CHARACTERISTIC_UUID, sampleTime,12,20,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        subjectLabelCharacteristic(SUBJECTLABEL_CHARACTERISTIC_UUID, subjectLabel,15,20,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
     {
         
-        GattCharacteristic *charTable[] = {&writeChar, &readChar}; //Set up characteristics to be broadcasted with the UPAS service
+        GattCharacteristic *charTable[] = {&rtcCharacteristic, &sampleTimeCharacteristic}; //Set up characteristics to be broadcasted with the UPAS service
         GattService         upasService(UPAS_Service::UPAS_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); //Finally, construct the service
         ble.gattServer().addService(upasService);
     }
--- a/main.cpp	Fri Oct 23 02:44:23 2015 +0000
+++ b/main.cpp	Mon Oct 26 21:27:48 2015 +0000
@@ -6,6 +6,13 @@
 #include "EEPROM.h"
 #include "CronoDot.h"
 #include "NCP5623BMUTBG.h"
+#include "SDFileSystem.h"
+#include "Adafruit_ADS1015.h"
+#include "MCP40D17.h"
+#include "STC3100.h"
+#include "LSM303.h"
+#include "BME280.h"
+#include "Calibration.h"
 
 BLE         ble;
 //DigitalOut  led1(LED1); //Use of leds is important for debugging
@@ -14,7 +21,14 @@
 DigitalOut          GPS_EN(p4,0); 
 EEPROM              E2PROM(p22, p20);
 CronoDot            RTC(p22, p20);  
-NCP5623BMUTBG       RGB_LED(p22, p20);          
+NCP5623BMUTBG       RGB_LED(p22, p20);   
+Calibration         calibrations(1);     //Default serial/calibration if there are no values for the selected option
+LSM303              movementsensor(p22, p20);
+I2C                 i2c(p22, p20);
+Adafruit_ADS1115    ads(&i2c);
+MCP40D17            DigPot(&i2c);
+BME280              bmesensor(p22, p20);
+STC3100             gasG(p22, p20);       
 /*EEPROM ADDRESSING:
     0:Status bit-Unused
     1-15:Device Name
@@ -33,25 +47,61 @@
     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?
 
+Timeout         stop;   //This is the stop call back object
+Timeout         logg;   //This is the logging call back object
 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
 
 UPAS_Service *upasServicePtr;
 
+float press,temp,rh;
+int uv,vis,ir;
+float accel_x ,accel_y ,accel_z,angle_x,angle_y,angle_z,compass,accel_comp,mag_x,mag_y,mag_z,massflow,volflow,omronVolt,atmoRho;
+
+int vInReading,vBlowerReading,omronDiff,omronReading,logInerval = 10;
+
+float volflowSet = 1.0; 
+//int   logInerval = 10;
+double secondsD = 0,lastsecondD = 0;
+float massflowSet;
+float deltaVflow = 0.0,deltaMflow = 0.0;
+float gainFlow;
+float sampledVol; //L, total sampled volume
+
+int digital_pot_setpoint,digital_pot_set,digital_pot_change; //min = 0x7F, max = 0x00
+int digitalpotMax = 127;
+int digitalpotMin = 2;
+
+int dutyUp,dutyDown;
+
+// variables are only place holders for the US_Menu //
+int refreshtime;
+float home_lat, home_lon, work_lat, work_lon;
+//*************************************************//
+
+char device_name[] = "---------------";
+char filename[] = "/sd/XXXX0000LOG000000000000---------------.txt";
+SDFileSystem sd(SPIS_PSELMOSI, SPIS_PSELMISO, SPIS_PSELSCK, SPIS_PSELSS, "sd");
+
+//FLAG: NEED FOR MY CODE
+//void check_stop()   // this checks if it's time to stop and shutdown
+//{
+//
+//    if(RTC.compare(Menu.f_sec, Menu.f_min, Menu.f_hour, Menu.f_day, Menu.f_month, Menu.f_year)) {
+//        pbKill = 0; // this is were we shut everything down
+//        printf("If you're reading this something has gone very wrong.");
+//    }
+//    stop.detach();
+//    stop.attach(&check_stop, 9);
+//}
+
+
+
+
+
+
+//MARK: THIS IS ALL CODE NOT TAKEN FROM OTHER MENU>>>DONT ALTER!!!
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)//Code called when mbed ble senses a disconnect
 {
     ble.gap().startAdvertising();
@@ -63,24 +113,24 @@
 }
 void readCharCallin(const GattReadCallbackParams *eventDataP)
 {
-     RTC.get_time();
+    RTC.get_time();
+    const uint8_t refreshPassValues[6] = {RTC.seconds, RTC.minutes,RTC.hour,RTC.date,RTC.month,RTC.year};
+    ble.updateCharacteristicValue( upasServicePtr->rtcCharacteristic.getValueHandle(),refreshPassValues,6);
 }
-void writeCharCallback(const GattWriteCallbackParams *params)
+void writeCharacteristicCallback(const GattWriteCallbackParams *params)
 {
- //   led1 = !led1; /* Do blinky on LED1 to indicate system aliveness. */
-    
+    uint8_t *writeData =  const_cast<uint8_t*>(params->data);
     // 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];
-        }
-        // 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);
+    if(params->handle == upasServicePtr->rtcCharacteristic.getValueHandle()) {
+
+        //ble.updateCharacteristicValue(upasServicePtr->readChar.getValueHandle(),params->data,params->len);
+        
+       // E2PROM.write(0x00015, writeData+6, 12);
         RTC.set_time(writeData[0],writeData[1],writeData[2],writeData[3],writeData[3],writeData[4],writeData[5]);
+   
+    }else if(params->handle == upasServicePtr->sampleTimeCharacteristic.getValueHandle()){
+        
+        E2PROM.write(0x00015, writeData, 12);
     }
 }
 
@@ -91,14 +141,17 @@
     ticker.attach(periodicCallback, 1);
     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);
+    uint8_t rtcPassValues[6] = {RTC.seconds, RTC.minutes,RTC.hour,RTC.date,RTC.month,RTC.year};
+    uint8_t sampleTimePassValues[12] = {0,};
+    uint8_t subjectLabelOriginal[15] = {0,};
+    E2PROM.read(0x00015, sampleTimePassValues, 12);
+    E2PROM.read(0x00001, subjectLabelOriginal,15);
 
     ble.init();
     ble.gap().onDisconnection(disconnectionCallback);
-    ble.gattServer().onDataWritten(writeCharCallback); //add writeCharCallback (custom function) to whenever data is being written to device
+    ble.gattServer().onDataWritten(writeCharacteristicCallback); //add writeCharCallback (custom function) to whenever data is being written to device
     ble.gattServer().onDataRead(readCharCallin);
-    UPAS_Service upasService(ble, false,newReadValues); //Create a GattService that is defined in UPAS_Service.h
+    UPAS_Service upasService(ble, false,rtcPassValues,sampleTimePassValues,subjectLabelOriginal); //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