Fan Control Demo

Dependencies:   mbed-rtos mbed

Fork of mbed_fota by KIM HyoengJun

Revision:
4:60be78a172c2
Parent:
3:1e70387e1337
Child:
5:e11b23f9aacc
--- a/dialog_fota/app.cpp	Tue Jun 23 06:32:40 2015 +0000
+++ b/dialog_fota/app.cpp	Wed Jun 24 08:50:07 2015 +0000
@@ -1,6 +1,7 @@
 #include "app.h"
 #include "gapm_task.h"
 #include "dialog_fota_config.h"
+#include "diss_task.h"
 
 
 namespace sevencore_fota{
@@ -20,4 +21,152 @@
     return;
 }
 
+void app_diss_db_create(BleMsgHandler* BMH)
+{
+    uint8_t *msg;
+    // Add DIS in the database
+    struct diss_create_db_req req;
+    unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct diss_create_db_req);
+    req.features = APP_DIS_FEATURES;
+    
+    msg = new uint8_t[msg_size];
+    
+    BMH->BleMsgAlloc(DISS_CREATE_DB_REQ,TASK_DISS, TASK_GTL,sizeof(struct diss_create_db_req),&req,msg);
+    BMH->BleSendMsg(msg,msg_size);
+}
+
+void app_adv_start(BleMsgHandler* BMH)
+{
+    uint8_t device_name_length;
+    uint8_t device_name_avail_space;
+    uint8_t device_name_temp_buf[64];
+    uint8_t *msg;
+    unsigned short msg_size;
+    msg_size = 1 + sizeof(ble_hdr) + sizeof(struct gapm_start_advertise_cmd);
+    msg = new uint8_t[msg_size];
+    
+    // Allocate a message for GAP
+    struct gapm_start_advertise_cmd cmd;
+    cmd.op.code     = GAPM_ADV_UNDIRECT;
+    cmd.op.addr_src = GAPM_PUBLIC_ADDR;
+    cmd.intv_min    = APP_ADV_INT_MIN;
+    cmd.intv_max    = APP_ADV_INT_MAX;
+    cmd.channel_map = APP_ADV_CHMAP;
+    cmd.info.host.mode = GAP_GEN_DISCOVERABLE;
+    cmd.info.host.adv_data_len       = APP_ADV_DATA_MAX_SIZE;
+    cmd.info.host.scan_rsp_data_len  = APP_SCAN_RESP_DATA_MAX_SIZE;
+
+    /*-----------------------------------------------------------------------------------
+     * Set the Advertising Data and the Scan Response Data
+     *---------------------------------------------------------------------------------*/
+    
+
+    // Advertising Data
+    #if (NVDS_SUPPORT)
+    if(nvds_get(NVDS_TAG_APP_BLE_ADV_DATA, &cmd.info.host.adv_data_len,
+                &cmd.info.host.adv_data[0]) != NVDS_OK)
+    #endif //(NVDS_SUPPORT)
+    {
+        cmd.info.host.adv_data_len = APP_DFLT_ADV_DATA_LEN;
+        memcpy(&cmd.info.host.adv_data[0], APP_DFLT_ADV_DATA, cmd.info.host.adv_data_len);
+
+        //Add list of UUID
+        #if (BLE_APP_HT)
+        cmd.info.host.adv_data_len += APP_HT_ADV_DATA_UUID_LEN;
+        memcpy(&cmd.info.host.adv_data[APP_DFLT_ADV_DATA_LEN], APP_HT_ADV_DATA_UUID, APP_HT_ADV_DATA_UUID_LEN);
+        #else
+            #if (BLE_APP_NEB)
+            cmd.info.host.adv_data_len += APP_NEB_ADV_DATA_UUID_LEN;
+            memcpy(&cmd.info.host.adv_data[APP_DFLT_ADV_DATA_LEN], APP_NEB_ADV_DATA_UUID, APP_NEB_ADV_DATA_UUID_LEN);
+            #endif //(BLE_APP_NEB)
+        #endif //(BLE_APP_HT)
+    }
+
+    // Scan Response Data
+    #if (NVDS_SUPPORT)
+    if(nvds_get(NVDS_TAG_APP_BLE_SCAN_RESP_DATA, &cmd.info.host.scan_rsp_data_len,
+                &cmd.info.host.scan_rsp_data[0]) != NVDS_OK)
+    #endif //(NVDS_SUPPORT)
+    {
+        cmd.info.host.scan_rsp_data_len = APP_SCNRSP_DATA_LENGTH;
+        memcpy(&cmd.info.host.scan_rsp_data[0], APP_SCNRSP_DATA, cmd.info.host.scan_rsp_data_len);
+    }
+
+    // Get remaining space in the Advertising Data - 2 bytes are used for name length/flag
+    device_name_avail_space = APP_ADV_DATA_MAX_SIZE - cmd.info.host.adv_data_len - 2;
+
+    // Check if data can be added to the Advertising data
+    if (device_name_avail_space > 0)
+    {
+        // Get the Device Name to add in the Advertising Data (Default one or NVDS one)
+        #if (NVDS_SUPPORT)
+        device_name_length = NVDS_LEN_DEVICE_NAME;
+        if (nvds_get(NVDS_TAG_DEVICE_NAME, &device_name_length, &device_name_temp_buf[0]) != NVDS_OK)
+        #endif //(NVDS_SUPPORT)
+        {
+            // Get default Device Name (No name if not enough space)
+            device_name_length = strlen(APP_DFLT_DEVICE_NAME);
+            memcpy(&device_name_temp_buf[0], APP_DFLT_DEVICE_NAME, device_name_length);
+        }
+
+        if(device_name_length > 0)
+        {
+            // Check available space
+            if( device_name_length > device_name_avail_space)
+                device_name_length = device_name_avail_space;
+
+            // Fill Length
+            cmd.info.host.adv_data[cmd.info.host.adv_data_len]     = device_name_length + 1;
+            // Fill Device Name Flag
+            cmd.info.host.adv_data[cmd.info.host.adv_data_len + 1] = '\x09';
+            // Copy device name
+            memcpy(&cmd.info.host.adv_data[cmd.info.host.adv_data_len + 2], device_name_temp_buf, device_name_length);
+
+            // Update Advertising Data Length
+            cmd.info.host.adv_data_len += (device_name_length + 2);
+        }
+    }
+    
+    // Send the message
+    BMH->BleMsgAlloc(GAPM_START_ADVERTISE_CMD,TASK_GAPM, TASK_GTL,sizeof (struct gapm_start_advertise_cmd),&cmd,msg);
+    BMH->BleSendMsg(msg, msg_size);
+
+    return;
+}
+
+void app_set_mode(BleMsgHandler* BMH)
+{
+    uint8_t *msg;
+    struct gapm_set_dev_config_cmd cmd;
+    unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct gapm_set_dev_config_cmd);
+    msg = new uint8_t[msg_size];
+    
+    cmd.operation = GAPM_SET_DEV_CONFIG;
+    // Device Role
+    cmd.role = GAP_PERIPHERAL_SLV;
+    // Device Appearance
+    cmd.appearance = 0x0000;
+    // Device Appearance write permission requirements for peer device
+    cmd.appearance_write_perm = GAPM_WRITE_DISABLE;
+    // Device Name write permission requirements for peer device
+    cmd.name_write_perm = GAPM_WRITE_DISABLE;
+    // Peripheral only: *****************************************************************
+    // Slave preferred Minimum of connection interval
+    cmd.con_intv_min = 8;         // 10ms (8*1.25ms)
+    // Slave preferred Maximum of connection interval
+    cmd.con_intv_max = 16;        // 20ms (16*1.25ms)
+    // Slave preferred Connection latency
+    cmd.con_latency  = 0;
+    // Slave preferred Link supervision timeout
+    cmd.superv_to    = 100;
+    // Privacy settings bit field
+    cmd.flags = 0;
+    
+    BMH->BleMsgAlloc(GAPM_SET_DEV_CONFIG_CMD, TASK_GAPM, TASK_GTL,sizeof(struct gapm_set_dev_config_cmd ),&cmd, msg);
+    BMH->BleSendMsg(msg,msg_size);
+
+    return;
+}
+
+
 }//namespace