sevencore fota solution development project
dialog_fota/app_task.cpp@5:e11b23f9aacc, 2015-07-13 (annotated)
- Committer:
- dudnwjs
- Date:
- Mon Jul 13 06:32:05 2015 +0000
- Revision:
- 5:e11b23f9aacc
- Parent:
- 4:60be78a172c2
- Child:
- 6:8dd20294b2aa
Fota Service Add complete
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudnwjs | 4:60be78a172c2 | 1 | #include "app_task.h" |
dudnwjs | 4:60be78a172c2 | 2 | #include "app.h" |
dudnwjs | 5:e11b23f9aacc | 3 | #include "fota_server_task.h" |
dudnwjs | 4:60be78a172c2 | 4 | |
dudnwjs | 4:60be78a172c2 | 5 | namespace sevencore_fota{ |
dudnwjs | 4:60be78a172c2 | 6 | |
dudnwjs | 4:60be78a172c2 | 7 | int gapm_adv_report_ind_handler(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 8 | struct gapm_adv_report_ind *param, |
dudnwjs | 4:60be78a172c2 | 9 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 10 | unsigned short src_id) |
dudnwjs | 4:60be78a172c2 | 11 | { |
dudnwjs | 4:60be78a172c2 | 12 | //if (app_env.state != APP_SCAN) |
dudnwjs | 4:60be78a172c2 | 13 | // return -1; |
dudnwjs | 4:60be78a172c2 | 14 | |
dudnwjs | 4:60be78a172c2 | 15 | return 0; |
dudnwjs | 4:60be78a172c2 | 16 | } |
dudnwjs | 4:60be78a172c2 | 17 | |
dudnwjs | 4:60be78a172c2 | 18 | int diss_create_db_cfm_handler(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 19 | struct diss_create_db_cfm *param, |
dudnwjs | 4:60be78a172c2 | 20 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 21 | unsigned short src_id, |
dudnwjs | 4:60be78a172c2 | 22 | BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 23 | { |
dudnwjs | 5:e11b23f9aacc | 24 | uint8_t len = strlen(APP_DIS_SW_REV); |
dudnwjs | 5:e11b23f9aacc | 25 | |
dudnwjs | 4:60be78a172c2 | 26 | if (param->status == CO_ERROR_NO_ERROR) |
dudnwjs | 4:60be78a172c2 | 27 | { |
dudnwjs | 5:e11b23f9aacc | 28 | char str[22] = "\nDIS SET DB\n"; |
dudnwjs | 5:e11b23f9aacc | 29 | BMH->HostPcPrint(str); |
dudnwjs | 4:60be78a172c2 | 30 | // Set Manufacturer Name value in the DB |
dudnwjs | 4:60be78a172c2 | 31 | { |
dudnwjs | 4:60be78a172c2 | 32 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 33 | struct diss_set_char_val_req req_name; |
dudnwjs | 5:e11b23f9aacc | 34 | 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 | 35 | |
dudnwjs | 4:60be78a172c2 | 36 | // Fill in the parameter structure |
dudnwjs | 4:60be78a172c2 | 37 | req_name.char_code = DIS_MANUFACTURER_NAME_CHAR; |
dudnwjs | 5:e11b23f9aacc | 38 | req_name.val_len = APP_DIS_MANUFACTURER_NAME_STR_LEN; |
dudnwjs | 5:e11b23f9aacc | 39 | memcpy(&req_name.val[0], APP_DIS_MANUFACTURER_NAME_STR, APP_DIS_MANUFACTURER_NAME_STR_LEN); |
dudnwjs | 5:e11b23f9aacc | 40 | |
dudnwjs | 4:60be78a172c2 | 41 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 42 | |
dudnwjs | 5:e11b23f9aacc | 43 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS,TASK_GTL, |
dudnwjs | 5:e11b23f9aacc | 44 | sizeof(struct diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_MANUFACTURER_NAME_STR_LEN),&req_name,msg); |
dudnwjs | 4:60be78a172c2 | 45 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 4:60be78a172c2 | 46 | free(msg); |
dudnwjs | 5:e11b23f9aacc | 47 | wait(0.5); |
dudnwjs | 5:e11b23f9aacc | 48 | |
dudnwjs | 4:60be78a172c2 | 49 | } |
dudnwjs | 4:60be78a172c2 | 50 | |
dudnwjs | 4:60be78a172c2 | 51 | // Set Model Number String value in the DB |
dudnwjs | 4:60be78a172c2 | 52 | { |
dudnwjs | 4:60be78a172c2 | 53 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 54 | struct diss_set_char_val_req req_mod; |
dudnwjs | 5:e11b23f9aacc | 55 | 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 | 56 | |
dudnwjs | 4:60be78a172c2 | 57 | // Fill in the parameter structure |
dudnwjs | 4:60be78a172c2 | 58 | req_mod.char_code = DIS_MODEL_NB_STR_CHAR; |
dudnwjs | 4:60be78a172c2 | 59 | req_mod.val_len = APP_DIS_MODEL_NB_STR_LEN; |
dudnwjs | 4:60be78a172c2 | 60 | memcpy(&req_mod.val[0], APP_DIS_MODEL_NB_STR, APP_DIS_MODEL_NB_STR_LEN); |
dudnwjs | 4:60be78a172c2 | 61 | |
dudnwjs | 4:60be78a172c2 | 62 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 63 | |
dudnwjs | 5:e11b23f9aacc | 64 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL, |
dudnwjs | 5:e11b23f9aacc | 65 | sizeof(struct diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_MODEL_NB_STR_LEN),&req_mod,msg); |
dudnwjs | 4:60be78a172c2 | 66 | // Send the message |
dudnwjs | 4:60be78a172c2 | 67 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 4:60be78a172c2 | 68 | free(msg); |
dudnwjs | 5:e11b23f9aacc | 69 | wait(0.5); |
dudnwjs | 4:60be78a172c2 | 70 | } |
dudnwjs | 5:e11b23f9aacc | 71 | |
dudnwjs | 5:e11b23f9aacc | 72 | // Set Serial Number String value in the DB |
dudnwjs | 5:e11b23f9aacc | 73 | { |
dudnwjs | 5:e11b23f9aacc | 74 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 75 | struct diss_set_char_val_req req_ser; |
dudnwjs | 5:e11b23f9aacc | 76 | 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 | 77 | |
dudnwjs | 5:e11b23f9aacc | 78 | // Fill in the parameter structure |
dudnwjs | 5:e11b23f9aacc | 79 | req_ser.char_code = DIS_SERIAL_NB_STR_CHAR; |
dudnwjs | 5:e11b23f9aacc | 80 | req_ser.val_len = APP_DIS_SERIAL_NB_STR_LEN; |
dudnwjs | 5:e11b23f9aacc | 81 | memcpy(&req_ser.val[0], APP_DIS_SERIAL_NB_STR, APP_DIS_SERIAL_NB_STR_LEN); |
dudnwjs | 5:e11b23f9aacc | 82 | |
dudnwjs | 5:e11b23f9aacc | 83 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 84 | |
dudnwjs | 5:e11b23f9aacc | 85 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL, |
dudnwjs | 5:e11b23f9aacc | 86 | sizeof(struct diss_set_char_val_req)-(STR_MAX_LEN-APP_DIS_SERIAL_NB_STR_LEN),&req_ser,msg); |
dudnwjs | 5:e11b23f9aacc | 87 | // Send the message |
dudnwjs | 5:e11b23f9aacc | 88 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 89 | free(msg); |
dudnwjs | 5:e11b23f9aacc | 90 | wait(0.5); |
dudnwjs | 5:e11b23f9aacc | 91 | } |
dudnwjs | 5:e11b23f9aacc | 92 | /* |
dudnwjs | 4:60be78a172c2 | 93 | // Set System ID 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_id; |
dudnwjs | 4:60be78a172c2 | 97 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); |
dudnwjs | 4:60be78a172c2 | 98 | |
dudnwjs | 4:60be78a172c2 | 99 | // Fill in the parameter structure |
dudnwjs | 4:60be78a172c2 | 100 | req_id.char_code = DIS_SYSTEM_ID_CHAR; |
dudnwjs | 4:60be78a172c2 | 101 | req_id.val_len = APP_DIS_SYSTEM_ID_LEN; |
dudnwjs | 4:60be78a172c2 | 102 | memcpy(&req_id.val[0], APP_DIS_SYSTEM_ID, APP_DIS_SYSTEM_ID_LEN); |
dudnwjs | 4:60be78a172c2 | 103 | |
dudnwjs | 4:60be78a172c2 | 104 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 105 | |
dudnwjs | 4:60be78a172c2 | 106 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg); |
dudnwjs | 4:60be78a172c2 | 107 | |
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 | 4:60be78a172c2 | 112 | |
dudnwjs | 4:60be78a172c2 | 113 | |
dudnwjs | 4:60be78a172c2 | 114 | // Set the software version in the DB |
dudnwjs | 4:60be78a172c2 | 115 | { |
dudnwjs | 4:60be78a172c2 | 116 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 117 | struct diss_set_char_val_req req_id; |
dudnwjs | 4:60be78a172c2 | 118 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); |
dudnwjs | 4:60be78a172c2 | 119 | |
dudnwjs | 4:60be78a172c2 | 120 | // Fill in the parameter structure |
dudnwjs | 4:60be78a172c2 | 121 | req_id.char_code = DIS_SW_REV_STR_CHAR; |
dudnwjs | 4:60be78a172c2 | 122 | req_id.val_len = len; |
dudnwjs | 4:60be78a172c2 | 123 | memcpy(&req_id.val[0], APP_DIS_SW_REV, len); |
dudnwjs | 4:60be78a172c2 | 124 | |
dudnwjs | 4:60be78a172c2 | 125 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 126 | |
dudnwjs | 4:60be78a172c2 | 127 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg); |
dudnwjs | 4:60be78a172c2 | 128 | // Send the message |
dudnwjs | 4:60be78a172c2 | 129 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 4:60be78a172c2 | 130 | free(msg); |
dudnwjs | 4:60be78a172c2 | 131 | } |
dudnwjs | 4:60be78a172c2 | 132 | |
dudnwjs | 4:60be78a172c2 | 133 | len = strlen(APP_DIS_FIRM_REV); |
dudnwjs | 4:60be78a172c2 | 134 | // Set the firmware version in the DB. This is the common code sw version |
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_FIRM_REV_STR_CHAR; |
dudnwjs | 4:60be78a172c2 | 142 | req_id.val_len = len; |
dudnwjs | 4:60be78a172c2 | 143 | memcpy(&req_id.val[0], APP_DIS_FIRM_REV, 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 | // Send the message |
dudnwjs | 4:60be78a172c2 | 149 | BMH->BleSendMsg(msg, msg_size); |
dudnwjs | 4:60be78a172c2 | 150 | free(msg); |
dudnwjs | 5:e11b23f9aacc | 151 | }*/ |
dudnwjs | 4:60be78a172c2 | 152 | } |
dudnwjs | 4:60be78a172c2 | 153 | |
dudnwjs | 5:e11b23f9aacc | 154 | if (app_env.state == APP_IDLE) |
dudnwjs | 5:e11b23f9aacc | 155 | { |
dudnwjs | 5:e11b23f9aacc | 156 | char str[30] = "\nfota db create req!!\n"; |
dudnwjs | 5:e11b23f9aacc | 157 | BMH->HostPcPrint(str); |
dudnwjs | 5:e11b23f9aacc | 158 | //app_set_mode(BMH); |
dudnwjs | 5:e11b23f9aacc | 159 | app_fota_server_db_create(BMH); |
dudnwjs | 5:e11b23f9aacc | 160 | } |
dudnwjs | 5:e11b23f9aacc | 161 | |
dudnwjs | 5:e11b23f9aacc | 162 | return 0; |
dudnwjs | 5:e11b23f9aacc | 163 | } |
dudnwjs | 5:e11b23f9aacc | 164 | |
dudnwjs | 5:e11b23f9aacc | 165 | int fota_server_create_db_cfm_handler(unsigned short msgid, |
dudnwjs | 5:e11b23f9aacc | 166 | struct fota_server_create_db_cfm *param, |
dudnwjs | 5:e11b23f9aacc | 167 | unsigned short dest_id, |
dudnwjs | 5:e11b23f9aacc | 168 | unsigned short src_id, |
dudnwjs | 5:e11b23f9aacc | 169 | BleMsgHandler* BMH) |
dudnwjs | 5:e11b23f9aacc | 170 | { |
dudnwjs | 5:e11b23f9aacc | 171 | uint8_t fota_normal = 0; |
dudnwjs | 5:e11b23f9aacc | 172 | uint8_t fota_normal_len = sizeof(fota_normal); |
dudnwjs | 5:e11b23f9aacc | 173 | if (param->status == CO_ERROR_NO_ERROR) |
dudnwjs | 4:60be78a172c2 | 174 | { |
dudnwjs | 5:e11b23f9aacc | 175 | // Initialization Firmware new Version Char ("00-00-00") |
dudnwjs | 5:e11b23f9aacc | 176 | { |
dudnwjs | 5:e11b23f9aacc | 177 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 178 | struct fota_server_set_char_val_req req_nv; |
dudnwjs | 5:e11b23f9aacc | 179 | 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 | 180 | // Fill in the parameter structure |
dudnwjs | 5:e11b23f9aacc | 181 | req_nv.char_code = FOTA_SERVER_FIRMWARE_NEW_VERSION_CHAR; |
dudnwjs | 5:e11b23f9aacc | 182 | req_nv.val_len = APP_FOTA_SERVER_FIRMWARE_NEW_VERSION_LEN; |
dudnwjs | 5:e11b23f9aacc | 183 | memcpy(&req_nv.val[0], APP_FOTA_SERVER_FIRMWARE_NEW_VERSION, APP_FOTA_SERVER_FIRMWARE_NEW_VERSION_LEN); |
dudnwjs | 5:e11b23f9aacc | 184 | |
dudnwjs | 5:e11b23f9aacc | 185 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 186 | |
dudnwjs | 5:e11b23f9aacc | 187 | 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 | 188 | // Send the message |
dudnwjs | 5:e11b23f9aacc | 189 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 190 | free(msg); |
dudnwjs | 5:e11b23f9aacc | 191 | } |
dudnwjs | 5:e11b23f9aacc | 192 | |
dudnwjs | 5:e11b23f9aacc | 193 | // Initialization Sequence Number Char ( = '0' ) |
dudnwjs | 5:e11b23f9aacc | 194 | { |
dudnwjs | 5:e11b23f9aacc | 195 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 196 | struct fota_server_set_char_val_req req_sn; |
dudnwjs | 5:e11b23f9aacc | 197 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len); |
dudnwjs | 5:e11b23f9aacc | 198 | |
dudnwjs | 5:e11b23f9aacc | 199 | // Fill in the parameter structure |
dudnwjs | 5:e11b23f9aacc | 200 | req_sn.char_code = FOTA_SERVER_SEQUENCE_NUMBER_CHAR; |
dudnwjs | 5:e11b23f9aacc | 201 | req_sn.val_len = fota_normal_len; |
dudnwjs | 5:e11b23f9aacc | 202 | memcpy(&req_sn.val[0], &fota_normal, fota_normal_len); |
dudnwjs | 5:e11b23f9aacc | 203 | |
dudnwjs | 5:e11b23f9aacc | 204 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 205 | |
dudnwjs | 5:e11b23f9aacc | 206 | 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 | 207 | // Send the message |
dudnwjs | 5:e11b23f9aacc | 208 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 209 | free(msg); |
dudnwjs | 5:e11b23f9aacc | 210 | } |
dudnwjs | 5:e11b23f9aacc | 211 | |
dudnwjs | 5:e11b23f9aacc | 212 | // Initialization Firmware Data Check Char ( = '0' ) |
dudnwjs | 5:e11b23f9aacc | 213 | { |
dudnwjs | 5:e11b23f9aacc | 214 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 215 | struct fota_server_set_char_val_req req_fdc; |
dudnwjs | 5:e11b23f9aacc | 216 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len); |
dudnwjs | 5:e11b23f9aacc | 217 | |
dudnwjs | 5:e11b23f9aacc | 218 | // Fill in the parameter structure |
dudnwjs | 5:e11b23f9aacc | 219 | req_fdc.char_code = FOTA_SERVER_FIRMWARE_DATA_CHECK_CHAR; |
dudnwjs | 5:e11b23f9aacc | 220 | req_fdc.val_len = fota_normal_len; |
dudnwjs | 5:e11b23f9aacc | 221 | memcpy(&req_fdc.val[0], &fota_normal, fota_normal_len); |
dudnwjs | 5:e11b23f9aacc | 222 | |
dudnwjs | 5:e11b23f9aacc | 223 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 224 | |
dudnwjs | 5:e11b23f9aacc | 225 | 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 | 226 | // Send the message |
dudnwjs | 5:e11b23f9aacc | 227 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 228 | free(msg); |
dudnwjs | 5:e11b23f9aacc | 229 | } |
dudnwjs | 5:e11b23f9aacc | 230 | |
dudnwjs | 5:e11b23f9aacc | 231 | // Initialization Firmware Status Char ( = '0' ) |
dudnwjs | 5:e11b23f9aacc | 232 | { |
dudnwjs | 5:e11b23f9aacc | 233 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 234 | struct fota_server_set_char_val_req req_stat; |
dudnwjs | 5:e11b23f9aacc | 235 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len); |
dudnwjs | 5:e11b23f9aacc | 236 | |
dudnwjs | 5:e11b23f9aacc | 237 | // Fill in the parameter structure |
dudnwjs | 5:e11b23f9aacc | 238 | req_stat.char_code = FOTA_SERVER_FIRMWARE_STATUS_CHAR; |
dudnwjs | 5:e11b23f9aacc | 239 | req_stat.val_len = fota_normal_len; |
dudnwjs | 5:e11b23f9aacc | 240 | memcpy(&req_stat.val[0], &fota_normal, fota_normal_len); |
dudnwjs | 5:e11b23f9aacc | 241 | |
dudnwjs | 5:e11b23f9aacc | 242 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 243 | |
dudnwjs | 5:e11b23f9aacc | 244 | 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 | 245 | // Send the message |
dudnwjs | 5:e11b23f9aacc | 246 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 247 | free(msg); |
dudnwjs | 5:e11b23f9aacc | 248 | } |
dudnwjs | 5:e11b23f9aacc | 249 | |
dudnwjs | 5:e11b23f9aacc | 250 | // Initialization Reset Char ( = '0' ) |
dudnwjs | 5:e11b23f9aacc | 251 | { |
dudnwjs | 5:e11b23f9aacc | 252 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 253 | struct fota_server_set_char_val_req req_reset; |
dudnwjs | 5:e11b23f9aacc | 254 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(fota_server_set_char_val_req)-(18-fota_normal_len); |
dudnwjs | 5:e11b23f9aacc | 255 | |
dudnwjs | 5:e11b23f9aacc | 256 | // Fill in the parameter structure |
dudnwjs | 5:e11b23f9aacc | 257 | req_reset.char_code = FOTA_SERVER_RESET_CHAR; |
dudnwjs | 5:e11b23f9aacc | 258 | req_reset.val_len = fota_normal_len; |
dudnwjs | 5:e11b23f9aacc | 259 | memcpy(&req_reset.val[0], &fota_normal, fota_normal_len); |
dudnwjs | 5:e11b23f9aacc | 260 | |
dudnwjs | 5:e11b23f9aacc | 261 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 262 | |
dudnwjs | 5:e11b23f9aacc | 263 | 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 | 264 | // Send the message |
dudnwjs | 5:e11b23f9aacc | 265 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 266 | free(msg); |
dudnwjs | 5:e11b23f9aacc | 267 | } |
dudnwjs | 5:e11b23f9aacc | 268 | |
dudnwjs | 5:e11b23f9aacc | 269 | } |
dudnwjs | 5:e11b23f9aacc | 270 | |
dudnwjs | 5:e11b23f9aacc | 271 | if (app_env.state == APP_IDLE) |
dudnwjs | 5:e11b23f9aacc | 272 | { |
dudnwjs | 5:e11b23f9aacc | 273 | app_set_mode(BMH); |
dudnwjs | 5:e11b23f9aacc | 274 | } |
dudnwjs | 4:60be78a172c2 | 275 | |
dudnwjs | 4:60be78a172c2 | 276 | return 0; |
dudnwjs | 4:60be78a172c2 | 277 | } |
dudnwjs | 4:60be78a172c2 | 278 | |
dudnwjs | 5:e11b23f9aacc | 279 | void fota_server_data_flash_ind_handler(BleMsgHandler* BMH) |
dudnwjs | 5:e11b23f9aacc | 280 | { |
dudnwjs | 5:e11b23f9aacc | 281 | BMH->ReceiveToSerialTest(); |
dudnwjs | 5:e11b23f9aacc | 282 | } |
dudnwjs | 5:e11b23f9aacc | 283 | |
dudnwjs | 4:60be78a172c2 | 284 | int gapm_device_ready_ind_handler(unsigned short msgid, |
dudnwjs | 5:e11b23f9aacc | 285 | struct gap_ready_evt *param, |
dudnwjs | 4:60be78a172c2 | 286 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 287 | unsigned short src_id, |
dudnwjs | 4:60be78a172c2 | 288 | BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 289 | { |
dudnwjs | 4:60be78a172c2 | 290 | // We are now in Connectable State |
dudnwjs | 4:60be78a172c2 | 291 | if (dest_id == TASK_GTL) |
dudnwjs | 4:60be78a172c2 | 292 | { |
dudnwjs | 4:60be78a172c2 | 293 | app_rst_gap(BMH); |
dudnwjs | 4:60be78a172c2 | 294 | } |
dudnwjs | 4:60be78a172c2 | 295 | |
dudnwjs | 4:60be78a172c2 | 296 | return 0; |
dudnwjs | 4:60be78a172c2 | 297 | } |
dudnwjs | 4:60be78a172c2 | 298 | |
dudnwjs | 4:60be78a172c2 | 299 | int gapm_reset_completion_handler(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 300 | struct gapm_cmp_evt *param, |
dudnwjs | 4:60be78a172c2 | 301 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 302 | unsigned short src_id, |
dudnwjs | 4:60be78a172c2 | 303 | BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 304 | { |
dudnwjs | 4:60be78a172c2 | 305 | // We are now in Connectable State |
dudnwjs | 4:60be78a172c2 | 306 | if (dest_id == TASK_GTL) |
dudnwjs | 4:60be78a172c2 | 307 | { |
dudnwjs | 5:e11b23f9aacc | 308 | app_env.state = APP_IDLE; |
dudnwjs | 4:60be78a172c2 | 309 | app_diss_db_create(BMH); |
dudnwjs | 4:60be78a172c2 | 310 | } |
dudnwjs | 4:60be78a172c2 | 311 | |
dudnwjs | 4:60be78a172c2 | 312 | return 0; |
dudnwjs | 4:60be78a172c2 | 313 | } |
dudnwjs | 4:60be78a172c2 | 314 | |
dudnwjs | 4:60be78a172c2 | 315 | int gapm_set_dev_config_completion_handler(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 316 | struct gapm_cmp_evt *param, |
dudnwjs | 4:60be78a172c2 | 317 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 318 | unsigned short src_id, |
dudnwjs | 4:60be78a172c2 | 319 | BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 320 | { |
dudnwjs | 5:e11b23f9aacc | 321 | app_env.state = APP_CONNECTABLE; |
dudnwjs | 5:e11b23f9aacc | 322 | wait(1); |
dudnwjs | 4:60be78a172c2 | 323 | app_adv_start(BMH); // start advertising |
dudnwjs | 4:60be78a172c2 | 324 | |
dudnwjs | 4:60be78a172c2 | 325 | return 0; |
dudnwjs | 4:60be78a172c2 | 326 | } |
dudnwjs | 4:60be78a172c2 | 327 | |
dudnwjs | 5:e11b23f9aacc | 328 | int gapc_connection_req_ind_handler(uint16_t msgid, |
dudnwjs | 5:e11b23f9aacc | 329 | struct gapc_connection_req_ind *param, |
dudnwjs | 5:e11b23f9aacc | 330 | uint16_t dest_id, |
dudnwjs | 5:e11b23f9aacc | 331 | uint16_t src_id, |
dudnwjs | 5:e11b23f9aacc | 332 | BleMsgHandler* BMH) |
dudnwjs | 5:e11b23f9aacc | 333 | { |
dudnwjs | 5:e11b23f9aacc | 334 | app_env.state = APP_CONNECTED; |
dudnwjs | 5:e11b23f9aacc | 335 | |
dudnwjs | 5:e11b23f9aacc | 336 | ble_dev device; |
dudnwjs | 5:e11b23f9aacc | 337 | |
dudnwjs | 5:e11b23f9aacc | 338 | // Retrieve the connection index from the GAPC task instance for the connection |
dudnwjs | 5:e11b23f9aacc | 339 | device.conidx = KE_IDX_GET(src_id); |
dudnwjs | 5:e11b23f9aacc | 340 | |
dudnwjs | 5:e11b23f9aacc | 341 | // Retrieve the connection handle from the parameters |
dudnwjs | 5:e11b23f9aacc | 342 | device.conhdl = param->conhdl; |
dudnwjs | 5:e11b23f9aacc | 343 | |
dudnwjs | 5:e11b23f9aacc | 344 | memcpy(device.adv_addr.addr, param->peer_addr.addr, sizeof(struct bd_addr)); |
dudnwjs | 5:e11b23f9aacc | 345 | |
dudnwjs | 5:e11b23f9aacc | 346 | |
dudnwjs | 5:e11b23f9aacc | 347 | char str[30] = "\nDIS&FOTA ENABLE and CONFIRM\n"; |
dudnwjs | 5:e11b23f9aacc | 348 | BMH->HostPcPrint(str); |
dudnwjs | 5:e11b23f9aacc | 349 | |
dudnwjs | 5:e11b23f9aacc | 350 | app_dis_enable(&device,BMH); |
dudnwjs | 5:e11b23f9aacc | 351 | app_fota_server_enable(&device,BMH); |
dudnwjs | 5:e11b23f9aacc | 352 | wait(0.5); |
dudnwjs | 5:e11b23f9aacc | 353 | app_connect_confirm(GAP_AUTH_REQ_NO_MITM_NO_BOND,&device,BMH); |
dudnwjs | 5:e11b23f9aacc | 354 | |
dudnwjs | 5:e11b23f9aacc | 355 | |
dudnwjs | 5:e11b23f9aacc | 356 | return 0; |
dudnwjs | 5:e11b23f9aacc | 357 | } |
dudnwjs | 5:e11b23f9aacc | 358 | |
dudnwjs | 5:e11b23f9aacc | 359 | int gapc_disconnect_ind_handler(uint16_t msgid, |
dudnwjs | 5:e11b23f9aacc | 360 | struct gapc_disconnect_ind *param, |
dudnwjs | 5:e11b23f9aacc | 361 | uint16_t dest_id, |
dudnwjs | 5:e11b23f9aacc | 362 | uint16_t src_id, |
dudnwjs | 5:e11b23f9aacc | 363 | BleMsgHandler* BMH) |
dudnwjs | 5:e11b23f9aacc | 364 | { |
dudnwjs | 5:e11b23f9aacc | 365 | char str[22] = "\nDevice Disconnected\n"; |
dudnwjs | 5:e11b23f9aacc | 366 | BMH->HostPcPrint(str); |
dudnwjs | 5:e11b23f9aacc | 367 | |
dudnwjs | 5:e11b23f9aacc | 368 | app_send_disconnect(TASK_FOTA_SERVER, param->conhdl, param->reason, BMH); |
dudnwjs | 5:e11b23f9aacc | 369 | app_env.state = APP_IDLE; |
dudnwjs | 5:e11b23f9aacc | 370 | |
dudnwjs | 5:e11b23f9aacc | 371 | wait(1); |
dudnwjs | 5:e11b23f9aacc | 372 | app_set_mode(BMH); |
dudnwjs | 5:e11b23f9aacc | 373 | |
dudnwjs | 5:e11b23f9aacc | 374 | return 0; |
dudnwjs | 5:e11b23f9aacc | 375 | } |
dudnwjs | 5:e11b23f9aacc | 376 | |
dudnwjs | 5:e11b23f9aacc | 377 | |
dudnwjs | 4:60be78a172c2 | 378 | }//namespace |
dudnwjs | 4:60be78a172c2 | 379 |