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:
8:9eec2c246a85
Parent:
7:3478c46cceef
Child:
9:fcf91f563147
--- a/ext_fota/BleMsgHandler.cpp	Mon Jul 20 09:22:15 2015 +0000
+++ b/ext_fota/BleMsgHandler.cpp	Thu Aug 20 05:16:55 2015 +0000
@@ -1,13 +1,39 @@
+/**
+ * @file BleMsgHandler.cpp
+ * @brief ble message handler ( Ble message is communication mathod between Mbed and DA14583 )
+ * Copyright 2015 SEVENCORE Co., Ltd.
+ *
+ * @author HyeongJun Kim 
+ * @version 1.0.0  
+ * @date 2015-08-19
+*/
+
 #include "BleMsgHandler.h"
 #include "dialog_fota_config.h"
 #include "diss_task.h"
 #include "fota_server_task.h"
 #include "app_task.h"
 
+/**
+ ****************************************************************************************
+ * @addtogroup ext_fota module
+ * @brief Ble message Handler Class Mathod Definition.
+ *
+ * @{
+ ****************************************************************************************
+ */
+
 extern "C" void mbed_reset();
 
 namespace sevencore_fota{
-
+    
+/**
+ ****************************************************************************************
+ * @brief Ble message Handler Constructor.
+ * @param[in] mbed serial class reference to device.
+ * @detail Create SerialManager instance and Create inner MsgQueue
+ ****************************************************************************************
+ */
 BleMsgHandler::BleMsgHandler(Serial *_device)
 {
     print_flag = 0;
@@ -16,7 +42,14 @@
     MsgQ = new MsgQueue(512);
     memset(recv_msg,0,512);
 }
-
+/**
+ ****************************************************************************************
+ * @brief Ble message Handler Constructor.
+ * @param[in] mbed serial class reference to device.
+ * @param[in] mbed serial class reference to hostpc.
+ * @detail Create SerialManager instance and Create inner MsgQueue
+ ****************************************************************************************
+ */
 BleMsgHandler::BleMsgHandler(Serial *_device, Serial *_hostpc)
 {
     print_flag = 1;
@@ -24,22 +57,42 @@
     hostpc = _hostpc;
     SerialM = new SerialManager(_device,_hostpc);
     MsgQ = new MsgQueue(512);
-    memset(recv_msg,0,512);
+    memset(recv_msg,0,512); 
 }
-
+/**
+ ****************************************************************************************
+ * @brief Ble message Handler Destructor.
+ ****************************************************************************************
+ */
 BleMsgHandler::~BleMsgHandler(void)
 {
     free(SerialM);
     free(MsgQ);
 }
-
+/**
+ ****************************************************************************************
+ * @brief Ble message handler Start title print function.
+ * @param[in] mbed serial class reference to device.
+ * @param[in] mbed serial class reference to hostpc.
+ ****************************************************************************************
+ */
 void BleMsgHandler::PrintTitle(void)
 {
     if( print_flag == 1 )
         hostpc->printf("\nSevencore Fota : BleMsg Handler Start\n");
     //SerialM->ReceiveToSerialTest();
 }
-
+/**
+ ****************************************************************************************
+ * @brief Create ble message.
+ * @param[in] 16byte ble message type. @ref structure 'ble_hdr' member 'bType'
+ * @param[in] 16byte ble dest task id(number). @ref structure 'ble_hdr' member 'bDstid'
+ * @param[in] 16byte ble source task id(number). @ref structure 'ble_hdr' member 'bSrcid'
+ * @param[in] 16byte ble message data length. @ref structure 'ble_hdr' member 'bLength'
+ * @param[in] input data pointer.
+ * @param[in] message alloc output pointer.
+ ****************************************************************************************
+ */
 void BleMsgHandler::BleMsgAlloc( unsigned short id,
                                  unsigned short dest_id,
                                  unsigned short src_id,
@@ -55,12 +108,23 @@
     memcpy(&msg[1+3*sizeof(unsigned short)],&data_len,sizeof(unsigned short));
     memcpy(&msg[1+4*sizeof(unsigned short)],pdata,data_len);
 }
-
+/**
+ ****************************************************************************************
+ * @brief Send ble message to device.
+ * @param[in] sending message pointer
+ * @param[in] message size.
+ ****************************************************************************************
+ */
 int BleMsgHandler::BleSendMsg(uint8_t *msg, unsigned short size)
 {
    return  SerialM->SendToSerial(msg,size);
 }
-
+/**
+ ****************************************************************************************
+ * @brief Receive ble message from device.
+ * @detail Received message insert inner MsgQueue
+ ****************************************************************************************
+ */
 void BleMsgHandler::BleReceiveMsg(void)
 {
     int receive_size = -1;//default
@@ -75,7 +139,12 @@
     memset(recv_msg,0,512);
     MsgQ->EnQueue(msg);
 }
-
+/**
+ ****************************************************************************************
+ * @brief Get message from MsgQueue and Execute corresponding function.
+ * @detail After get message, extract message type. Each message type connect corresponding function
+ ****************************************************************************************
+ */
 void BleMsgHandler::BleMsgHandle(void)
 {
     uint8_t *msg;
@@ -83,7 +152,7 @@
     unsigned short paramPos = 1 + sizeof(msg_hdr);
     
     if( print_flag == 1)
-        hostpc->printf("Ble-Massage Handle Function!\n");
+        hostpc->printf("Ble-message Handle Function!\n");
     
     msg = (uint8_t*)MsgQ->DeQueue();
     memcpy(&msg_hdr, &msg[1], sizeof(msg_hdr));
@@ -159,11 +228,16 @@
             break;    
         default:
             if( print_flag == 1)
-                hostpc->printf("Massage Type Not Defined ! \n");
+                hostpc->printf("message Type Not Defined ! \n");
             break;
     }
 }//gapc_disconnect_ind_handler(GAPC_DISCONNECT_IND),(GAPC_CONNECTION_REQ_IND)gapc_connection_req_ind_handler
-
+/**
+ ****************************************************************************************
+ * @brief GAPM Command Event Handler.
+ * @detail After get GAPM command, extract operation. Each operation connect corresponding function
+ ****************************************************************************************
+ */
 void BleMsgHandler::HandleGapmCmpEvt(unsigned short msgid,
                     struct gapm_cmp_evt *param,
                     unsigned short dest_id,
@@ -284,7 +358,12 @@
             hostpc->printf("?status ERROR?\n");
     } 
 }
-
+/**
+ ****************************************************************************************
+ * @brief GAPC Command Event Handler.
+ * @detail After get GAPC command, extract operation. Each operation connect corresponding function
+ ****************************************************************************************
+ */
 void BleMsgHandler::HandleGapcCmpEvt(unsigned short msgid,
                     struct gapc_cmp_evt *param,
                     unsigned short dest_id,
@@ -324,18 +403,33 @@
             break;
     }
 }
-
+/**
+ ****************************************************************************************
+ * @brief Debugging message output to hostpc.
+ * @param[in] output char array pointer
+ ****************************************************************************************
+ */
 void BleMsgHandler::HostPcPrint(char *str)
 {
     if(print_flag == 1)
         hostpc->printf("%s",str);
 }
-
+/**
+ ****************************************************************************************
+ * @brief Receive test method
+ ****************************************************************************************
+ */
 void BleMsgHandler::ReceiveToSerialTest(void)
 {
     SerialM->ReceiveToSerialTest();
 }
-
+/**
+ ****************************************************************************************
+ * @brief Receive and Store Da14583 flash data.
+ * @param[in] mbed binary file size
+ * @param[in] mbed binary version string
+ ****************************************************************************************
+ */
 void BleMsgHandler::FirmwareDataReceive(unsigned short code_size, char *version)
 {
     unsigned short stored_data_cnt = 0;
@@ -398,6 +492,9 @@
             hostpc->printf("\n!!Firmware Data Transmition END ERROR!!\n");
     }
     fclose(fp);
+    wait(5);
+    if(print_flag == 1)
+            hostpc->printf("\n!!RESET MBED!!\n");
     mbed_reset();
 }
     
@@ -405,3 +502,4 @@
 
  
 }//namespace
+/// @} ext_fota module
\ No newline at end of file