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