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