![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
BLE fota Lamp Demo
Dependencies: mbed-rtos mbed mbed_fota_fan_control
Fork of mbed_fota_fan_control by
ext_fota/BleMsgHandler.cpp@13:e714e2971c49, 2015-10-13 (annotated)
- Committer:
- dudnwjs
- Date:
- Tue Oct 13 06:35:19 2015 +0000
- Revision:
- 13:e714e2971c49
- Parent:
- 12:e3d3676753cc
lamp demo;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudnwjs | 8:9eec2c246a85 | 1 | /** |
dudnwjs | 8:9eec2c246a85 | 2 | * @file BleMsgHandler.cpp |
dudnwjs | 9:fcf91f563147 | 3 | * @brief Ble message handler ( Ble message is communication mathod between Mbed and DA14583 ) |
dudnwjs | 8:9eec2c246a85 | 4 | * Copyright 2015 SEVENCORE Co., Ltd. |
dudnwjs | 8:9eec2c246a85 | 5 | * |
dudnwjs | 8:9eec2c246a85 | 6 | * @author HyeongJun Kim |
dudnwjs | 8:9eec2c246a85 | 7 | * @version 1.0.0 |
dudnwjs | 8:9eec2c246a85 | 8 | * @date 2015-08-19 |
dudnwjs | 8:9eec2c246a85 | 9 | */ |
dudnwjs | 8:9eec2c246a85 | 10 | |
dudnwjs | 0:a1f6b1ba8a1e | 11 | #include "BleMsgHandler.h" |
dudnwjs | 3:1e70387e1337 | 12 | #include "dialog_fota_config.h" |
dudnwjs | 4:60be78a172c2 | 13 | #include "diss_task.h" |
dudnwjs | 5:e11b23f9aacc | 14 | #include "fota_server_task.h" |
dudnwjs | 4:60be78a172c2 | 15 | #include "app_task.h" |
dudnwjs | 12:e3d3676753cc | 16 | #include "fan_control_task.h" |
dudnwjs | 13:e714e2971c49 | 17 | #include "lamp_control_task.h" |
dudnwjs | 4:60be78a172c2 | 18 | |
dudnwjs | 8:9eec2c246a85 | 19 | /** |
dudnwjs | 8:9eec2c246a85 | 20 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 21 | * @addtogroup ext_fota module |
dudnwjs | 8:9eec2c246a85 | 22 | * @brief Ble message Handler Class Mathod Definition. |
dudnwjs | 8:9eec2c246a85 | 23 | * |
dudnwjs | 8:9eec2c246a85 | 24 | * @{ |
dudnwjs | 8:9eec2c246a85 | 25 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 26 | */ |
dudnwjs | 8:9eec2c246a85 | 27 | |
dudnwjs | 6:8dd20294b2aa | 28 | extern "C" void mbed_reset(); |
dudnwjs | 0:a1f6b1ba8a1e | 29 | |
dudnwjs | 0:a1f6b1ba8a1e | 30 | namespace sevencore_fota{ |
dudnwjs | 8:9eec2c246a85 | 31 | |
dudnwjs | 8:9eec2c246a85 | 32 | /** |
dudnwjs | 8:9eec2c246a85 | 33 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 34 | * @brief Ble message Handler Constructor. |
dudnwjs | 8:9eec2c246a85 | 35 | * @param[in] mbed serial class reference to device. |
dudnwjs | 8:9eec2c246a85 | 36 | * @detail Create SerialManager instance and Create inner MsgQueue |
dudnwjs | 8:9eec2c246a85 | 37 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 38 | */ |
dudnwjs | 0:a1f6b1ba8a1e | 39 | BleMsgHandler::BleMsgHandler(Serial *_device) |
dudnwjs | 0:a1f6b1ba8a1e | 40 | { |
dudnwjs | 0:a1f6b1ba8a1e | 41 | print_flag = 0; |
dudnwjs | 0:a1f6b1ba8a1e | 42 | device = _device; |
dudnwjs | 2:dba344c91bce | 43 | SerialM = new SerialManager(_device); |
dudnwjs | 3:1e70387e1337 | 44 | MsgQ = new MsgQueue(512); |
dudnwjs | 3:1e70387e1337 | 45 | memset(recv_msg,0,512); |
dudnwjs | 0:a1f6b1ba8a1e | 46 | } |
dudnwjs | 8:9eec2c246a85 | 47 | /** |
dudnwjs | 8:9eec2c246a85 | 48 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 49 | * @brief Ble message Handler Constructor. |
dudnwjs | 8:9eec2c246a85 | 50 | * @param[in] mbed serial class reference to device. |
dudnwjs | 8:9eec2c246a85 | 51 | * @param[in] mbed serial class reference to hostpc. |
dudnwjs | 8:9eec2c246a85 | 52 | * @detail Create SerialManager instance and Create inner MsgQueue |
dudnwjs | 8:9eec2c246a85 | 53 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 54 | */ |
dudnwjs | 0:a1f6b1ba8a1e | 55 | BleMsgHandler::BleMsgHandler(Serial *_device, Serial *_hostpc) |
dudnwjs | 0:a1f6b1ba8a1e | 56 | { |
dudnwjs | 0:a1f6b1ba8a1e | 57 | print_flag = 1; |
dudnwjs | 0:a1f6b1ba8a1e | 58 | device = _device; |
dudnwjs | 0:a1f6b1ba8a1e | 59 | hostpc = _hostpc; |
dudnwjs | 2:dba344c91bce | 60 | SerialM = new SerialManager(_device,_hostpc); |
dudnwjs | 3:1e70387e1337 | 61 | MsgQ = new MsgQueue(512); |
dudnwjs | 8:9eec2c246a85 | 62 | memset(recv_msg,0,512); |
dudnwjs | 0:a1f6b1ba8a1e | 63 | } |
dudnwjs | 8:9eec2c246a85 | 64 | /** |
dudnwjs | 8:9eec2c246a85 | 65 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 66 | * @brief Ble message Handler Destructor. |
dudnwjs | 8:9eec2c246a85 | 67 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 68 | */ |
dudnwjs | 1:5cf3a6c969be | 69 | BleMsgHandler::~BleMsgHandler(void) |
dudnwjs | 1:5cf3a6c969be | 70 | { |
dudnwjs | 2:dba344c91bce | 71 | free(SerialM); |
dudnwjs | 3:1e70387e1337 | 72 | free(MsgQ); |
dudnwjs | 1:5cf3a6c969be | 73 | } |
dudnwjs | 8:9eec2c246a85 | 74 | /** |
dudnwjs | 8:9eec2c246a85 | 75 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 76 | * @brief Ble message handler Start title print function. |
dudnwjs | 8:9eec2c246a85 | 77 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 78 | */ |
dudnwjs | 0:a1f6b1ba8a1e | 79 | void BleMsgHandler::PrintTitle(void) |
dudnwjs | 0:a1f6b1ba8a1e | 80 | { |
dudnwjs | 0:a1f6b1ba8a1e | 81 | if( print_flag == 1 ) |
dudnwjs | 5:e11b23f9aacc | 82 | hostpc->printf("\nSevencore Fota : BleMsg Handler Start\n"); |
dudnwjs | 5:e11b23f9aacc | 83 | //SerialM->ReceiveToSerialTest(); |
dudnwjs | 0:a1f6b1ba8a1e | 84 | } |
dudnwjs | 8:9eec2c246a85 | 85 | /** |
dudnwjs | 8:9eec2c246a85 | 86 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 87 | * @brief Create ble message. |
dudnwjs | 8:9eec2c246a85 | 88 | * @param[in] 16byte ble message type. @ref structure 'ble_hdr' member 'bType' |
dudnwjs | 8:9eec2c246a85 | 89 | * @param[in] 16byte ble dest task id(number). @ref structure 'ble_hdr' member 'bDstid' |
dudnwjs | 8:9eec2c246a85 | 90 | * @param[in] 16byte ble source task id(number). @ref structure 'ble_hdr' member 'bSrcid' |
dudnwjs | 8:9eec2c246a85 | 91 | * @param[in] 16byte ble message data length. @ref structure 'ble_hdr' member 'bLength' |
dudnwjs | 8:9eec2c246a85 | 92 | * @param[in] input data pointer. |
dudnwjs | 8:9eec2c246a85 | 93 | * @param[in] message alloc output pointer. |
dudnwjs | 8:9eec2c246a85 | 94 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 95 | */ |
dudnwjs | 3:1e70387e1337 | 96 | void BleMsgHandler::BleMsgAlloc( unsigned short id, |
dudnwjs | 3:1e70387e1337 | 97 | unsigned short dest_id, |
dudnwjs | 3:1e70387e1337 | 98 | unsigned short src_id, |
dudnwjs | 3:1e70387e1337 | 99 | unsigned short data_len, |
dudnwjs | 3:1e70387e1337 | 100 | void *pdata, |
dudnwjs | 3:1e70387e1337 | 101 | uint8_t *msg ) |
dudnwjs | 3:1e70387e1337 | 102 | { |
dudnwjs | 3:1e70387e1337 | 103 | memset(msg,0,sizeof(msg)); |
dudnwjs | 3:1e70387e1337 | 104 | msg[0] = 0x05; |
dudnwjs | 3:1e70387e1337 | 105 | memcpy(&msg[1],&id,sizeof(unsigned short)); |
dudnwjs | 3:1e70387e1337 | 106 | memcpy(&msg[1+1*sizeof(unsigned short)],&dest_id,sizeof(unsigned short)); |
dudnwjs | 3:1e70387e1337 | 107 | memcpy(&msg[1+2*sizeof(unsigned short)],&src_id,sizeof(unsigned short)); |
dudnwjs | 3:1e70387e1337 | 108 | memcpy(&msg[1+3*sizeof(unsigned short)],&data_len,sizeof(unsigned short)); |
dudnwjs | 3:1e70387e1337 | 109 | memcpy(&msg[1+4*sizeof(unsigned short)],pdata,data_len); |
dudnwjs | 3:1e70387e1337 | 110 | } |
dudnwjs | 8:9eec2c246a85 | 111 | /** |
dudnwjs | 8:9eec2c246a85 | 112 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 113 | * @brief Send ble message to device. |
dudnwjs | 8:9eec2c246a85 | 114 | * @param[in] sending message pointer |
dudnwjs | 8:9eec2c246a85 | 115 | * @param[in] message size. |
dudnwjs | 8:9eec2c246a85 | 116 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 117 | */ |
dudnwjs | 3:1e70387e1337 | 118 | int BleMsgHandler::BleSendMsg(uint8_t *msg, unsigned short size) |
dudnwjs | 3:1e70387e1337 | 119 | { |
dudnwjs | 3:1e70387e1337 | 120 | return SerialM->SendToSerial(msg,size); |
dudnwjs | 3:1e70387e1337 | 121 | } |
dudnwjs | 8:9eec2c246a85 | 122 | /** |
dudnwjs | 8:9eec2c246a85 | 123 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 124 | * @brief Receive ble message from device. |
dudnwjs | 8:9eec2c246a85 | 125 | * @detail Received message insert inner MsgQueue |
dudnwjs | 8:9eec2c246a85 | 126 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 127 | */ |
dudnwjs | 3:1e70387e1337 | 128 | void BleMsgHandler::BleReceiveMsg(void) |
dudnwjs | 3:1e70387e1337 | 129 | { |
dudnwjs | 3:1e70387e1337 | 130 | int receive_size = -1;//default |
dudnwjs | 3:1e70387e1337 | 131 | while(receive_size == -1) |
dudnwjs | 3:1e70387e1337 | 132 | { |
dudnwjs | 3:1e70387e1337 | 133 | receive_size = SerialM->ReceiveToSerial(recv_msg); |
dudnwjs | 3:1e70387e1337 | 134 | } |
dudnwjs | 3:1e70387e1337 | 135 | |
dudnwjs | 3:1e70387e1337 | 136 | uint8_t *msg; |
dudnwjs | 3:1e70387e1337 | 137 | msg = new uint8_t[receive_size]; |
dudnwjs | 3:1e70387e1337 | 138 | memcpy(msg,recv_msg,receive_size); |
dudnwjs | 3:1e70387e1337 | 139 | memset(recv_msg,0,512); |
dudnwjs | 3:1e70387e1337 | 140 | MsgQ->EnQueue(msg); |
dudnwjs | 3:1e70387e1337 | 141 | } |
dudnwjs | 8:9eec2c246a85 | 142 | /** |
dudnwjs | 8:9eec2c246a85 | 143 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 144 | * @brief Get message from MsgQueue and Execute corresponding function. |
dudnwjs | 8:9eec2c246a85 | 145 | * @detail After get message, extract message type. Each message type connect corresponding function |
dudnwjs | 8:9eec2c246a85 | 146 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 147 | */ |
dudnwjs | 3:1e70387e1337 | 148 | void BleMsgHandler::BleMsgHandle(void) |
dudnwjs | 3:1e70387e1337 | 149 | { |
dudnwjs | 4:60be78a172c2 | 150 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 151 | ble_hdr msg_hdr; |
dudnwjs | 4:60be78a172c2 | 152 | unsigned short paramPos = 1 + sizeof(msg_hdr); |
dudnwjs | 4:60be78a172c2 | 153 | |
dudnwjs | 3:1e70387e1337 | 154 | if( print_flag == 1) |
dudnwjs | 8:9eec2c246a85 | 155 | hostpc->printf("Ble-message Handle Function!\n"); |
dudnwjs | 4:60be78a172c2 | 156 | |
dudnwjs | 3:1e70387e1337 | 157 | msg = (uint8_t*)MsgQ->DeQueue(); |
dudnwjs | 3:1e70387e1337 | 158 | memcpy(&msg_hdr, &msg[1], sizeof(msg_hdr)); |
dudnwjs | 3:1e70387e1337 | 159 | |
dudnwjs | 3:1e70387e1337 | 160 | if( print_flag == 1 ) |
dudnwjs | 3:1e70387e1337 | 161 | hostpc->printf(" handle msg : id(%d), dst(%d), src(%d), len(%d) !\n", |
dudnwjs | 3:1e70387e1337 | 162 | msg_hdr.bType, msg_hdr.bDstid, msg_hdr.bSrcid, msg_hdr.bLength); |
dudnwjs | 3:1e70387e1337 | 163 | |
dudnwjs | 6:8dd20294b2aa | 164 | if (msg_hdr.bDstid != TASK_GTL){ |
dudnwjs | 6:8dd20294b2aa | 165 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 166 | hostpc->printf("Dstid not TASK_GTL!\n"); |
dudnwjs | 3:1e70387e1337 | 167 | return; |
dudnwjs | 6:8dd20294b2aa | 168 | } |
dudnwjs | 3:1e70387e1337 | 169 | |
dudnwjs | 4:60be78a172c2 | 170 | switch( msg_hdr.bType ) |
dudnwjs | 4:60be78a172c2 | 171 | { |
dudnwjs | 4:60be78a172c2 | 172 | case GAPM_CMP_EVT: |
dudnwjs | 5:e11b23f9aacc | 173 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 174 | hostpc->printf("==> GAPM_CMP_EVT!!\n"); |
dudnwjs | 4:60be78a172c2 | 175 | HandleGapmCmpEvt(msg_hdr.bType,(struct gapm_cmp_evt *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid); |
dudnwjs | 4:60be78a172c2 | 176 | break; |
dudnwjs | 4:60be78a172c2 | 177 | case GAPM_DEVICE_READY_IND: |
dudnwjs | 5:e11b23f9aacc | 178 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 179 | hostpc->printf("==> GAPM_DEVICE_READY_IND!!\n"); |
dudnwjs | 5:e11b23f9aacc | 180 | gapm_device_ready_ind_handler(msg_hdr.bType,(struct gap_ready_evt *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 4:60be78a172c2 | 181 | break; |
dudnwjs | 4:60be78a172c2 | 182 | case GAPM_ADV_REPORT_IND: |
dudnwjs | 5:e11b23f9aacc | 183 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 184 | hostpc->printf("==> GAPM_ADV_REPORT_IND!!\n"); |
dudnwjs | 4:60be78a172c2 | 185 | gapm_adv_report_ind_handler(msg_hdr.bType,(struct gapm_adv_report_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid); |
dudnwjs | 4:60be78a172c2 | 186 | break; |
dudnwjs | 4:60be78a172c2 | 187 | case GAPC_CMP_EVT: |
dudnwjs | 5:e11b23f9aacc | 188 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 189 | hostpc->printf("==> GAPC_CMP_EVT!!\n"); |
dudnwjs | 4:60be78a172c2 | 190 | HandleGapcCmpEvt(msg_hdr.bType,(struct gapc_cmp_evt *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid); |
dudnwjs | 4:60be78a172c2 | 191 | break; |
dudnwjs | 5:e11b23f9aacc | 192 | case GAPC_CONNECTION_REQ_IND: |
dudnwjs | 5:e11b23f9aacc | 193 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 194 | hostpc->printf("==> GAPC_CONNECTION_REQ_IND!!\n"); |
dudnwjs | 5:e11b23f9aacc | 195 | gapc_connection_req_ind_handler(msg_hdr.bType,(struct gapc_connection_req_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 5:e11b23f9aacc | 196 | break; |
dudnwjs | 5:e11b23f9aacc | 197 | case GAPC_DISCONNECT_IND: |
dudnwjs | 5:e11b23f9aacc | 198 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 199 | hostpc->printf("==> GAPC_DISCONNECT_IND!!\n"); |
dudnwjs | 5:e11b23f9aacc | 200 | gapc_disconnect_ind_handler(msg_hdr.bType,(struct gapc_disconnect_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 5:e11b23f9aacc | 201 | break; |
dudnwjs | 4:60be78a172c2 | 202 | case DISS_CREATE_DB_CFM: |
dudnwjs | 5:e11b23f9aacc | 203 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 204 | hostpc->printf("==> DISS_CREATE_DB_CFM!!\n"); |
dudnwjs | 4:60be78a172c2 | 205 | diss_create_db_cfm_handler(msg_hdr.bType,(struct diss_create_db_cfm *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 4:60be78a172c2 | 206 | break; |
dudnwjs | 4:60be78a172c2 | 207 | case DISS_DISABLE_IND: |
dudnwjs | 5:e11b23f9aacc | 208 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 209 | hostpc->printf("==> DISS_DISABLE_IND!!\n"); |
dudnwjs | 4:60be78a172c2 | 210 | break; |
dudnwjs | 4:60be78a172c2 | 211 | case DISS_ERROR_IND: |
dudnwjs | 4:60be78a172c2 | 212 | if ( print_flag == 1) |
dudnwjs | 4:60be78a172c2 | 213 | hostpc->printf("Rcved DISS_ERROR_IND Msg\n"); |
dudnwjs | 4:60be78a172c2 | 214 | break; |
dudnwjs | 5:e11b23f9aacc | 215 | case FOTA_SERVER_CREATE_DB_CFM: |
dudnwjs | 5:e11b23f9aacc | 216 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 217 | hostpc->printf("==> FOTA_SERVER_CREATE_DB_CFM!!\n"); |
dudnwjs | 5:e11b23f9aacc | 218 | fota_server_create_db_cfm_handler(msg_hdr.bType,(struct fota_server_create_db_cfm *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 5:e11b23f9aacc | 219 | break; |
dudnwjs | 5:e11b23f9aacc | 220 | case FOTA_SERVER_DISABLE_IND: |
dudnwjs | 5:e11b23f9aacc | 221 | if( print_flag == 1) |
dudnwjs | 12:e3d3676753cc | 222 | hostpc->printf("==> FOTA_SERVER_DISABLE_IND!!\n"); |
dudnwjs | 12:e3d3676753cc | 223 | break; |
dudnwjs | 12:e3d3676753cc | 224 | case FOTA_SERVER_DATA_FLASH_IND: |
dudnwjs | 12:e3d3676753cc | 225 | if ( print_flag == 1) |
dudnwjs | 12:e3d3676753cc | 226 | hostpc->printf("Rcved FOTA_SERVER_DATA_FLASH_IND Msg\n"); |
dudnwjs | 12:e3d3676753cc | 227 | fota_server_data_flash_ind_handler(msg_hdr.bType,(struct fota_server_data_flash_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 5:e11b23f9aacc | 228 | break; |
dudnwjs | 5:e11b23f9aacc | 229 | case FOTA_SERVER_ERROR_IND: |
dudnwjs | 5:e11b23f9aacc | 230 | if ( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 231 | hostpc->printf("Rcved FOTA_SERVER_ERROR_IND Msg\n"); |
dudnwjs | 12:e3d3676753cc | 232 | break; |
dudnwjs | 12:e3d3676753cc | 233 | case FAN_CONTROL_CREATE_DB_CFM: |
dudnwjs | 12:e3d3676753cc | 234 | if ( print_flag == 1) |
dudnwjs | 12:e3d3676753cc | 235 | hostpc->printf("Rcved FAN_CONTROL_CREATE_DB_CFM Msg\n"); |
dudnwjs | 12:e3d3676753cc | 236 | fan_control_create_db_cfm_handler(msg_hdr.bType,(struct fan_control_create_db_cfm *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 12:e3d3676753cc | 237 | break; |
dudnwjs | 12:e3d3676753cc | 238 | case FAN_CONTROL_DISABLE_IND: |
dudnwjs | 12:e3d3676753cc | 239 | if( print_flag == 1) |
dudnwjs | 12:e3d3676753cc | 240 | hostpc->printf("==> FAN_CONTROL_DISABLE_IND!!\n"); |
dudnwjs | 12:e3d3676753cc | 241 | break; |
dudnwjs | 12:e3d3676753cc | 242 | case FAN_CONTROL_COMMAND_IND: |
dudnwjs | 12:e3d3676753cc | 243 | if( print_flag == 1) |
dudnwjs | 12:e3d3676753cc | 244 | hostpc->printf("==> FAN_CONTROL_COMMAND_IND msg\n"); |
dudnwjs | 12:e3d3676753cc | 245 | fan_control_command_ind_handler(msg_hdr.bType,(struct fan_control_command_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 12:e3d3676753cc | 246 | break; |
dudnwjs | 12:e3d3676753cc | 247 | case FAN_CONTROL_ERROR_IND: |
dudnwjs | 12:e3d3676753cc | 248 | if( print_flag == 1) |
dudnwjs | 12:e3d3676753cc | 249 | hostpc->printf("==> FAN_CONTROL_ERROR_IND !!\n"); |
dudnwjs | 12:e3d3676753cc | 250 | break; |
dudnwjs | 13:e714e2971c49 | 251 | case LAMP_CONTROL_CREATE_DB_CFM: |
dudnwjs | 13:e714e2971c49 | 252 | if ( print_flag == 1) |
dudnwjs | 13:e714e2971c49 | 253 | hostpc->printf("Rcved LAMP_CONTROL_CREATE_DB_CFM Msg\n"); |
dudnwjs | 13:e714e2971c49 | 254 | lamp_control_create_db_cfm_handler(msg_hdr.bType,(struct lamp_control_create_db_cfm *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 13:e714e2971c49 | 255 | break; |
dudnwjs | 13:e714e2971c49 | 256 | case LAMP_CONTROL_DISABLE_IND: |
dudnwjs | 13:e714e2971c49 | 257 | if( print_flag == 1) |
dudnwjs | 13:e714e2971c49 | 258 | hostpc->printf("==> LAMP_CONTROL_DISABLE_IND!!\n"); |
dudnwjs | 13:e714e2971c49 | 259 | break; |
dudnwjs | 13:e714e2971c49 | 260 | case LAMP_CONTROL_COMMAND_IND: |
dudnwjs | 13:e714e2971c49 | 261 | if( print_flag == 1) |
dudnwjs | 13:e714e2971c49 | 262 | hostpc->printf("==> LAMP_CONTROL_COMMAND_IND msg\n"); |
dudnwjs | 13:e714e2971c49 | 263 | lamp_control_command_ind_handler(msg_hdr.bType,(struct lamp_control_command_ind *)&msg[paramPos],msg_hdr.bDstid,msg_hdr.bSrcid,this); |
dudnwjs | 13:e714e2971c49 | 264 | break; |
dudnwjs | 13:e714e2971c49 | 265 | case LAMP_CONTROL_ERROR_IND: |
dudnwjs | 13:e714e2971c49 | 266 | if( print_flag == 1) |
dudnwjs | 13:e714e2971c49 | 267 | hostpc->printf("==> LAMP_CONTROL_ERROR_IND !!\n"); |
dudnwjs | 13:e714e2971c49 | 268 | break; |
dudnwjs | 4:60be78a172c2 | 269 | default: |
dudnwjs | 4:60be78a172c2 | 270 | if( print_flag == 1) |
dudnwjs | 8:9eec2c246a85 | 271 | hostpc->printf("message Type Not Defined ! \n"); |
dudnwjs | 4:60be78a172c2 | 272 | break; |
dudnwjs | 4:60be78a172c2 | 273 | } |
dudnwjs | 5:e11b23f9aacc | 274 | }//gapc_disconnect_ind_handler(GAPC_DISCONNECT_IND),(GAPC_CONNECTION_REQ_IND)gapc_connection_req_ind_handler |
dudnwjs | 8:9eec2c246a85 | 275 | /** |
dudnwjs | 8:9eec2c246a85 | 276 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 277 | * @brief GAPM Command Event Handler. |
dudnwjs | 8:9eec2c246a85 | 278 | * @detail After get GAPM command, extract operation. Each operation connect corresponding function |
dudnwjs | 8:9eec2c246a85 | 279 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 280 | */ |
dudnwjs | 4:60be78a172c2 | 281 | void BleMsgHandler::HandleGapmCmpEvt(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 282 | struct gapm_cmp_evt *param, |
dudnwjs | 4:60be78a172c2 | 283 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 284 | unsigned short src_id) |
dudnwjs | 4:60be78a172c2 | 285 | { |
dudnwjs | 4:60be78a172c2 | 286 | if (param->status == CO_ERROR_NO_ERROR) |
dudnwjs | 4:60be78a172c2 | 287 | { |
dudnwjs | 4:60be78a172c2 | 288 | switch(param->operation) |
dudnwjs | 4:60be78a172c2 | 289 | { |
dudnwjs | 4:60be78a172c2 | 290 | case GAPM_NO_OP:// No operation. |
dudnwjs | 4:60be78a172c2 | 291 | break; |
dudnwjs | 4:60be78a172c2 | 292 | case GAPM_RESET:// Reset BLE subsystem: LL and HL. |
dudnwjs | 5:e11b23f9aacc | 293 | if( print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 294 | hostpc->printf("GAPM_RESET!! Start...\n"); |
dudnwjs | 4:60be78a172c2 | 295 | gapm_reset_completion_handler (msgid, (struct gapm_cmp_evt *)param, dest_id, src_id,this); |
dudnwjs | 4:60be78a172c2 | 296 | break; |
dudnwjs | 4:60be78a172c2 | 297 | case GAPM_CANCEL:// Cancel currently executed operation. |
dudnwjs | 6:8dd20294b2aa | 298 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 299 | hostpc->printf("GAPM_CANCEL\n"); |
dudnwjs | 4:60be78a172c2 | 300 | break; |
dudnwjs | 4:60be78a172c2 | 301 | case GAPM_SET_DEV_CONFIG:// Set device configuration |
dudnwjs | 4:60be78a172c2 | 302 | if( print_flag == 1) |
dudnwjs | 4:60be78a172c2 | 303 | hostpc->printf("Adverting Start...\n"); |
dudnwjs | 4:60be78a172c2 | 304 | gapm_set_dev_config_completion_handler(msgid, (struct gapm_cmp_evt *)param, dest_id, src_id,this); |
dudnwjs | 4:60be78a172c2 | 305 | break; |
dudnwjs | 4:60be78a172c2 | 306 | case GAPM_SET_DEV_NAME: // Set device name |
dudnwjs | 6:8dd20294b2aa | 307 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 308 | hostpc->printf("GAPM_SET_DEV_NAME\n"); |
dudnwjs | 4:60be78a172c2 | 309 | break; |
dudnwjs | 4:60be78a172c2 | 310 | case GAPM_SET_CHANNEL_MAP:// Set device channel map |
dudnwjs | 6:8dd20294b2aa | 311 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 312 | hostpc->printf("GAPM_SET_CHANNEL_MAP\n"); |
dudnwjs | 4:60be78a172c2 | 313 | break; |
dudnwjs | 4:60be78a172c2 | 314 | case GAPM_GET_DEV_NAME:// Get Local device name |
dudnwjs | 6:8dd20294b2aa | 315 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 316 | hostpc->printf("GAPM_GET_DEV_NAME\n"); |
dudnwjs | 4:60be78a172c2 | 317 | break; |
dudnwjs | 4:60be78a172c2 | 318 | case GAPM_GET_DEV_VERSION:// Get Local device version |
dudnwjs | 6:8dd20294b2aa | 319 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 320 | hostpc->printf("GAPM_GET_DEV_VERSION\n"); |
dudnwjs | 4:60be78a172c2 | 321 | break; |
dudnwjs | 4:60be78a172c2 | 322 | case GAPM_GET_DEV_BDADDR:// Get Local device BD Address |
dudnwjs | 6:8dd20294b2aa | 323 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 324 | hostpc->printf("GAPM_GET_DEV_BDADDR\n"); |
dudnwjs | 4:60be78a172c2 | 325 | break; |
dudnwjs | 4:60be78a172c2 | 326 | case GAPM_GET_WLIST_SIZE:// Get White List Size. |
dudnwjs | 6:8dd20294b2aa | 327 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 328 | hostpc->printf("GAPM_GET_WLIST_SIZE\n"); |
dudnwjs | 4:60be78a172c2 | 329 | break; |
dudnwjs | 4:60be78a172c2 | 330 | case GAPM_ADD_DEV_IN_WLIST:// Add devices in white list. |
dudnwjs | 6:8dd20294b2aa | 331 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 332 | hostpc->printf("GAPM_ADD_DEV_IN_WLIST\n"); |
dudnwjs | 4:60be78a172c2 | 333 | break; |
dudnwjs | 4:60be78a172c2 | 334 | case GAPM_RMV_DEV_FRM_WLIST:// Remove devices form white list. |
dudnwjs | 6:8dd20294b2aa | 335 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 336 | hostpc->printf("GAPM_RMV_DEV_FRM_WLIST\n"); |
dudnwjs | 4:60be78a172c2 | 337 | break; |
dudnwjs | 4:60be78a172c2 | 338 | case GAPM_CLEAR_WLIST:// Clear all devices from white list. |
dudnwjs | 6:8dd20294b2aa | 339 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 340 | hostpc->printf("GAPM_CLEAR_WLIST\n"); |
dudnwjs | 4:60be78a172c2 | 341 | break; |
dudnwjs | 4:60be78a172c2 | 342 | case GAPM_ADV_NON_CONN:// Start non connectable advertising |
dudnwjs | 4:60be78a172c2 | 343 | case GAPM_ADV_UNDIRECT:// Start undirected connectable advertising |
dudnwjs | 4:60be78a172c2 | 344 | case GAPM_ADV_DIRECT:// Start directed connectable advertising |
dudnwjs | 6:8dd20294b2aa | 345 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 346 | hostpc->printf("GAPM_ADV_~\n"); |
dudnwjs | 6:8dd20294b2aa | 347 | break; |
dudnwjs | 4:60be78a172c2 | 348 | case GAPM_SCAN_ACTIVE:// Start active scan operation |
dudnwjs | 4:60be78a172c2 | 349 | case GAPM_SCAN_PASSIVE: // Start passive scan operation |
dudnwjs | 6:8dd20294b2aa | 350 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 351 | hostpc->printf("GAPM_SCAN_~\n"); |
dudnwjs | 4:60be78a172c2 | 352 | break; |
dudnwjs | 4:60be78a172c2 | 353 | case GAPM_CONNECTION_DIRECT:// Direct connection operation |
dudnwjs | 6:8dd20294b2aa | 354 | //break; |
dudnwjs | 4:60be78a172c2 | 355 | case GAPM_CONNECTION_AUTO:// Automatic connection operation |
dudnwjs | 6:8dd20294b2aa | 356 | //break; |
dudnwjs | 4:60be78a172c2 | 357 | case GAPM_CONNECTION_SELECTIVE:// Selective connection operation |
dudnwjs | 6:8dd20294b2aa | 358 | //break; |
dudnwjs | 4:60be78a172c2 | 359 | case GAPM_CONNECTION_NAME_REQUEST:// Name Request operation (requires to start a direct connection) |
dudnwjs | 6:8dd20294b2aa | 360 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 361 | hostpc->printf("GAPM_CONNECT_~\n"); |
dudnwjs | 4:60be78a172c2 | 362 | break; |
dudnwjs | 4:60be78a172c2 | 363 | case GAPM_RESOLV_ADDR:// Resolve device address |
dudnwjs | 6:8dd20294b2aa | 364 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 365 | hostpc->printf("GAPM_RESOLV_ADDR\n"); |
dudnwjs | 4:60be78a172c2 | 366 | break; |
dudnwjs | 4:60be78a172c2 | 367 | case GAPM_GEN_RAND_ADDR:// Generate a random address |
dudnwjs | 6:8dd20294b2aa | 368 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 369 | hostpc->printf("GAPM_GEN_RAND_ADDR\n"); |
dudnwjs | 4:60be78a172c2 | 370 | break; |
dudnwjs | 4:60be78a172c2 | 371 | case GAPM_USE_ENC_BLOCK:// Use the controller's AES-128 block |
dudnwjs | 6:8dd20294b2aa | 372 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 373 | hostpc->printf("GAPM_USE_ENC_BLOCK\n"); |
dudnwjs | 4:60be78a172c2 | 374 | break; |
dudnwjs | 4:60be78a172c2 | 375 | case GAPM_GEN_RAND_NB:// Generate a 8-byte random number |
dudnwjs | 6:8dd20294b2aa | 376 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 377 | hostpc->printf("GAPM_GEN_RAND_NB\n"); |
dudnwjs | 4:60be78a172c2 | 378 | break; |
dudnwjs | 4:60be78a172c2 | 379 | case GAPM_DBG_GET_MEM_INFO:// Get memory usage |
dudnwjs | 6:8dd20294b2aa | 380 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 381 | hostpc->printf("GAPM_GAPM_DBG_GET_MEM_INFO\n"); |
dudnwjs | 4:60be78a172c2 | 382 | break; |
dudnwjs | 4:60be78a172c2 | 383 | case GAPM_PLF_RESET:// Perform a platform reset |
dudnwjs | 6:8dd20294b2aa | 384 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 385 | hostpc->printf("GAPM_PLF_RESET\n"); |
dudnwjs | 4:60be78a172c2 | 386 | break; |
dudnwjs | 4:60be78a172c2 | 387 | case GAPM_GET_DEV_ADV_TX_POWER:// Get device advertising power level |
dudnwjs | 6:8dd20294b2aa | 388 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 389 | hostpc->printf("GAPM_GET_DEV_ADV_TX_POWER\n"); |
dudnwjs | 6:8dd20294b2aa | 390 | break; |
dudnwjs | 6:8dd20294b2aa | 391 | default: |
dudnwjs | 6:8dd20294b2aa | 392 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 393 | hostpc->printf("??????????????????????????\n"); |
dudnwjs | 4:60be78a172c2 | 394 | break; |
dudnwjs | 4:60be78a172c2 | 395 | } |
dudnwjs | 6:8dd20294b2aa | 396 | }else{ |
dudnwjs | 6:8dd20294b2aa | 397 | if( print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 398 | hostpc->printf("?status ERROR?\n"); |
dudnwjs | 4:60be78a172c2 | 399 | } |
dudnwjs | 4:60be78a172c2 | 400 | } |
dudnwjs | 8:9eec2c246a85 | 401 | /** |
dudnwjs | 8:9eec2c246a85 | 402 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 403 | * @brief GAPC Command Event Handler. |
dudnwjs | 8:9eec2c246a85 | 404 | * @detail After get GAPC command, extract operation. Each operation connect corresponding function |
dudnwjs | 8:9eec2c246a85 | 405 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 406 | */ |
dudnwjs | 4:60be78a172c2 | 407 | void BleMsgHandler::HandleGapcCmpEvt(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 408 | struct gapc_cmp_evt *param, |
dudnwjs | 4:60be78a172c2 | 409 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 410 | unsigned short src_id) |
dudnwjs | 4:60be78a172c2 | 411 | { |
dudnwjs | 4:60be78a172c2 | 412 | switch(param->operation) |
dudnwjs | 4:60be78a172c2 | 413 | { |
dudnwjs | 4:60be78a172c2 | 414 | case GAPC_NO_OP: // No operation |
dudnwjs | 4:60be78a172c2 | 415 | break; |
dudnwjs | 4:60be78a172c2 | 416 | case GAPC_DISCONNECT: // Disconnect link |
dudnwjs | 4:60be78a172c2 | 417 | break; |
dudnwjs | 4:60be78a172c2 | 418 | case GAPC_GET_PEER_NAME: // Retrieve name of peer device |
dudnwjs | 4:60be78a172c2 | 419 | break; |
dudnwjs | 4:60be78a172c2 | 420 | case GAPC_GET_PEER_VERSION: // Retrieve peer device version info. |
dudnwjs | 4:60be78a172c2 | 421 | break; |
dudnwjs | 4:60be78a172c2 | 422 | case GAPC_GET_PEER_FEATURES: // Retrieve peer device features. |
dudnwjs | 4:60be78a172c2 | 423 | break; |
dudnwjs | 4:60be78a172c2 | 424 | case GAPC_GET_CON_RSSI: // Retrieve connection RSSI. |
dudnwjs | 4:60be78a172c2 | 425 | break; |
dudnwjs | 4:60be78a172c2 | 426 | case GAPC_GET_PRIVACY: // Retrieve Privacy Info. |
dudnwjs | 4:60be78a172c2 | 427 | break; |
dudnwjs | 4:60be78a172c2 | 428 | case GAPC_GET_RECON_ADDR: // Retrieve Reconnection Address Value. |
dudnwjs | 4:60be78a172c2 | 429 | break; |
dudnwjs | 4:60be78a172c2 | 430 | case GAPC_SET_PRIVACY: // Set Privacy flag. |
dudnwjs | 4:60be78a172c2 | 431 | break; |
dudnwjs | 4:60be78a172c2 | 432 | case GAPC_SET_RECON_ADDR: // Set Reconnection Address Value. |
dudnwjs | 4:60be78a172c2 | 433 | break; |
dudnwjs | 4:60be78a172c2 | 434 | case GAPC_UPDATE_PARAMS: // Perform update of connection parameters. |
dudnwjs | 4:60be78a172c2 | 435 | break; |
dudnwjs | 4:60be78a172c2 | 436 | case GAPC_BOND: // Start bonding procedure. |
dudnwjs | 4:60be78a172c2 | 437 | break; |
dudnwjs | 4:60be78a172c2 | 438 | case GAPC_ENCRYPT: // Start encryption procedure. |
dudnwjs | 4:60be78a172c2 | 439 | break; |
dudnwjs | 4:60be78a172c2 | 440 | case GAPC_SECURITY_REQ: // Start security request procedure |
dudnwjs | 4:60be78a172c2 | 441 | break; |
dudnwjs | 4:60be78a172c2 | 442 | case GAPC_GET_CON_CHANNEL_MAP: // Retrieve Connection Channel MAP. |
dudnwjs | 4:60be78a172c2 | 443 | break; |
dudnwjs | 4:60be78a172c2 | 444 | } |
dudnwjs | 4:60be78a172c2 | 445 | } |
dudnwjs | 8:9eec2c246a85 | 446 | /** |
dudnwjs | 8:9eec2c246a85 | 447 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 448 | * @brief Debugging message output to hostpc. |
dudnwjs | 8:9eec2c246a85 | 449 | * @param[in] output char array pointer |
dudnwjs | 8:9eec2c246a85 | 450 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 451 | */ |
dudnwjs | 5:e11b23f9aacc | 452 | void BleMsgHandler::HostPcPrint(char *str) |
dudnwjs | 5:e11b23f9aacc | 453 | { |
dudnwjs | 5:e11b23f9aacc | 454 | if(print_flag == 1) |
dudnwjs | 5:e11b23f9aacc | 455 | hostpc->printf("%s",str); |
dudnwjs | 5:e11b23f9aacc | 456 | } |
dudnwjs | 8:9eec2c246a85 | 457 | /** |
dudnwjs | 8:9eec2c246a85 | 458 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 459 | * @brief Receive test method |
dudnwjs | 8:9eec2c246a85 | 460 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 461 | */ |
dudnwjs | 5:e11b23f9aacc | 462 | void BleMsgHandler::ReceiveToSerialTest(void) |
dudnwjs | 5:e11b23f9aacc | 463 | { |
dudnwjs | 5:e11b23f9aacc | 464 | SerialM->ReceiveToSerialTest(); |
dudnwjs | 5:e11b23f9aacc | 465 | } |
dudnwjs | 8:9eec2c246a85 | 466 | /** |
dudnwjs | 8:9eec2c246a85 | 467 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 468 | * @brief Receive and Store Da14583 flash data. |
dudnwjs | 8:9eec2c246a85 | 469 | * @param[in] mbed binary file size |
dudnwjs | 8:9eec2c246a85 | 470 | * @param[in] mbed binary version string |
dudnwjs | 8:9eec2c246a85 | 471 | **************************************************************************************** |
dudnwjs | 8:9eec2c246a85 | 472 | */ |
dudnwjs | 6:8dd20294b2aa | 473 | void BleMsgHandler::FirmwareDataReceive(unsigned short code_size, char *version) |
dudnwjs | 6:8dd20294b2aa | 474 | { |
dudnwjs | 6:8dd20294b2aa | 475 | unsigned short stored_data_cnt = 0; |
dudnwjs | 7:3478c46cceef | 476 | char path[20]="/local/"; |
dudnwjs | 7:3478c46cceef | 477 | char databuf[FIRMWARE_DATA_FRAGMENT_SIZE]="/local/"; |
dudnwjs | 6:8dd20294b2aa | 478 | if(print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 479 | hostpc->printf("\n!!File name = %s!! code_size = %d\n",version,code_size); |
dudnwjs | 7:3478c46cceef | 480 | strcat(databuf, version); |
dudnwjs | 7:3478c46cceef | 481 | strcat(databuf, ".BIN"); |
dudnwjs | 6:8dd20294b2aa | 482 | hostpc->printf("\n!!name = %s!\n",databuf); |
dudnwjs | 6:8dd20294b2aa | 483 | |
dudnwjs | 6:8dd20294b2aa | 484 | |
dudnwjs | 6:8dd20294b2aa | 485 | DIR *d = opendir("/local/"); |
dudnwjs | 6:8dd20294b2aa | 486 | struct dirent *p; |
dudnwjs | 6:8dd20294b2aa | 487 | while ((p = readdir(d)) != NULL) |
dudnwjs | 6:8dd20294b2aa | 488 | { |
dudnwjs | 7:3478c46cceef | 489 | hostpc->printf("%s,%d\n", p->d_name,strcmp(strchr(p->d_name,'.')+1,"BIN")); |
dudnwjs | 7:3478c46cceef | 490 | if( strcmp(strchr(p->d_name,'.')+1,"BIN") == 0 ){ |
dudnwjs | 7:3478c46cceef | 491 | strcat(path,p->d_name); |
dudnwjs | 7:3478c46cceef | 492 | hostpc->printf("%s\n",path); |
dudnwjs | 7:3478c46cceef | 493 | remove(path); |
dudnwjs | 7:3478c46cceef | 494 | strcpy(path,"/local/"); |
dudnwjs | 7:3478c46cceef | 495 | } |
dudnwjs | 6:8dd20294b2aa | 496 | } |
dudnwjs | 6:8dd20294b2aa | 497 | closedir(d); |
dudnwjs | 6:8dd20294b2aa | 498 | |
dudnwjs | 7:3478c46cceef | 499 | fp = fopen(databuf, "w"); |
dudnwjs | 6:8dd20294b2aa | 500 | |
dudnwjs | 7:3478c46cceef | 501 | SerialM->DataReceive((uint8_t*)databuf,2); |
dudnwjs | 6:8dd20294b2aa | 502 | if(databuf[0] == 0x80 && databuf[1] == 0x46 ){ |
dudnwjs | 6:8dd20294b2aa | 503 | if(print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 504 | hostpc->printf("\n!!Firmware Data Transmition Start!!\n"); |
dudnwjs | 6:8dd20294b2aa | 505 | }else{ |
dudnwjs | 6:8dd20294b2aa | 506 | if(print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 507 | hostpc->printf("\n!!Firmware Data Transmition ERROR!!\n"); |
dudnwjs | 6:8dd20294b2aa | 508 | } |
dudnwjs | 6:8dd20294b2aa | 509 | |
dudnwjs | 6:8dd20294b2aa | 510 | memset(databuf,0,FIRMWARE_DATA_FRAGMENT_SIZE); |
dudnwjs | 6:8dd20294b2aa | 511 | |
dudnwjs | 6:8dd20294b2aa | 512 | while( stored_data_cnt < code_size ) |
dudnwjs | 6:8dd20294b2aa | 513 | { |
dudnwjs | 6:8dd20294b2aa | 514 | if( code_size - stored_data_cnt >= FIRMWARE_DATA_FRAGMENT_SIZE ){ |
dudnwjs | 7:3478c46cceef | 515 | SerialM->DataReceive((uint8_t*)databuf,FIRMWARE_DATA_FRAGMENT_SIZE); |
dudnwjs | 6:8dd20294b2aa | 516 | fwrite(databuf, 1, FIRMWARE_DATA_FRAGMENT_SIZE, fp); |
dudnwjs | 6:8dd20294b2aa | 517 | stored_data_cnt += FIRMWARE_DATA_FRAGMENT_SIZE; |
dudnwjs | 6:8dd20294b2aa | 518 | }else{ |
dudnwjs | 7:3478c46cceef | 519 | SerialM->DataReceive((uint8_t*)databuf, code_size - stored_data_cnt); |
dudnwjs | 6:8dd20294b2aa | 520 | fwrite(databuf, 1, code_size - stored_data_cnt, fp); |
dudnwjs | 6:8dd20294b2aa | 521 | stored_data_cnt = code_size ; |
dudnwjs | 6:8dd20294b2aa | 522 | } |
dudnwjs | 6:8dd20294b2aa | 523 | memset(databuf,0,FIRMWARE_DATA_FRAGMENT_SIZE); |
dudnwjs | 6:8dd20294b2aa | 524 | } |
dudnwjs | 6:8dd20294b2aa | 525 | |
dudnwjs | 7:3478c46cceef | 526 | SerialM->DataReceive((uint8_t*)databuf,2); |
dudnwjs | 6:8dd20294b2aa | 527 | if(databuf[0] == 0x80 && databuf[1] == 0x46 ){ |
dudnwjs | 6:8dd20294b2aa | 528 | if(print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 529 | hostpc->printf("\n!!Firmware Data Transmition END!!\n"); |
dudnwjs | 6:8dd20294b2aa | 530 | }else{ |
dudnwjs | 6:8dd20294b2aa | 531 | if(print_flag == 1) |
dudnwjs | 6:8dd20294b2aa | 532 | hostpc->printf("\n!!Firmware Data Transmition END ERROR!!\n"); |
dudnwjs | 6:8dd20294b2aa | 533 | } |
dudnwjs | 6:8dd20294b2aa | 534 | fclose(fp); |
dudnwjs | 8:9eec2c246a85 | 535 | wait(5); |
dudnwjs | 8:9eec2c246a85 | 536 | if(print_flag == 1) |
dudnwjs | 8:9eec2c246a85 | 537 | hostpc->printf("\n!!RESET MBED!!\n"); |
dudnwjs | 6:8dd20294b2aa | 538 | mbed_reset(); |
dudnwjs | 6:8dd20294b2aa | 539 | } |
dudnwjs | 5:e11b23f9aacc | 540 | |
dudnwjs | 5:e11b23f9aacc | 541 | |
dudnwjs | 3:1e70387e1337 | 542 | |
dudnwjs | 0:a1f6b1ba8a1e | 543 | |
dudnwjs | 0:a1f6b1ba8a1e | 544 | }//namespace |
dudnwjs | 8:9eec2c246a85 | 545 | /// @} ext_fota module |