BLE fota Lamp Demo

Dependencies:   mbed-rtos mbed mbed_fota_fan_control

Fork of mbed_fota_fan_control by KIM HyoengJun

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?

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 12:e3d3676753cc 13 #include "fan_control_task.h"
dudnwjs 13:e714e2971c49 14 #include "lamp_control_task.h"
dudnwjs 12:e3d3676753cc 15 #include "mbed.h"
dudnwjs 12:e3d3676753cc 16
dudnwjs 12:e3d3676753cc 17 extern DigitalOut port18;//mid
dudnwjs 12:e3d3676753cc 18 extern DigitalOut port19;//low
dudnwjs 12:e3d3676753cc 19 extern DigitalOut port20;//high
dudnwjs 13:e714e2971c49 20
dudnwjs 13:e714e2971c49 21 extern DigitalOut port21;//low
dudnwjs 13:e714e2971c49 22 extern DigitalOut port22;//high
dudnwjs 13:e714e2971c49 23
dudnwjs 12:e3d3676753cc 24 extern uint8_t Timer_flag;
dudnwjs 12:e3d3676753cc 25 extern uint32_t Residual_Time;
dudnwjs 4:60be78a172c2 26
dudnwjs 6:8dd20294b2aa 27 #define BLE_FOTA_SERVICE 1
dudnwjs 9:fcf91f563147 28 /**
dudnwjs 9:fcf91f563147 29 ****************************************************************************************
dudnwjs 9:fcf91f563147 30 * @addtogroup dialog_fota module
dudnwjs 9:fcf91f563147 31 * @brief application handlers for ble events and responses.
dudnwjs 9:fcf91f563147 32 *
dudnwjs 9:fcf91f563147 33 * @{
dudnwjs 9:fcf91f563147 34 ****************************************************************************************
dudnwjs 9:fcf91f563147 35 */
dudnwjs 4:60be78a172c2 36 namespace sevencore_fota{
dudnwjs 9:fcf91f563147 37
dudnwjs 12:e3d3676753cc 38
dudnwjs 9:fcf91f563147 39 /**
dudnwjs 9:fcf91f563147 40 ****************************************************************************************
dudnwjs 9:fcf91f563147 41 * @brief Handles GAPM_ADV_REPORT_IND event.
dudnwjs 9:fcf91f563147 42 *
dudnwjs 9:fcf91f563147 43 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 44 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 45 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 46 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 47 *
dudnwjs 9:fcf91f563147 48 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 49 ****************************************************************************************
dudnwjs 9:fcf91f563147 50 */
dudnwjs 4:60be78a172c2 51 int gapm_adv_report_ind_handler(unsigned short msgid,
dudnwjs 4:60be78a172c2 52 struct gapm_adv_report_ind *param,
dudnwjs 4:60be78a172c2 53 unsigned short dest_id,
dudnwjs 4:60be78a172c2 54 unsigned short src_id)
dudnwjs 4:60be78a172c2 55 {
dudnwjs 4:60be78a172c2 56 //if (app_env.state != APP_SCAN)
dudnwjs 4:60be78a172c2 57 // return -1;
dudnwjs 4:60be78a172c2 58
dudnwjs 4:60be78a172c2 59 return 0;
dudnwjs 4:60be78a172c2 60 }
dudnwjs 9:fcf91f563147 61 /**
dudnwjs 9:fcf91f563147 62 ****************************************************************************************
dudnwjs 9:fcf91f563147 63 * @brief Handles the DISS_CREATE_DB_CFM message.
dudnwjs 9:fcf91f563147 64 *
dudnwjs 9:fcf91f563147 65 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 66 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 67 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 68 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 69 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 70 *
dudnwjs 9:fcf91f563147 71 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 72 ****************************************************************************************
dudnwjs 9:fcf91f563147 73 */
dudnwjs 4:60be78a172c2 74 int diss_create_db_cfm_handler(unsigned short msgid,
dudnwjs 4:60be78a172c2 75 struct diss_create_db_cfm *param,
dudnwjs 4:60be78a172c2 76 unsigned short dest_id,
dudnwjs 4:60be78a172c2 77 unsigned short src_id,
dudnwjs 4:60be78a172c2 78 BleMsgHandler* BMH)
dudnwjs 4:60be78a172c2 79 {
dudnwjs 6:8dd20294b2aa 80
dudnwjs 5:e11b23f9aacc 81 uint8_t len = strlen(APP_DIS_SW_REV);
dudnwjs 5:e11b23f9aacc 82
dudnwjs 4:60be78a172c2 83 if (param->status == CO_ERROR_NO_ERROR)
dudnwjs 4:60be78a172c2 84 {
dudnwjs 5:e11b23f9aacc 85 char str[22] = "\nDIS SET DB\n";
dudnwjs 5:e11b23f9aacc 86 BMH->HostPcPrint(str);
dudnwjs 4:60be78a172c2 87 // Set Manufacturer Name value in the DB
dudnwjs 4:60be78a172c2 88 {
dudnwjs 4:60be78a172c2 89 uint8_t *msg;
dudnwjs 4:60be78a172c2 90 struct diss_set_char_val_req req_name;
dudnwjs 5:e11b23f9aacc 91 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 92
dudnwjs 4:60be78a172c2 93 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 94 req_name.char_code = DIS_MANUFACTURER_NAME_CHAR;
dudnwjs 5:e11b23f9aacc 95 req_name.val_len = APP_DIS_MANUFACTURER_NAME_STR_LEN;
dudnwjs 5:e11b23f9aacc 96 memcpy(&req_name.val[0], APP_DIS_MANUFACTURER_NAME_STR, APP_DIS_MANUFACTURER_NAME_STR_LEN);
dudnwjs 5:e11b23f9aacc 97
dudnwjs 4:60be78a172c2 98 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 99
dudnwjs 5:e11b23f9aacc 100 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS,TASK_GTL,
dudnwjs 5:e11b23f9aacc 101 sizeof(struct diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_MANUFACTURER_NAME_STR_LEN),&req_name,msg);
dudnwjs 4:60be78a172c2 102 BMH->BleSendMsg(msg,msg_size);
dudnwjs 4:60be78a172c2 103 free(msg);
dudnwjs 5:e11b23f9aacc 104
dudnwjs 4:60be78a172c2 105 }
dudnwjs 4:60be78a172c2 106
dudnwjs 4:60be78a172c2 107 // Set Model Number String value in the DB
dudnwjs 4:60be78a172c2 108 {
dudnwjs 4:60be78a172c2 109 uint8_t *msg;
dudnwjs 4:60be78a172c2 110 struct diss_set_char_val_req req_mod;
dudnwjs 5:e11b23f9aacc 111 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 112
dudnwjs 4:60be78a172c2 113 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 114 req_mod.char_code = DIS_MODEL_NB_STR_CHAR;
dudnwjs 4:60be78a172c2 115 req_mod.val_len = APP_DIS_MODEL_NB_STR_LEN;
dudnwjs 4:60be78a172c2 116 memcpy(&req_mod.val[0], APP_DIS_MODEL_NB_STR, APP_DIS_MODEL_NB_STR_LEN);
dudnwjs 4:60be78a172c2 117
dudnwjs 4:60be78a172c2 118 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 119
dudnwjs 5:e11b23f9aacc 120 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,
dudnwjs 5:e11b23f9aacc 121 sizeof(struct diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_MODEL_NB_STR_LEN),&req_mod,msg);
dudnwjs 4:60be78a172c2 122 // Send the message
dudnwjs 4:60be78a172c2 123 BMH->BleSendMsg(msg,msg_size);
dudnwjs 4:60be78a172c2 124 free(msg);
dudnwjs 4:60be78a172c2 125 }
dudnwjs 6:8dd20294b2aa 126 #if (BLE_FOTA_SERVICE)
dudnwjs 5:e11b23f9aacc 127 // Set Serial Number String value in the DB
dudnwjs 5:e11b23f9aacc 128 {
dudnwjs 5:e11b23f9aacc 129 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 130 struct diss_set_char_val_req req_ser;
dudnwjs 5:e11b23f9aacc 131 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 132
dudnwjs 5:e11b23f9aacc 133 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 134 req_ser.char_code = DIS_SERIAL_NB_STR_CHAR;
dudnwjs 5:e11b23f9aacc 135 req_ser.val_len = APP_DIS_SERIAL_NB_STR_LEN;
dudnwjs 5:e11b23f9aacc 136 memcpy(&req_ser.val[0], APP_DIS_SERIAL_NB_STR, APP_DIS_SERIAL_NB_STR_LEN);
dudnwjs 5:e11b23f9aacc 137
dudnwjs 5:e11b23f9aacc 138 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 139
dudnwjs 5:e11b23f9aacc 140 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,
dudnwjs 5:e11b23f9aacc 141 sizeof(struct diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_SERIAL_NB_STR_LEN),&req_ser,msg);
dudnwjs 5:e11b23f9aacc 142 // Send the message
dudnwjs 5:e11b23f9aacc 143 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 144 free(msg);
dudnwjs 5:e11b23f9aacc 145 }
dudnwjs 6:8dd20294b2aa 146 #endif //(BLE_FOTA_SERVICE)
dudnwjs 6:8dd20294b2aa 147 #if !(BLE_FOTA_SERVICE)
dudnwjs 4:60be78a172c2 148 // Set System ID value in the DB
dudnwjs 4:60be78a172c2 149 {
dudnwjs 4:60be78a172c2 150 uint8_t *msg;
dudnwjs 4:60be78a172c2 151 struct diss_set_char_val_req req_id;
dudnwjs 4:60be78a172c2 152 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req);
dudnwjs 4:60be78a172c2 153
dudnwjs 4:60be78a172c2 154 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 155 req_id.char_code = DIS_SYSTEM_ID_CHAR;
dudnwjs 4:60be78a172c2 156 req_id.val_len = APP_DIS_SYSTEM_ID_LEN;
dudnwjs 4:60be78a172c2 157 memcpy(&req_id.val[0], APP_DIS_SYSTEM_ID, APP_DIS_SYSTEM_ID_LEN);
dudnwjs 4:60be78a172c2 158
dudnwjs 4:60be78a172c2 159 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 160
dudnwjs 4:60be78a172c2 161 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg);
dudnwjs 4:60be78a172c2 162
dudnwjs 4:60be78a172c2 163 // Send the message
dudnwjs 4:60be78a172c2 164 BMH->BleSendMsg(msg, msg_size);
dudnwjs 4:60be78a172c2 165 free(msg);
dudnwjs 4:60be78a172c2 166 }
dudnwjs 4:60be78a172c2 167
dudnwjs 4:60be78a172c2 168
dudnwjs 4:60be78a172c2 169 // Set the software version in the DB
dudnwjs 4:60be78a172c2 170 {
dudnwjs 4:60be78a172c2 171 uint8_t *msg;
dudnwjs 4:60be78a172c2 172 struct diss_set_char_val_req req_id;
dudnwjs 4:60be78a172c2 173 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req);
dudnwjs 4:60be78a172c2 174
dudnwjs 4:60be78a172c2 175 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 176 req_id.char_code = DIS_SW_REV_STR_CHAR;
dudnwjs 4:60be78a172c2 177 req_id.val_len = len;
dudnwjs 4:60be78a172c2 178 memcpy(&req_id.val[0], APP_DIS_SW_REV, len);
dudnwjs 4:60be78a172c2 179
dudnwjs 4:60be78a172c2 180 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 181
dudnwjs 4:60be78a172c2 182 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg);
dudnwjs 4:60be78a172c2 183 // Send the message
dudnwjs 4:60be78a172c2 184 BMH->BleSendMsg(msg,msg_size);
dudnwjs 4:60be78a172c2 185 free(msg);
dudnwjs 4:60be78a172c2 186 }
dudnwjs 4:60be78a172c2 187
dudnwjs 4:60be78a172c2 188 len = strlen(APP_DIS_FIRM_REV);
dudnwjs 4:60be78a172c2 189 // Set the firmware version in the DB. This is the common code sw version
dudnwjs 4:60be78a172c2 190 {
dudnwjs 4:60be78a172c2 191 uint8_t *msg;
dudnwjs 4:60be78a172c2 192 struct diss_set_char_val_req req_id;
dudnwjs 4:60be78a172c2 193 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req);
dudnwjs 4:60be78a172c2 194
dudnwjs 4:60be78a172c2 195 // Fill in the parameter structure
dudnwjs 4:60be78a172c2 196 req_id.char_code = DIS_FIRM_REV_STR_CHAR;
dudnwjs 4:60be78a172c2 197 req_id.val_len = len;
dudnwjs 4:60be78a172c2 198 memcpy(&req_id.val[0], APP_DIS_FIRM_REV, len);
dudnwjs 4:60be78a172c2 199
dudnwjs 4:60be78a172c2 200 msg = new uint8_t[msg_size];
dudnwjs 4:60be78a172c2 201
dudnwjs 4:60be78a172c2 202 BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg);
dudnwjs 4:60be78a172c2 203 // Send the message
dudnwjs 4:60be78a172c2 204 BMH->BleSendMsg(msg, msg_size);
dudnwjs 4:60be78a172c2 205 free(msg);
dudnwjs 6:8dd20294b2aa 206 }
dudnwjs 6:8dd20294b2aa 207 #endif //!(BLE_FOTA_SERVICE)
dudnwjs 4:60be78a172c2 208 }
dudnwjs 4:60be78a172c2 209
dudnwjs 5:e11b23f9aacc 210 if (app_env.state == APP_IDLE)
dudnwjs 5:e11b23f9aacc 211 {
dudnwjs 5:e11b23f9aacc 212 char str[30] = "\nfota db create req!!\n";
dudnwjs 5:e11b23f9aacc 213 BMH->HostPcPrint(str);
dudnwjs 8:9eec2c246a85 214 //app_set_mode(BMH);
dudnwjs 5:e11b23f9aacc 215 app_fota_server_db_create(BMH);
dudnwjs 5:e11b23f9aacc 216 }
dudnwjs 5:e11b23f9aacc 217
dudnwjs 5:e11b23f9aacc 218 return 0;
dudnwjs 5:e11b23f9aacc 219 }
dudnwjs 9:fcf91f563147 220 /**
dudnwjs 9:fcf91f563147 221 ****************************************************************************************
dudnwjs 9:fcf91f563147 222 * @brief Handles the FOTA_SERVER_CREATE_DB_CFM message.
dudnwjs 9:fcf91f563147 223 *
dudnwjs 9:fcf91f563147 224 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 225 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 226 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 227 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 228 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 229 *
dudnwjs 9:fcf91f563147 230 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 231 ****************************************************************************************
dudnwjs 9:fcf91f563147 232 */
dudnwjs 5:e11b23f9aacc 233 int fota_server_create_db_cfm_handler(unsigned short msgid,
dudnwjs 5:e11b23f9aacc 234 struct fota_server_create_db_cfm *param,
dudnwjs 5:e11b23f9aacc 235 unsigned short dest_id,
dudnwjs 5:e11b23f9aacc 236 unsigned short src_id,
dudnwjs 5:e11b23f9aacc 237 BleMsgHandler* BMH)
dudnwjs 5:e11b23f9aacc 238 {
dudnwjs 5:e11b23f9aacc 239 uint8_t fota_normal = 0;
dudnwjs 5:e11b23f9aacc 240 uint8_t fota_normal_len = sizeof(fota_normal);
dudnwjs 5:e11b23f9aacc 241 if (param->status == CO_ERROR_NO_ERROR)
dudnwjs 4:60be78a172c2 242 {
dudnwjs 5:e11b23f9aacc 243 // Initialization Firmware new Version Char ("00-00-00")
dudnwjs 5:e11b23f9aacc 244 {
dudnwjs 5:e11b23f9aacc 245 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 246 struct fota_server_set_char_val_req req_nv;
dudnwjs 5:e11b23f9aacc 247 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 248 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 249 req_nv.char_code = FOTA_SERVER_FIRMWARE_NEW_VERSION_CHAR;
dudnwjs 5:e11b23f9aacc 250 req_nv.val_len = APP_FOTA_SERVER_FIRMWARE_NEW_VERSION_LEN;
dudnwjs 5:e11b23f9aacc 251 memcpy(&req_nv.val[0], APP_FOTA_SERVER_FIRMWARE_NEW_VERSION, APP_FOTA_SERVER_FIRMWARE_NEW_VERSION_LEN);
dudnwjs 5:e11b23f9aacc 252
dudnwjs 5:e11b23f9aacc 253 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 254
dudnwjs 5:e11b23f9aacc 255 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 256 // Send the message
dudnwjs 5:e11b23f9aacc 257 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 258 free(msg);
dudnwjs 5:e11b23f9aacc 259 }
dudnwjs 5:e11b23f9aacc 260
dudnwjs 5:e11b23f9aacc 261 // Initialization Sequence Number Char ( = '0' )
dudnwjs 5:e11b23f9aacc 262 {
dudnwjs 5:e11b23f9aacc 263 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 264 struct fota_server_set_char_val_req req_sn;
dudnwjs 5:e11b23f9aacc 265 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len);
dudnwjs 5:e11b23f9aacc 266
dudnwjs 5:e11b23f9aacc 267 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 268 req_sn.char_code = FOTA_SERVER_SEQUENCE_NUMBER_CHAR;
dudnwjs 5:e11b23f9aacc 269 req_sn.val_len = fota_normal_len;
dudnwjs 5:e11b23f9aacc 270 memcpy(&req_sn.val[0], &fota_normal, fota_normal_len);
dudnwjs 5:e11b23f9aacc 271
dudnwjs 5:e11b23f9aacc 272 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 273
dudnwjs 5:e11b23f9aacc 274 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 275 // Send the message
dudnwjs 5:e11b23f9aacc 276 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 277 free(msg);
dudnwjs 5:e11b23f9aacc 278 }
dudnwjs 5:e11b23f9aacc 279
dudnwjs 5:e11b23f9aacc 280 // Initialization Firmware Data Check Char ( = '0' )
dudnwjs 5:e11b23f9aacc 281 {
dudnwjs 5:e11b23f9aacc 282 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 283 struct fota_server_set_char_val_req req_fdc;
dudnwjs 5:e11b23f9aacc 284 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len);
dudnwjs 5:e11b23f9aacc 285
dudnwjs 5:e11b23f9aacc 286 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 287 req_fdc.char_code = FOTA_SERVER_FIRMWARE_DATA_CHECK_CHAR;
dudnwjs 5:e11b23f9aacc 288 req_fdc.val_len = fota_normal_len;
dudnwjs 5:e11b23f9aacc 289 memcpy(&req_fdc.val[0], &fota_normal, fota_normal_len);
dudnwjs 5:e11b23f9aacc 290
dudnwjs 5:e11b23f9aacc 291 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 292
dudnwjs 5:e11b23f9aacc 293 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 294 // Send the message
dudnwjs 5:e11b23f9aacc 295 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 296 free(msg);
dudnwjs 5:e11b23f9aacc 297 }
dudnwjs 5:e11b23f9aacc 298
dudnwjs 5:e11b23f9aacc 299 // Initialization Firmware Status Char ( = '0' )
dudnwjs 5:e11b23f9aacc 300 {
dudnwjs 5:e11b23f9aacc 301 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 302 struct fota_server_set_char_val_req req_stat;
dudnwjs 5:e11b23f9aacc 303 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len);
dudnwjs 5:e11b23f9aacc 304
dudnwjs 5:e11b23f9aacc 305 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 306 req_stat.char_code = FOTA_SERVER_FIRMWARE_STATUS_CHAR;
dudnwjs 5:e11b23f9aacc 307 req_stat.val_len = fota_normal_len;
dudnwjs 5:e11b23f9aacc 308 memcpy(&req_stat.val[0], &fota_normal, fota_normal_len);
dudnwjs 5:e11b23f9aacc 309
dudnwjs 5:e11b23f9aacc 310 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 311
dudnwjs 5:e11b23f9aacc 312 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 313 // Send the message
dudnwjs 5:e11b23f9aacc 314 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 315 free(msg);
dudnwjs 5:e11b23f9aacc 316 }
dudnwjs 5:e11b23f9aacc 317
dudnwjs 5:e11b23f9aacc 318 // Initialization Reset Char ( = '0' )
dudnwjs 5:e11b23f9aacc 319 {
dudnwjs 5:e11b23f9aacc 320 uint8_t *msg;
dudnwjs 5:e11b23f9aacc 321 struct fota_server_set_char_val_req req_reset;
dudnwjs 5:e11b23f9aacc 322 unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len);
dudnwjs 5:e11b23f9aacc 323
dudnwjs 5:e11b23f9aacc 324 // Fill in the parameter structure
dudnwjs 5:e11b23f9aacc 325 req_reset.char_code = FOTA_SERVER_RESET_CHAR;
dudnwjs 5:e11b23f9aacc 326 req_reset.val_len = fota_normal_len;
dudnwjs 5:e11b23f9aacc 327 memcpy(&req_reset.val[0], &fota_normal, fota_normal_len);
dudnwjs 5:e11b23f9aacc 328
dudnwjs 5:e11b23f9aacc 329 msg = new uint8_t[msg_size];
dudnwjs 5:e11b23f9aacc 330
dudnwjs 5:e11b23f9aacc 331 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 332 // Send the message
dudnwjs 5:e11b23f9aacc 333 BMH->BleSendMsg(msg,msg_size);
dudnwjs 5:e11b23f9aacc 334 free(msg);
dudnwjs 5:e11b23f9aacc 335 }
dudnwjs 5:e11b23f9aacc 336
dudnwjs 5:e11b23f9aacc 337 }
dudnwjs 5:e11b23f9aacc 338
dudnwjs 5:e11b23f9aacc 339 if (app_env.state == APP_IDLE)
dudnwjs 5:e11b23f9aacc 340 {
dudnwjs 12:e3d3676753cc 341 //app_set_mode(BMH);
dudnwjs 13:e714e2971c49 342 //app_fan_control_db_create(BMH);
dudnwjs 13:e714e2971c49 343 app_lamp_control_db_create(BMH);
dudnwjs 5:e11b23f9aacc 344 }
dudnwjs 4:60be78a172c2 345
dudnwjs 4:60be78a172c2 346 return 0;
dudnwjs 4:60be78a172c2 347 }
dudnwjs 9:fcf91f563147 348 /**
dudnwjs 9:fcf91f563147 349 ****************************************************************************************
dudnwjs 9:fcf91f563147 350 * @brief Handles Firmware Data Copy event.
dudnwjs 9:fcf91f563147 351 *
dudnwjs 9:fcf91f563147 352 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 353 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 354 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 355 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 356 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 357 *
dudnwjs 9:fcf91f563147 358 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 359 ****************************************************************************************
dudnwjs 9:fcf91f563147 360 */
dudnwjs 6:8dd20294b2aa 361 void fota_server_data_flash_ind_handler(unsigned short msgid,
dudnwjs 6:8dd20294b2aa 362 struct fota_server_data_flash_ind *param,
dudnwjs 6:8dd20294b2aa 363 unsigned short dest_id,
dudnwjs 6:8dd20294b2aa 364 unsigned short src_id,
dudnwjs 6:8dd20294b2aa 365 BleMsgHandler* BMH)
dudnwjs 5:e11b23f9aacc 366 {
dudnwjs 6:8dd20294b2aa 367 char version[9];
dudnwjs 6:8dd20294b2aa 368 memcpy(version,param->version,8);
dudnwjs 6:8dd20294b2aa 369 version[8] = '\0';
dudnwjs 12:e3d3676753cc 370 port18 = 1;
dudnwjs 6:8dd20294b2aa 371 BMH->FirmwareDataReceive(param->code_size,version);
dudnwjs 5:e11b23f9aacc 372 }
dudnwjs 12:e3d3676753cc 373
dudnwjs 12:e3d3676753cc 374 /**
dudnwjs 12:e3d3676753cc 375 ****************************************************************************************
dudnwjs 12:e3d3676753cc 376 * @brief Handles the FAN_CONTROL_CREATE_DB_CFM message.
dudnwjs 12:e3d3676753cc 377 *
dudnwjs 12:e3d3676753cc 378 * @param[in] msgid Id of the message received.
dudnwjs 12:e3d3676753cc 379 * @param[in] param Pointer to the parameters of the message.
dudnwjs 12:e3d3676753cc 380 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 12:e3d3676753cc 381 * @param[in] src_id ID of the sending task instance.
dudnwjs 12:e3d3676753cc 382 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 12:e3d3676753cc 383 *
dudnwjs 12:e3d3676753cc 384 * @return If the message was consumed or not.
dudnwjs 12:e3d3676753cc 385 ****************************************************************************************
dudnwjs 12:e3d3676753cc 386 */
dudnwjs 12:e3d3676753cc 387 void fan_control_create_db_cfm_handler(unsigned short msgid,
dudnwjs 12:e3d3676753cc 388 struct fan_control_create_db_cfm *param,
dudnwjs 12:e3d3676753cc 389 unsigned short dest_id,
dudnwjs 12:e3d3676753cc 390 unsigned short src_id,
dudnwjs 12:e3d3676753cc 391 BleMsgHandler* BMH)
dudnwjs 12:e3d3676753cc 392 {
dudnwjs 12:e3d3676753cc 393 uint8_t fota_normal = 0;
dudnwjs 12:e3d3676753cc 394 uint8_t fota_normal_len = sizeof(fota_normal);
dudnwjs 12:e3d3676753cc 395 if (param->status == CO_ERROR_NO_ERROR)
dudnwjs 12:e3d3676753cc 396 {
dudnwjs 12:e3d3676753cc 397 // Initialization All Characteristic
dudnwjs 12:e3d3676753cc 398 {
dudnwjs 12:e3d3676753cc 399 uint8_t *msg;
dudnwjs 12:e3d3676753cc 400 struct fan_control_set_char_val_req power_state_val;
dudnwjs 12:e3d3676753cc 401 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE);
dudnwjs 12:e3d3676753cc 402 // Fill in the parameter structure
dudnwjs 12:e3d3676753cc 403 power_state_val.char_code = FAN_CONTROL_POWER_STATE_CHAR;
dudnwjs 12:e3d3676753cc 404 power_state_val.val_len = FAN_CONTROL_MIN_SIZE;
dudnwjs 12:e3d3676753cc 405 memcpy(&power_state_val.val[0], &fota_normal, fota_normal_len);
dudnwjs 12:e3d3676753cc 406
dudnwjs 12:e3d3676753cc 407 msg = new uint8_t[msg_size];
dudnwjs 12:e3d3676753cc 408
dudnwjs 12:e3d3676753cc 409 BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ,TASK_FAN_CONTROL, TASK_GTL,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE),&power_state_val,msg );
dudnwjs 12:e3d3676753cc 410 // Send the message
dudnwjs 12:e3d3676753cc 411 BMH->BleSendMsg(msg,msg_size);
dudnwjs 12:e3d3676753cc 412 free(msg);
dudnwjs 12:e3d3676753cc 413 }
dudnwjs 12:e3d3676753cc 414 {
dudnwjs 12:e3d3676753cc 415 uint8_t *msg;
dudnwjs 12:e3d3676753cc 416 struct fan_control_set_char_val_req wind_strength_val;
dudnwjs 12:e3d3676753cc 417 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE);
dudnwjs 12:e3d3676753cc 418 // Fill in the parameter structure
dudnwjs 12:e3d3676753cc 419 wind_strength_val.char_code = FAN_CONTROL_WIND_STRENGTH_CHAR;
dudnwjs 12:e3d3676753cc 420 wind_strength_val.val_len = FAN_CONTROL_MIN_SIZE;
dudnwjs 12:e3d3676753cc 421 memcpy(&wind_strength_val.val[0], &fota_normal, fota_normal_len);
dudnwjs 12:e3d3676753cc 422
dudnwjs 12:e3d3676753cc 423 msg = new uint8_t[msg_size];
dudnwjs 12:e3d3676753cc 424
dudnwjs 12:e3d3676753cc 425 BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ,TASK_FAN_CONTROL, TASK_GTL,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE),&wind_strength_val,msg );
dudnwjs 12:e3d3676753cc 426 // Send the message
dudnwjs 12:e3d3676753cc 427 BMH->BleSendMsg(msg,msg_size);
dudnwjs 12:e3d3676753cc 428 free(msg);
dudnwjs 12:e3d3676753cc 429 }
dudnwjs 12:e3d3676753cc 430 {
dudnwjs 12:e3d3676753cc 431 uint8_t *msg;
dudnwjs 12:e3d3676753cc 432 struct fan_control_set_char_val_req fan_spin_val;
dudnwjs 12:e3d3676753cc 433 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE);
dudnwjs 12:e3d3676753cc 434 // Fill in the parameter structure
dudnwjs 12:e3d3676753cc 435 fan_spin_val.char_code = FAN_CONTROL_FAN_SPIN_CHAR;
dudnwjs 12:e3d3676753cc 436 fan_spin_val.val_len = FAN_CONTROL_MIN_SIZE;
dudnwjs 12:e3d3676753cc 437 memcpy(&fan_spin_val.val[0], &fota_normal, fota_normal_len);
dudnwjs 12:e3d3676753cc 438
dudnwjs 12:e3d3676753cc 439 msg = new uint8_t[msg_size];
dudnwjs 12:e3d3676753cc 440
dudnwjs 12:e3d3676753cc 441 BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ,TASK_FAN_CONTROL, TASK_GTL,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE),&fan_spin_val,msg );
dudnwjs 12:e3d3676753cc 442 // Send the message
dudnwjs 12:e3d3676753cc 443 BMH->BleSendMsg(msg,msg_size);
dudnwjs 12:e3d3676753cc 444 free(msg);
dudnwjs 12:e3d3676753cc 445 }
dudnwjs 12:e3d3676753cc 446 {
dudnwjs 12:e3d3676753cc 447 uint8_t *msg;
dudnwjs 12:e3d3676753cc 448 struct fan_control_set_char_val_req fan_timer_val;
dudnwjs 12:e3d3676753cc 449 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE);
dudnwjs 12:e3d3676753cc 450 // Fill in the parameter structure
dudnwjs 12:e3d3676753cc 451 fan_timer_val.char_code = FAN_CONTROL_FAN_TIMER_CHAR;
dudnwjs 12:e3d3676753cc 452 fan_timer_val.val_len = FAN_CONTROL_MIN_SIZE;
dudnwjs 12:e3d3676753cc 453 memcpy(&fan_timer_val.val[0], &fota_normal, fota_normal_len);
dudnwjs 12:e3d3676753cc 454
dudnwjs 12:e3d3676753cc 455 msg = new uint8_t[msg_size];
dudnwjs 12:e3d3676753cc 456
dudnwjs 12:e3d3676753cc 457 BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ,TASK_FAN_CONTROL, TASK_GTL,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE),&fan_timer_val,msg );
dudnwjs 12:e3d3676753cc 458 // Send the message
dudnwjs 12:e3d3676753cc 459 BMH->BleSendMsg(msg,msg_size);
dudnwjs 12:e3d3676753cc 460 free(msg);
dudnwjs 12:e3d3676753cc 461 }
dudnwjs 12:e3d3676753cc 462 {
dudnwjs 12:e3d3676753cc 463 uint8_t *msg;
dudnwjs 12:e3d3676753cc 464 struct fan_control_set_char_val_req residual_time_val;
dudnwjs 12:e3d3676753cc 465 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MAX_SIZE);
dudnwjs 12:e3d3676753cc 466 // Fill in the parameter structure
dudnwjs 12:e3d3676753cc 467 residual_time_val.char_code = FAN_CONTROL_RESIDUAL_TIME_CHAR;
dudnwjs 12:e3d3676753cc 468 residual_time_val.val_len = FAN_CONTROL_MAX_SIZE;
dudnwjs 12:e3d3676753cc 469 memcpy(&residual_time_val.val[0], &fota_normal, fota_normal_len*4);
dudnwjs 12:e3d3676753cc 470
dudnwjs 12:e3d3676753cc 471 msg = new uint8_t[msg_size];
dudnwjs 12:e3d3676753cc 472
dudnwjs 12:e3d3676753cc 473 BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ,TASK_FAN_CONTROL, TASK_GTL,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MAX_SIZE),&residual_time_val,msg );
dudnwjs 12:e3d3676753cc 474 // Send the message
dudnwjs 12:e3d3676753cc 475 BMH->BleSendMsg(msg,msg_size);
dudnwjs 12:e3d3676753cc 476 free(msg);
dudnwjs 12:e3d3676753cc 477 }
dudnwjs 12:e3d3676753cc 478 }
dudnwjs 12:e3d3676753cc 479 if (app_env.state == APP_IDLE)
dudnwjs 12:e3d3676753cc 480 {
dudnwjs 12:e3d3676753cc 481 app_set_mode(BMH);
dudnwjs 12:e3d3676753cc 482 }
dudnwjs 12:e3d3676753cc 483 }
dudnwjs 12:e3d3676753cc 484
dudnwjs 12:e3d3676753cc 485 /**
dudnwjs 12:e3d3676753cc 486 ****************************************************************************************
dudnwjs 12:e3d3676753cc 487 * @brief Handles the FAN_CONTROL_COMMAND_IND message.
dudnwjs 12:e3d3676753cc 488 *
dudnwjs 12:e3d3676753cc 489 * @param[in] msgid Id of the message received.
dudnwjs 12:e3d3676753cc 490 * @param[in] param Pointer to the parameters of the message.
dudnwjs 12:e3d3676753cc 491 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 12:e3d3676753cc 492 * @param[in] src_id ID of the sending task instance.
dudnwjs 12:e3d3676753cc 493 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 12:e3d3676753cc 494 *
dudnwjs 12:e3d3676753cc 495 * @return If the message was consumed or not.
dudnwjs 12:e3d3676753cc 496 ****************************************************************************************
dudnwjs 12:e3d3676753cc 497 */
dudnwjs 12:e3d3676753cc 498 void fan_control_command_ind_handler(unsigned short msgid,
dudnwjs 12:e3d3676753cc 499 struct fan_control_command_ind *param,
dudnwjs 12:e3d3676753cc 500 unsigned short dest_id,
dudnwjs 12:e3d3676753cc 501 unsigned short src_id,
dudnwjs 12:e3d3676753cc 502 BleMsgHandler* BMH)
dudnwjs 12:e3d3676753cc 503 {
dudnwjs 12:e3d3676753cc 504 char str[30] = "\nFAN remote control START!!\n";
dudnwjs 12:e3d3676753cc 505 BMH->HostPcPrint(str);
dudnwjs 12:e3d3676753cc 506 if( param->char_code == FAN_CONTROL_POWER_STATE_CHAR){
dudnwjs 12:e3d3676753cc 507 if(param->command == 0){
dudnwjs 12:e3d3676753cc 508 Timer_flag = 0;
dudnwjs 12:e3d3676753cc 509 Residual_Time = 0;
dudnwjs 12:e3d3676753cc 510 port18 = 0;
dudnwjs 12:e3d3676753cc 511 port19 = 0;
dudnwjs 12:e3d3676753cc 512 port20 = 0;
dudnwjs 12:e3d3676753cc 513 }
dudnwjs 12:e3d3676753cc 514 if(param->command == 1){
dudnwjs 12:e3d3676753cc 515 if( port18 == 0 && port19 == 0 && port20 == 0 )
dudnwjs 12:e3d3676753cc 516 port19 = 1;
dudnwjs 12:e3d3676753cc 517 }
dudnwjs 12:e3d3676753cc 518 }else if( param->char_code == FAN_CONTROL_WIND_STRENGTH_CHAR){
dudnwjs 12:e3d3676753cc 519 if( param->command == 1 ){ //low
dudnwjs 12:e3d3676753cc 520 port18 = 0;
dudnwjs 12:e3d3676753cc 521 port20 = 0;
dudnwjs 12:e3d3676753cc 522 port19 = 1;
dudnwjs 12:e3d3676753cc 523 }
dudnwjs 12:e3d3676753cc 524 else if( param->command == 2 ){ //mid
dudnwjs 12:e3d3676753cc 525 port19 = 0;
dudnwjs 12:e3d3676753cc 526 port20 = 0;
dudnwjs 12:e3d3676753cc 527 port18 = 1;
dudnwjs 12:e3d3676753cc 528 }else if( param->command == 3 ){ //high
dudnwjs 12:e3d3676753cc 529 port18 = 0;
dudnwjs 12:e3d3676753cc 530 port19 = 0;
dudnwjs 12:e3d3676753cc 531 port20 = 1;
dudnwjs 12:e3d3676753cc 532 }
dudnwjs 12:e3d3676753cc 533 }else if( param->char_code == FAN_CONTROL_FAN_SPIN_CHAR){
dudnwjs 12:e3d3676753cc 534
dudnwjs 12:e3d3676753cc 535 }else if( param->char_code == FAN_CONTROL_FAN_TIMER_CHAR){
dudnwjs 12:e3d3676753cc 536 Timer_flag = param->command;
dudnwjs 12:e3d3676753cc 537 }else if( param->char_code == FAN_CONTROL_RESIDUAL_TIME_CHAR){
dudnwjs 12:e3d3676753cc 538 Residual_Time = param->residual_time;
dudnwjs 12:e3d3676753cc 539 {
dudnwjs 12:e3d3676753cc 540 uint8_t fota_normal = 0;
dudnwjs 12:e3d3676753cc 541 uint8_t *msg;
dudnwjs 12:e3d3676753cc 542 struct fan_control_set_char_val_req char_set_req;
dudnwjs 12:e3d3676753cc 543 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE);
dudnwjs 12:e3d3676753cc 544 // Fill in the parameter structure
dudnwjs 12:e3d3676753cc 545 char_set_req.char_code = FAN_CONTROL_POWER_STATE_CHAR;
dudnwjs 12:e3d3676753cc 546 char_set_req.val_len = FAN_CONTROL_MIN_SIZE;
dudnwjs 12:e3d3676753cc 547 memcpy(&char_set_req.val[0], &fota_normal, sizeof(fota_normal));
dudnwjs 12:e3d3676753cc 548
dudnwjs 12:e3d3676753cc 549 msg = new uint8_t[msg_size];
dudnwjs 12:e3d3676753cc 550
dudnwjs 12:e3d3676753cc 551 BMH->BleMsgAlloc(FAN_CONTROL_SET_CHAR_VAL_REQ
dudnwjs 12:e3d3676753cc 552 ,TASK_FAN_CONTROL, TASK_GTL
dudnwjs 12:e3d3676753cc 553 ,sizeof(struct fan_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE)
dudnwjs 12:e3d3676753cc 554 ,&char_set_req,msg );
dudnwjs 12:e3d3676753cc 555 // Send the message
dudnwjs 12:e3d3676753cc 556 BMH->BleSendMsg(msg,msg_size);
dudnwjs 12:e3d3676753cc 557 free(msg);
dudnwjs 12:e3d3676753cc 558 }
dudnwjs 12:e3d3676753cc 559 }
dudnwjs 12:e3d3676753cc 560 }
dudnwjs 13:e714e2971c49 561 /**
dudnwjs 13:e714e2971c49 562 ****************************************************************************************
dudnwjs 13:e714e2971c49 563 * @brief Handles the LAMP_CONTROL_CREATE_DB_CFM message.
dudnwjs 13:e714e2971c49 564 *
dudnwjs 13:e714e2971c49 565 * @param[in] msgid Id of the message received.
dudnwjs 13:e714e2971c49 566 * @param[in] param Pointer to the parameters of the message.
dudnwjs 13:e714e2971c49 567 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 13:e714e2971c49 568 * @param[in] src_id ID of the sending task instance.
dudnwjs 13:e714e2971c49 569 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 13:e714e2971c49 570 *
dudnwjs 13:e714e2971c49 571 * @return If the message was consumed or not.
dudnwjs 13:e714e2971c49 572 ****************************************************************************************
dudnwjs 13:e714e2971c49 573 */
dudnwjs 13:e714e2971c49 574 void lamp_control_create_db_cfm_handler(unsigned short msgid,
dudnwjs 13:e714e2971c49 575 struct lamp_control_create_db_cfm *param,
dudnwjs 13:e714e2971c49 576 unsigned short dest_id,
dudnwjs 13:e714e2971c49 577 unsigned short src_id,
dudnwjs 13:e714e2971c49 578 BleMsgHandler* BMH)
dudnwjs 13:e714e2971c49 579 {
dudnwjs 13:e714e2971c49 580 uint8_t fota_normal = 0;
dudnwjs 13:e714e2971c49 581 uint8_t fota_normal_len = sizeof(fota_normal);
dudnwjs 13:e714e2971c49 582 if (param->status == CO_ERROR_NO_ERROR)
dudnwjs 13:e714e2971c49 583 {
dudnwjs 13:e714e2971c49 584 // Initialization All Characteristic
dudnwjs 13:e714e2971c49 585 {
dudnwjs 13:e714e2971c49 586 uint8_t *msg;
dudnwjs 13:e714e2971c49 587 struct lamp_control_set_char_val_req power_state_val;
dudnwjs 13:e714e2971c49 588 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(lamp_control_set_char_val_req)-(4-LAMP_CONTROL_MIN_SIZE);
dudnwjs 13:e714e2971c49 589 // Fill in the parameter structure
dudnwjs 13:e714e2971c49 590 power_state_val.char_code = LAMP_CONTROL_POWER_STATE_CHAR;
dudnwjs 13:e714e2971c49 591 power_state_val.val_len = LAMP_CONTROL_MIN_SIZE;
dudnwjs 13:e714e2971c49 592 memcpy(&power_state_val.val[0], &fota_normal, fota_normal_len);
dudnwjs 13:e714e2971c49 593
dudnwjs 13:e714e2971c49 594 msg = new uint8_t[msg_size];
dudnwjs 13:e714e2971c49 595
dudnwjs 13:e714e2971c49 596 BMH->BleMsgAlloc(LAMP_CONTROL_SET_CHAR_VAL_REQ,TASK_LAMP_CONTROL, TASK_GTL,sizeof(struct lamp_control_set_char_val_req)-(4-FAN_CONTROL_MIN_SIZE),&power_state_val,msg );
dudnwjs 13:e714e2971c49 597 // Send the message
dudnwjs 13:e714e2971c49 598 BMH->BleSendMsg(msg,msg_size);
dudnwjs 13:e714e2971c49 599 free(msg);
dudnwjs 13:e714e2971c49 600 }
dudnwjs 13:e714e2971c49 601 {
dudnwjs 13:e714e2971c49 602 uint8_t *msg;
dudnwjs 13:e714e2971c49 603 struct lamp_control_set_char_val_req light_intensity_val;
dudnwjs 13:e714e2971c49 604 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(lamp_control_set_char_val_req)-(4-LAMP_CONTROL_MIN_SIZE);
dudnwjs 13:e714e2971c49 605 // Fill in the parameter structure
dudnwjs 13:e714e2971c49 606 light_intensity_val.char_code = LAMP_CONTROL_LIGHT_INTENSITY_CHAR;
dudnwjs 13:e714e2971c49 607 light_intensity_val.val_len = LAMP_CONTROL_MIN_SIZE;
dudnwjs 13:e714e2971c49 608 memcpy(&light_intensity_val.val[0], &fota_normal, fota_normal_len);
dudnwjs 13:e714e2971c49 609
dudnwjs 13:e714e2971c49 610 msg = new uint8_t[msg_size];
dudnwjs 13:e714e2971c49 611
dudnwjs 13:e714e2971c49 612 BMH->BleMsgAlloc(LAMP_CONTROL_SET_CHAR_VAL_REQ,TASK_LAMP_CONTROL, TASK_GTL,sizeof(struct lamp_control_set_char_val_req)-(4-LAMP_CONTROL_MIN_SIZE),&light_intensity_val,msg );
dudnwjs 13:e714e2971c49 613 // Send the message
dudnwjs 13:e714e2971c49 614 BMH->BleSendMsg(msg,msg_size);
dudnwjs 13:e714e2971c49 615 free(msg);
dudnwjs 13:e714e2971c49 616 }
dudnwjs 13:e714e2971c49 617 {
dudnwjs 13:e714e2971c49 618 uint8_t *msg;
dudnwjs 13:e714e2971c49 619 struct lamp_control_set_char_val_req lamp_timer_val;
dudnwjs 13:e714e2971c49 620 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(lamp_control_set_char_val_req)-(4-LAMP_CONTROL_MIN_SIZE);
dudnwjs 13:e714e2971c49 621 // Fill in the parameter structure
dudnwjs 13:e714e2971c49 622 lamp_timer_val.char_code = LAMP_CONTROL_LAMP_TIMER_CHAR;
dudnwjs 13:e714e2971c49 623 lamp_timer_val.val_len = LAMP_CONTROL_MIN_SIZE;
dudnwjs 13:e714e2971c49 624 memcpy(&lamp_timer_val.val[0], &fota_normal, fota_normal_len);
dudnwjs 13:e714e2971c49 625
dudnwjs 13:e714e2971c49 626 msg = new uint8_t[msg_size];
dudnwjs 13:e714e2971c49 627
dudnwjs 13:e714e2971c49 628 BMH->BleMsgAlloc(LAMP_CONTROL_SET_CHAR_VAL_REQ,TASK_LAMP_CONTROL, TASK_GTL,sizeof(struct lamp_control_set_char_val_req)-(4-LAMP_CONTROL_MIN_SIZE),&lamp_timer_val,msg );
dudnwjs 13:e714e2971c49 629 // Send the message
dudnwjs 13:e714e2971c49 630 BMH->BleSendMsg(msg,msg_size);
dudnwjs 13:e714e2971c49 631 free(msg);
dudnwjs 13:e714e2971c49 632 }
dudnwjs 13:e714e2971c49 633 {
dudnwjs 13:e714e2971c49 634 uint8_t *msg;
dudnwjs 13:e714e2971c49 635 struct lamp_control_set_char_val_req residual_time_val;
dudnwjs 13:e714e2971c49 636 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(lamp_control_set_char_val_req)-(4-LAMP_CONTROL_MAX_SIZE);
dudnwjs 13:e714e2971c49 637 // Fill in the parameter structure
dudnwjs 13:e714e2971c49 638 residual_time_val.char_code = LAMP_CONTROL_RESIDUAL_TIME_CHAR;
dudnwjs 13:e714e2971c49 639 residual_time_val.val_len = LAMP_CONTROL_MAX_SIZE;
dudnwjs 13:e714e2971c49 640 memcpy(&residual_time_val.val[0], &fota_normal, fota_normal_len*4);
dudnwjs 13:e714e2971c49 641
dudnwjs 13:e714e2971c49 642 msg = new uint8_t[msg_size];
dudnwjs 13:e714e2971c49 643
dudnwjs 13:e714e2971c49 644 BMH->BleMsgAlloc(LAMP_CONTROL_SET_CHAR_VAL_REQ,TASK_LAMP_CONTROL, TASK_GTL,sizeof(struct lamp_control_set_char_val_req)-(4-FAN_CONTROL_MAX_SIZE),&residual_time_val,msg );
dudnwjs 13:e714e2971c49 645 // Send the message
dudnwjs 13:e714e2971c49 646 BMH->BleSendMsg(msg,msg_size);
dudnwjs 13:e714e2971c49 647 free(msg);
dudnwjs 13:e714e2971c49 648 }
dudnwjs 13:e714e2971c49 649 }
dudnwjs 13:e714e2971c49 650 if (app_env.state == APP_IDLE)
dudnwjs 13:e714e2971c49 651 {
dudnwjs 13:e714e2971c49 652 app_set_mode(BMH);
dudnwjs 13:e714e2971c49 653 }
dudnwjs 13:e714e2971c49 654 }
dudnwjs 12:e3d3676753cc 655
dudnwjs 9:fcf91f563147 656 /**
dudnwjs 9:fcf91f563147 657 ****************************************************************************************
dudnwjs 13:e714e2971c49 658 * @brief Handles the LAMP_CONTROL_COMMAND_IND message.
dudnwjs 13:e714e2971c49 659 *
dudnwjs 13:e714e2971c49 660 * @param[in] msgid Id of the message received.
dudnwjs 13:e714e2971c49 661 * @param[in] param Pointer to the parameters of the message.
dudnwjs 13:e714e2971c49 662 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 13:e714e2971c49 663 * @param[in] src_id ID of the sending task instance.
dudnwjs 13:e714e2971c49 664 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 13:e714e2971c49 665 *
dudnwjs 13:e714e2971c49 666 * @return If the message was consumed or not.
dudnwjs 13:e714e2971c49 667 ****************************************************************************************
dudnwjs 13:e714e2971c49 668 */
dudnwjs 13:e714e2971c49 669 void lamp_control_command_ind_handler(unsigned short msgid,
dudnwjs 13:e714e2971c49 670 struct lamp_control_command_ind *param,
dudnwjs 13:e714e2971c49 671 unsigned short dest_id,
dudnwjs 13:e714e2971c49 672 unsigned short src_id,
dudnwjs 13:e714e2971c49 673 BleMsgHandler* BMH)
dudnwjs 13:e714e2971c49 674 {
dudnwjs 13:e714e2971c49 675 char str[30] = "\nLAMP remote control START!!\n";
dudnwjs 13:e714e2971c49 676 BMH->HostPcPrint(str);
dudnwjs 13:e714e2971c49 677 if( param->char_code == LAMP_CONTROL_POWER_STATE_CHAR){
dudnwjs 13:e714e2971c49 678 if(param->command == 0){
dudnwjs 13:e714e2971c49 679 Timer_flag = 0;
dudnwjs 13:e714e2971c49 680 Residual_Time = 0;
dudnwjs 13:e714e2971c49 681 port21 = 0;
dudnwjs 13:e714e2971c49 682 port22 = 0;
dudnwjs 13:e714e2971c49 683 }
dudnwjs 13:e714e2971c49 684 if(param->command == 1){
dudnwjs 13:e714e2971c49 685 if( port21 == 0 && port22 == 0 )
dudnwjs 13:e714e2971c49 686 port21 = 1;
dudnwjs 13:e714e2971c49 687 }
dudnwjs 13:e714e2971c49 688 }else if( param->char_code == LAMP_CONTROL_LIGHT_INTENSITY_CHAR){
dudnwjs 13:e714e2971c49 689 if( param->command == 1 ){ //low
dudnwjs 13:e714e2971c49 690 port21 = 1;
dudnwjs 13:e714e2971c49 691 port22 = 0;
dudnwjs 13:e714e2971c49 692 }
dudnwjs 13:e714e2971c49 693 else if( param->command == 2 ){ //mid
dudnwjs 13:e714e2971c49 694 port21 = 0;
dudnwjs 13:e714e2971c49 695 port22 = 1;
dudnwjs 13:e714e2971c49 696 }
dudnwjs 13:e714e2971c49 697 }else if( param->char_code == LAMP_CONTROL_LAMP_TIMER_CHAR){
dudnwjs 13:e714e2971c49 698 Timer_flag = param->command;
dudnwjs 13:e714e2971c49 699 }else if( param->char_code == LAMP_CONTROL_RESIDUAL_TIME_CHAR){
dudnwjs 13:e714e2971c49 700 Residual_Time = param->residual_time;
dudnwjs 13:e714e2971c49 701 {
dudnwjs 13:e714e2971c49 702 uint8_t fota_normal = 0;
dudnwjs 13:e714e2971c49 703 uint8_t *msg;
dudnwjs 13:e714e2971c49 704 struct lamp_control_set_char_val_req char_set_req;
dudnwjs 13:e714e2971c49 705 unsigned short msg_size = 1+sizeof(ble_hdr)+ sizeof(lamp_control_set_char_val_req)-(4-LAMP_CONTROL_MIN_SIZE);
dudnwjs 13:e714e2971c49 706 // Fill in the parameter structure
dudnwjs 13:e714e2971c49 707 char_set_req.char_code = LAMP_CONTROL_POWER_STATE_CHAR;
dudnwjs 13:e714e2971c49 708 char_set_req.val_len = LAMP_CONTROL_MIN_SIZE;
dudnwjs 13:e714e2971c49 709 memcpy(&char_set_req.val[0], &fota_normal, sizeof(fota_normal));
dudnwjs 13:e714e2971c49 710
dudnwjs 13:e714e2971c49 711 msg = new uint8_t[msg_size];
dudnwjs 13:e714e2971c49 712
dudnwjs 13:e714e2971c49 713 BMH->BleMsgAlloc(LAMP_CONTROL_SET_CHAR_VAL_REQ
dudnwjs 13:e714e2971c49 714 ,TASK_LAMP_CONTROL, TASK_GTL
dudnwjs 13:e714e2971c49 715 ,sizeof(struct fan_control_set_char_val_req)-(4-LAMP_CONTROL_MIN_SIZE)
dudnwjs 13:e714e2971c49 716 ,&char_set_req,msg );
dudnwjs 13:e714e2971c49 717 // Send the message
dudnwjs 13:e714e2971c49 718 BMH->BleSendMsg(msg,msg_size);
dudnwjs 13:e714e2971c49 719 free(msg);
dudnwjs 13:e714e2971c49 720 }
dudnwjs 13:e714e2971c49 721 }
dudnwjs 13:e714e2971c49 722 }
dudnwjs 13:e714e2971c49 723 /**
dudnwjs 13:e714e2971c49 724 ****************************************************************************************
dudnwjs 9:fcf91f563147 725 * @brief Handles ready indication from the GAP.
dudnwjs 9:fcf91f563147 726 *
dudnwjs 9:fcf91f563147 727 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 728 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 729 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 730 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 731 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 732 *
dudnwjs 9:fcf91f563147 733 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 734 ****************************************************************************************
dudnwjs 9:fcf91f563147 735 */
dudnwjs 4:60be78a172c2 736 int gapm_device_ready_ind_handler(unsigned short msgid,
dudnwjs 5:e11b23f9aacc 737 struct gap_ready_evt *param,
dudnwjs 4:60be78a172c2 738 unsigned short dest_id,
dudnwjs 4:60be78a172c2 739 unsigned short src_id,
dudnwjs 4:60be78a172c2 740 BleMsgHandler* BMH)
dudnwjs 4:60be78a172c2 741 {
dudnwjs 4:60be78a172c2 742 // We are now in Connectable State
dudnwjs 4:60be78a172c2 743 if (dest_id == TASK_GTL)
dudnwjs 4:60be78a172c2 744 {
dudnwjs 4:60be78a172c2 745 app_rst_gap(BMH);
dudnwjs 4:60be78a172c2 746 }
dudnwjs 4:60be78a172c2 747
dudnwjs 4:60be78a172c2 748 return 0;
dudnwjs 4:60be78a172c2 749 }
dudnwjs 9:fcf91f563147 750 /**
dudnwjs 9:fcf91f563147 751 ****************************************************************************************
dudnwjs 9:fcf91f563147 752 * @brief Handle reset GAP request completion event.
dudnwjs 9:fcf91f563147 753 *
dudnwjs 9:fcf91f563147 754 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 755 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 756 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 757 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 758 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 759 *
dudnwjs 9:fcf91f563147 760 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 761 ****************************************************************************************
dudnwjs 9:fcf91f563147 762 */
dudnwjs 4:60be78a172c2 763 int gapm_reset_completion_handler(unsigned short msgid,
dudnwjs 4:60be78a172c2 764 struct gapm_cmp_evt *param,
dudnwjs 4:60be78a172c2 765 unsigned short dest_id,
dudnwjs 4:60be78a172c2 766 unsigned short src_id,
dudnwjs 4:60be78a172c2 767 BleMsgHandler* BMH)
dudnwjs 4:60be78a172c2 768 {
dudnwjs 4:60be78a172c2 769 // We are now in Connectable State
dudnwjs 4:60be78a172c2 770 if (dest_id == TASK_GTL)
dudnwjs 4:60be78a172c2 771 {
dudnwjs 5:e11b23f9aacc 772 app_env.state = APP_IDLE;
dudnwjs 4:60be78a172c2 773 app_diss_db_create(BMH);
dudnwjs 4:60be78a172c2 774 }
dudnwjs 4:60be78a172c2 775
dudnwjs 4:60be78a172c2 776 return 0;
dudnwjs 4:60be78a172c2 777 }
dudnwjs 9:fcf91f563147 778 /**
dudnwjs 9:fcf91f563147 779 ****************************************************************************************
dudnwjs 9:fcf91f563147 780 * @brief Handles GAPM_CMP_EVT event for GAPM_SET_DEV_CONFIG_CMD.
dudnwjs 9:fcf91f563147 781 *
dudnwjs 9:fcf91f563147 782 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 783 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 784 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 785 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 786 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 787 *
dudnwjs 9:fcf91f563147 788 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 789 ****************************************************************************************
dudnwjs 9:fcf91f563147 790 */
dudnwjs 4:60be78a172c2 791 int gapm_set_dev_config_completion_handler(unsigned short msgid,
dudnwjs 4:60be78a172c2 792 struct gapm_cmp_evt *param,
dudnwjs 4:60be78a172c2 793 unsigned short dest_id,
dudnwjs 4:60be78a172c2 794 unsigned short src_id,
dudnwjs 4:60be78a172c2 795 BleMsgHandler* BMH)
dudnwjs 4:60be78a172c2 796 {
dudnwjs 5:e11b23f9aacc 797 app_env.state = APP_CONNECTABLE;
dudnwjs 5:e11b23f9aacc 798 wait(1);
dudnwjs 4:60be78a172c2 799 app_adv_start(BMH); // start advertising
dudnwjs 4:60be78a172c2 800
dudnwjs 4:60be78a172c2 801 return 0;
dudnwjs 4:60be78a172c2 802 }
dudnwjs 9:fcf91f563147 803 /**
dudnwjs 9:fcf91f563147 804 ****************************************************************************************
dudnwjs 9:fcf91f563147 805 * @brief Handles Connection request indication event.
dudnwjs 9:fcf91f563147 806 *
dudnwjs 9:fcf91f563147 807 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 808 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 809 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 810 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 811 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 812 *
dudnwjs 9:fcf91f563147 813 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 814 ****************************************************************************************
dudnwjs 9:fcf91f563147 815 */
dudnwjs 5:e11b23f9aacc 816 int gapc_connection_req_ind_handler(uint16_t msgid,
dudnwjs 5:e11b23f9aacc 817 struct gapc_connection_req_ind *param,
dudnwjs 5:e11b23f9aacc 818 uint16_t dest_id,
dudnwjs 5:e11b23f9aacc 819 uint16_t src_id,
dudnwjs 5:e11b23f9aacc 820 BleMsgHandler* BMH)
dudnwjs 5:e11b23f9aacc 821 {
dudnwjs 5:e11b23f9aacc 822 app_env.state = APP_CONNECTED;
dudnwjs 5:e11b23f9aacc 823
dudnwjs 5:e11b23f9aacc 824 ble_dev device;
dudnwjs 5:e11b23f9aacc 825
dudnwjs 5:e11b23f9aacc 826 // Retrieve the connection index from the GAPC task instance for the connection
dudnwjs 5:e11b23f9aacc 827 device.conidx = KE_IDX_GET(src_id);
dudnwjs 5:e11b23f9aacc 828
dudnwjs 5:e11b23f9aacc 829 // Retrieve the connection handle from the parameters
dudnwjs 5:e11b23f9aacc 830 device.conhdl = param->conhdl;
dudnwjs 5:e11b23f9aacc 831
dudnwjs 5:e11b23f9aacc 832 memcpy(device.adv_addr.addr, param->peer_addr.addr, sizeof(struct bd_addr));
dudnwjs 5:e11b23f9aacc 833
dudnwjs 5:e11b23f9aacc 834
dudnwjs 12:e3d3676753cc 835 char str[30] = "\nPROFILE ENABLE and CONFIRM\n";
dudnwjs 5:e11b23f9aacc 836 BMH->HostPcPrint(str);
dudnwjs 5:e11b23f9aacc 837
dudnwjs 5:e11b23f9aacc 838 app_dis_enable(&device,BMH);
dudnwjs 5:e11b23f9aacc 839 app_fota_server_enable(&device,BMH);
dudnwjs 13:e714e2971c49 840 //app_fan_control_enable(&device,BMH);
dudnwjs 13:e714e2971c49 841 app_lamp_control_enable(&device,BMH);
dudnwjs 5:e11b23f9aacc 842 app_connect_confirm(GAP_AUTH_REQ_NO_MITM_NO_BOND,&device,BMH);
dudnwjs 6:8dd20294b2aa 843
dudnwjs 5:e11b23f9aacc 844 return 0;
dudnwjs 5:e11b23f9aacc 845 }
dudnwjs 9:fcf91f563147 846 /**
dudnwjs 9:fcf91f563147 847 ****************************************************************************************
dudnwjs 9:fcf91f563147 848 * @brief Handles Discconnection indication event.
dudnwjs 9:fcf91f563147 849 *
dudnwjs 9:fcf91f563147 850 * @param[in] msgid Id of the message received.
dudnwjs 9:fcf91f563147 851 * @param[in] param Pointer to the parameters of the message.
dudnwjs 9:fcf91f563147 852 * @param[in] dest_id ID of the receiving task instance (TASK_GAP).
dudnwjs 9:fcf91f563147 853 * @param[in] src_id ID of the sending task instance.
dudnwjs 9:fcf91f563147 854 * @param[in] BMH Ble Message Handler class reference.
dudnwjs 9:fcf91f563147 855 *
dudnwjs 9:fcf91f563147 856 * @return If the message was consumed or not.
dudnwjs 9:fcf91f563147 857 ****************************************************************************************
dudnwjs 9:fcf91f563147 858 */
dudnwjs 5:e11b23f9aacc 859 int gapc_disconnect_ind_handler(uint16_t msgid,
dudnwjs 5:e11b23f9aacc 860 struct gapc_disconnect_ind *param,
dudnwjs 5:e11b23f9aacc 861 uint16_t dest_id,
dudnwjs 5:e11b23f9aacc 862 uint16_t src_id,
dudnwjs 5:e11b23f9aacc 863 BleMsgHandler* BMH)
dudnwjs 5:e11b23f9aacc 864 {
dudnwjs 5:e11b23f9aacc 865 char str[22] = "\nDevice Disconnected\n";
dudnwjs 5:e11b23f9aacc 866 BMH->HostPcPrint(str);
dudnwjs 5:e11b23f9aacc 867
dudnwjs 5:e11b23f9aacc 868 app_send_disconnect(TASK_FOTA_SERVER, param->conhdl, param->reason, BMH);
dudnwjs 5:e11b23f9aacc 869 app_env.state = APP_IDLE;
dudnwjs 5:e11b23f9aacc 870
dudnwjs 5:e11b23f9aacc 871 wait(1);
dudnwjs 5:e11b23f9aacc 872 app_set_mode(BMH);
dudnwjs 5:e11b23f9aacc 873
dudnwjs 5:e11b23f9aacc 874 return 0;
dudnwjs 5:e11b23f9aacc 875 }
dudnwjs 5:e11b23f9aacc 876
dudnwjs 5:e11b23f9aacc 877
dudnwjs 4:60be78a172c2 878 }//namespace
dudnwjs 4:60be78a172c2 879
dudnwjs 9:fcf91f563147 880 /// @} dialog_fota module