BLE fota Robot Demo
Dependencies: mbed-rtos mbed mbed_fota_fan_control
Fork of mbed_fota_lamp_control by
dialog_fota/app_task.cpp
- Committer:
- dudnwjs
- Date:
- 2015-06-24
- Revision:
- 4:60be78a172c2
- Child:
- 5:e11b23f9aacc
File content as of revision 4:60be78a172c2:
#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