Bluetooth Low Energy based Firmware Over The Air with Mbed. Mbed part is a external processor of the IoT devices and communicate with a Bluetooth module. The Bluetooth module have to support BLE and implement BLE FOTA profile designed by ours. BLE FOTA profile specification is available from our GIT hub wiki(https://github.com/sevencore/BLEFOTA).
Dependencies: mbed
Fork of mbed_fota by
Bluetooth Low Energy based Firmware Over The Air with Mbed. Mbed part is a external processor of the IoT devices and communicate with a Bluetooth module. The Bluetooth module have to support BLE and implement BLE FOTA profile designed by ours. BLE FOTA profile specification is available from our GIT hub wiki.
dialog_fota/app_task.cpp@4:60be78a172c2, 2015-06-24 (annotated)
- Committer:
- dudnwjs
- Date:
- Wed Jun 24 08:50:07 2015 +0000
- Revision:
- 4:60be78a172c2
- Child:
- 5:e11b23f9aacc
Add advertising feature;
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 | 4:60be78a172c2 | 3 | |
dudnwjs | 4:60be78a172c2 | 4 | namespace sevencore_fota{ |
dudnwjs | 4:60be78a172c2 | 5 | |
dudnwjs | 4:60be78a172c2 | 6 | int gapm_adv_report_ind_handler(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 7 | struct gapm_adv_report_ind *param, |
dudnwjs | 4:60be78a172c2 | 8 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 9 | unsigned short src_id) |
dudnwjs | 4:60be78a172c2 | 10 | { |
dudnwjs | 4:60be78a172c2 | 11 | //if (app_env.state != APP_SCAN) |
dudnwjs | 4:60be78a172c2 | 12 | // return -1; |
dudnwjs | 4:60be78a172c2 | 13 | |
dudnwjs | 4:60be78a172c2 | 14 | return 0; |
dudnwjs | 4:60be78a172c2 | 15 | } |
dudnwjs | 4:60be78a172c2 | 16 | |
dudnwjs | 4:60be78a172c2 | 17 | int diss_create_db_cfm_handler(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 18 | struct diss_create_db_cfm *param, |
dudnwjs | 4:60be78a172c2 | 19 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 20 | unsigned short src_id, |
dudnwjs | 4:60be78a172c2 | 21 | BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 22 | { |
dudnwjs | 4:60be78a172c2 | 23 | uint8_t len = strlen(APP_DIS_SW_REV); |
dudnwjs | 4:60be78a172c2 | 24 | |
dudnwjs | 4:60be78a172c2 | 25 | if (param->status == CO_ERROR_NO_ERROR) |
dudnwjs | 4:60be78a172c2 | 26 | { |
dudnwjs | 4:60be78a172c2 | 27 | // Set Manufacturer Name value in the DB |
dudnwjs | 4:60be78a172c2 | 28 | { |
dudnwjs | 4:60be78a172c2 | 29 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 30 | struct diss_set_char_val_req req_name; |
dudnwjs | 4:60be78a172c2 | 31 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req)+APP_DIS_MANUFACTURER_NAME_LEN; |
dudnwjs | 4:60be78a172c2 | 32 | // Fill in the parameter structure |
dudnwjs | 4:60be78a172c2 | 33 | req_name.char_code = DIS_MANUFACTURER_NAME_CHAR; |
dudnwjs | 4:60be78a172c2 | 34 | req_name.val_len = APP_DIS_MANUFACTURER_NAME_LEN; |
dudnwjs | 4:60be78a172c2 | 35 | memcpy(&req_name.val[0], APP_DIS_MANUFACTURER_NAME, APP_DIS_MANUFACTURER_NAME_LEN); |
dudnwjs | 4:60be78a172c2 | 36 | |
dudnwjs | 4:60be78a172c2 | 37 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 38 | |
dudnwjs | 4:60be78a172c2 | 39 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req) + APP_DIS_MANUFACTURER_NAME_LEN,&req_name,msg ); |
dudnwjs | 4:60be78a172c2 | 40 | |
dudnwjs | 4:60be78a172c2 | 41 | // Send the message |
dudnwjs | 4:60be78a172c2 | 42 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 4:60be78a172c2 | 43 | free(msg); |
dudnwjs | 4:60be78a172c2 | 44 | } |
dudnwjs | 4:60be78a172c2 | 45 | |
dudnwjs | 4:60be78a172c2 | 46 | // Set Model Number String value in the DB |
dudnwjs | 4:60be78a172c2 | 47 | { |
dudnwjs | 4:60be78a172c2 | 48 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 49 | struct diss_set_char_val_req req_mod; |
dudnwjs | 4:60be78a172c2 | 50 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); |
dudnwjs | 4:60be78a172c2 | 51 | |
dudnwjs | 4:60be78a172c2 | 52 | // Fill in the parameter structure |
dudnwjs | 4:60be78a172c2 | 53 | req_mod.char_code = DIS_MODEL_NB_STR_CHAR; |
dudnwjs | 4:60be78a172c2 | 54 | req_mod.val_len = APP_DIS_MODEL_NB_STR_LEN; |
dudnwjs | 4:60be78a172c2 | 55 | memcpy(&req_mod.val[0], APP_DIS_MODEL_NB_STR, APP_DIS_MODEL_NB_STR_LEN); |
dudnwjs | 4:60be78a172c2 | 56 | |
dudnwjs | 4:60be78a172c2 | 57 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 58 | |
dudnwjs | 4:60be78a172c2 | 59 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_mod,msg ); |
dudnwjs | 4:60be78a172c2 | 60 | // Send the message |
dudnwjs | 4:60be78a172c2 | 61 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 4:60be78a172c2 | 62 | free(msg); |
dudnwjs | 4:60be78a172c2 | 63 | } |
dudnwjs | 4:60be78a172c2 | 64 | |
dudnwjs | 4:60be78a172c2 | 65 | // Set System ID value in the DB |
dudnwjs | 4:60be78a172c2 | 66 | { |
dudnwjs | 4:60be78a172c2 | 67 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 68 | struct diss_set_char_val_req req_id; |
dudnwjs | 4:60be78a172c2 | 69 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); |
dudnwjs | 4:60be78a172c2 | 70 | |
dudnwjs | 4:60be78a172c2 | 71 | // Fill in the parameter structure |
dudnwjs | 4:60be78a172c2 | 72 | req_id.char_code = DIS_SYSTEM_ID_CHAR; |
dudnwjs | 4:60be78a172c2 | 73 | req_id.val_len = APP_DIS_SYSTEM_ID_LEN; |
dudnwjs | 4:60be78a172c2 | 74 | memcpy(&req_id.val[0], APP_DIS_SYSTEM_ID, APP_DIS_SYSTEM_ID_LEN); |
dudnwjs | 4:60be78a172c2 | 75 | |
dudnwjs | 4:60be78a172c2 | 76 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 77 | |
dudnwjs | 4:60be78a172c2 | 78 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg); |
dudnwjs | 4:60be78a172c2 | 79 | |
dudnwjs | 4:60be78a172c2 | 80 | // Send the message |
dudnwjs | 4:60be78a172c2 | 81 | BMH->BleSendMsg(msg, msg_size); |
dudnwjs | 4:60be78a172c2 | 82 | free(msg); |
dudnwjs | 4:60be78a172c2 | 83 | } |
dudnwjs | 4:60be78a172c2 | 84 | |
dudnwjs | 4:60be78a172c2 | 85 | |
dudnwjs | 4:60be78a172c2 | 86 | // Set the software version in the DB |
dudnwjs | 4:60be78a172c2 | 87 | { |
dudnwjs | 4:60be78a172c2 | 88 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 89 | struct diss_set_char_val_req req_id; |
dudnwjs | 4:60be78a172c2 | 90 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); |
dudnwjs | 4:60be78a172c2 | 91 | |
dudnwjs | 4:60be78a172c2 | 92 | // Fill in the parameter structure |
dudnwjs | 4:60be78a172c2 | 93 | req_id.char_code = DIS_SW_REV_STR_CHAR; |
dudnwjs | 4:60be78a172c2 | 94 | req_id.val_len = len; |
dudnwjs | 4:60be78a172c2 | 95 | memcpy(&req_id.val[0], APP_DIS_SW_REV, len); |
dudnwjs | 4:60be78a172c2 | 96 | |
dudnwjs | 4:60be78a172c2 | 97 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 98 | |
dudnwjs | 4:60be78a172c2 | 99 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg); |
dudnwjs | 4:60be78a172c2 | 100 | // Send the message |
dudnwjs | 4:60be78a172c2 | 101 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 4:60be78a172c2 | 102 | free(msg); |
dudnwjs | 4:60be78a172c2 | 103 | } |
dudnwjs | 4:60be78a172c2 | 104 | |
dudnwjs | 4:60be78a172c2 | 105 | len = strlen(APP_DIS_FIRM_REV); |
dudnwjs | 4:60be78a172c2 | 106 | // Set the firmware version in the DB. This is the common code sw version |
dudnwjs | 4:60be78a172c2 | 107 | { |
dudnwjs | 4:60be78a172c2 | 108 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 109 | struct diss_set_char_val_req req_id; |
dudnwjs | 4:60be78a172c2 | 110 | unsigned short msg_size = 1+sizeof(ble_hdr)+sizeof(diss_set_char_val_req); |
dudnwjs | 4:60be78a172c2 | 111 | |
dudnwjs | 4:60be78a172c2 | 112 | // Fill in the parameter structure |
dudnwjs | 4:60be78a172c2 | 113 | req_id.char_code = DIS_FIRM_REV_STR_CHAR; |
dudnwjs | 4:60be78a172c2 | 114 | req_id.val_len = len; |
dudnwjs | 4:60be78a172c2 | 115 | memcpy(&req_id.val[0], APP_DIS_FIRM_REV, len); |
dudnwjs | 4:60be78a172c2 | 116 | |
dudnwjs | 4:60be78a172c2 | 117 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 118 | |
dudnwjs | 4:60be78a172c2 | 119 | BMH->BleMsgAlloc(DISS_SET_CHAR_VAL_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_set_char_val_req),&req_id,msg); |
dudnwjs | 4:60be78a172c2 | 120 | // Send the message |
dudnwjs | 4:60be78a172c2 | 121 | BMH->BleSendMsg(msg, msg_size); |
dudnwjs | 4:60be78a172c2 | 122 | free(msg); |
dudnwjs | 4:60be78a172c2 | 123 | } |
dudnwjs | 4:60be78a172c2 | 124 | } |
dudnwjs | 4:60be78a172c2 | 125 | |
dudnwjs | 4:60be78a172c2 | 126 | /*if (app_env.state == APP_IDLE) |
dudnwjs | 4:60be78a172c2 | 127 | { |
dudnwjs | 4:60be78a172c2 | 128 | app_proxr_db_create(); |
dudnwjs | 4:60be78a172c2 | 129 | }*/ |
dudnwjs | 4:60be78a172c2 | 130 | app_set_mode(BMH); |
dudnwjs | 4:60be78a172c2 | 131 | |
dudnwjs | 4:60be78a172c2 | 132 | return 0; |
dudnwjs | 4:60be78a172c2 | 133 | } |
dudnwjs | 4:60be78a172c2 | 134 | |
dudnwjs | 4:60be78a172c2 | 135 | int gapm_device_ready_ind_handler(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 136 | void *param, |
dudnwjs | 4:60be78a172c2 | 137 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 138 | unsigned short src_id, |
dudnwjs | 4:60be78a172c2 | 139 | BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 140 | { |
dudnwjs | 4:60be78a172c2 | 141 | // We are now in Connectable State |
dudnwjs | 4:60be78a172c2 | 142 | if (dest_id == TASK_GTL) |
dudnwjs | 4:60be78a172c2 | 143 | { |
dudnwjs | 4:60be78a172c2 | 144 | app_rst_gap(BMH); |
dudnwjs | 4:60be78a172c2 | 145 | } |
dudnwjs | 4:60be78a172c2 | 146 | |
dudnwjs | 4:60be78a172c2 | 147 | return 0; |
dudnwjs | 4:60be78a172c2 | 148 | } |
dudnwjs | 4:60be78a172c2 | 149 | |
dudnwjs | 4:60be78a172c2 | 150 | int gapm_reset_completion_handler(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 151 | struct gapm_cmp_evt *param, |
dudnwjs | 4:60be78a172c2 | 152 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 153 | unsigned short src_id, |
dudnwjs | 4:60be78a172c2 | 154 | BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 155 | { |
dudnwjs | 4:60be78a172c2 | 156 | // We are now in Connectable State |
dudnwjs | 4:60be78a172c2 | 157 | if (dest_id == TASK_GTL) |
dudnwjs | 4:60be78a172c2 | 158 | { |
dudnwjs | 4:60be78a172c2 | 159 | // app_env.state = APP_IDLE; |
dudnwjs | 4:60be78a172c2 | 160 | app_diss_db_create(BMH); |
dudnwjs | 4:60be78a172c2 | 161 | } |
dudnwjs | 4:60be78a172c2 | 162 | |
dudnwjs | 4:60be78a172c2 | 163 | return 0; |
dudnwjs | 4:60be78a172c2 | 164 | } |
dudnwjs | 4:60be78a172c2 | 165 | |
dudnwjs | 4:60be78a172c2 | 166 | int gapm_set_dev_config_completion_handler(unsigned short msgid, |
dudnwjs | 4:60be78a172c2 | 167 | struct gapm_cmp_evt *param, |
dudnwjs | 4:60be78a172c2 | 168 | unsigned short dest_id, |
dudnwjs | 4:60be78a172c2 | 169 | unsigned short src_id, |
dudnwjs | 4:60be78a172c2 | 170 | BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 171 | { |
dudnwjs | 4:60be78a172c2 | 172 | //app_env.state = APP_CONNECTABLE; |
dudnwjs | 4:60be78a172c2 | 173 | |
dudnwjs | 4:60be78a172c2 | 174 | //Sleep(100); |
dudnwjs | 4:60be78a172c2 | 175 | |
dudnwjs | 4:60be78a172c2 | 176 | app_adv_start(BMH); // start advertising |
dudnwjs | 4:60be78a172c2 | 177 | |
dudnwjs | 4:60be78a172c2 | 178 | return 0; |
dudnwjs | 4:60be78a172c2 | 179 | } |
dudnwjs | 4:60be78a172c2 | 180 | |
dudnwjs | 4:60be78a172c2 | 181 | }//namespace |
dudnwjs | 4:60be78a172c2 | 182 |