Fan Control Demo

Dependencies:   mbed-rtos mbed

Fork of mbed_fota by KIM HyoengJun

Committer:
dudnwjs
Date:
Mon Aug 24 03:24:19 2015 +0000
Revision:
11:1ed93accb3fb
Parent:
9:fcf91f563147
Child:
12:e3d3676753cc
Modify app_task.cpp comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dudnwjs 9:fcf91f563147 1 /**
dudnwjs 11:1ed93accb3fb 2 * @file app_task.cpp
dudnwjs 9:fcf91f563147 3 * @brief Handling for ble events and responses.
dudnwjs 9:fcf91f563147 4 * Copyright 2015 SEVENCORE Co., Ltd.
dudnwjs 9:fcf91f563147 5 *
dudnwjs 9:fcf91f563147 6 * @author HyeongJun Kim
dudnwjs 9:fcf91f563147 7 * @version 1.0.0
dudnwjs 9:fcf91f563147 8 * @date 2015-08-20
dudnwjs 9:fcf91f563147 9 */
dudnwjs 4:60be78a172c2 10 #include "app_task.h"
dudnwjs 4:60be78a172c2 11 #include "app.h"
dudnwjs 5:e11b23f9aacc 12 #include "fota_server_task.h"
dudnwjs 4:60be78a172c2 13
dudnwjs 6:8dd20294b2aa 14 #define BLE_FOTA_SERVICE 1
dudnwjs 9:fcf91f563147 15 /**
dudnwjs 9:fcf91f563147 16 ****************************************************************************************
dudnwjs 9:fcf91f563147 17 * @addtogroup dialog_fota module
dudnwjs 9:fcf91f563147 18 * @brief application handlers for ble events and responses.
dudnwjs 9:fcf91f563147 19 *
dudnwjs 9:fcf91f563147 20 * @{
dudnwjs 9:fcf91f563147 21 ****************************************************************************************
dudnwjs 9:fcf91f563147 22 */
dudnwjs 4:60be78a172c2 23 namespace sevencore_fota{
dudnwjs 9:fcf91f563147 24
dudnwjs 9:fcf91f563147 25 /**
dudnwjs 9:fcf91f563147 26 ****************************************************************************************
dudnwjs 9:fcf91f563147 27 * @brief Handles GAPM_ADV_REPORT_IND event.
dudnwjs 9:fcf91f563147 28 *
dudnwjs 9:fcf91f563147 29 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 30 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 31 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 32 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 33 *
dudnwjs 9:fcf91f563147 34 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 35 ****************************************************************************************
dudnwjs 9:fcf91f563147 36 */
dudnwjs 4:60be78a172c2 37 int gapm_adv_report_ind_handler(unsigned short msgid,
dudnwjs 4:60be78a172c2 38 struct gapm_adv_report_ind *param,
dudnwjs 4:60be78a172c2 39 unsigned short dest_id,
dudnwjs 4:60be78a172c2 40 unsigned short src_id)
dudnwjs 4:60be78a172c2 41 {
dudnwjs 4:60be78a172c2 42 //if (app_env.state != APP_SCAN)
dudnwjs 4:60be78a172c2 43 // return -1;
dudnwjs 4:60be78a172c2 44
dudnwjs 4:60be78a172c2 45 return 0;
dudnwjs 4:60be78a172c2 46 }
dudnwjs 9:fcf91f563147 47 /**
dudnwjs 9:fcf91f563147 48 ****************************************************************************************
dudnwjs 9:fcf91f563147 49 * @brief Handles the DISS_CREATE_DB_CFM message.
dudnwjs 9:fcf91f563147 50 *
dudnwjs 9:fcf91f563147 51 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 52 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 53 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 54 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 55 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 56 *
dudnwjs 9:fcf91f563147 57 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 58 ****************************************************************************************
dudnwjs 9:fcf91f563147 59 */
dudnwjs 4:60be78a172c2 60 int diss_create_db_cfm_handler(unsigned short msgid,
dudnwjs 4:60be78a172c2 61 struct diss_create_db_cfm *param,
dudnwjs 4:60be78a172c2 62 unsigned short dest_id,
dudnwjs 4:60be78a172c2 63 unsigned short src_id,
dudnwjs 4:60be78a172c2 64 BleMsgHandler* BMH)
dudnwjs 4:60be78a172c2 65 {
dudnwjs 6:8dd20294b2aa 66
dudnwjs 5:e11b23f9aacc 67 uint8_t len = strlen(APP_DIS_SW_REV);
dudnwjs 5:e11b23f9aacc 68
dudnwjs 4:60be78a172c2 69 if (param->status == CO_ERROR_NO_ERROR)
dudnwjs 4:60be78a172c2 70 {
dudnwjs 5:e11b23f9aacc 71 char str[22] = "\nDIS SET DB\n";
dudnwjs 5:e11b23f9aacc 72 BMH->HostPcPrint(str);
dudnwjs 4:60be78a172c2 73 // Set Manufacturer Name value in the DB
dudnwjs 4:60be78a172c2 74 {
dudnwjs 4:60be78a172c2 75 uint8_t *msg;
dudnwjs 4:60be78a172c2 76 struct diss_set_char_val_req req_name;
dudnwjs 5:e11b23f9aacc 77 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_MANUFACTURER_NAME_STR_LEN);
dudnwjs 5:e11b23f9aacc 78
dudnwjs 4:60be78a172c2 79 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 80 req_name.char_code = DIS_MANUFACTURER_NAME_CHAR;
dudnwjs 5:e11b23f9aacc 81 req_name.val_len = APP_DIS_MANUFACTURER_NAME_STR_LEN;
dudnwjs 5:e11b23f9aacc 82 memcpy(&req_name.val[0], APP_DIS_MANUFACTURER_NAME_STR, APP_DIS_MANUFACTURER_NAME_STR_LEN);
dudnwjs 5:e11b23f9aacc 83
dudnwjs 4:60be78a172c2 84 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 85
dudnwjs 5:e11b23f9aacc 86 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS,TASK_GTL,
dudnwjs 5:e11b23f9aacc 87 sizeof(struct diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_MANUFACTURER_NAME_STR_LEN),&req_name,msg);
dudnwjs 4:60be78a172c2 88 BMH->BleSendMsg(msg,msg_size);
dudnwjs 4:60be78a172c2 89 free(msg);
dudnwjs 5:e11b23f9aacc 90
dudnwjs 4:60be78a172c2 91 }
dudnwjs 4:60be78a172c2 92
dudnwjs 4:60be78a172c2 93 // Set Model Number String value in the DB
dudnwjs 4:60be78a172c2 94 {
dudnwjs 4:60be78a172c2 95 uint8_t *msg;
dudnwjs 4:60be78a172c2 96 struct diss_set_char_val_req req_mod;
dudnwjs 5:e11b23f9aacc 97 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_MODEL_NB_STR_LEN);
dudnwjs 4:60be78a172c2 98
dudnwjs 4:60be78a172c2 99 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 100 req_mod.char_code = DIS_MODEL_NB_STR_CHAR;
dudnwjs 4:60be78a172c2 101 req_mod.val_len = APP_DIS_MODEL_NB_STR_LEN;
dudnwjs 4:60be78a172c2 102 memcpy(&req_mod.val[0], APP_DIS_MODEL_NB_STR, APP_DIS_MODEL_NB_STR_LEN);
dudnwjs 4:60be78a172c2 103
dudnwjs 4:60be78a172c2 104 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 105
dudnwjs 5:e11b23f9aacc 106 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,
dudnwjs 5:e11b23f9aacc 107 sizeof(struct diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_MODEL_NB_STR_LEN),&req_mod,msg);
dudnwjs 4:60be78a172c2 108 // Send the message
dudnwjs 4:60be78a172c2 109 BMH->BleSendMsg(msg,msg_size);
dudnwjs 4:60be78a172c2 110 free(msg);
dudnwjs 4:60be78a172c2 111 }
dudnwjs 6:8dd20294b2aa 112 #if (BLE_FOTA_SERVICE)
dudnwjs 5:e11b23f9aacc 113 // Set Serial Number String value in the DB
dudnwjs 5:e11b23f9aacc 114 {
dudnwjs 5:e11b23f9aacc 115 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 116 struct diss_set_char_val_req req_ser;
dudnwjs 5:e11b23f9aacc 117 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_SERIAL_NB_STR_LEN);
dudnwjs 4:60be78a172c2 118
dudnwjs 5:e11b23f9aacc 119 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 120 req_ser.char_code = DIS_SERIAL_NB_STR_CHAR;
dudnwjs 5:e11b23f9aacc 121 req_ser.val_len = APP_DIS_SERIAL_NB_STR_LEN;
dudnwjs 5:e11b23f9aacc 122 memcpy(&req_ser.val[0], APP_DIS_SERIAL_NB_STR, APP_DIS_SERIAL_NB_STR_LEN);
dudnwjs 5:e11b23f9aacc 123
dudnwjs 5:e11b23f9aacc 124 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 125
dudnwjs 5:e11b23f9aacc 126 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,
dudnwjs 5:e11b23f9aacc 127 sizeof(struct diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_SERIAL_NB_STR_LEN),&req_ser,msg);
dudnwjs 5:e11b23f9aacc 128 // Send the message
dudnwjs 5:e11b23f9aacc 129 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 130 free(msg);
dudnwjs 5:e11b23f9aacc 131 }
dudnwjs 6:8dd20294b2aa 132 #endif //(BLE_FOTA_SERVICE)
dudnwjs 6:8dd20294b2aa 133 #if !(BLE_FOTA_SERVICE)
dudnwjs 4:60be78a172c2 134 // Set System ID value in the DB
dudnwjs 4:60be78a172c2 135 {
dudnwjs 4:60be78a172c2 136 uint8_t *msg;
dudnwjs 4:60be78a172c2 137 struct diss_set_char_val_req req_id;
dudnwjs 4:60be78a172c2 138 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req);
dudnwjs 4:60be78a172c2 139
dudnwjs 4:60be78a172c2 140 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 141 req_id.char_code = DIS_SYSTEM_ID_CHAR;
dudnwjs 4:60be78a172c2 142 req_id.val_len = APP_DIS_SYSTEM_ID_LEN;
dudnwjs 4:60be78a172c2 143 memcpy(&req_id.val[0], APP_DIS_SYSTEM_ID, APP_DIS_SYSTEM_ID_LEN);
dudnwjs 4:60be78a172c2 144
dudnwjs 4:60be78a172c2 145 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 146
dudnwjs 4:60be78a172c2 147 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg);
dudnwjs 4:60be78a172c2 148
dudnwjs 4:60be78a172c2 149 // Send the message
dudnwjs 4:60be78a172c2 150 BMH->BleSendMsg(msg, msg_size);
dudnwjs 4:60be78a172c2 151 free(msg);
dudnwjs 4:60be78a172c2 152 }
dudnwjs 4:60be78a172c2 153
dudnwjs 4:60be78a172c2 154
dudnwjs 4:60be78a172c2 155 // Set the software version in the DB
dudnwjs 4:60be78a172c2 156 {
dudnwjs 4:60be78a172c2 157 uint8_t *msg;
dudnwjs 4:60be78a172c2 158 struct diss_set_char_val_req req_id;
dudnwjs 4:60be78a172c2 159 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req);
dudnwjs 4:60be78a172c2 160
dudnwjs 4:60be78a172c2 161 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 162 req_id.char_code = DIS_SW_REV_STR_CHAR;
dudnwjs 4:60be78a172c2 163 req_id.val_len = len;
dudnwjs 4:60be78a172c2 164 memcpy(&req_id.val[0], APP_DIS_SW_REV, len);
dudnwjs 4:60be78a172c2 165
dudnwjs 4:60be78a172c2 166 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 167
dudnwjs 4:60be78a172c2 168 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg);
dudnwjs 4:60be78a172c2 169 // Send the message
dudnwjs 4:60be78a172c2 170 BMH->BleSendMsg(msg,msg_size);
dudnwjs 4:60be78a172c2 171 free(msg);
dudnwjs 4:60be78a172c2 172 }
dudnwjs 4:60be78a172c2 173
dudnwjs 4:60be78a172c2 174 len = strlen(APP_DIS_FIRM_REV);
dudnwjs 4:60be78a172c2 175 // Set the firmware version in the DB. This is the common code sw version
dudnwjs 4:60be78a172c2 176 {
dudnwjs 4:60be78a172c2 177 uint8_t *msg;
dudnwjs 4:60be78a172c2 178 struct diss_set_char_val_req req_id;
dudnwjs 4:60be78a172c2 179 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req);
dudnwjs 4:60be78a172c2 180
dudnwjs 4:60be78a172c2 181 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 182 req_id.char_code = DIS_FIRM_REV_STR_CHAR;
dudnwjs 4:60be78a172c2 183 req_id.val_len = len;
dudnwjs 4:60be78a172c2 184 memcpy(&req_id.val[0], APP_DIS_FIRM_REV, len);
dudnwjs 4:60be78a172c2 185
dudnwjs 4:60be78a172c2 186 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 187
dudnwjs 4:60be78a172c2 188 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg);
dudnwjs 4:60be78a172c2 189 // Send the message
dudnwjs 4:60be78a172c2 190 BMH->BleSendMsg(msg, msg_size);
dudnwjs 4:60be78a172c2 191 free(msg);
dudnwjs 6:8dd20294b2aa 192 }
dudnwjs 6:8dd20294b2aa 193 #endif //!(BLE_FOTA_SERVICE)
dudnwjs 4:60be78a172c2 194 }
dudnwjs 4:60be78a172c2 195
dudnwjs 5:e11b23f9aacc 196 if (app_env.state == APP_IDLE)
dudnwjs 5:e11b23f9aacc 197 {
dudnwjs 5:e11b23f9aacc 198 char str[30] = "\nfota db create req!!\n";
dudnwjs 5:e11b23f9aacc 199 BMH->HostPcPrint(str);
dudnwjs 8:9eec2c246a85 200 //app_set_mode(BMH);
dudnwjs 5:e11b23f9aacc 201 app_fota_server_db_create(BMH);
dudnwjs 5:e11b23f9aacc 202 }
dudnwjs 5:e11b23f9aacc 203
dudnwjs 5:e11b23f9aacc 204 return 0;
dudnwjs 5:e11b23f9aacc 205 }
dudnwjs 9:fcf91f563147 206 /**
dudnwjs 9:fcf91f563147 207 ****************************************************************************************
dudnwjs 9:fcf91f563147 208 * @brief Handles the FOTA_SERVER_CREATE_DB_CFM message.
dudnwjs 9:fcf91f563147 209 *
dudnwjs 9:fcf91f563147 210 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 211 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 212 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 213 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 214 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 215 *
dudnwjs 9:fcf91f563147 216 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 217 ****************************************************************************************
dudnwjs 9:fcf91f563147 218 */
dudnwjs 5:e11b23f9aacc 219 int fota_server_create_db_cfm_handler(unsigned short msgid,
dudnwjs 5:e11b23f9aacc 220 struct fota_server_create_db_cfm *param,
dudnwjs 5:e11b23f9aacc 221 unsigned short dest_id,
dudnwjs 5:e11b23f9aacc 222 unsigned short src_id,
dudnwjs 5:e11b23f9aacc 223 BleMsgHandler* BMH)
dudnwjs 5:e11b23f9aacc 224 {
dudnwjs 5:e11b23f9aacc 225 uint8_t fota_normal = 0;
dudnwjs 5:e11b23f9aacc 226 uint8_t fota_normal_len = sizeof(fota_normal);
dudnwjs 5:e11b23f9aacc 227 if (param->status == CO_ERROR_NO_ERROR)
dudnwjs 4:60be78a172c2 228 {
dudnwjs 5:e11b23f9aacc 229 // Initialization Firmware new Version Char ("00-00-00")
dudnwjs 5:e11b23f9aacc 230 {
dudnwjs 5:e11b23f9aacc 231 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 232 struct fota_server_set_char_val_req req_nv;
dudnwjs 5:e11b23f9aacc 233 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fota_server_set_char_val_req)-(18-APP_FOTA_SERVER_FIRMWARE_NEW_VERSION_LEN);
dudnwjs 5:e11b23f9aacc 234 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 235 req_nv.char_code = FOTA_SERVER_FIRMWARE_NEW_VERSION_CHAR;
dudnwjs 5:e11b23f9aacc 236 req_nv.val_len = APP_FOTA_SERVER_FIRMWARE_NEW_VERSION_LEN;
dudnwjs 5:e11b23f9aacc 237 memcpy(&req_nv.val[0], APP_FOTA_SERVER_FIRMWARE_NEW_VERSION, APP_FOTA_SERVER_FIRMWARE_NEW_VERSION_LEN);
dudnwjs 5:e11b23f9aacc 238
dudnwjs 5:e11b23f9aacc 239 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 240
dudnwjs 5:e11b23f9aacc 241 BMH->BleMsgAlloc(FOTA_SERVER_SET_CHAR_VAL_REQ,TASK_FOTA_SERVER, TASK_GTL,sizeof(struct fota_server_set_char_val_req)-(18-APP_FOTA_SERVER_FIRMWARE_NEW_VERSION_LEN),&req_nv,msg );
dudnwjs 5:e11b23f9aacc 242 // Send the message
dudnwjs 5:e11b23f9aacc 243 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 244 free(msg);
dudnwjs 5:e11b23f9aacc 245 }
dudnwjs 5:e11b23f9aacc 246
dudnwjs 5:e11b23f9aacc 247 // Initialization Sequence Number Char ( = '0' )
dudnwjs 5:e11b23f9aacc 248 {
dudnwjs 5:e11b23f9aacc 249 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 250 struct fota_server_set_char_val_req req_sn;
dudnwjs 5:e11b23f9aacc 251 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len);
dudnwjs 5:e11b23f9aacc 252
dudnwjs 5:e11b23f9aacc 253 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 254 req_sn.char_code = FOTA_SERVER_SEQUENCE_NUMBER_CHAR;
dudnwjs 5:e11b23f9aacc 255 req_sn.val_len = fota_normal_len;
dudnwjs 5:e11b23f9aacc 256 memcpy(&req_sn.val[0], &fota_normal, fota_normal_len);
dudnwjs 5:e11b23f9aacc 257
dudnwjs 5:e11b23f9aacc 258 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 259
dudnwjs 5:e11b23f9aacc 260 BMH->BleMsgAlloc(FOTA_SERVER_SET_CHAR_VAL_REQ,TASK_FOTA_SERVER, TASK_GTL,sizeof(struct fota_server_set_char_val_req)-(18-fota_normal_len),&req_sn,msg );
dudnwjs 5:e11b23f9aacc 261 // Send the message
dudnwjs 5:e11b23f9aacc 262 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 263 free(msg);
dudnwjs 5:e11b23f9aacc 264 }
dudnwjs 5:e11b23f9aacc 265
dudnwjs 5:e11b23f9aacc 266 // Initialization Firmware Data Check Char ( = '0' )
dudnwjs 5:e11b23f9aacc 267 {
dudnwjs 5:e11b23f9aacc 268 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 269 struct fota_server_set_char_val_req req_fdc;
dudnwjs 5:e11b23f9aacc 270 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len);
dudnwjs 5:e11b23f9aacc 271
dudnwjs 5:e11b23f9aacc 272 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 273 req_fdc.char_code = FOTA_SERVER_FIRMWARE_DATA_CHECK_CHAR;
dudnwjs 5:e11b23f9aacc 274 req_fdc.val_len = fota_normal_len;
dudnwjs 5:e11b23f9aacc 275 memcpy(&req_fdc.val[0], &fota_normal, fota_normal_len);
dudnwjs 5:e11b23f9aacc 276
dudnwjs 5:e11b23f9aacc 277 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 278
dudnwjs 5:e11b23f9aacc 279 BMH->BleMsgAlloc(FOTA_SERVER_SET_CHAR_VAL_REQ,TASK_FOTA_SERVER, TASK_GTL,sizeof(struct fota_server_set_char_val_req)-(18-fota_normal_len),&req_fdc,msg );
dudnwjs 5:e11b23f9aacc 280 // Send the message
dudnwjs 5:e11b23f9aacc 281 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 282 free(msg);
dudnwjs 5:e11b23f9aacc 283 }
dudnwjs 5:e11b23f9aacc 284
dudnwjs 5:e11b23f9aacc 285 // Initialization Firmware Status Char ( = '0' )
dudnwjs 5:e11b23f9aacc 286 {
dudnwjs 5:e11b23f9aacc 287 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 288 struct fota_server_set_char_val_req req_stat;
dudnwjs 5:e11b23f9aacc 289 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len);
dudnwjs 5:e11b23f9aacc 290
dudnwjs 5:e11b23f9aacc 291 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 292 req_stat.char_code = FOTA_SERVER_FIRMWARE_STATUS_CHAR;
dudnwjs 5:e11b23f9aacc 293 req_stat.val_len = fota_normal_len;
dudnwjs 5:e11b23f9aacc 294 memcpy(&req_stat.val[0], &fota_normal, fota_normal_len);
dudnwjs 5:e11b23f9aacc 295
dudnwjs 5:e11b23f9aacc 296 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 297
dudnwjs 5:e11b23f9aacc 298 BMH->BleMsgAlloc(FOTA_SERVER_SET_CHAR_VAL_REQ,TASK_FOTA_SERVER, TASK_GTL,sizeof(struct fota_server_set_char_val_req)-(18-fota_normal_len),&req_stat,msg );
dudnwjs 5:e11b23f9aacc 299 // Send the message
dudnwjs 5:e11b23f9aacc 300 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 301 free(msg);
dudnwjs 5:e11b23f9aacc 302 }
dudnwjs 5:e11b23f9aacc 303
dudnwjs 5:e11b23f9aacc 304 // Initialization Reset Char ( = '0' )
dudnwjs 5:e11b23f9aacc 305 {
dudnwjs 5:e11b23f9aacc 306 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 307 struct fota_server_set_char_val_req req_reset;
dudnwjs 5:e11b23f9aacc 308 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len);
dudnwjs 5:e11b23f9aacc 309
dudnwjs 5:e11b23f9aacc 310 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 311 req_reset.char_code = FOTA_SERVER_RESET_CHAR;
dudnwjs 5:e11b23f9aacc 312 req_reset.val_len = fota_normal_len;
dudnwjs 5:e11b23f9aacc 313 memcpy(&req_reset.val[0], &fota_normal, fota_normal_len);
dudnwjs 5:e11b23f9aacc 314
dudnwjs 5:e11b23f9aacc 315 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 316
dudnwjs 5:e11b23f9aacc 317 BMH->BleMsgAlloc(FOTA_SERVER_SET_CHAR_VAL_REQ,TASK_FOTA_SERVER, TASK_GTL,sizeof(struct fota_server_set_char_val_req)-(18-fota_normal_len),&req_reset,msg );
dudnwjs 5:e11b23f9aacc 318 // Send the message
dudnwjs 5:e11b23f9aacc 319 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 320 free(msg);
dudnwjs 5:e11b23f9aacc 321 }
dudnwjs 5:e11b23f9aacc 322
dudnwjs 5:e11b23f9aacc 323 }
dudnwjs 5:e11b23f9aacc 324
dudnwjs 5:e11b23f9aacc 325 if (app_env.state == APP_IDLE)
dudnwjs 5:e11b23f9aacc 326 {
dudnwjs 5:e11b23f9aacc 327 app_set_mode(BMH);
dudnwjs 5:e11b23f9aacc 328 }
dudnwjs 4:60be78a172c2 329
dudnwjs 4:60be78a172c2 330 return 0;
dudnwjs 4:60be78a172c2 331 }
dudnwjs 9:fcf91f563147 332 /**
dudnwjs 9:fcf91f563147 333 ****************************************************************************************
dudnwjs 9:fcf91f563147 334 * @brief Handles Firmware Data Copy event.
dudnwjs 9:fcf91f563147 335 *
dudnwjs 9:fcf91f563147 336 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 337 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 338 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 339 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 340 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 341 *
dudnwjs 9:fcf91f563147 342 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 343 ****************************************************************************************
dudnwjs 9:fcf91f563147 344 */
dudnwjs 6:8dd20294b2aa 345 void fota_server_data_flash_ind_handler(unsigned short msgid,
dudnwjs 6:8dd20294b2aa 346 struct fota_server_data_flash_ind *param,
dudnwjs 6:8dd20294b2aa 347 unsigned short dest_id,
dudnwjs 6:8dd20294b2aa 348 unsigned short src_id,
dudnwjs 6:8dd20294b2aa 349 BleMsgHandler* BMH)
dudnwjs 5:e11b23f9aacc 350 {
dudnwjs 6:8dd20294b2aa 351 char version[9];
dudnwjs 6:8dd20294b2aa 352 memcpy(version,param->version,8);
dudnwjs 6:8dd20294b2aa 353 version[8] = '\0';
dudnwjs 6:8dd20294b2aa 354 BMH->FirmwareDataReceive(param->code_size,version);
dudnwjs 5:e11b23f9aacc 355 }
dudnwjs 9:fcf91f563147 356 /**
dudnwjs 9:fcf91f563147 357 ****************************************************************************************
dudnwjs 9:fcf91f563147 358 * @brief Handles ready indication from the GAP.
dudnwjs 9:fcf91f563147 359 *
dudnwjs 9:fcf91f563147 360 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 361 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 362 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 363 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 364 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 365 *
dudnwjs 9:fcf91f563147 366 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 367 ****************************************************************************************
dudnwjs 9:fcf91f563147 368 */
dudnwjs 4:60be78a172c2 369 int gapm_device_ready_ind_handler(unsigned short msgid,
dudnwjs 5:e11b23f9aacc 370 struct gap_ready_evt *param,
dudnwjs 4:60be78a172c2 371 unsigned short dest_id,
dudnwjs 4:60be78a172c2 372 unsigned short src_id,
dudnwjs 4:60be78a172c2 373 BleMsgHandler* BMH)
dudnwjs 4:60be78a172c2 374 {
dudnwjs 4:60be78a172c2 375 // We are now in Connectable State
dudnwjs 4:60be78a172c2 376 if (dest_id == TASK_GTL)
dudnwjs 4:60be78a172c2 377 {
dudnwjs 4:60be78a172c2 378 app_rst_gap(BMH);
dudnwjs 4:60be78a172c2 379 }
dudnwjs 4:60be78a172c2 380
dudnwjs 4:60be78a172c2 381 return 0;
dudnwjs 4:60be78a172c2 382 }
dudnwjs 9:fcf91f563147 383 /**
dudnwjs 9:fcf91f563147 384 ****************************************************************************************
dudnwjs 9:fcf91f563147 385 * @brief Handle reset GAP request completion event.
dudnwjs 9:fcf91f563147 386 *
dudnwjs 9:fcf91f563147 387 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 388 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 389 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 390 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 391 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 392 *
dudnwjs 9:fcf91f563147 393 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 394 ****************************************************************************************
dudnwjs 9:fcf91f563147 395 */
dudnwjs 4:60be78a172c2 396 int gapm_reset_completion_handler(unsigned short msgid,
dudnwjs 4:60be78a172c2 397 struct gapm_cmp_evt *param,
dudnwjs 4:60be78a172c2 398 unsigned short dest_id,
dudnwjs 4:60be78a172c2 399 unsigned short src_id,
dudnwjs 4:60be78a172c2 400 BleMsgHandler* BMH)
dudnwjs 4:60be78a172c2 401 {
dudnwjs 4:60be78a172c2 402 // We are now in Connectable State
dudnwjs 4:60be78a172c2 403 if (dest_id == TASK_GTL)
dudnwjs 4:60be78a172c2 404 {
dudnwjs 5:e11b23f9aacc 405 app_env.state = APP_IDLE;
dudnwjs 4:60be78a172c2 406 app_diss_db_create(BMH);
dudnwjs 4:60be78a172c2 407 }
dudnwjs 4:60be78a172c2 408
dudnwjs 4:60be78a172c2 409 return 0;
dudnwjs 4:60be78a172c2 410 }
dudnwjs 9:fcf91f563147 411 /**
dudnwjs 9:fcf91f563147 412 ****************************************************************************************
dudnwjs 9:fcf91f563147 413 * @brief Handles GAPM_CMP_EVT event for GAPM_SET_DEV_CONFIG_CMD.
dudnwjs 9:fcf91f563147 414 *
dudnwjs 9:fcf91f563147 415 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 416 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 417 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 418 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 419 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 420 *
dudnwjs 9:fcf91f563147 421 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 422 ****************************************************************************************
dudnwjs 9:fcf91f563147 423 */
dudnwjs 4:60be78a172c2 424 int gapm_set_dev_config_completion_handler(unsigned short msgid,
dudnwjs 4:60be78a172c2 425 struct gapm_cmp_evt *param,
dudnwjs 4:60be78a172c2 426 unsigned short dest_id,
dudnwjs 4:60be78a172c2 427 unsigned short src_id,
dudnwjs 4:60be78a172c2 428 BleMsgHandler* BMH)
dudnwjs 4:60be78a172c2 429 {
dudnwjs 5:e11b23f9aacc 430 app_env.state = APP_CONNECTABLE;
dudnwjs 5:e11b23f9aacc 431 wait(1);
dudnwjs 4:60be78a172c2 432 app_adv_start(BMH); // start advertising
dudnwjs 4:60be78a172c2 433
dudnwjs 4:60be78a172c2 434 return 0;
dudnwjs 4:60be78a172c2 435 }
dudnwjs 9:fcf91f563147 436 /**
dudnwjs 9:fcf91f563147 437 ****************************************************************************************
dudnwjs 9:fcf91f563147 438 * @brief Handles Connection request indication event.
dudnwjs 9:fcf91f563147 439 *
dudnwjs 9:fcf91f563147 440 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 441 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 442 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 443 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 444 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 445 *
dudnwjs 9:fcf91f563147 446 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 447 ****************************************************************************************
dudnwjs 9:fcf91f563147 448 */
dudnwjs 5:e11b23f9aacc 449 int gapc_connection_req_ind_handler(uint16_t msgid,
dudnwjs 5:e11b23f9aacc 450 struct gapc_connection_req_ind *param,
dudnwjs 5:e11b23f9aacc 451 uint16_t dest_id,
dudnwjs 5:e11b23f9aacc 452 uint16_t src_id,
dudnwjs 5:e11b23f9aacc 453 BleMsgHandler* BMH)
dudnwjs 5:e11b23f9aacc 454 {
dudnwjs 5:e11b23f9aacc 455 app_env.state = APP_CONNECTED;
dudnwjs 5:e11b23f9aacc 456
dudnwjs 5:e11b23f9aacc 457 ble_dev device;
dudnwjs 5:e11b23f9aacc 458
dudnwjs 5:e11b23f9aacc 459 // Retrieve the connection index from the GAPC task instance for the connection
dudnwjs 5:e11b23f9aacc 460 device.conidx = KE_IDX_GET(src_id);
dudnwjs 5:e11b23f9aacc 461
dudnwjs 5:e11b23f9aacc 462 // Retrieve the connection handle from the parameters
dudnwjs 5:e11b23f9aacc 463 device.conhdl = param->conhdl;
dudnwjs 5:e11b23f9aacc 464
dudnwjs 5:e11b23f9aacc 465 memcpy(device.adv_addr.addr, param->peer_addr.addr, sizeof(struct bd_addr));
dudnwjs 5:e11b23f9aacc 466
dudnwjs 5:e11b23f9aacc 467
dudnwjs 5:e11b23f9aacc 468 char str[30] = "\nDIS&FOTA ENABLE and CONFIRM\n";
dudnwjs 5:e11b23f9aacc 469 BMH->HostPcPrint(str);
dudnwjs 5:e11b23f9aacc 470
dudnwjs 5:e11b23f9aacc 471 app_dis_enable(&device,BMH);
dudnwjs 5:e11b23f9aacc 472 app_fota_server_enable(&device,BMH);
dudnwjs 5:e11b23f9aacc 473 app_connect_confirm(GAP_AUTH_REQ_NO_MITM_NO_BOND,&device,BMH);
dudnwjs 6:8dd20294b2aa 474
dudnwjs 5:e11b23f9aacc 475 return 0;
dudnwjs 5:e11b23f9aacc 476 }
dudnwjs 9:fcf91f563147 477 /**
dudnwjs 9:fcf91f563147 478 ****************************************************************************************
dudnwjs 9:fcf91f563147 479 * @brief Handles Discconnection indication event.
dudnwjs 9:fcf91f563147 480 *
dudnwjs 9:fcf91f563147 481 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 482 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 483 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 484 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 485 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 486 *
dudnwjs 9:fcf91f563147 487 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 488 ****************************************************************************************
dudnwjs 9:fcf91f563147 489 */
dudnwjs 5:e11b23f9aacc 490 int gapc_disconnect_ind_handler(uint16_t msgid,
dudnwjs 5:e11b23f9aacc 491 struct gapc_disconnect_ind *param,
dudnwjs 5:e11b23f9aacc 492 uint16_t dest_id,
dudnwjs 5:e11b23f9aacc 493 uint16_t src_id,
dudnwjs 5:e11b23f9aacc 494 BleMsgHandler* BMH)
dudnwjs 5:e11b23f9aacc 495 {
dudnwjs 5:e11b23f9aacc 496 char str[22] = "\nDevice Disconnected\n";
dudnwjs 5:e11b23f9aacc 497 BMH->HostPcPrint(str);
dudnwjs 5:e11b23f9aacc 498
dudnwjs 5:e11b23f9aacc 499 app_send_disconnect(TASK_FOTA_SERVER, param->conhdl, param->reason, BMH);
dudnwjs 5:e11b23f9aacc 500 app_env.state = APP_IDLE;
dudnwjs 5:e11b23f9aacc 501
dudnwjs 5:e11b23f9aacc 502 wait(1);
dudnwjs 5:e11b23f9aacc 503 app_set_mode(BMH);
dudnwjs 5:e11b23f9aacc 504
dudnwjs 5:e11b23f9aacc 505 return 0;
dudnwjs 5:e11b23f9aacc 506 }
dudnwjs 5:e11b23f9aacc 507
dudnwjs 5:e11b23f9aacc 508
dudnwjs 4:60be78a172c2 509 }//namespace
dudnwjs 4:60be78a172c2 510
dudnwjs 9:fcf91f563147 511 /// @} dialog_fota module