Bluetooth Low Energy based Firmware Over The Air with Mbed. Mbed part is a external processor of the IoT devices and communicate with a Bluetooth module. The Bluetooth module have to support BLE and implement BLE FOTA profile designed by ours. BLE FOTA profile specification is available from our GIT hub wiki(https://github.com/sevencore/BLEFOTA).

Dependencies:   mbed

Fork of mbed_fota by KIM HyoengJun

Bluetooth Low Energy based Firmware Over The Air with Mbed. Mbed part is a external processor of the IoT devices and communicate with a Bluetooth module. The Bluetooth module have to support BLE and implement BLE FOTA profile designed by ours. BLE FOTA profile specification is available from our GIT hub wiki.

Revision:
6:8dd20294b2aa
Parent:
5:e11b23f9aacc
Child:
7:3478c46cceef
--- a/ext_fota/BleMsgHandler.cpp	Mon Jul 13 06:32:05 2015 +0000
+++ b/ext_fota/BleMsgHandler.cpp	Fri Jul 17 14:04:12 2015 +0000
@@ -4,6 +4,7 @@
 #include "fota_server_task.h"
 #include "app_task.h"
 
+extern "C" void mbed_reset();
 
 namespace sevencore_fota{
 
@@ -91,8 +92,11 @@
         hostpc->printf(" handle msg : id(%d), dst(%d), src(%d), len(%d) !\n",
          msg_hdr.bType, msg_hdr.bDstid, msg_hdr.bSrcid, msg_hdr.bLength);
     
-    if (msg_hdr.bDstid != TASK_GTL)
+    if (msg_hdr.bDstid != TASK_GTL){
+        if( print_flag == 1)
+            hostpc->printf("Dstid not TASK_GTL!\n");
         return;
+    }
     
     switch( msg_hdr.bType )
     {
@@ -151,7 +155,7 @@
         case FOTA_SERVER_ERROR_IND:
             if ( print_flag == 1)
                 hostpc->printf("Rcved FOTA_SERVER_ERROR_IND Msg\n");
-            fota_server_data_flash_ind_handler(this);
+            fota_server_data_flash_ind_handler(msg_hdr.bType,(struct fota_server_data_flash_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this);
             break;    
         default:
             if( print_flag == 1)
@@ -177,6 +181,8 @@
                 gapm_reset_completion_handler (msgid, (struct gapm_cmp_evt *)param, dest_id, src_id,this);
                 break;
             case GAPM_CANCEL:// Cancel currently executed operation.
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_CANCEL\n");
                 break;
             case GAPM_SET_DEV_CONFIG:// Set device configuration
                 if( print_flag == 1)
@@ -184,53 +190,98 @@
                 gapm_set_dev_config_completion_handler(msgid, (struct gapm_cmp_evt *)param, dest_id, src_id,this);
                 break;
             case GAPM_SET_DEV_NAME: // Set device name
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_SET_DEV_NAME\n");
                 break;
             case GAPM_SET_CHANNEL_MAP:// Set device channel map
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_SET_CHANNEL_MAP\n");
                 break;
             case  GAPM_GET_DEV_NAME:// Get Local device name
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_GET_DEV_NAME\n");
                 break;
             case GAPM_GET_DEV_VERSION:// Get Local device version
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_GET_DEV_VERSION\n");
                 break;
             case GAPM_GET_DEV_BDADDR:// Get Local device BD Address
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_GET_DEV_BDADDR\n");
                 break;
             case GAPM_GET_WLIST_SIZE:// Get White List Size.
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_GET_WLIST_SIZE\n");
                 break;
             case GAPM_ADD_DEV_IN_WLIST:// Add devices in white list.
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_ADD_DEV_IN_WLIST\n");
                 break;
             case GAPM_RMV_DEV_FRM_WLIST:// Remove devices form white list.
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_RMV_DEV_FRM_WLIST\n");
                 break;
             case GAPM_CLEAR_WLIST:// Clear all devices from white list.
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_CLEAR_WLIST\n");
                 break;
             case GAPM_ADV_NON_CONN:// Start non connectable advertising
             case GAPM_ADV_UNDIRECT:// Start undirected connectable advertising
             case GAPM_ADV_DIRECT:// Start directed connectable advertising
-                    break;
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_ADV_~\n");
+                break;
             case GAPM_SCAN_ACTIVE:// Start active scan operation
             case GAPM_SCAN_PASSIVE:   // Start passive scan operation
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_SCAN_~\n");
                 break;
             case GAPM_CONNECTION_DIRECT:// Direct connection operation
-                break;
+                //break;
             case GAPM_CONNECTION_AUTO:// Automatic connection operation
-                break;
+                //break;
             case GAPM_CONNECTION_SELECTIVE:// Selective connection operation
-                break;
+                //break;
             case GAPM_CONNECTION_NAME_REQUEST:// Name Request operation (requires to start a direct connection)
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_CONNECT_~\n");
                 break;
             case GAPM_RESOLV_ADDR:// Resolve device address
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_RESOLV_ADDR\n");
                 break;
             case GAPM_GEN_RAND_ADDR:// Generate a random address
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_GEN_RAND_ADDR\n");
                 break;
             case GAPM_USE_ENC_BLOCK:// Use the controller's AES-128 block
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_USE_ENC_BLOCK\n");
                 break;
             case GAPM_GEN_RAND_NB:// Generate a 8-byte random number
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_GEN_RAND_NB\n");
                 break;
             case GAPM_DBG_GET_MEM_INFO:// Get memory usage
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_GAPM_DBG_GET_MEM_INFO\n");
                 break;
             case GAPM_PLF_RESET:// Perform a platform reset
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_PLF_RESET\n");
                 break;
             case GAPM_GET_DEV_ADV_TX_POWER:// Get device advertising power level
+                if( print_flag == 1)
+                    hostpc->printf("GAPM_GET_DEV_ADV_TX_POWER\n");
+                break;
+            default:
+                if( print_flag == 1)
+                    hostpc->printf("??????????????????????????\n");
                 break;
         }
+    }else{
+        if( print_flag == 1)
+            hostpc->printf("?status ERROR?\n");
     } 
 }
 
@@ -284,6 +335,65 @@
 {
     SerialM->ReceiveToSerialTest();
 }
+
+void BleMsgHandler::FirmwareDataReceive(unsigned short code_size, char *version)
+{
+    unsigned short stored_data_cnt = 0;
+    uint8_t databuf[FIRMWARE_DATA_FRAGMENT_SIZE]="/local/";
+    if(print_flag == 1)
+        hostpc->printf("\n!!File name = %s!! code_size = %d\n",version,code_size);
+    memcpy(&databuf[7], version, 8);    
+    databuf[15] = '\0';   
+    hostpc->printf("\n!!name = %s!\n",databuf);
+    
+    
+    DIR *d = opendir("/local/");
+    struct dirent *p;
+    while ((p = readdir(d)) != NULL)
+    {
+        if(print_flag == 1)
+            hostpc->printf("%s\n", p->d_name);
+    }
+    closedir(d); 
+            
+    fp = fopen("/local/TEST.bin", "w");
+    
+    SerialM->DataReceive(databuf,2);
+    if(databuf[0] == 0x80 && databuf[1] == 0x46 ){
+        if(print_flag == 1)
+            hostpc->printf("\n!!Firmware Data Transmition Start!!\n");
+    }else{
+        if(print_flag == 1)
+            hostpc->printf("\n!!Firmware Data Transmition ERROR!!\n");
+    }
+    
+    memset(databuf,0,FIRMWARE_DATA_FRAGMENT_SIZE);
+    
+    while( stored_data_cnt < code_size )
+    {
+        if( code_size - stored_data_cnt >= FIRMWARE_DATA_FRAGMENT_SIZE ){
+            SerialM->DataReceive(databuf,FIRMWARE_DATA_FRAGMENT_SIZE);
+            fwrite(databuf, 1, FIRMWARE_DATA_FRAGMENT_SIZE, fp);
+            stored_data_cnt += FIRMWARE_DATA_FRAGMENT_SIZE;    
+        }else{
+            SerialM->DataReceive(databuf, code_size - stored_data_cnt);
+            fwrite(databuf, 1, code_size - stored_data_cnt, fp);
+            stored_data_cnt = code_size ;
+        }
+        memset(databuf,0,FIRMWARE_DATA_FRAGMENT_SIZE);      
+    }
+    
+    SerialM->DataReceive(databuf,2);
+    if(databuf[0] == 0x80 && databuf[1] == 0x46 ){
+        if(print_flag == 1)
+            hostpc->printf("\n!!Firmware Data Transmition END!!\n");
+    }else{
+        if(print_flag == 1)
+            hostpc->printf("\n!!Firmware Data Transmition END ERROR!!\n");
+    }
+    fclose(fp);
+    mbed_reset();
+}