|
发表于 2015-4-20 14:51:49
只看该作者
7#
hi,thong
以下代码为某一项目创建server 关键代码,希望能帮到你
- static int fireble_create_db_req_handler(ke_msg_id_t const msgid,
- struct fireble_create_db_req const *param,
- ke_task_id_t const dest_id,
- ke_task_id_t const src_id)
- {
- //Service Configuration Flag
- volatile uint64_t cfg_flag = 0;//FIREBLE_MANDATORY_SUM_MASK;
- volatile uint8_t idx_nb = 0;//FIREBLE_MANDATORY_SUM_NUM;//base size of data base
- //Database Creation Status
- volatile uint8_t status;
- //Save Application ID
- fireble_env.appid = src_id;
-
- /*---------------------------------------------------*
- * fireble private Service Creation
- *---------------------------------------------------*/
- int i = 0;
- struct atts_desc *fireble_db = NULL;
- struct atts_char_desc *char_in_desc_def = NULL;
- struct atts_char_desc *char_out_desc_def = NULL;
- atts_svc_desc_t *service_desc_def = NULL;
-
- uint16_t sizeofdb = sizeof(struct atts_desc)+//for service
- FIREBLE_MANDATORY_IN_INCREASE_NUM * (FirebleRXNum) * sizeof(struct atts_desc)+
- FIREBLE_MANDATORY_OUT_INCREASE_NUM * (FirebleTXNum) * sizeof(struct atts_desc);
- fireble_db = (struct atts_desc *)ke_malloc(sizeofdb);
- /* begin create service db */
- service_desc_def = (atts_svc_desc_t *)ke_malloc(sizeof(atts_svc_desc_t));
- service_desc_def[0] = FIREBLE_SVC_PRIVATE_UUID;
- fireble_db[idx_nb].uuid = ATT_DECL_PRIMARY_SERVICE;
- fireble_db[idx_nb].perm = PERM(RD, ENABLE);
- fireble_db[idx_nb].max_length = sizeof(service_desc_def[0]);
- fireble_db[idx_nb].length = sizeof(service_desc_def[0]);
- fireble_db[idx_nb++].value = (uint8_t*)&service_desc_def[0];
- cfg_flag = 1;
- /* end create service db */
- char_in_desc_def = (struct atts_char_desc *)ke_malloc((FirebleRXNum) * sizeof(struct atts_char_desc));
- char_out_desc_def = (struct atts_char_desc *)ke_malloc((FirebleTXNum) * sizeof(struct atts_char_desc));
- for (i = 0; i < FirebleTXNum; i++)
- {
- const struct atts_char_desc value_char = ATTS_CHAR(ATT_CHAR_PROP_NTF , 0,
- FIREBLE_DATA_OUT_UUID + i);
- char_out_desc_def[i] = value_char;
-
- fireble_db[idx_nb].uuid = ATT_DECL_CHARACTERISTIC;
- fireble_db[idx_nb].perm = PERM(RD, ENABLE);
- fireble_db[idx_nb].max_length = sizeof(char_out_desc_def[i]);
- fireble_db[idx_nb].length = sizeof(char_out_desc_def[i]);
- fireble_db[idx_nb++].value = (uint8_t*)&char_out_desc_def[i];
- fireble_db[idx_nb].uuid = FIREBLE_DATA_OUT_UUID + i;
- fireble_db[idx_nb].perm = PERM(NTF, ENABLE);
- fireble_db[idx_nb].max_length = FIREBLE_SEND_DATA_MAX_LEN;
- fireble_db[idx_nb].length = 0;
- fireble_db[idx_nb++].value = NULL;
- fireble_db[idx_nb].uuid = ATT_DESC_CLIENT_CHAR_CFG;
- fireble_db[idx_nb].perm = PERM(RD, ENABLE)|PERM(WR, ENABLE);
- fireble_db[idx_nb].max_length = sizeof(uint16_t);
- fireble_db[idx_nb].length = 0;
- fireble_db[idx_nb++].value = NULL;
- cfg_flag = (cfg_flag << FIREBLE_MANDATORY_OUT_INCREASE_NUM) | FIREBLE_MANDATORY_OUT_INCREASE_MASK;
- }
- for (i = 0; i < FirebleRXNum; i++)
- {
- const struct atts_char_desc value_char = ATTS_CHAR(ATT_CHAR_PROP_WR | ATT_CHAR_PROP_WR_NO_RESP, 0,
- FIREBLE_DATA_IN_UUID + i);
- char_in_desc_def[i] = value_char;
- fireble_db[idx_nb].uuid = ATT_DECL_CHARACTERISTIC;
- fireble_db[idx_nb].perm = PERM(RD, ENABLE);
- fireble_db[idx_nb].max_length = sizeof(char_in_desc_def[i]);
- fireble_db[idx_nb].length = sizeof(char_in_desc_def[i]);
- fireble_db[idx_nb++].value = (uint8_t*)&char_in_desc_def[i];
- fireble_db[idx_nb].uuid = FIREBLE_DATA_IN_UUID + i;
- fireble_db[idx_nb].perm = PERM(WR, ENABLE);
- fireble_db[idx_nb].max_length = FIREBLE_REC_DATA_MAX_LEN;
- fireble_db[idx_nb].length = 0;
- fireble_db[idx_nb++].value = NULL;
- cfg_flag = (cfg_flag << FIREBLE_MANDATORY_IN_INCREASE_NUM) | FIREBLE_MANDATORY_IN_INCREASE_MASK;
- }
- //Add Service Into Database
- status = atts_svc_create_db(&fireble_env.shdl, (uint8_t *)&cfg_flag, idx_nb, NULL,
- dest_id, &fireble_db[0]);
- ke_free(fireble_db);
- ke_free(char_in_desc_def);
- ke_free(char_out_desc_def);
- ke_free(service_desc_def);
-
- if(fireble_env.rx.pdata == NULL)
- fireble_env.rx.pdata = (uint8_t*)ke_malloc(FirebleRXNum * FIREBLE_RX_CHAR_PER_VOLUME);
- if(fireble_env.tx.pdata == NULL)
- fireble_env.tx.pdata = (uint8_t*)ke_malloc(FirebleTXNum * FIREBLE_TX_CHAR_PER_VOLUME);
- //Disable FIREBLE
- attsdb_svc_set_permission(fireble_env.shdl, PERM(SVC, DISABLE));
- //Go to Idle State
- if (status == ATT_ERR_NO_ERROR)
- {
- //If we are here, database has been fulfilled with success, go to idle test
- ke_state_set(TASK_FIREBLE, FIREBLE_IDLE);
- }
- //Send response to application
- struct fireble_create_db_cfm * cfm = KE_MSG_ALLOC(FIREBLE_CREATE_DB_CFM, fireble_env.appid,
- TASK_FIREBLE, fireble_create_db_cfm);
- cfm->status = status;
- ke_msg_send(cfm);
- return (KE_MSG_CONSUMED);
- }
复制代码
请具体分析,应能对理解UUID和服务有帮助
|
|