BLE Nano Code.Tested with Integrated mDot code

Dependencies:   BLE_API mbed nRF51822

Fork of eco_Labs_ble_Client by Happiest

Revision:
15:67fbed00edf2
Parent:
14:dc3e3d327d7c
Child:
16:79b149aae10a
--- a/ble_uart.cpp	Fri Oct 07 10:10:17 2016 +0000
+++ b/ble_uart.cpp	Tue Oct 11 09:49:14 2016 +0000
@@ -12,7 +12,7 @@
   *
   ******************************************************************************
   */
-
+ 
 /******************************************************************************/
 /* Include Files*/
 /******************************************************************************/
@@ -21,33 +21,33 @@
 #include "BLE.h"
 #include "ble_types.h"
 #include "UARTService.h"
-
+ 
 /******************************************************************************/
 /* Local Defines                                                              */
 /******************************************************************************/
 #define DEBUG(STR) { if (uart) uart->write(STR, strlen(STR)); }
-
+ 
 #define BLE_DEVICE_NAME "Ecolab-ICE"
-
+ 
 /******************************************************************************/
 /* Global Variables                                                           */
 /******************************************************************************/
-
+ 
 extern void enable_interrupt_line(bool status );
 extern void enable_interrupt_line(bool status );
 void spi_slave_tx_data(uint8_t *tx_buf, uint8_t len);
 bool isDeviceConnected = false;
-
-
+ 
+ 
 #define DEBUG(STR) { if (uart) uart->write(STR, strlen(STR)); }
-
+ 
 /******************************************************************************/
 /* Static Variable Declarations */
 /******************************************************************************/
 static BLEDevice  ble;
 static UARTService *uart;
 static ble_data_ready_callback_t data_ready_cb;
-
+ 
 /******************************************************************************/
 /* Static Functions                                                           */
 /******************************************************************************/
@@ -68,7 +68,7 @@
  //   enable_interrupt_line(true);    
     toggle_led();
 }
-
+ 
 /**
  * @brief  Device disconnection callback
  * @param  
@@ -88,7 +88,7 @@
   //  enable_interrupt_line(false);  
     ble.startAdvertising();
 }
-
+ 
 /**
  * @brief  onDataWrittenCallback - On data received callback???
  * @param  
@@ -98,19 +98,37 @@
  
 static void ble_dataReceiveCallback(const GattWriteCallbackParams *params)                         
 {    
-
+ 
+ #if 1
     uint8_t buf[32] = {0};
     
     memcpy(buf, params->data, params->len);
         
-    if (data_ready_cb != NULL) {
-        data_ready_cb(buf, sizeof(buf));
+ //   if (data_ready_cb != NULL) {
+        data_ready_cb(buf, params->len);
+ //   }
+  //  spi_slave_tx_data(buf, (params->len));
+   // ble_send_data((uint8_t *)params->data, params->len);
+ #endif
+ #if 0
+    uint8_t tx_buf[10];
+    tx_buf[0] = 0x01;
+    tx_buf[1] = 0xA5;
+    tx_buf[2] = 0x06;
+    tx_buf[3] = 0x0B;
+    tx_buf[4] = 0x04;
+    
+ //   spi_slave_tx_data(tx_buf, 6);
+    
+    
+     if (data_ready_cb != NULL) {
+        data_ready_cb(tx_buf, 6);
     }
     
-    ble_send_data((uint8_t *)params->data, params->len);
-
+    ble_send_data(tx_buf, 6);
+ #endif
 }
-
+ 
 /******************************************************************************/
 /* Global Functions                                                           */
 /******************************************************************************/
@@ -129,7 +147,7 @@
     ble.onConnection(ble_connectionCallback);
     ble.onDisconnection(ble_disconnectionCallback);
     ble.onDataWritten(ble_dataReceiveCallback);
-
+ 
     uart = new UARTService(ble);
 #if 0
     /* setup advertising */
@@ -139,10 +157,10 @@
                                      (const uint8_t *)BLE_DEVICE_NAME, sizeof(BLE_DEVICE_NAME) - 1);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                      (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
-
+ 
     ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
 #endif
-
+ 
     /* Setup advertising */
     ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
@@ -154,7 +172,7 @@
     ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
     ble.startAdvertising();
 }
-
+ 
 /**
  * @brief  Function used to register ble data receive callback 
  * @param  none
@@ -164,7 +182,7 @@
 {
     data_ready_cb = data_rx_callback;
 }
-
+ 
 /**
  * @brief  Send data over BLE UART
  * @param  
@@ -180,7 +198,7 @@
     }
     return ret_code;
 }
-
+ 
 /**
  * @brief  Wait for the BLE events
  * @param  
@@ -190,7 +208,8 @@
 {
     ble.waitForEvent();
 }
-
+ 
 /******************************************************************************/
 /* END OF FILE                                                                */
 /******************************************************************************/
+ 
\ No newline at end of file