Ble Demo with Raspberry PI updated

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_DEMO_SPI by HM_IOT_Demo

Files at this revision

API Documentation at this revision

Comitter:
hmiot
Date:
Mon Oct 16 05:28:06 2017 +0000
Parent:
19:f5777473e125
Child:
21:a73c37ae9e7e
Commit message:
updated spi

Changed in this revision

Light_Header/hm_config.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
--- a/Light_Header/hm_config.h	Sat Oct 14 15:00:30 2017 +0000
+++ b/Light_Header/hm_config.h	Mon Oct 16 05:28:06 2017 +0000
@@ -31,7 +31,7 @@
 static ble_error_t error_status;
 bool serviceDiscover = true;
 bool first_on=true;
-int receiveBufSize = 0;
+
 bool read_flag = true;
 bool write_flag = false;
 bool disconnect_status = true;
--- a/main.cpp	Sat Oct 14 15:00:30 2017 +0000
+++ b/main.cpp	Mon Oct 16 05:28:06 2017 +0000
@@ -16,7 +16,9 @@
 uint8_t statusWR;
 uint8_t read_buffer[128];
 uint8_t nDiscoveredDevice = 0;
+static int receiveBufSize = 0;
 bool scanFlag = false;
+bool response_flag = false;
 bool first_connection = true;
 
 SPISlave spiSlave(P0_9, P0_11, P0_8, P0_10);
@@ -76,7 +78,7 @@
     
     while(scanFlag)
     {
-        wait(15.0);
+        wait(10.0);
         scanFlag = false;
         BLE::Instance().gap().stopScan();
     }
@@ -255,7 +257,8 @@
 {
     printf("reading data : \r\n");
     if (response->handle == lightCharacteristic.getValueHandle())
-    {
+    {   
+        response_flag = true;
         printf("triggerToggledWrite: handle %u, offset %u, len %u\r\n", response->handle, response->offset, response->len);
         memcpy(read_buffer,response->data,response->len);
         receiveBufSize = response->len;
@@ -418,7 +421,7 @@
 
     int read_temp_data;
     int write_temp_data;
-    uint8_t read_bufferSize = 0;
+    uint8_t read_bufferSize;
     
     bleint();
     
@@ -441,23 +444,34 @@
       
         if(connect_status && charDiscover)
         {
+            read_bufferSize = 0;
             if(read_flag)
             {
                 pc.printf("Read\r\n");
                 read_Characteristics();
-                read_bufferSize = 0;
-                if(spiSlave.receive())
+                printf("receiveBufSize : %d",receiveBufSize);
+                if(spiSlave.receive()  && response_flag)//
                 {   
+                    
                     read_temp_data = spiSlave.read();
-                                            
-                    while(read_bufferSize < receiveBufSize) 
+                          
+                    while(spiSlave.receive()) 
                     {   
-                        if(!checkBytes(read_temp_data))
+                        if(read_bufferSize == 0)  
+                            spiSlave.reply(receiveBufSize);
+                            
+                        //if(read_bufferSize < receiveBufSize)
+                         //   break;
+                        
+                        if(checkBytes(read_temp_data))
                             break;
                             
-                        spiSlave.reply(read_buffer[read_bufferSize]);
-                        read_bufferSize++;
                         read_temp_data = spiSlave.read();
+                        spiSlave.reply(0x02);//read_buffer[read_bufferSize]
+                        read_bufferSize++;   
+                        
+                        
+                        
                     }
                 
                     if(read_bufferSize >= receiveBufSize)
@@ -476,7 +490,7 @@
                     write_bufferSize = 0;
                     while(write_flag)
                     {
-                        if(!checkBytes(write_temp_data))
+                        if(checkBytes(write_temp_data))
                             break;
                             
                         spiSlave.reply(spiRX[write_bufferSize]);