BLE fota Lamp Demo

Dependencies:   mbed-rtos mbed mbed_fota_fan_control

Fork of mbed_fota_fan_control by KIM HyoengJun

Committer:
dudnwjs
Date:
Mon Aug 24 02:29:16 2015 +0000
Revision:
9:fcf91f563147
Parent:
8:9eec2c246a85
Child:
12:e3d3676753cc
Add comment for form doxygen;

Who changed what in which revision?

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