首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android和Garmin FR230之间BLE上的直接消息传递失败(SDK1.3.x)

Android和Garmin FR230之间BLE上的直接消息传递失败(SDK1.3.x)
EN

Stack Overflow用户
提问于 2016-12-23 19:25:42
回答 2查看 844关注 0票数 3

嗨,Garmin的开发人员,

我一直试图在我的安卓应用程序和我的connectIQ应用程序之间(在GarminForerunner230上,SDK1.3.x版)开发一个在BLE上的直接消息传递通信设置。这里的目标是Android应用程序收集一些数据,然后将其推送到手表应用程序中。

按照开发人员站点上的详细信息,我已经设法让它正常工作了,但是有很多丢弃的消息没有被发送,并且手表接收的值比发送的要少。

在Android上,我在调试语句中获得了这个状态(ConnectIQ.IQMessageStatus) = FAILURE_DURING_TRANSFER。240是正在发送的数据。

D/GarminMessenger: onMessageStatus: Message: 240,device: Forerunner 230,FAILURE_DURING_TRANSFER

这是我在garmin上的应用程序代码:

SampleApp.mc

代码语言:javascript
复制
using Toybox.Application as App;
using Toybox.Communications as Comm;
using Toybox.WatchUi as Ui;
using Toybox.System as Sys;

var mailMethod;
var crashOnMessage = false;

var msg;

class SampleApp extends App.AppBase {

    function initialize() {
        AppBase.initialize();
        Sys.println("app-initialize()");

        msg = "0";

        mailMethod = method(:onMail);
        Comm.setMailboxListener(mailMethod);
        Sys.println("app-initialize(): mail box listener has been set");
    }

    // onStart() is called on application start up
    function onStart(state) {
        System.println("app-onStart()");
    }

    // Return the initial view of your application here
    function getInitialView() {
        Sys.println("app-getInitialView()");
        return [ new SampleAppView() ];
    }

    function onMail(mailIter) {
        var mail = mailIter.next();

        while(mail!=null) {
            Sys.println("app-onMail: received - "+mail);

            message = mail.toString();
            Ui.requestUpdate();
            mail = mailIter.next();
        }

        Comm.emptyMailbox();
    }

    // onStop() is called when your application is exiting
    function onStop(state) {
        System.println("app-onStop()");
    }   
}

class CommListener extends Comm.ConnectionListener {
    function initialize() {
        Comm.ConnectionListener.initialize();
        sys.println("commlistener-initialize");
    }

    function onComplete() {
        Sys.println("commlistener-onComplete: Transmit Complete");
    }

    function onError() {
        Sys.println("commlistener-onError: Transmit Failed");
    }
}

对于什么可能导致这个问题,有什么想法吗?我正在Android端执行所有必要的检查,以验证Garmin手表是否成对并连接(&该应用程序已打开)。

这种情况可能发生的原因之一是,我试图每秒钟发送1-2个数据值(每个值都带有一个ConnectIQ.sendMessage()),所以也许Garmin /BLE模块不支持这种速率的通信?

提前感谢您的解决方案和建议。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-01-27 12:24:05

我认为Connect消息传递系统只是进入了一些坏状态,然后就不会有任何消息通过。您可以尝试的是在onStart方法中设置邮箱侦听器,而不是初始化。

此外,还有一种新的方法可以使消息的读取更加容易。它仍然很大程度上没有文档化,但我得到一个词,它将在下一个SDK版本中被记录下来。然而,它已经在每一个ConnectIQ手表上工作。方法是:

Comm.registerForPhoneAppMessages(method(:onMsg));

在回调方法中所做的事情:

代码语言:javascript
复制
function onMsg(msg) {
    handleIncomingMessage(msg.data.toString());
}

或者类似的东西。输入对象msg可能属于Toybox::Communications::Message类(这还没有文档化)。

票数 1
EN

Stack Overflow用户

发布于 2017-02-10 21:53:08

因此,我在Garmin论坛这里上发布了一个类似的问题,并得到了对我的问题的部分回答。在那里发布一个摘要。

我希望实现的是生活中的一些东西:

假设来自Android的消息是1,2,3,4,5:我希望应用程序在收到消息时更新UI,就像这样:

代码语言:javascript
复制
app-onMail: received - 1
//update the UI
app-onMail: received - 2
//update the UI
app-onMail: received - 3
//update the UI
app-onMail: received - 4
//update the UI
app-onMail: received - 5
//update the UI

相反,这会发生

代码语言:javascript
复制
app-onMail: received - 1 
app-onMail: received - 2 
app-onMail: received - 3 
app-onMail: received - 4 
app-onMail: received - 5 
//update the UI 
//update the UI 
//update the UI 
//update the UI 
//update the UI

答案

框架轮询查看是否有新的未读邮件。如果存在,则调用应用程序onMail()回调,该回调将消耗队列中的每个消息,并反复设置指示UI需要更新的标志。调用返回后,框架将检查标志,以查看是否需要更新UI,如果需要,则为活动视图调用onUpdate()。

因此,只有当我每隔5秒从Android发送消息时,我才能显示每条消息。由于数据的消息轮询频率,我无法找到以更高的速率接收和显示数据的方法。

我的响应者建议保持邮件项目的队列(或仅仅是一个计数器),然后在抽签之间处理邮件项目,如下所示:

代码语言:javascript
复制
class MyApp extends App.AppBase
{
    hidden var _M_messages;
    hidden var _M_count;

    function initialize() {
        AppBase.initialize();
        _M_messages = new [10];
        _M_count = 0;
    }

    function getInitialView() {
        return [ new MyView() ];
    }

    function onStart(params) {
        Comm.setMailboxListener(self.method(:onMail));
    }

    function onStop(params) {
        Comm.setMailboxListener(null);
    }

    function onMail(mailIter) {

        var mail = mailIter.next();
        while (mail != null) {

            // only track up to 10 messages
            if (_M_count < 10) {
                _M_messages[_M_count] = mail;
                ++_M_count;
            }
            else {
                break;
            }

            mail = mailIter.next();
        }

        Comm.emptyMailbox();

        startProcessingMessages();
    }


    hidden function startProcessingMessages() {
        if (_M_timer == null) {
            _M_timer = new Timer.Timer();
            _M_timer.start(self.method(:processOneMessage), 250, true);
        }
    }

    hidden function stopProcessingMessages() {
        if (_M_timer != null) {
            _M_timer.stop();
            _M_timer = null;
        } 
    }

    function getMessageCount() {
        return _M_messages;
    }

    function processOneMessage() {
        if (_M_count != 0) {
            --_M_count;
            var mail = _M_messages[_M_count];
            _M_messages[_M_count] = null;

            // process the message here

           Ui.requestUpdate();

           if (_M_count == 0) {
               stopProcessingMessages();
           }
        }
    }
}

class MyView extends Ui.View
{
    hidden var _M_app;

    function initialize(app) {
        View.initialize();
        _M_app = app;
    }

    function onUpdate(dc) {

        var mailMessages = _M_app.getMessageCount();

        // draw the number of mail messages
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41306890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档