查看: 6313|回复: 2

【Fireblue】之四--proxr协议之简易的蓝牙防丢器

[复制链接]
  • TA的每日心情
    无聊
    2021-6-6 21:56
  • 签到天数: 225 天

    连续签到: 1 天

    [LV.7]常住居民III

    发表于 2015-7-9 17:14:17 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 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.png
    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





    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    2016-8-15 09:28
  • 签到天数: 222 天

    连续签到: 1 天

    [LV.7]常住居民III

    发表于 2015-7-10 08:41:29 | 显示全部楼层
    多谢楼主分享!
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2020-2-14 12:16
  • 签到天数: 827 天

    连续签到: 1 天

    [LV.10]以坛为家III

    发表于 2015-10-1 10:23:11 | 显示全部楼层
    可以双向防丢吗?即智能手机如果丢失,则利用防丢器的及时报警功能可以迅速查找到,如果防丢器设备丢失,利用智能手机也可以实现查找
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-3-29 14:51 , Processed in 0.125111 second(s), 20 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.