BLE fota Lamp Demo
Dependencies: mbed-rtos mbed mbed_fota_fan_control
Fork of mbed_fota_fan_control by
dialog_fota/app.cpp@12:e3d3676753cc, 2015-09-02 (annotated)
- Committer:
- dudnwjs
- Date:
- Wed Sep 02 07:44:29 2015 +0000
- Revision:
- 12:e3d3676753cc
- Parent:
- 9:fcf91f563147
- Child:
- 13:e714e2971c49
Fan Control Demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudnwjs | 9:fcf91f563147 | 1 | /** |
dudnwjs | 9:fcf91f563147 | 2 | * @file app.cpp |
dudnwjs | 9:fcf91f563147 | 3 | * @brief Application entry point |
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-17 |
dudnwjs | 9:fcf91f563147 | 9 | */ |
dudnwjs | 3:1e70387e1337 | 10 | #include "app.h" |
dudnwjs | 3:1e70387e1337 | 11 | #include "gapm_task.h" |
dudnwjs | 3:1e70387e1337 | 12 | #include "dialog_fota_config.h" |
dudnwjs | 4:60be78a172c2 | 13 | #include "diss_task.h" |
dudnwjs | 5:e11b23f9aacc | 14 | #include "fota_server_task.h" |
dudnwjs | 12:e3d3676753cc | 15 | #include "fan_control_task.h" |
dudnwjs | 3:1e70387e1337 | 16 | |
dudnwjs | 3:1e70387e1337 | 17 | namespace sevencore_fota{ |
dudnwjs | 9:fcf91f563147 | 18 | /** |
dudnwjs | 9:fcf91f563147 | 19 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 20 | * @addtogroup dialog_fota module |
dudnwjs | 9:fcf91f563147 | 21 | * @brief Application entry point function definition. |
dudnwjs | 9:fcf91f563147 | 22 | * |
dudnwjs | 9:fcf91f563147 | 23 | * @{ |
dudnwjs | 9:fcf91f563147 | 24 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 25 | */ |
dudnwjs | 5:e11b23f9aacc | 26 | struct app_env_tag app_env; |
dudnwjs | 9:fcf91f563147 | 27 | /** |
dudnwjs | 9:fcf91f563147 | 28 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 29 | * @brief Send Reset request to GAPM task. |
dudnwjs | 9:fcf91f563147 | 30 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 9:fcf91f563147 | 31 | * @return void. |
dudnwjs | 9:fcf91f563147 | 32 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 33 | */ |
dudnwjs | 3:1e70387e1337 | 34 | void app_rst_gap(BleMsgHandler *BMH) |
dudnwjs | 3:1e70387e1337 | 35 | { |
dudnwjs | 3:1e70387e1337 | 36 | struct gapm_reset_cmd gm_cmd; |
dudnwjs | 3:1e70387e1337 | 37 | gm_cmd.operation = GAPM_RESET; |
dudnwjs | 5:e11b23f9aacc | 38 | |
dudnwjs | 5:e11b23f9aacc | 39 | app_env.state = APP_IDLE; |
dudnwjs | 5:e11b23f9aacc | 40 | app_env.num_of_devices = 0; |
dudnwjs | 5:e11b23f9aacc | 41 | for (int i=0; i < MAX_SCAN_DEVICES; i++) |
dudnwjs | 5:e11b23f9aacc | 42 | { |
dudnwjs | 5:e11b23f9aacc | 43 | app_env.devices[i].free = true; |
dudnwjs | 5:e11b23f9aacc | 44 | app_env.devices[i].adv_addr.addr[0] = '\0'; |
dudnwjs | 5:e11b23f9aacc | 45 | app_env.devices[i].data[0] = '\0'; |
dudnwjs | 5:e11b23f9aacc | 46 | app_env.devices[i].data_len = 0; |
dudnwjs | 5:e11b23f9aacc | 47 | app_env.devices[i].rssi = 0; |
dudnwjs | 5:e11b23f9aacc | 48 | } |
dudnwjs | 5:e11b23f9aacc | 49 | |
dudnwjs | 3:1e70387e1337 | 50 | uint8_t *msg; |
dudnwjs | 3:1e70387e1337 | 51 | unsigned short msg_size = 1+sizeof(ble_hdr) + sizeof(gapm_reset_cmd); |
dudnwjs | 3:1e70387e1337 | 52 | msg = new uint8_t[msg_size]; |
dudnwjs | 3:1e70387e1337 | 53 | BMH->BleMsgAlloc(GAPM_RESET_CMD, TASK_GAPM, TASK_GTL, |
dudnwjs | 3:1e70387e1337 | 54 | sizeof(struct gapm_reset_cmd),&gm_cmd,msg); |
dudnwjs | 3:1e70387e1337 | 55 | |
dudnwjs | 3:1e70387e1337 | 56 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 3:1e70387e1337 | 57 | |
dudnwjs | 3:1e70387e1337 | 58 | return; |
dudnwjs | 3:1e70387e1337 | 59 | } |
dudnwjs | 9:fcf91f563147 | 60 | /** |
dudnwjs | 9:fcf91f563147 | 61 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 62 | * @brief Send enable request to DISS profile task. |
dudnwjs | 9:fcf91f563147 | 63 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 9:fcf91f563147 | 64 | * @return void. |
dudnwjs | 9:fcf91f563147 | 65 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 66 | */ |
dudnwjs | 4:60be78a172c2 | 67 | void app_diss_db_create(BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 68 | { |
dudnwjs | 4:60be78a172c2 | 69 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 70 | // Add DIS in the database |
dudnwjs | 4:60be78a172c2 | 71 | struct diss_create_db_req req; |
dudnwjs | 4:60be78a172c2 | 72 | unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct diss_create_db_req); |
dudnwjs | 6:8dd20294b2aa | 73 | req.features = (DIS_MANUFACTURER_NAME_CHAR_SUP|DIS_MODEL_NB_STR_CHAR_SUP|DIS_SERIAL_NB_STR_CHAR_SUP); |
dudnwjs | 4:60be78a172c2 | 74 | |
dudnwjs | 4:60be78a172c2 | 75 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 76 | |
dudnwjs | 4:60be78a172c2 | 77 | BMH->BleMsgAlloc(DISS_CREATE_DB_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_create_db_req),&req,msg); |
dudnwjs | 4:60be78a172c2 | 78 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 4:60be78a172c2 | 79 | } |
dudnwjs | 9:fcf91f563147 | 80 | /** |
dudnwjs | 9:fcf91f563147 | 81 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 82 | * @brief Send enable request to FOTA profile task. |
dudnwjs | 9:fcf91f563147 | 83 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 9:fcf91f563147 | 84 | * @return void. |
dudnwjs | 9:fcf91f563147 | 85 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 86 | */ |
dudnwjs | 5:e11b23f9aacc | 87 | void app_fota_server_db_create(BleMsgHandler* BMH) |
dudnwjs | 5:e11b23f9aacc | 88 | { |
dudnwjs | 5:e11b23f9aacc | 89 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 90 | // Add DIS in the database |
dudnwjs | 5:e11b23f9aacc | 91 | struct fota_server_create_db_req req; |
dudnwjs | 5:e11b23f9aacc | 92 | unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct fota_server_create_db_req); |
dudnwjs | 5:e11b23f9aacc | 93 | req.features = 0x01FF; |
dudnwjs | 5:e11b23f9aacc | 94 | |
dudnwjs | 5:e11b23f9aacc | 95 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 96 | |
dudnwjs | 5:e11b23f9aacc | 97 | BMH->BleMsgAlloc(FOTA_SERVER_CREATE_DB_REQ,TASK_FOTA_SERVER, TASK_GTL,sizeof(struct fota_server_create_db_req),&req,msg); |
dudnwjs | 5:e11b23f9aacc | 98 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 99 | } |
dudnwjs | 9:fcf91f563147 | 100 | /** |
dudnwjs | 9:fcf91f563147 | 101 | **************************************************************************************** |
dudnwjs | 12:e3d3676753cc | 102 | * @brief Send enable request to Fan Control profile task. |
dudnwjs | 12:e3d3676753cc | 103 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 12:e3d3676753cc | 104 | * @return void. |
dudnwjs | 12:e3d3676753cc | 105 | **************************************************************************************** |
dudnwjs | 12:e3d3676753cc | 106 | */ |
dudnwjs | 12:e3d3676753cc | 107 | void app_fan_control_db_create(BleMsgHandler* BMH) |
dudnwjs | 12:e3d3676753cc | 108 | { |
dudnwjs | 12:e3d3676753cc | 109 | uint8_t *msg; |
dudnwjs | 12:e3d3676753cc | 110 | // Add fan_control service table in the database |
dudnwjs | 12:e3d3676753cc | 111 | struct fan_control_create_db_req req; |
dudnwjs | 12:e3d3676753cc | 112 | unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct fan_control_create_db_req); |
dudnwjs | 12:e3d3676753cc | 113 | req.features = 0x001F; |
dudnwjs | 12:e3d3676753cc | 114 | |
dudnwjs | 12:e3d3676753cc | 115 | msg = new uint8_t[msg_size]; |
dudnwjs | 12:e3d3676753cc | 116 | |
dudnwjs | 12:e3d3676753cc | 117 | BMH->BleMsgAlloc(FAN_CONTROL_CREATE_DB_REQ,TASK_FAN_CONTROL, TASK_GTL,sizeof(struct fan_control_create_db_req),&req,msg); |
dudnwjs | 12:e3d3676753cc | 118 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 12:e3d3676753cc | 119 | } |
dudnwjs | 12:e3d3676753cc | 120 | /** |
dudnwjs | 12:e3d3676753cc | 121 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 122 | * @brief Send Start Advertising command to GAPM task. |
dudnwjs | 9:fcf91f563147 | 123 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 9:fcf91f563147 | 124 | * @return void. |
dudnwjs | 9:fcf91f563147 | 125 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 126 | */ |
dudnwjs | 4:60be78a172c2 | 127 | void app_adv_start(BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 128 | { |
dudnwjs | 4:60be78a172c2 | 129 | uint8_t device_name_length; |
dudnwjs | 4:60be78a172c2 | 130 | uint8_t device_name_avail_space; |
dudnwjs | 4:60be78a172c2 | 131 | uint8_t device_name_temp_buf[64]; |
dudnwjs | 4:60be78a172c2 | 132 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 133 | unsigned short msg_size; |
dudnwjs | 4:60be78a172c2 | 134 | msg_size = 1 + sizeof(ble_hdr) + sizeof(struct gapm_start_advertise_cmd); |
dudnwjs | 4:60be78a172c2 | 135 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 136 | |
dudnwjs | 4:60be78a172c2 | 137 | // Allocate a message for GAP |
dudnwjs | 4:60be78a172c2 | 138 | struct gapm_start_advertise_cmd cmd; |
dudnwjs | 4:60be78a172c2 | 139 | cmd.op.code = GAPM_ADV_UNDIRECT; |
dudnwjs | 4:60be78a172c2 | 140 | cmd.op.addr_src = GAPM_PUBLIC_ADDR; |
dudnwjs | 4:60be78a172c2 | 141 | cmd.intv_min = APP_ADV_INT_MIN; |
dudnwjs | 4:60be78a172c2 | 142 | cmd.intv_max = APP_ADV_INT_MAX; |
dudnwjs | 4:60be78a172c2 | 143 | cmd.channel_map = APP_ADV_CHMAP; |
dudnwjs | 4:60be78a172c2 | 144 | cmd.info.host.mode = GAP_GEN_DISCOVERABLE; |
dudnwjs | 4:60be78a172c2 | 145 | cmd.info.host.adv_data_len = APP_ADV_DATA_MAX_SIZE; |
dudnwjs | 4:60be78a172c2 | 146 | cmd.info.host.scan_rsp_data_len = APP_SCAN_RESP_DATA_MAX_SIZE; |
dudnwjs | 4:60be78a172c2 | 147 | |
dudnwjs | 4:60be78a172c2 | 148 | /*----------------------------------------------------------------------------------- |
dudnwjs | 4:60be78a172c2 | 149 | * Set the Advertising Data and the Scan Response Data |
dudnwjs | 4:60be78a172c2 | 150 | *---------------------------------------------------------------------------------*/ |
dudnwjs | 4:60be78a172c2 | 151 | |
dudnwjs | 4:60be78a172c2 | 152 | |
dudnwjs | 4:60be78a172c2 | 153 | // Advertising Data |
dudnwjs | 4:60be78a172c2 | 154 | #if (NVDS_SUPPORT) |
dudnwjs | 4:60be78a172c2 | 155 | if(nvds_get(NVDS_TAG_APP_BLE_ADV_DATA, &cmd.info.host.adv_data_len, |
dudnwjs | 4:60be78a172c2 | 156 | &cmd.info.host.adv_data[0]) != NVDS_OK) |
dudnwjs | 4:60be78a172c2 | 157 | #endif //(NVDS_SUPPORT) |
dudnwjs | 4:60be78a172c2 | 158 | { |
dudnwjs | 4:60be78a172c2 | 159 | cmd.info.host.adv_data_len = APP_DFLT_ADV_DATA_LEN; |
dudnwjs | 4:60be78a172c2 | 160 | memcpy(&cmd.info.host.adv_data[0], APP_DFLT_ADV_DATA, cmd.info.host.adv_data_len); |
dudnwjs | 4:60be78a172c2 | 161 | |
dudnwjs | 4:60be78a172c2 | 162 | //Add list of UUID |
dudnwjs | 4:60be78a172c2 | 163 | #if (BLE_APP_HT) |
dudnwjs | 4:60be78a172c2 | 164 | cmd.info.host.adv_data_len += APP_HT_ADV_DATA_UUID_LEN; |
dudnwjs | 4:60be78a172c2 | 165 | memcpy(&cmd.info.host.adv_data[APP_DFLT_ADV_DATA_LEN], APP_HT_ADV_DATA_UUID, APP_HT_ADV_DATA_UUID_LEN); |
dudnwjs | 4:60be78a172c2 | 166 | #else |
dudnwjs | 4:60be78a172c2 | 167 | #if (BLE_APP_NEB) |
dudnwjs | 4:60be78a172c2 | 168 | cmd.info.host.adv_data_len += APP_NEB_ADV_DATA_UUID_LEN; |
dudnwjs | 4:60be78a172c2 | 169 | memcpy(&cmd.info.host.adv_data[APP_DFLT_ADV_DATA_LEN], APP_NEB_ADV_DATA_UUID, APP_NEB_ADV_DATA_UUID_LEN); |
dudnwjs | 4:60be78a172c2 | 170 | #endif //(BLE_APP_NEB) |
dudnwjs | 4:60be78a172c2 | 171 | #endif //(BLE_APP_HT) |
dudnwjs | 4:60be78a172c2 | 172 | } |
dudnwjs | 4:60be78a172c2 | 173 | |
dudnwjs | 4:60be78a172c2 | 174 | // Scan Response Data |
dudnwjs | 4:60be78a172c2 | 175 | #if (NVDS_SUPPORT) |
dudnwjs | 4:60be78a172c2 | 176 | if(nvds_get(NVDS_TAG_APP_BLE_SCAN_RESP_DATA, &cmd.info.host.scan_rsp_data_len, |
dudnwjs | 4:60be78a172c2 | 177 | &cmd.info.host.scan_rsp_data[0]) != NVDS_OK) |
dudnwjs | 4:60be78a172c2 | 178 | #endif //(NVDS_SUPPORT) |
dudnwjs | 4:60be78a172c2 | 179 | { |
dudnwjs | 4:60be78a172c2 | 180 | cmd.info.host.scan_rsp_data_len = APP_SCNRSP_DATA_LENGTH; |
dudnwjs | 4:60be78a172c2 | 181 | memcpy(&cmd.info.host.scan_rsp_data[0], APP_SCNRSP_DATA, cmd.info.host.scan_rsp_data_len); |
dudnwjs | 4:60be78a172c2 | 182 | } |
dudnwjs | 4:60be78a172c2 | 183 | |
dudnwjs | 4:60be78a172c2 | 184 | // Get remaining space in the Advertising Data - 2 bytes are used for name length/flag |
dudnwjs | 4:60be78a172c2 | 185 | device_name_avail_space = APP_ADV_DATA_MAX_SIZE - cmd.info.host.adv_data_len - 2; |
dudnwjs | 4:60be78a172c2 | 186 | |
dudnwjs | 4:60be78a172c2 | 187 | // Check if data can be added to the Advertising data |
dudnwjs | 4:60be78a172c2 | 188 | if (device_name_avail_space > 0) |
dudnwjs | 4:60be78a172c2 | 189 | { |
dudnwjs | 4:60be78a172c2 | 190 | // Get the Device Name to add in the Advertising Data (Default one or NVDS one) |
dudnwjs | 4:60be78a172c2 | 191 | #if (NVDS_SUPPORT) |
dudnwjs | 4:60be78a172c2 | 192 | device_name_length = NVDS_LEN_DEVICE_NAME; |
dudnwjs | 4:60be78a172c2 | 193 | if (nvds_get(NVDS_TAG_DEVICE_NAME, &device_name_length, &device_name_temp_buf[0]) != NVDS_OK) |
dudnwjs | 4:60be78a172c2 | 194 | #endif //(NVDS_SUPPORT) |
dudnwjs | 4:60be78a172c2 | 195 | { |
dudnwjs | 4:60be78a172c2 | 196 | // Get default Device Name (No name if not enough space) |
dudnwjs | 4:60be78a172c2 | 197 | device_name_length = strlen(APP_DFLT_DEVICE_NAME); |
dudnwjs | 4:60be78a172c2 | 198 | memcpy(&device_name_temp_buf[0], APP_DFLT_DEVICE_NAME, device_name_length); |
dudnwjs | 4:60be78a172c2 | 199 | } |
dudnwjs | 4:60be78a172c2 | 200 | |
dudnwjs | 4:60be78a172c2 | 201 | if(device_name_length > 0) |
dudnwjs | 4:60be78a172c2 | 202 | { |
dudnwjs | 4:60be78a172c2 | 203 | // Check available space |
dudnwjs | 4:60be78a172c2 | 204 | if( device_name_length > device_name_avail_space) |
dudnwjs | 4:60be78a172c2 | 205 | device_name_length = device_name_avail_space; |
dudnwjs | 4:60be78a172c2 | 206 | |
dudnwjs | 4:60be78a172c2 | 207 | // Fill Length |
dudnwjs | 4:60be78a172c2 | 208 | cmd.info.host.adv_data[cmd.info.host.adv_data_len] = device_name_length + 1; |
dudnwjs | 4:60be78a172c2 | 209 | // Fill Device Name Flag |
dudnwjs | 4:60be78a172c2 | 210 | cmd.info.host.adv_data[cmd.info.host.adv_data_len + 1] = '\x09'; |
dudnwjs | 4:60be78a172c2 | 211 | // Copy device name |
dudnwjs | 4:60be78a172c2 | 212 | memcpy(&cmd.info.host.adv_data[cmd.info.host.adv_data_len + 2], device_name_temp_buf, device_name_length); |
dudnwjs | 4:60be78a172c2 | 213 | |
dudnwjs | 4:60be78a172c2 | 214 | // Update Advertising Data Length |
dudnwjs | 4:60be78a172c2 | 215 | cmd.info.host.adv_data_len += (device_name_length + 2); |
dudnwjs | 4:60be78a172c2 | 216 | } |
dudnwjs | 4:60be78a172c2 | 217 | } |
dudnwjs | 4:60be78a172c2 | 218 | |
dudnwjs | 4:60be78a172c2 | 219 | // Send the message |
dudnwjs | 4:60be78a172c2 | 220 | BMH->BleMsgAlloc(GAPM_START_ADVERTISE_CMD,TASK_GAPM, TASK_GTL,sizeof (struct gapm_start_advertise_cmd),&cmd,msg); |
dudnwjs | 4:60be78a172c2 | 221 | BMH->BleSendMsg(msg, msg_size); |
dudnwjs | 4:60be78a172c2 | 222 | |
dudnwjs | 4:60be78a172c2 | 223 | return; |
dudnwjs | 4:60be78a172c2 | 224 | } |
dudnwjs | 9:fcf91f563147 | 225 | /** |
dudnwjs | 9:fcf91f563147 | 226 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 227 | * @brief Set Bondabe mode. |
dudnwjs | 9:fcf91f563147 | 228 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 9:fcf91f563147 | 229 | * @return void. |
dudnwjs | 9:fcf91f563147 | 230 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 231 | */ |
dudnwjs | 4:60be78a172c2 | 232 | void app_set_mode(BleMsgHandler* BMH) |
dudnwjs | 4:60be78a172c2 | 233 | { |
dudnwjs | 4:60be78a172c2 | 234 | uint8_t *msg; |
dudnwjs | 4:60be78a172c2 | 235 | struct gapm_set_dev_config_cmd cmd; |
dudnwjs | 4:60be78a172c2 | 236 | unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct gapm_set_dev_config_cmd); |
dudnwjs | 4:60be78a172c2 | 237 | msg = new uint8_t[msg_size]; |
dudnwjs | 4:60be78a172c2 | 238 | |
dudnwjs | 4:60be78a172c2 | 239 | cmd.operation = GAPM_SET_DEV_CONFIG; |
dudnwjs | 4:60be78a172c2 | 240 | // Device Role |
dudnwjs | 4:60be78a172c2 | 241 | cmd.role = GAP_PERIPHERAL_SLV; |
dudnwjs | 4:60be78a172c2 | 242 | // Device Appearance |
dudnwjs | 4:60be78a172c2 | 243 | cmd.appearance = 0x0000; |
dudnwjs | 4:60be78a172c2 | 244 | // Device Appearance write permission requirements for peer device |
dudnwjs | 4:60be78a172c2 | 245 | cmd.appearance_write_perm = GAPM_WRITE_DISABLE; |
dudnwjs | 4:60be78a172c2 | 246 | // Device Name write permission requirements for peer device |
dudnwjs | 4:60be78a172c2 | 247 | cmd.name_write_perm = GAPM_WRITE_DISABLE; |
dudnwjs | 4:60be78a172c2 | 248 | // Peripheral only: ***************************************************************** |
dudnwjs | 5:e11b23f9aacc | 249 | // Maximum trasnimt unit size |
dudnwjs | 5:e11b23f9aacc | 250 | //cmd.max_mtu = 16; |
dudnwjs | 4:60be78a172c2 | 251 | // Slave preferred Minimum of connection interval |
dudnwjs | 4:60be78a172c2 | 252 | cmd.con_intv_min = 8; // 10ms (8*1.25ms) |
dudnwjs | 4:60be78a172c2 | 253 | // Slave preferred Maximum of connection interval |
dudnwjs | 4:60be78a172c2 | 254 | cmd.con_intv_max = 16; // 20ms (16*1.25ms) |
dudnwjs | 4:60be78a172c2 | 255 | // Slave preferred Connection latency |
dudnwjs | 4:60be78a172c2 | 256 | cmd.con_latency = 0; |
dudnwjs | 4:60be78a172c2 | 257 | // Slave preferred Link supervision timeout |
dudnwjs | 4:60be78a172c2 | 258 | cmd.superv_to = 100; |
dudnwjs | 4:60be78a172c2 | 259 | // Privacy settings bit field |
dudnwjs | 4:60be78a172c2 | 260 | cmd.flags = 0; |
dudnwjs | 4:60be78a172c2 | 261 | |
dudnwjs | 4:60be78a172c2 | 262 | BMH->BleMsgAlloc(GAPM_SET_DEV_CONFIG_CMD, TASK_GAPM, TASK_GTL,sizeof(struct gapm_set_dev_config_cmd ),&cmd, msg); |
dudnwjs | 4:60be78a172c2 | 263 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 4:60be78a172c2 | 264 | |
dudnwjs | 4:60be78a172c2 | 265 | return; |
dudnwjs | 4:60be78a172c2 | 266 | } |
dudnwjs | 9:fcf91f563147 | 267 | /** |
dudnwjs | 9:fcf91f563147 | 268 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 269 | * @brief Send enable request to DISS profile task. |
dudnwjs | 9:fcf91f563147 | 270 | * @param[in] device Ble device info |
dudnwjs | 9:fcf91f563147 | 271 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 9:fcf91f563147 | 272 | * @return void. |
dudnwjs | 9:fcf91f563147 | 273 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 274 | */ |
dudnwjs | 9:fcf91f563147 | 275 | void app_dis_enable(ble_dev *device,BleMsgHandler* BMH) |
dudnwjs | 5:e11b23f9aacc | 276 | { |
dudnwjs | 5:e11b23f9aacc | 277 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 278 | // Allocate the message |
dudnwjs | 5:e11b23f9aacc | 279 | struct diss_enable_req req; |
dudnwjs | 5:e11b23f9aacc | 280 | unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(diss_enable_req); |
dudnwjs | 5:e11b23f9aacc | 281 | // Fill in the parameter structure |
dudnwjs | 5:e11b23f9aacc | 282 | req.conhdl = device->conhdl; |
dudnwjs | 5:e11b23f9aacc | 283 | req.sec_lvl = 1; |
dudnwjs | 5:e11b23f9aacc | 284 | req.con_type = PRF_CON_DISCOVERY; |
dudnwjs | 5:e11b23f9aacc | 285 | |
dudnwjs | 5:e11b23f9aacc | 286 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 287 | |
dudnwjs | 5:e11b23f9aacc | 288 | // Send the message |
dudnwjs | 5:e11b23f9aacc | 289 | BMH->BleMsgAlloc(DISS_ENABLE_REQ,TASK_DISS, TASK_GTL, sizeof(struct diss_enable_req),&req,msg); |
dudnwjs | 5:e11b23f9aacc | 290 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 291 | } |
dudnwjs | 9:fcf91f563147 | 292 | /** |
dudnwjs | 9:fcf91f563147 | 293 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 294 | * @brief Send enable request to FOTA profile task. |
dudnwjs | 9:fcf91f563147 | 295 | * @param[in] device Ble device info |
dudnwjs | 9:fcf91f563147 | 296 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 9:fcf91f563147 | 297 | * @return void. |
dudnwjs | 9:fcf91f563147 | 298 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 299 | */ |
dudnwjs | 9:fcf91f563147 | 300 | void app_fota_server_enable(ble_dev *device,BleMsgHandler* BMH) |
dudnwjs | 9:fcf91f563147 | 301 | { |
dudnwjs | 9:fcf91f563147 | 302 | uint8_t *msg; |
dudnwjs | 9:fcf91f563147 | 303 | struct fota_server_enable_req req; |
dudnwjs | 9:fcf91f563147 | 304 | unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct fota_server_enable_req); |
dudnwjs | 9:fcf91f563147 | 305 | req.conhdl = device->conhdl; |
dudnwjs | 9:fcf91f563147 | 306 | req.sec_lvl = 1; |
dudnwjs | 9:fcf91f563147 | 307 | |
dudnwjs | 9:fcf91f563147 | 308 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 309 | |
dudnwjs | 9:fcf91f563147 | 310 | // Send the message |
dudnwjs | 9:fcf91f563147 | 311 | BMH->BleMsgAlloc(FOTA_SERVER_ENABLE_REQ, TASK_FOTA_SERVER, TASK_GTL,sizeof(struct fota_server_enable_req),&req,msg); |
dudnwjs | 9:fcf91f563147 | 312 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 9:fcf91f563147 | 313 | } |
dudnwjs | 9:fcf91f563147 | 314 | /** |
dudnwjs | 9:fcf91f563147 | 315 | **************************************************************************************** |
dudnwjs | 12:e3d3676753cc | 316 | * @brief Send enable request to fan_control profile task. |
dudnwjs | 12:e3d3676753cc | 317 | * @param[in] device Ble device info |
dudnwjs | 12:e3d3676753cc | 318 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 12:e3d3676753cc | 319 | * @return void. |
dudnwjs | 12:e3d3676753cc | 320 | **************************************************************************************** |
dudnwjs | 12:e3d3676753cc | 321 | */ |
dudnwjs | 12:e3d3676753cc | 322 | void app_fan_control_enable(ble_dev *device,BleMsgHandler* BMH) |
dudnwjs | 12:e3d3676753cc | 323 | { |
dudnwjs | 12:e3d3676753cc | 324 | uint8_t *msg; |
dudnwjs | 12:e3d3676753cc | 325 | struct fan_control_enable_req req; |
dudnwjs | 12:e3d3676753cc | 326 | unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct fan_control_enable_req); |
dudnwjs | 12:e3d3676753cc | 327 | req.conhdl = device->conhdl; |
dudnwjs | 12:e3d3676753cc | 328 | req.sec_lvl = 1; |
dudnwjs | 12:e3d3676753cc | 329 | |
dudnwjs | 12:e3d3676753cc | 330 | msg = new uint8_t[msg_size]; |
dudnwjs | 12:e3d3676753cc | 331 | |
dudnwjs | 12:e3d3676753cc | 332 | // Send the message |
dudnwjs | 12:e3d3676753cc | 333 | BMH->BleMsgAlloc(FAN_CONTROL_ENABLE_REQ, TASK_FAN_CONTROL, TASK_GTL,sizeof(struct fan_control_enable_req),&req,msg); |
dudnwjs | 12:e3d3676753cc | 334 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 12:e3d3676753cc | 335 | } |
dudnwjs | 12:e3d3676753cc | 336 | /** |
dudnwjs | 12:e3d3676753cc | 337 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 338 | * @brief Send connection confirmation. |
dudnwjs | 9:fcf91f563147 | 339 | * param[in] auth Authentication requirements. |
dudnwjs | 9:fcf91f563147 | 340 | * @param[in] device Ble device info |
dudnwjs | 9:fcf91f563147 | 341 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 9:fcf91f563147 | 342 | * @return void. |
dudnwjs | 9:fcf91f563147 | 343 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 344 | */ |
dudnwjs | 5:e11b23f9aacc | 345 | void app_connect_confirm(uint8_t auth,ble_dev *device,BleMsgHandler* BMH) |
dudnwjs | 5:e11b23f9aacc | 346 | { |
dudnwjs | 5:e11b23f9aacc | 347 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 348 | // confirm connection |
dudnwjs | 5:e11b23f9aacc | 349 | struct gapc_connection_cfm cfm; |
dudnwjs | 5:e11b23f9aacc | 350 | unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(gapc_connection_cfm); |
dudnwjs | 5:e11b23f9aacc | 351 | cfm.auth = auth; |
dudnwjs | 5:e11b23f9aacc | 352 | cfm.authorize = GAP_AUTHZ_NOT_SET; |
dudnwjs | 5:e11b23f9aacc | 353 | |
dudnwjs | 5:e11b23f9aacc | 354 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 355 | |
dudnwjs | 5:e11b23f9aacc | 356 | // Send the message |
dudnwjs | 5:e11b23f9aacc | 357 | BMH->BleMsgAlloc(GAPC_CONNECTION_CFM, KE_BUILD_ID(TASK_GAPC,device->conidx), TASK_GTL,sizeof (struct gapc_connection_cfm),&cfm,msg); |
dudnwjs | 5:e11b23f9aacc | 358 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 359 | } |
dudnwjs | 9:fcf91f563147 | 360 | /** |
dudnwjs | 9:fcf91f563147 | 361 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 362 | * @brief Send the GAPC_DISCONNECT_IND message to a task. |
dudnwjs | 9:fcf91f563147 | 363 | * @param[in] dst Task id of the destination task. |
dudnwjs | 9:fcf91f563147 | 364 | * @param[in] conhdl The conhdl parameter of the GAPC_DISCONNECT_IND message. |
dudnwjs | 9:fcf91f563147 | 365 | * @param[in] reason The reason parameter of the GAPC_DISCONNECT_IND message. |
dudnwjs | 9:fcf91f563147 | 366 | * @param[in] BMH Ble Message Handler class reference |
dudnwjs | 9:fcf91f563147 | 367 | * @return void. |
dudnwjs | 9:fcf91f563147 | 368 | **************************************************************************************** |
dudnwjs | 9:fcf91f563147 | 369 | */ |
dudnwjs | 5:e11b23f9aacc | 370 | void app_send_disconnect(uint16_t dst, uint16_t conhdl, uint8_t reason,BleMsgHandler* BMH) |
dudnwjs | 5:e11b23f9aacc | 371 | { |
dudnwjs | 5:e11b23f9aacc | 372 | uint8_t *msg; |
dudnwjs | 5:e11b23f9aacc | 373 | struct gapc_disconnect_ind disconnect_ind; |
dudnwjs | 5:e11b23f9aacc | 374 | unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(gapc_disconnect_ind); |
dudnwjs | 5:e11b23f9aacc | 375 | // fill parameters |
dudnwjs | 5:e11b23f9aacc | 376 | disconnect_ind.conhdl = conhdl; |
dudnwjs | 5:e11b23f9aacc | 377 | disconnect_ind.reason = reason; |
dudnwjs | 5:e11b23f9aacc | 378 | |
dudnwjs | 5:e11b23f9aacc | 379 | msg = new uint8_t[msg_size]; |
dudnwjs | 5:e11b23f9aacc | 380 | |
dudnwjs | 5:e11b23f9aacc | 381 | // send indication |
dudnwjs | 5:e11b23f9aacc | 382 | BMH->BleMsgAlloc(GAPC_DISCONNECT_IND,dst, TASK_GTL,sizeof(struct gapc_disconnect_ind),&disconnect_ind,msg); |
dudnwjs | 5:e11b23f9aacc | 383 | BMH->BleSendMsg(msg,msg_size); |
dudnwjs | 5:e11b23f9aacc | 384 | } |
dudnwjs | 5:e11b23f9aacc | 385 | |
dudnwjs | 9:fcf91f563147 | 386 | }//namespace |
dudnwjs | 5:e11b23f9aacc | 387 | |
dudnwjs | 9:fcf91f563147 | 388 | /// @} dialog_fota module |