Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos mbed mbed_fota_fan_control
Fork of mbed_fota_lamp_control by
BleMsgHandler.cpp
00001 /** 00002 * @file BleMsgHandler.cpp 00003 * @brief Ble message handler ( Ble message is communication mathod between Mbed and DA14583 ) 00004 * Copyright 2015 SEVENCORE Co., Ltd. 00005 * 00006 * @author HyeongJun Kim 00007 * @version 1.0.0 00008 * @date 2015-08-19 00009 */ 00010 00011 #include "BleMsgHandler.h" 00012 #include "dialog_fota_config.h" 00013 #include "diss_task.h" 00014 #include "fota_server_task.h" 00015 #include "app_task.h" 00016 #include "fan_control_task.h" 00017 #include "lamp_control_task.h" 00018 00019 /** 00020 **************************************************************************************** 00021 * @addtogroup ext_fota module 00022 * @brief Ble message Handler Class Mathod Definition. 00023 * 00024 * @{ 00025 **************************************************************************************** 00026 */ 00027 00028 extern "C" void mbed_reset(); 00029 00030 namespace sevencore_fota{ 00031 00032 /** 00033 **************************************************************************************** 00034 * @brief Ble message Handler Constructor. 00035 * @param[in] mbed serial class reference to device. 00036 * @detail Create SerialManager instance and Create inner MsgQueue 00037 **************************************************************************************** 00038 */ 00039 BleMsgHandler::BleMsgHandler(Serial *_device) 00040 { 00041 print_flag = 0; 00042 device = _device; 00043 SerialM = new SerialManager(_device); 00044 MsgQ = new MsgQueue(512); 00045 memset(recv_msg,0,512); 00046 } 00047 /** 00048 **************************************************************************************** 00049 * @brief Ble message Handler Constructor. 00050 * @param[in] mbed serial class reference to device. 00051 * @param[in] mbed serial class reference to hostpc. 00052 * @detail Create SerialManager instance and Create inner MsgQueue 00053 **************************************************************************************** 00054 */ 00055 BleMsgHandler::BleMsgHandler(Serial *_device, Serial *_hostpc) 00056 { 00057 print_flag = 1; 00058 device = _device; 00059 hostpc = _hostpc; 00060 SerialM = new SerialManager(_device,_hostpc); 00061 MsgQ = new MsgQueue(512); 00062 memset(recv_msg,0,512); 00063 } 00064 /** 00065 **************************************************************************************** 00066 * @brief Ble message Handler Destructor. 00067 **************************************************************************************** 00068 */ 00069 BleMsgHandler::~BleMsgHandler(void) 00070 { 00071 free(SerialM); 00072 free(MsgQ); 00073 } 00074 /** 00075 **************************************************************************************** 00076 * @brief Ble message handler Start title print function. 00077 **************************************************************************************** 00078 */ 00079 void BleMsgHandler::PrintTitle(void) 00080 { 00081 if( print_flag == 1 ) 00082 hostpc->printf("\nSevencore Fota : BleMsg Handler Start\n"); 00083 //SerialM->ReceiveToSerialTest(); 00084 } 00085 /** 00086 **************************************************************************************** 00087 * @brief Create ble message. 00088 * @param[in] 16byte ble message type. @ref structure 'ble_hdr' member 'bType' 00089 * @param[in] 16byte ble dest task id(number). @ref structure 'ble_hdr' member 'bDstid' 00090 * @param[in] 16byte ble source task id(number). @ref structure 'ble_hdr' member 'bSrcid' 00091 * @param[in] 16byte ble message data length. @ref structure 'ble_hdr' member 'bLength' 00092 * @param[in] input data pointer. 00093 * @param[in] message alloc output pointer. 00094 **************************************************************************************** 00095 */ 00096 void BleMsgHandler::BleMsgAlloc( unsigned short id, 00097 unsigned short dest_id, 00098 unsigned short src_id, 00099 unsigned short data_len, 00100 void *pdata, 00101 uint8_t *msg ) 00102 { 00103 memset(msg,0,sizeof(msg)); 00104 msg[0] = 0x05; 00105 memcpy(&msg[1],&id,sizeof(unsigned short)); 00106 memcpy(&msg[1+1*sizeof(unsigned short)],&dest_id,sizeof(unsigned short)); 00107 memcpy(&msg[1+2*sizeof(unsigned short)],&src_id,sizeof(unsigned short)); 00108 memcpy(&msg[1+3*sizeof(unsigned short)],&data_len,sizeof(unsigned short)); 00109 memcpy(&msg[1+4*sizeof(unsigned short)],pdata,data_len); 00110 } 00111 /** 00112 **************************************************************************************** 00113 * @brief Send ble message to device. 00114 * @param[in] sending message pointer 00115 * @param[in] message size. 00116 **************************************************************************************** 00117 */ 00118 int BleMsgHandler::BleSendMsg(uint8_t *msg, unsigned short size) 00119 { 00120 return SerialM->SendToSerial(msg,size); 00121 } 00122 /** 00123 **************************************************************************************** 00124 * @brief Receive ble message from device. 00125 * @detail Received message insert inner MsgQueue 00126 **************************************************************************************** 00127 */ 00128 void BleMsgHandler::BleReceiveMsg(void) 00129 { 00130 int receive_size = -1;//default 00131 while(receive_size == -1) 00132 { 00133 receive_size = SerialM->ReceiveToSerial(recv_msg); 00134 } 00135 00136 uint8_t *msg; 00137 msg = new uint8_t[receive_size]; 00138 memcpy(msg,recv_msg,receive_size); 00139 memset(recv_msg,0,512); 00140 MsgQ->EnQueue(msg); 00141 } 00142 /** 00143 **************************************************************************************** 00144 * @brief Get message from MsgQueue and Execute corresponding function. 00145 * @detail After get message, extract message type. Each message type connect corresponding function 00146 **************************************************************************************** 00147 */ 00148 void BleMsgHandler::BleMsgHandle(void) 00149 { 00150 uint8_t *msg; 00151 ble_hdr msg_hdr; 00152 unsigned short paramPos = 1 + sizeof(msg_hdr); 00153 00154 if( print_flag == 1) 00155 hostpc->printf("Ble-message Handle Function!\n"); 00156 00157 msg = (uint8_t*)MsgQ->DeQueue(); 00158 memcpy(&msg_hdr, &msg[1], sizeof(msg_hdr)); 00159 00160 if( print_flag == 1 ) 00161 hostpc->printf(" handle msg : id(%d), dst(%d), src(%d), len(%d) !\n", 00162 msg_hdr.bType, msg_hdr.bDstid, msg_hdr.bSrcid, msg_hdr.bLength); 00163 00164 if (msg_hdr.bDstid != TASK_GTL){ 00165 if( print_flag == 1) 00166 hostpc->printf("Dstid not TASK_GTL!\n"); 00167 return; 00168 } 00169 00170 switch( msg_hdr.bType ) 00171 { 00172 case GAPM_CMP_EVT: 00173 if( print_flag == 1) 00174 hostpc->printf("==> GAPM_CMP_EVT!!\n"); 00175 HandleGapmCmpEvt(msg_hdr.bType,(struct gapm_cmp_evt *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid); 00176 break; 00177 case GAPM_DEVICE_READY_IND: 00178 if( print_flag == 1) 00179 hostpc->printf("==> GAPM_DEVICE_READY_IND!!\n"); 00180 gapm_device_ready_ind_handler(msg_hdr.bType,(struct gap_ready_evt *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00181 break; 00182 case GAPM_ADV_REPORT_IND: 00183 if( print_flag == 1) 00184 hostpc->printf("==> GAPM_ADV_REPORT_IND!!\n"); 00185 gapm_adv_report_ind_handler(msg_hdr.bType,(struct gapm_adv_report_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid); 00186 break; 00187 case GAPC_CMP_EVT: 00188 if( print_flag == 1) 00189 hostpc->printf("==> GAPC_CMP_EVT!!\n"); 00190 HandleGapcCmpEvt(msg_hdr.bType,(struct gapc_cmp_evt *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid); 00191 break; 00192 case GAPC_CONNECTION_REQ_IND: 00193 if( print_flag == 1) 00194 hostpc->printf("==> GAPC_CONNECTION_REQ_IND!!\n"); 00195 gapc_connection_req_ind_handler(msg_hdr.bType,(struct gapc_connection_req_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00196 break; 00197 case GAPC_DISCONNECT_IND: 00198 if( print_flag == 1) 00199 hostpc->printf("==> GAPC_DISCONNECT_IND!!\n"); 00200 gapc_disconnect_ind_handler(msg_hdr.bType,(struct gapc_disconnect_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00201 break; 00202 case DISS_CREATE_DB_CFM: 00203 if( print_flag == 1) 00204 hostpc->printf("==> DISS_CREATE_DB_CFM!!\n"); 00205 diss_create_db_cfm_handler(msg_hdr.bType,(struct diss_create_db_cfm *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00206 break; 00207 case DISS_DISABLE_IND: 00208 if( print_flag == 1) 00209 hostpc->printf("==> DISS_DISABLE_IND!!\n"); 00210 break; 00211 case DISS_ERROR_IND: 00212 if ( print_flag == 1) 00213 hostpc->printf("Rcved DISS_ERROR_IND Msg\n"); 00214 break; 00215 case FOTA_SERVER_CREATE_DB_CFM: 00216 if( print_flag == 1) 00217 hostpc->printf("==> FOTA_SERVER_CREATE_DB_CFM!!\n"); 00218 fota_server_create_db_cfm_handler(msg_hdr.bType,(struct fota_server_create_db_cfm *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00219 break; 00220 case FOTA_SERVER_DISABLE_IND: 00221 if( print_flag == 1) 00222 hostpc->printf("==> FOTA_SERVER_DISABLE_IND!!\n"); 00223 break; 00224 case FOTA_SERVER_DATA_FLASH_IND: 00225 if ( print_flag == 1) 00226 hostpc->printf("Rcved FOTA_SERVER_DATA_FLASH_IND Msg\n"); 00227 fota_server_data_flash_ind_handler(msg_hdr.bType,(struct fota_server_data_flash_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00228 break; 00229 case FOTA_SERVER_ERROR_IND: 00230 if ( print_flag == 1) 00231 hostpc->printf("Rcved FOTA_SERVER_ERROR_IND Msg\n"); 00232 break; 00233 case FAN_CONTROL_CREATE_DB_CFM: 00234 if ( print_flag == 1) 00235 hostpc->printf("Rcved FAN_CONTROL_CREATE_DB_CFM Msg\n"); 00236 fan_control_create_db_cfm_handler(msg_hdr.bType,(struct fan_control_create_db_cfm *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00237 break; 00238 case FAN_CONTROL_DISABLE_IND: 00239 if( print_flag == 1) 00240 hostpc->printf("==> FAN_CONTROL_DISABLE_IND!!\n"); 00241 break; 00242 case FAN_CONTROL_COMMAND_IND: 00243 if( print_flag == 1) 00244 hostpc->printf("==> FAN_CONTROL_COMMAND_IND msg\n"); 00245 fan_control_command_ind_handler(msg_hdr.bType,(struct fan_control_command_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00246 break; 00247 case FAN_CONTROL_ERROR_IND: 00248 if( print_flag == 1) 00249 hostpc->printf("==> FAN_CONTROL_ERROR_IND !!\n"); 00250 break; 00251 case LAMP_CONTROL_CREATE_DB_CFM: 00252 if ( print_flag == 1) 00253 hostpc->printf("Rcved LAMP_CONTROL_CREATE_DB_CFM Msg\n"); 00254 lamp_control_create_db_cfm_handler(msg_hdr.bType,(struct lamp_control_create_db_cfm *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00255 break; 00256 case LAMP_CONTROL_DISABLE_IND: 00257 if( print_flag == 1) 00258 hostpc->printf("==> LAMP_CONTROL_DISABLE_IND!!\n"); 00259 break; 00260 case LAMP_CONTROL_COMMAND_IND: 00261 if( print_flag == 1) 00262 hostpc->printf("==> LAMP_CONTROL_COMMAND_IND msg\n"); 00263 lamp_control_command_ind_handler(msg_hdr.bType,(struct lamp_control_command_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); 00264 break; 00265 case LAMP_CONTROL_ERROR_IND: 00266 if( print_flag == 1) 00267 hostpc->printf("==> LAMP_CONTROL_ERROR_IND !!\n"); 00268 break; 00269 default: 00270 if( print_flag == 1) 00271 hostpc->printf("message Type Not Defined ! \n"); 00272 break; 00273 } 00274 }//gapc_disconnect_ind_handler(GAPC_DISCONNECT_IND),(GAPC_CONNECTION_REQ_IND)gapc_connection_req_ind_handler 00275 /** 00276 **************************************************************************************** 00277 * @brief GAPM Command Event Handler. 00278 * @detail After get GAPM command, extract operation. Each operation connect corresponding function 00279 **************************************************************************************** 00280 */ 00281 void BleMsgHandler::HandleGapmCmpEvt(unsigned short msgid, 00282 struct gapm_cmp_evt *param, 00283 unsigned short dest_id, 00284 unsigned short src_id) 00285 { 00286 if (param->status == CO_ERROR_NO_ERROR) 00287 { 00288 switch(param->operation) 00289 { 00290 case GAPM_NO_OP:// No operation. 00291 break; 00292 case GAPM_RESET:// Reset BLE subsystem: LL and HL. 00293 if( print_flag == 1) 00294 hostpc->printf("GAPM_RESET!! Start...\n"); 00295 gapm_reset_completion_handler (msgid, (struct gapm_cmp_evt *)param, dest_id, src_id,this); 00296 break; 00297 case GAPM_CANCEL:// Cancel currently executed operation. 00298 if( print_flag == 1) 00299 hostpc->printf("GAPM_CANCEL\n"); 00300 break; 00301 case GAPM_SET_DEV_CONFIG:// Set device configuration 00302 if( print_flag == 1) 00303 hostpc->printf("Adverting Start...\n"); 00304 gapm_set_dev_config_completion_handler(msgid, (struct gapm_cmp_evt *)param, dest_id, src_id,this); 00305 break; 00306 case GAPM_SET_DEV_NAME: // Set device name 00307 if( print_flag == 1) 00308 hostpc->printf("GAPM_SET_DEV_NAME\n"); 00309 break; 00310 case GAPM_SET_CHANNEL_MAP:// Set device channel map 00311 if( print_flag == 1) 00312 hostpc->printf("GAPM_SET_CHANNEL_MAP\n"); 00313 break; 00314 case GAPM_GET_DEV_NAME:// Get Local device name 00315 if( print_flag == 1) 00316 hostpc->printf("GAPM_GET_DEV_NAME\n"); 00317 break; 00318 case GAPM_GET_DEV_VERSION:// Get Local device version 00319 if( print_flag == 1) 00320 hostpc->printf("GAPM_GET_DEV_VERSION\n"); 00321 break; 00322 case GAPM_GET_DEV_BDADDR:// Get Local device BD Address 00323 if( print_flag == 1) 00324 hostpc->printf("GAPM_GET_DEV_BDADDR\n"); 00325 break; 00326 case GAPM_GET_WLIST_SIZE:// Get White List Size. 00327 if( print_flag == 1) 00328 hostpc->printf("GAPM_GET_WLIST_SIZE\n"); 00329 break; 00330 case GAPM_ADD_DEV_IN_WLIST:// Add devices in white list. 00331 if( print_flag == 1) 00332 hostpc->printf("GAPM_ADD_DEV_IN_WLIST\n"); 00333 break; 00334 case GAPM_RMV_DEV_FRM_WLIST:// Remove devices form white list. 00335 if( print_flag == 1) 00336 hostpc->printf("GAPM_RMV_DEV_FRM_WLIST\n"); 00337 break; 00338 case GAPM_CLEAR_WLIST:// Clear all devices from white list. 00339 if( print_flag == 1) 00340 hostpc->printf("GAPM_CLEAR_WLIST\n"); 00341 break; 00342 case GAPM_ADV_NON_CONN:// Start non connectable advertising 00343 case GAPM_ADV_UNDIRECT:// Start undirected connectable advertising 00344 case GAPM_ADV_DIRECT:// Start directed connectable advertising 00345 if( print_flag == 1) 00346 hostpc->printf("GAPM_ADV_~\n"); 00347 break; 00348 case GAPM_SCAN_ACTIVE:// Start active scan operation 00349 case GAPM_SCAN_PASSIVE: // Start passive scan operation 00350 if( print_flag == 1) 00351 hostpc->printf("GAPM_SCAN_~\n"); 00352 break; 00353 case GAPM_CONNECTION_DIRECT:// Direct connection operation 00354 //break; 00355 case GAPM_CONNECTION_AUTO:// Automatic connection operation 00356 //break; 00357 case GAPM_CONNECTION_SELECTIVE:// Selective connection operation 00358 //break; 00359 case GAPM_CONNECTION_NAME_REQUEST:// Name Request operation (requires to start a direct connection) 00360 if( print_flag == 1) 00361 hostpc->printf("GAPM_CONNECT_~\n"); 00362 break; 00363 case GAPM_RESOLV_ADDR:// Resolve device address 00364 if( print_flag == 1) 00365 hostpc->printf("GAPM_RESOLV_ADDR\n"); 00366 break; 00367 case GAPM_GEN_RAND_ADDR:// Generate a random address 00368 if( print_flag == 1) 00369 hostpc->printf("GAPM_GEN_RAND_ADDR\n"); 00370 break; 00371 case GAPM_USE_ENC_BLOCK:// Use the controller's AES-128 block 00372 if( print_flag == 1) 00373 hostpc->printf("GAPM_USE_ENC_BLOCK\n"); 00374 break; 00375 case GAPM_GEN_RAND_NB:// Generate a 8-byte random number 00376 if( print_flag == 1) 00377 hostpc->printf("GAPM_GEN_RAND_NB\n"); 00378 break; 00379 case GAPM_DBG_GET_MEM_INFO:// Get memory usage 00380 if( print_flag == 1) 00381 hostpc->printf("GAPM_GAPM_DBG_GET_MEM_INFO\n"); 00382 break; 00383 case GAPM_PLF_RESET:// Perform a platform reset 00384 if( print_flag == 1) 00385 hostpc->printf("GAPM_PLF_RESET\n"); 00386 break; 00387 case GAPM_GET_DEV_ADV_TX_POWER:// Get device advertising power level 00388 if( print_flag == 1) 00389 hostpc->printf("GAPM_GET_DEV_ADV_TX_POWER\n"); 00390 break; 00391 default: 00392 if( print_flag == 1) 00393 hostpc->printf("??????????????????????????\n"); 00394 break; 00395 } 00396 }else{ 00397 if( print_flag == 1) 00398 hostpc->printf("?status ERROR?\n"); 00399 } 00400 } 00401 /** 00402 **************************************************************************************** 00403 * @brief GAPC Command Event Handler. 00404 * @detail After get GAPC command, extract operation. Each operation connect corresponding function 00405 **************************************************************************************** 00406 */ 00407 void BleMsgHandler::HandleGapcCmpEvt(unsigned short msgid, 00408 struct gapc_cmp_evt *param, 00409 unsigned short dest_id, 00410 unsigned short src_id) 00411 { 00412 switch(param->operation) 00413 { 00414 case GAPC_NO_OP: // No operation 00415 break; 00416 case GAPC_DISCONNECT: // Disconnect link 00417 break; 00418 case GAPC_GET_PEER_NAME: // Retrieve name of peer device 00419 break; 00420 case GAPC_GET_PEER_VERSION: // Retrieve peer device version info. 00421 break; 00422 case GAPC_GET_PEER_FEATURES: // Retrieve peer device features. 00423 break; 00424 case GAPC_GET_CON_RSSI: // Retrieve connection RSSI. 00425 break; 00426 case GAPC_GET_PRIVACY: // Retrieve Privacy Info. 00427 break; 00428 case GAPC_GET_RECON_ADDR: // Retrieve Reconnection Address Value. 00429 break; 00430 case GAPC_SET_PRIVACY: // Set Privacy flag. 00431 break; 00432 case GAPC_SET_RECON_ADDR: // Set Reconnection Address Value. 00433 break; 00434 case GAPC_UPDATE_PARAMS: // Perform update of connection parameters. 00435 break; 00436 case GAPC_BOND: // Start bonding procedure. 00437 break; 00438 case GAPC_ENCRYPT: // Start encryption procedure. 00439 break; 00440 case GAPC_SECURITY_REQ: // Start security request procedure 00441 break; 00442 case GAPC_GET_CON_CHANNEL_MAP: // Retrieve Connection Channel MAP. 00443 break; 00444 } 00445 } 00446 /** 00447 **************************************************************************************** 00448 * @brief Debugging message output to hostpc. 00449 * @param[in] output char array pointer 00450 **************************************************************************************** 00451 */ 00452 void BleMsgHandler::HostPcPrint(char *str) 00453 { 00454 if(print_flag == 1) 00455 hostpc->printf("%s",str); 00456 } 00457 /** 00458 **************************************************************************************** 00459 * @brief Receive test method 00460 **************************************************************************************** 00461 */ 00462 void BleMsgHandler::ReceiveToSerialTest(void) 00463 { 00464 SerialM->ReceiveToSerialTest(); 00465 } 00466 /** 00467 **************************************************************************************** 00468 * @brief Receive and Store Da14583 flash data. 00469 * @param[in] mbed binary file size 00470 * @param[in] mbed binary version string 00471 **************************************************************************************** 00472 */ 00473 void BleMsgHandler::FirmwareDataReceive(unsigned short code_size, char *version) 00474 { 00475 unsigned short stored_data_cnt = 0; 00476 char path[20]="/local/"; 00477 char databuf[FIRMWARE_DATA_FRAGMENT_SIZE]="/local/"; 00478 if(print_flag == 1) 00479 hostpc->printf("\n!!File name = %s!! code_size = %d\n",version,code_size); 00480 strcat(databuf, version); 00481 strcat(databuf, ".BIN"); 00482 hostpc->printf("\n!!name = %s!\n",databuf); 00483 00484 00485 DIR *d = opendir("/local/"); 00486 struct dirent *p; 00487 while ((p = readdir(d)) != NULL) 00488 { 00489 hostpc->printf("%s,%d\n", p->d_name,strcmp(strchr(p->d_name,'.')+1,"BIN")); 00490 if( strcmp(strchr(p->d_name,'.')+1,"BIN") == 0 ){ 00491 strcat(path,p->d_name); 00492 hostpc->printf("%s\n",path); 00493 remove(path); 00494 strcpy(path,"/local/"); 00495 } 00496 } 00497 closedir(d); 00498 00499 fp = fopen(databuf, "w"); 00500 00501 SerialM->DataReceive((uint8_t*)databuf,2); 00502 if(databuf[0] == 0x80 && databuf[1] == 0x46 ){ 00503 if(print_flag == 1) 00504 hostpc->printf("\n!!Firmware Data Transmition Start!!\n"); 00505 }else{ 00506 if(print_flag == 1) 00507 hostpc->printf("\n!!Firmware Data Transmition ERROR!!\n"); 00508 } 00509 00510 memset(databuf,0,FIRMWARE_DATA_FRAGMENT_SIZE); 00511 00512 while( stored_data_cnt < code_size ) 00513 { 00514 if( code_size - stored_data_cnt >= FIRMWARE_DATA_FRAGMENT_SIZE ){ 00515 SerialM->DataReceive((uint8_t*)databuf,FIRMWARE_DATA_FRAGMENT_SIZE); 00516 fwrite(databuf, 1, FIRMWARE_DATA_FRAGMENT_SIZE, fp); 00517 stored_data_cnt += FIRMWARE_DATA_FRAGMENT_SIZE; 00518 }else{ 00519 SerialM->DataReceive((uint8_t*)databuf, code_size - stored_data_cnt); 00520 fwrite(databuf, 1, code_size - stored_data_cnt, fp); 00521 stored_data_cnt = code_size ; 00522 } 00523 memset(databuf,0,FIRMWARE_DATA_FRAGMENT_SIZE); 00524 } 00525 00526 SerialM->DataReceive((uint8_t*)databuf,2); 00527 if(databuf[0] == 0x80 && databuf[1] == 0x46 ){ 00528 if(print_flag == 1) 00529 hostpc->printf("\n!!Firmware Data Transmition END!!\n"); 00530 }else{ 00531 if(print_flag == 1) 00532 hostpc->printf("\n!!Firmware Data Transmition END ERROR!!\n"); 00533 } 00534 fclose(fp); 00535 wait(5); 00536 if(print_flag == 1) 00537 hostpc->printf("\n!!RESET MBED!!\n"); 00538 mbed_reset(); 00539 } 00540 00541 00542 00543 00544 }//namespace 00545 /// @} ext_fota module
Generated on Tue Jul 12 2022 21:25:05 by
