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
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.
Diff: dialog_fota/app_task.cpp
- Revision:
- 4:60be78a172c2
- Child:
- 5:e11b23f9aacc
diff -r 1e70387e1337 -r 60be78a172c2 dialog_fota/app_task.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dialog_fota/app_task.cpp Wed Jun 24 08:50:07 2015 +0000 @@ -0,0 +1,182 @@ +#include "app_task.h" +#include "app.h" + +namespace sevencore_fota{ + +int gapm_adv_report_ind_handler(unsigned short msgid, + struct gapm_adv_report_ind *param, + unsigned short dest_id, + unsigned short src_id) +{ + //if (app_env.state != APP_SCAN) + // return -1; + + return 0; +} + +int diss_create_db_cfm_handler(unsigned short msgid, + struct diss_create_db_cfm *param, + unsigned short dest_id, + unsigned short src_id, + BleMsgHandler* BMH) +{ + uint8_t len = strlen(APP_DIS_SW_REV); + + if (param->status == CO_ERROR_NO_ERROR) + { + // Set Manufacturer Name value in the DB + { + uint8_t *msg; + struct diss_set_char_val_req req_name; + unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req)+APP_DIS_MANUFACTURER_NAME_LEN; + // Fill in the parameter structure + req_name.char_code = DIS_MANUFACTURER_NAME_CHAR; + req_name.val_len = APP_DIS_MANUFACTURER_NAME_LEN; + memcpy(&req_name.val[0], APP_DIS_MANUFACTURER_NAME, APP_DIS_MANUFACTURER_NAME_LEN); + + msg = new uint8_t[msg_size]; + + BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req) + APP_DIS_MANUFACTURER_NAME_LEN,&req_name,msg ); + + // Send the message + BMH->BleSendMsg(msg,msg_size); + free(msg); + } + + // Set Model Number String value in the DB + { + uint8_t *msg; + struct diss_set_char_val_req req_mod; + unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); + + // Fill in the parameter structure + req_mod.char_code = DIS_MODEL_NB_STR_CHAR; + req_mod.val_len = APP_DIS_MODEL_NB_STR_LEN; + memcpy(&req_mod.val[0], APP_DIS_MODEL_NB_STR, APP_DIS_MODEL_NB_STR_LEN); + + msg = new uint8_t[msg_size]; + + BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_mod,msg ); + // Send the message + BMH->BleSendMsg(msg,msg_size); + free(msg); + } + + // Set System ID value in the DB + { + uint8_t *msg; + struct diss_set_char_val_req req_id; + unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); + + // Fill in the parameter structure + req_id.char_code = DIS_SYSTEM_ID_CHAR; + req_id.val_len = APP_DIS_SYSTEM_ID_LEN; + memcpy(&req_id.val[0], APP_DIS_SYSTEM_ID, APP_DIS_SYSTEM_ID_LEN); + + msg = new uint8_t[msg_size]; + + BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg); + + // Send the message + BMH->BleSendMsg(msg, msg_size); + free(msg); + } + + + // Set the software version in the DB + { + uint8_t *msg; + struct diss_set_char_val_req req_id; + unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); + + // Fill in the parameter structure + req_id.char_code = DIS_SW_REV_STR_CHAR; + req_id.val_len = len; + memcpy(&req_id.val[0], APP_DIS_SW_REV, len); + + msg = new uint8_t[msg_size]; + + BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg); + // Send the message + BMH->BleSendMsg(msg,msg_size); + free(msg); + } + + len = strlen(APP_DIS_FIRM_REV); + // Set the firmware version in the DB. This is the common code sw version + { + uint8_t *msg; + struct diss_set_char_val_req req_id; + unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); + + // Fill in the parameter structure + req_id.char_code = DIS_FIRM_REV_STR_CHAR; + req_id.val_len = len; + memcpy(&req_id.val[0], APP_DIS_FIRM_REV, len); + + msg = new uint8_t[msg_size]; + + BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg); + // Send the message + BMH->BleSendMsg(msg, msg_size); + free(msg); + } + } + + /*if (app_env.state == APP_IDLE) + { + app_proxr_db_create(); + }*/ + app_set_mode(BMH); + + return 0; +} + +int gapm_device_ready_ind_handler(unsigned short msgid, + void *param, + unsigned short dest_id, + unsigned short src_id, + BleMsgHandler* BMH) +{ + // We are now in Connectable State + if (dest_id == TASK_GTL) + { + app_rst_gap(BMH); + } + + return 0; +} + +int gapm_reset_completion_handler(unsigned short msgid, + struct gapm_cmp_evt *param, + unsigned short dest_id, + unsigned short src_id, + BleMsgHandler* BMH) +{ + // We are now in Connectable State + if (dest_id == TASK_GTL) + { + // app_env.state = APP_IDLE; + app_diss_db_create(BMH); + } + + return 0; +} + +int gapm_set_dev_config_completion_handler(unsigned short msgid, + struct gapm_cmp_evt *param, + unsigned short dest_id, + unsigned short src_id, + BleMsgHandler* BMH) +{ + //app_env.state = APP_CONNECTABLE; + + //Sleep(100); + + app_adv_start(BMH); // start advertising + + return 0; +} + +}//namespace +