AKM Development Platform. This is the D7.014 version.

Dependencies:   AK09970 AK099XX AK7401 AK7451 AK8963X AK9750 AK9752 AkmSensor BLE_API I2CNano MCP342x SerialNano SpiNano TCA9554A mbed nRF51822

Fork of AKDP by Masahiko Fukasawa

Revision:
19:7a6913400380
Parent:
18:d75838bceaaf
Child:
20:15fb57ad4f70
--- a/main.cpp	Wed Aug 10 23:51:01 2016 +0000
+++ b/main.cpp	Fri Aug 12 00:04:58 2016 +0000
@@ -8,6 +8,7 @@
 #include "akmsensormanager.h"
 #include "debug.h"
 #include "tca9554a.h"
+#include "akmakd.h"
 
 #define BLE_UUID_TXRX_SERVICE            0x0000 /**< The UUID of the Nordic UART Service. */
 #define BLE_UUID_TX_CHARACTERISTIC       0x0002 /**< The UUID of the TX Characteristic. */
@@ -19,7 +20,7 @@
 #define CR                              '\r'
 #define LF                              '\n'
 
-#define DEVICE_NAME                     "AKDP Rev.D7.007"
+#define DEVICE_NAME                     "AKDP D7.008 "
 
 BLE                 ble;
 UARTService*        uartService;
@@ -39,11 +40,26 @@
     UNIT_10_MS    = 10000
 };
 
+// default setting of Nexus 5X, Motorola Droid Turbo:
+//#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(45, UNIT_1_25_MS)              /**< Minimum connection interval (45 ms) */
+//#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(45, UNIT_1_25_MS)               /**< Maximum connection interval (45 ms). */
+//#define SLAVE_LATENCY                   0                                             /**< Slave latency. */
+//#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(20000, UNIT_10_MS)               /**< Connection supervisory timeout (20 seconds). */
+
+/*
+iOS requirement:
+Interval Max * (Slave Latency + 1) ≤ 2 seconds
+Interval Min ≥ 20 ms
+Interval Min + 20 ms ≤ Interval Max Slave Latency ≤ 4
+connSupervisionTimeout ≤ 6 seconds
+Interval Max * (Slave Latency + 1) * 3 < connSupervisionTimeout
+*/
+
 #define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
 #define MIN_CONN_INTERVAL               MSEC_TO_UNITS(7.5, UNIT_1_25_MS)              /**< Minimum connection interval (7.5 ms) */
 #define MAX_CONN_INTERVAL               MSEC_TO_UNITS(30, UNIT_1_25_MS)               /**< Maximum connection interval (30 ms). */
 #define SLAVE_LATENCY                   0                                             /**< Slave latency. */
-#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(3000, UNIT_10_MS)               /**< Connection supervisory timeout (3 seconds). */
+#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)               /**< Connection supervisory timeout (4 seconds). */
 
 void WrittenHandler(const GattWriteCallbackParams *Handler)
 {   
@@ -104,15 +120,24 @@
 
 static void connectionCallback(const Gap::ConnectionCallbackParams_t *params)
 {
-  
+    MSG("#From central: minConnectionInterval = %d\r\n", params->connectionParams->minConnectionInterval);
+    MSG("#From central: maxConnectionInterval = %d\r\n", params->connectionParams->maxConnectionInterval);
+    MSG("#From central: slaveLatency = %d\r\n", params->connectionParams->slaveLatency);
+    MSG("#From central: connectionSupervisionTimeout = %d\r\n", params->connectionParams->connectionSupervisionTimeout);
+    
     Gap::Handle_t gap_handle = params->handle;
     Gap::ConnectionParams_t gap_conn_params;
-    gap_conn_params.minConnectionInterval = MIN_CONN_INTERVAL;
-    gap_conn_params.maxConnectionInterval = MAX_CONN_INTERVAL;
-    gap_conn_params.slaveLatency = SLAVE_LATENCY;
+    gap_conn_params.minConnectionInterval = params->connectionParams->minConnectionInterval;
+    gap_conn_params.maxConnectionInterval = params->connectionParams->maxConnectionInterval;
+    gap_conn_params.slaveLatency = params->connectionParams->slaveLatency;
     gap_conn_params.connectionSupervisionTimeout = CONN_SUP_TIMEOUT;
     ble.updateConnectionParams(gap_handle, &gap_conn_params);
 
+    MSG("#From peripheral: minConnectionInterval = %d\r\n", gap_conn_params.minConnectionInterval);
+    MSG("#From peripheral: maxConnectionInterval = %d\r\n", gap_conn_params.maxConnectionInterval);
+    MSG("#From peripheral: slaveLatency = %d\r\n", gap_conn_params.slaveLatency);
+    MSG("#From peripheral: connectionSupervisionTimeout = %d\r\n", gap_conn_params.connectionSupervisionTimeout);
+
     manager->setEventConnected();
     MSG("#Connected\r\n");
 }
@@ -124,16 +149,18 @@
     ble.gap().startAdvertising();
 } 
 
-void bleSetup(){
+void bleSetup(char* device_name){
     ble.init();
 
     // setup advertising 
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
     ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
-                                    (const uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME) - 1);
+                                    (const uint8_t *)device_name, strlen(device_name));
+//                                    (const uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME) - 1);
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
+
     
     // Set desired connection parameters
     Gap::ConnectionParams_t gap_conn_params;
@@ -322,11 +349,19 @@
 }
 
 
+char* my_strcat(char* str1, char* str2)
+{
+    int num1;
+    char* str;
+    
+    num1=strlen(str1) + strlen(str2);
+    str = (char *)malloc(num1 + 1);
+    sprintf(str,"%s%s",str1,str2);
+    return str;
+}
 
 int main(void)
 {
-//    bool isFailedBoot = false;
-       
     // USB serial
     serial.baud(115200);
     
@@ -340,31 +375,30 @@
     
     // initialize AKDP board
     if( initAkdpBoard() ){
-//        isFailedBoot = true;
         MSG("#Error: AKDP boot failed.\r\n");
     }
-
-    // ble initialize
-    bleSetup();
+        
+    // create sensor manager
+    manager = new AkmSensorManager(&serial);
+    
+    if( manager->init(id, subId) == AkmSensorManager::ERROR){
+        MSG("#Error: sensor is NULL\r\n");
+    }
+    
+    // create BLE device name
+    char* name = my_strcat(DEVICE_NAME, manager->getSensorName());
+    
+    // BLE initialize
+    bleSetup(name);
     
     // BLE UART service
     uartService = new UARTService(ble);
     
-    // create sensor manager
-    manager = new AkmSensorManager(&serial, uartService);
-    
-    if( manager->init(id, subId) == AkmSensorManager::ERROR){
-//        isFailedBoot = true;
-        MSG("#Error: sensor is NULL\r\n");
-    }
+    // set BLE UART service
+    manager->setBleUartService(uartService);
     
     MSG("#Connecting...\r\n");
-/*
-    Message msg;
-    msg.setCommand(Message::CMD_BOOT_STATUS);
-    msg.setArgument( 0, isFailedBoot ? 1 : 0  );
-    manager->throwMessage(&msg);       
-*/
+
     // main loop
     while(1)
     {