Test

Files at this revision

API Documentation at this revision

Comitter:
HelGast95
Date:
Fri Feb 01 14:08:20 2019 +0000
Parent:
79:9f3aca04de4e
Child:
81:dded8c042cca
Commit message:
Se soluciona lo de enviar mas de 20 bytes

Changed in this revision

mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
module.json Show annotated file Show diff for this revision Revisions of this file
readme.md Show diff for this revision Revisions of this file
source/TOFService.h Show annotated file Show diff for this revision Revisions of this file
source/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/mbed-os.lib	Thu Jan 31 12:55:00 2019 +0000
+++ b/mbed-os.lib	Fri Feb 01 14:08:20 2019 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#2fd0c5cfbd83fce62da6308f9d64c0ab64e1f0d6
+https://github.com/ARMmbed/mbed-os/#a8d1d26fa76a27263cc9a69f65df45e3458517a5
--- a/module.json	Thu Jan 31 12:55:00 2019 +0000
+++ b/module.json	Fri Feb 01 14:08:20 2019 +0000
@@ -1,7 +1,7 @@
 {
-  "name": "ble-heartrate",
+  "name": "BLE Controller",
   "version": "0.0.1",
-  "description": "BLE Heartreate example, building with yotta",
+  "description": "BLE Controller,
   "licenses": [
     {
       "url": "https://spdx.org/licenses/Apache-2.0",
--- a/readme.md	Thu Jan 31 12:55:00 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-# BLE Heart Rate Monitor
-
-This application transmits a heart rate value using the [Bluetooth SIG Heart Rate Profile](https://developer.bluetooth.org/TechnologyOverview/Pages/HRP.aspx). The heart rate value is provided by the application itself, not by a sensor, so that you don't have to get a sensor just to run the example.
-
-Technical details are better presented [in the mbed Classic equivalent of this example](https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_HeartRate/).
-
-# Running the application
-
-## Requirements
-
-To see the heart rate information on your phone, use a BLE scanner:
-
-- [nRF Master Control Panel](https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp) for Android.
-
-- [LightBlue](https://itunes.apple.com/gb/app/lightblue-bluetooth-low-energy/id557428110?mt=8) for iPhone.
-
-Hardware requirements are in the [main readme](https://github.com/ARMmbed/mbed-os-example-ble/blob/master/README.md).
-
-## Building instructions
-
-Building instructions for all samples are in the [main readme](https://github.com/ARMmbed/mbed-os-example-ble/blob/master/README.md).
-
-## Checking for success
-
-**Note:** Screens captures depicted below show what is expected from this example if the scanner used is *nRF Master Control Panel* version 4.0.5. If you encounter any difficulties consider trying another scanner or another version of nRF Master Control Panel. Alternative scanners may require reference to their manuals.
-
-1. Build the application and install it on your board as explained in the building instructions.
-1. Open the BLE scanner on your phone.
-1. Start a scan.
-
-    ![](img/start_scan.png)
-
-    **figure 1** How to start scan using nRF Master Control Panel 4.0.5
-
-1. Find your device; it should be named `HRM`.
-
-    ![](img/scan_result.png)
-
-    **figure 2** Scan results using nRF Master Control Panel 4.0.5
-
-1. Establish a connection with your device.
-
-    ![](img/connection.png)
-
-    **figure 3**  How to establish a connection using Master Control Panel 4.0.5
-
-1. Discover the services and the characteristics on the device. The *Heart Rate* service has the UUID `0x180D` and includes the *Heart Rate Measurement* characteristic which has the UUID `0x2A37`.
-
-    ![](img/discovery.png)
-
-    **figure 4** Representation of the Heart Rate service using Master Control Panel 4.0.5
-
-1. Register for the notifications sent by the *Heart Rate Measurement* characteristic.
-
-    ![](img/register_to_notifications.png)
-
-    **figure 5** How to register to notifications using Master Control Panel 4.0.5
-
-
-1. You should see the heart rate value change every half second. It begins at 100, goes up to 175 (in steps of 1), resets to 100 and so on.
-
-    ![](img/notifications.png)
-
-    **figure 6** Notifications view using Master Control Panel 4.0.5
--- a/source/TOFService.h	Thu Jan 31 12:55:00 2019 +0000
+++ b/source/TOFService.h	Fri Feb 01 14:08:20 2019 +0000
@@ -5,17 +5,15 @@
 
 class TOFService {
     public:
-        const static uint8_t    TOF_CHAR_ARRAY_SIZE                   =    100;
+        const static uint16_t   TOF_CHAR_ARRAY_SIZE                   =    100;
         const static uint16_t   CUSTOM_TOF_SERVICE_UUID               = 0xA000;
         const static uint16_t   TOF_CHAR_WRITE_CHARACTERISTIC_UUID    = 0xA001;
         
         TOFService(BLE& _ble) :
             ble(_ble),
-            //writeCharArrayCharacteristic(TOF_CHAR_WRITE_CHARACTERISTIC_UUID, writeValue)
-            writeCharArrayCharacteristic(TOF_CHAR_WRITE_CHARACTERISTIC_UUID, writeBuffer, 1, 100,
-                         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_EXTENDED_PROPERTIES)
+            writeCharArrayCharacteristic(TOF_CHAR_WRITE_CHARACTERISTIC_UUID, writeBuffer)
         {
-            static bool serviceAdded = false; /* We should only ever need to add the information service once. */
+            static bool serviceAdded = false;
             if (serviceAdded) {
                 return;
             }
@@ -37,8 +35,7 @@
     
         uint8_t writeBuffer[TOF_CHAR_ARRAY_SIZE];
     
-        //WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(writeBuffer)> writeCharArrayCharacteristic;
-        GattCharacteristic writeCharArrayCharacteristic;
+        WriteOnlyArrayGattCharacteristic<uint8_t, sizeof(writeBuffer)> writeCharArrayCharacteristic;
 };
 
 #endif /* #ifndef __BLE_TOF_SERVICE_H__*/
\ No newline at end of file
--- a/source/main.cpp	Thu Jan 31 12:55:00 2019 +0000
+++ b/source/main.cpp	Fri Feb 01 14:08:20 2019 +0000
@@ -1,5 +1,4 @@
 #define END_OF_JSON          0xFE
-#define MAC_FILTER           0x8E
 #define VERBOSE_MODE            1  // Habilita la generacion de logs por el puerto USB      
 
 #include "mbed.h"
@@ -20,8 +19,9 @@
 char finalCharacterJSON    = END_OF_JSON;
 
 typedef struct {
-    string           MAC;       /* Dirección MAC */
-    float            ToF;       /* Tiempo de vuelo */
+    string           MAC1;       /* Dirección MAC1*/
+    string           MAC2;       /* Dirección MAC2*/
+    double            ToF;       /* Tiempo de vuelo*/
 } BLEdata_t;
 
 DigitalOut led3Test(LED3);
@@ -31,12 +31,13 @@
 TOFService* tofService;
 
 EventQueue eventQueue;
+//Queue<EventData_t, 32> Eventqueue; WIP
 Queue<BLEdata_t, 32> BLEqueue;
 MemoryPool<BLEdata_t, 32> BLEmpool;
 
-Thread threadLED(osPriorityAboveNormal1, 1000);
+Thread threadLED(osPriorityAboveNormal1, 400);
 Thread threadSerial(osPriorityAboveNormal2, 2500);
-Thread threadBLE(osPriorityRealtime3, 1000);
+Thread threadBLE(osPriorityRealtime3, 2500);
 
 template<typename arg>
 void printLog(const char * log, arg data) {
@@ -88,7 +89,7 @@
             BLEmpool.free(BLEdata);
                 
             int type = rand() % 4;
-            event["idEvent"] = picojson::value(BLEdata->MAC);
+            event["idEvent"] = picojson::value(BLEdata->MAC1);
             event["type"] = picojson::value((double) type);
             str = "E9:ED:F4:AC:BF:8E";
             extraInfo["hazardousDevice"] = picojson::value(str);
@@ -119,18 +120,42 @@
     printLog("Conectado al servidor\r\n");    
 }
 
+void parseRawJSONToQueue(string JSONsource) {
+    picojson::value v;
+    string err;
+    BLEdata_t* data = BLEmpool.alloc();
+    
+    picojson::parse(v, JSONsource.c_str(), JSONsource.c_str() + strlen(JSONsource.c_str()), &err);
+    printLog("res error? %s\r\n", err);
+    
+    data->ToF  = v.get("TOF").get<double>();
+    data->MAC1 = v.get("MAC1").get<string>();
+    data->MAC2 = v.get("MAC2").get<string>();
+    
+    printLog("ToF = %f", data->ToF);
+    printLog(" MAC1 = %s", data->MAC1);
+    printLog(" MAC2 = %s\r\n", data->MAC2);
+    
+    //EventQueue.put(data); WIP
+}
+
 void writeCharCallback(const GattWriteCallbackParams *params) {
     if(params->handle == tofService->getValueHandle()) {
-        char toChar [TOFService::TOF_CHAR_ARRAY_SIZE + 1];
+        //BLEdata_t* data = BLEmpool.alloc();
+        //BLEdata_t data;
+        char toChar [TOFService::TOF_CHAR_ARRAY_SIZE];
         printLog("Data received: length = %d, data = 0x", params->len);
         for(int x=0; x < params->len; x++) {
             toChar[x] = (char) params->data[x];
             printLog("%x", params->data[x]);
         }
-        toChar[params->len] = '\0';
+        //toChar[params->len] = '\0';
+        printLog("\n\r");
+        
+        printLog("Cadena: %s\n\r", toChar);
         string str(toChar);
-        printLog("\n\r");
-        printLog("Dato parseado a string: %s\n\r", str);
+        eventQueue.call(parseRawJSONToQueue, str);
+        //BLEqueue.put(data);
     }
 }
 
@@ -141,18 +166,6 @@
     printLog("Ha ocurrido un error al inicializar la configuracion del BLE\n");
 }
 
-void printMacAddress() {
-    /* Print out device MAC address to the console*/
-    Gap::AddressType_t addr_type;
-    Gap::Address_t address;
-    BLE::Instance().gap().getAddress(&addr_type, address);
-    printLog("DEVICE MAC ADDRESS: ");
-    for (int i = 5; i >= 1; i--){
-        printLog("%02x:", address[i]);
-    }
-    printLog("%02x\r\n", address[0]);
-}
-
 /**
  * Callback triggered when the ble initialization process has finished
  */
@@ -198,7 +211,7 @@
     srand(time(NULL));
     threadLED.start(callback(blinkLED3));
     threadBLE.start(callback(BLEServiceManagment));
-    //threadSerial.start(callback(sendJsonOverSerial));
+    //threadSerial.start(callback(sendJsonOverSerial)); WIP
             
     threadLED.join();
     threadBLE.join();