TA的每日心情 | 无聊 2021-6-6 21:56 |
---|
签到天数: 225 天 连续签到: 1 天 [LV.7]常住居民III
|
本帖最后由 youzizhile 于 2015-7-9 17:27 编辑
简易的蓝牙防丢器,最主要是采用了proxr的协议,主要实现的功能有:
未连接状态下:发出广播或者关闭广播。
连接状态下:
未超出预设范围安静工作,不报警不闪烁。
超出预设范围报警并且闪烁。
未超出预设范围,手机主动呼叫报警,寻找物品所在位置。
为超出预设范围,防丢器主动呼叫手机,确定手机位置。
断开状态下:如果丢失物品信号出现重新连接。
程序设计:
proxr为标准的蓝牙协议,在源代码中已经实现,只需添加proxr协议的实现代码(proxr.c,proxr.h,proxr_task.c,proxr_task.h,app_proxr.c,app_proxr.h,app_proxr_task.c,app_proxr_task.h)打开proxr的宏配置即可开启proxr协议,
程序架构图
proxr 初始化:
void proxr_init(void)
{
// Reset Environment
memset(&proxr_env, 0, sizeof(proxr_env));
// Register PROXR task into kernel
task_proxr_desc_register();
ke_state_set(TASK_PROXR, PROXR_DISABLED);
}
void proxr_alert_start(uint8_t lvl, uint8_t char_code)
{
// Allocate the alert value change indication
struct proxr_alert_ind *ind = KE_MSG_ALLOC(PROXR_ALERT_IND,
proxr_env.con_info.appid, TASK_PROXR,
proxr_alert_ind);
// Fill in the parameter structure
memcpy(&ind->conhdl, &proxr_env.con_info.conhdl, sizeof(uint16_t));
ind->alert_lvl = lvl;
ind->char_code = char_code;
// Send the message
ke_msg_send(ind);
}
void proxr_disable(void)
{
atts_size_t length;
uint8_t *alert_lvl;
// Disable LLS in database
attsdb_svc_set_permission(proxr_env.lls_shdl, PERM_RIGHT_DISABLE);
// If IAS is supported
if (proxr_env.ias_shdl != ATT_INVALID_HANDLE)
{
// Disable IAS in database
attsdb_svc_set_permission(proxr_env.ias_shdl, PERM_RIGHT_DISABLE);
}
// If TXPS is supported
if (proxr_env.txps_shdl != ATT_INVALID_HANDLE)
{
// Disable TXPS in database
attsdb_svc_set_permission(proxr_env.txps_shdl, PERM_RIGHT_DISABLE);
}
struct proxr_disable_ind *ind = KE_MSG_ALLOC(PROXR_DISABLE_IND,
proxr_env.con_info.appid, TASK_PROXR,
proxr_disable_ind);
//Get Alert Level value stored in DB
attsdb_att_get_value(proxr_env.lls_shdl + LLS_IDX_ALERT_LVL_VAL,
&length, &alert_lvl);
// Fill in the parameter structure
ind->conhdl = proxr_env.con_info.conhdl;
ind->lls_alert_lvl = *alert_lvl;
// Send the message
ke_msg_send(ind);
// Go to idle state
ke_state_set(TASK_PROXR, PROXR_IDLE);
}
proxr任务说明,省去程序内容,只列举函数名和函数参数:
处理PROXR_CREATE_DB_REQ 消息,
/**
****************************************************************************************
* @brief Handles reception of the @ref PROXR_CREATE_DB_REQ message.
* The handler adds LLS and optionally TXPS into the database.
* @param[in] msgid Id of the message received (probably unused).
* @param[in] param Pointer to the parameters of the message.
* @param[in] dest_id ID of the receiving task instance (probably unused).
* @param[in] src_id ID of the sending task instance.
* @return If the message was consumed or not.
****************************************************************************************
*/
static int proxr_create_db_req_handler(ke_msg_id_t const msgid,
struct proxr_create_db_req const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
说明:在连接之后,使能Proximity 报告角色
/**
****************************************************************************************
* @brief Enable the Proximity Reporter role, used after connection.
* @param[in] msgid Id of the message received.
* @param[in] param Pointer to the parameters of the message.
* @param[in] dest_id ID of the receiving task instance
* @param[in] src_id ID of the sending task instance.
* @return If the message was consumed or not.
****************************************************************************************
*/
static int proxr_enable_req_handler(ke_msg_id_t const msgid,
struct proxr_enable_req const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
说明:处理接收到的GATT_WRITE_CMD_IND 消息
/**
****************************************************************************************
* @brief Handles reception of the @ref GATT_WRITE_CMD_IND message.
* The handler will analyse what has been set and decide alert level
* @param[in] msgid Id of the message received (probably unused).
* @param[in] param Pointer to the parameters of the message.
* @param[in] dest_id ID of the receiving task instance (probably unused).
* @param[in] src_id ID of the sending task instance.
* @return If the message was consumed or not.
****************************************************************************************
*/
static int gatt_write_cmd_ind_handler(ke_msg_id_t const msgid,
struct gatt_write_cmd_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
说明:断开连接
/**
****************************************************************************************
* @brief Disconnection indication to proximity reporter.
* Alert according to LLS alert level.
* @param[in] msgid Id of the message received.
* @param[in] param Pointer to the parameters of the message.
* @param[in] dest_id ID of the receiving task instance
* @param[in] src_id ID of the sending task instance.
* @return If the message was consumed or not.
****************************************************************************************
*/
static int gap_discon_cmp_evt_handler(ke_msg_id_t const msgid,
struct gap_discon_cmp_evt const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
我的其他帖子:
3.【Fireblue】之三---官方测试程序安装和连接https://www.cirmall.com/bbs/thread-42376-1-2.html
2.【Fireblue】之二---git同步代码https://www.cirmall.com/bbs/forum ... =42373&fromuid=8155
1.【Fireblue】之一---首贴开箱照 https://www.cirmall.com/bbs/forum ... =42371&fromuid=8155
|
|