new version for central test two peripherals

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_Nano_Central_Type3 by Francesco Pavoni

Revision:
5:68a31613f28a
Parent:
4:722dfc6fe1de
Child:
6:d37a6e3c17c4
--- a/main.cpp	Wed Jun 01 15:18:25 2016 +0000
+++ b/main.cpp	Thu Jun 02 10:17:33 2016 +0000
@@ -38,7 +38,7 @@
 static uint8_t service1_chars3[]  = {0x71, 0x3D, 0, 4, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
 
 
-UUID service_uuid(0x180D);
+UUID service_uuid(0x180D); // (1) this change in sensor PWM 
 UUID chars_uuid1(0x2A37);
 UUID chars_uuid2(service1_chars2);
 UUID chars_uuid3(service1_chars3);
@@ -78,6 +78,8 @@
 
 uint32_t ble_advdata_parser(uint8_t type, uint8_t advdata_len, uint8_t *p_advdata, uint8_t *len, uint8_t *p_field_data)
 {
+       pc.printf("ble_advdata_parse  \r\n");
+
     uint8_t index=0;
     uint8_t field_length, field_type;
     
@@ -91,8 +93,10 @@
             *len = field_length - 1;
             return NRF_SUCCESS;
         }
+        pc.printf("FOUND  \r\n");
         index += field_length + 1;
     }
+     pc.printf("NRF_ERROR_NOT_FOUND  \r\n");
     return NRF_ERROR_NOT_FOUND;
 }
 
@@ -125,6 +129,7 @@
    *
    * @return   BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error.
    */
+   pc.printf("start discovery \r\n");
   if(device_is_hrm)
     ble.gattClient().launchServiceDiscovery(handle, discoveredServiceCallBack, discoveredCharacteristicCallBack, service_uuid, chars_uuid1);
   if(device_is_simple_peripheral)
@@ -161,9 +166,11 @@
                 gs_peripheral[i].deviceName = adv_name;
                 ble.connect(params->peerAddr, BLEProtocol::AddressType::RANDOM_STATIC, NULL, NULL);
                 // new edit add FP
+                // (2) Make set name peripheral with button
                 if( memcmp("TXRX", adv_name, 4) == 0x00 ) {
                           device_is_simple_peripheral = 1;
                     }
+                    // (3) make set name peripheral with sensor 
                     if(memcmp("Nordic_HRM", adv_name, 10) == 0x00) {
                               device_is_hrm = 1;
                         }
@@ -226,6 +233,7 @@
   
   //Comment 3
   // check is set Ok
+     pc.printf("connectionCallBack \r\n");
   startDiscovery(params->handle);
 }
 
@@ -243,7 +251,8 @@
  
 void disconnectionCallBack(const Gap::DisconnectionCallbackParams_t *params) {
  // Serial.println("Disconnected, start to scanning");
- 
+      pc.printf("Disconnected, start to scanning \r\n");
+
  // New edit FP
   device_is_simple_peripheral = 0;
   device_is_hrm = 0;
@@ -254,7 +263,7 @@
   
   pc.printf("disconnected\r\n");
     
-    for(uint8_t i=0; i<3; i++){
+    for(uint8_t i=0; i<2; i++){
         if(gs_peripheral[i].handle == params->handle){
             gs_peripheral[i].connected = false;
             gs_peripheral[i].handle = 0xFFFF;
@@ -293,7 +302,7 @@
     pc.printf("characteristicDiscoveryCallback\r\n");
     
     //accelChar = *characteristicP;
-    
+    // (4) change serial.print -> println how make ?
     // New edit FP
     if(characteristicP->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) {
     //Serial.println(chars->getUUID().getShortUUID(), HEX);
@@ -410,11 +419,19 @@
   Serial.println(params->offset, DEC);
   Serial.print("The len : ");
   Serial.println(params->len, DEC);
-  Serial.print("The data : ");
+  Serial.print("The data : ");*/
+  
+    pc.printf("triggerRead.....\r\n");
+    pc.printf("len: %d\r\n", params->len);
+    const uint8_t *data = params->data;
+    pc.printf("data ");
+  
   for(uint8_t index=0; index<params->len; index++) {
-    Serial.print( params->data[index], HEX);
+    //Serial.print( params->data[index], HEX);
+     pc.printf("%f ", (float)data[index]);  
   }
-  Serial.println("");*/
+    pc.printf("\r\n");
+  //Serial.println("");
 }
 
 /** @brief  hvx callback handle
@@ -431,14 +448,16 @@
  // delete Cooment
  /* Serial.println("GattClient notify call back ");
   Serial.print("The len : ");
-  Serial.println(params->len, DEC);
+  Serial.println(params->len, DEC);*/
   for(unsigned char index=0; index<params->len; index++) {
-    Serial.print(params->data[index], HEX);
+    //Serial.print(params->data[index], HEX);
+    pc.printf("%f ", (float)params->data[index]);  
   }
-  Serial.println("");*/
+  // Serial.println("");
 }
 
-void triggerRead(const GattReadCallbackParams *response) {
+// Option
+/*void triggerRead(const GattReadCallbackParams *response) {
     pc.printf("triggerRead.....\r\n");
     
     pc.printf("len: %d\r\n", response->len);
@@ -450,7 +469,7 @@
     pc.printf("\r\n");
     // Comment property
     //accelChar.read();
-}
+}*/
 
 // is set before
 /*void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params){
@@ -470,6 +489,8 @@
     pc.baud(9600);
     wait(8.0);
     pc.printf("start\r\n");
+    pc.printf("Avvio start\r\n");
+
 
     ble.init();
 
@@ -504,12 +525,13 @@
   */
 
     while (true) {
+        pc.printf("while true\r\n");
         ble.waitForEvent();
     }
 }
 
 // Altenativa
-void loop() {
+/*void loop() {
   // put your main code here, to run repeatedly:
   ble.waitForEvent();
-}
\ No newline at end of file
+}*/
\ No newline at end of file