diff options
author | Scott Murray <scott.murray@konsulko.com> | 2019-12-18 10:53:42 -0500 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2019-12-18 16:07:53 +0000 |
commit | 37b9a2dfa67e45689cab15d4edfd98808c7315ae (patch) | |
tree | eb38bf1243d9bc6183f15cf8755dbbe03774369f | |
parent | f269917773e8c019ae497c83ed2b7c914829157b (diff) |
Switch to using signal-composer speed eventsicefish_8.99.5icefish_8.99.4icefish/8.99.5icefish/8.99.48.99.58.99.4
Switch from using the vehicle and engine speeds messages from the
low-can binding directly to using the abstracted events from the
signal-composer binding instead.
Bug-AGL: SPEC-3042
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I36f4d1c7f8565daf43014f47811cd5d3fdfd1dd6
-rw-r--r-- | app/Dashboard.qml | 67 | ||||
-rw-r--r-- | app/app.pro | 3 | ||||
-rw-r--r-- | app/main.cpp | 12 | ||||
-rw-r--r-- | package/config.xml | 2 |
4 files changed, 29 insertions, 55 deletions
diff --git a/app/Dashboard.qml b/app/Dashboard.qml index d343d8a..7371667 100644 --- a/app/Dashboard.qml +++ b/app/Dashboard.qml @@ -18,7 +18,6 @@ import QtQuick 2.6 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.0 -import QtWebSockets 1.0 import Translator 1.0 ApplicationWindow { @@ -31,65 +30,25 @@ ApplicationWindow { id: translator } - property string api_str: "low-can" - property string verb_str: "subscribe" - property var msgid_enu: { "call":2, "retok":3, "reterr":4, "event":5 } - property string request_str: "" - property string status_str: "" - - property double speed_val: 0 + property double vehicleSpeed: 0 property double engineSpeed: 0 - WebSocket { - id: websocket - url: bindingAddress - - onTextMessageReceived: { - var message_json = JSON.parse (message); - /* - console.log ("Raw response: " + message) - console.log ("JSON response: " + message_json) - */ - if (message_json[0] == msgid_enu.event) { + Connections { + target: SignalComposer - var property_name = message_json[2].event.split("/")[1] - if(property_name === "messages.vehicle.average.speed") { - speed_val = message_json[2].data.value - } - else if (property_name === "messages.engine.speed") { - engineSpeed = message_json[2].data.value - tachometer.value = engineSpeed / 7000 - } - } - else - { - if (message_json[0] != msgid_enu.retok) { - console.log ("Return value is not ok !") - return + onSignalEvent: { + if (uid === "event.vehicle.speed") { + var speed_tmp = parseFloat(value) + if(units == "km/h") { + speed_tmp /= 1.609 } + vehicleSpeed = speed_tmp } - /* refresh happen */ - } - onStatusChanged: { - if (websocket.status == WebSocket.Error) { - status_str = "Error: " + websocket.errorString - } - else - if (websocket.status == WebSocket.Open) { - status_str = "Socket opened; sending message..." - if (verb_str == "subscribe") { - request_str ='[' + msgid_enu.call + ',"99998","' + api_str +'/'+ verb_str +'",{ \"event\" : \"vehicle.average.speed\" } ]'; - websocket.sendTextMessage (request_str) - request_str ='[' + msgid_enu.call + ',"99999","' + api_str +'/'+ verb_str +'",{ \"event\" : \"engine.speed\" } ]'; - websocket.sendTextMessage (request_str) - } - } else - if (websocket.status == WebSocket.Closed) { - status_str = "Socket closed" + else if (uid === "event.engine.speed") { + engineSpeed = parseFloat(value) + tachometer.value = engineSpeed / 7000 } - console.log (status_str) } - active: true } Item { @@ -104,7 +63,7 @@ ApplicationWindow { anchors.left: parent.left anchors.top: parent.top anchors.margins: 20 - text: speed_val.toFixed(0) /* MPH */ + text: vehicleSpeed.toFixed(0) /* MPH */ font.pixelSize: 256 } Label { diff --git a/app/app.pro b/app/app.pro index 197675e..551acc3 100644 --- a/app/app.pro +++ b/app/app.pro @@ -7,6 +7,9 @@ HEADERS += \ SOURCES = main.cpp \ translator.cpp +CONFIG += link_pkgconfig +PKGCONFIG += qtappfw + RESOURCES += \ dashboard.qrc \ images/images.qrc diff --git a/app/main.cpp b/app/main.cpp index 3520605..d1486c5 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 The Qt Company Ltd. + * Copyright (C) 2019 Konsulko Group * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +17,8 @@ #include <QtAGLExtras/AGLApplication> #include <QtQml/QQmlApplicationEngine> +#include <QtQml/QQmlContext> +#include <signalcomposer.h> #include "translator.h" int main(int argc, char *argv[]) @@ -24,6 +27,15 @@ int main(int argc, char *argv[]) app.setApplicationName("Dashboard"); app.setupApplicationRole("dashboard"); + QQmlApplicationEngine *engine = app.getQmlApplicationEngine(); + QQmlContext *context = engine->rootContext(); + QVariant v = context->contextProperty(QStringLiteral("bindingAddress")); + if(v.canConvert(QMetaType::QUrl)) { + QUrl bindingAddress = v.toUrl(); + context->setContextProperty("SignalComposer", new SignalComposer(bindingAddress, context)); + } else { + qCritical("Cannot find bindingAddress property in context, SignalComposer unavailable"); + } qmlRegisterType<Translator>("Translator", 1, 0, "Translator"); app.load(QUrl(QStringLiteral("qrc:/Dashboard.qml"))); return app.exec(); diff --git a/package/config.xml b/package/config.xml index 9b45b3c..193c62e 100644 --- a/package/config.xml +++ b/package/config.xml @@ -9,7 +9,7 @@ <feature name="urn:AGL:widget:required-api"> <param name="windowmanager" value="ws"/> <param name="homescreen" value="ws"/> - <param name="low-can" value="ws"/> + <param name="signal-composer" value="ws"/> </feature> <feature name="urn:AGL:widget:required-permission"> <param name="urn:AGL:permission::public:no-htdocs" value="required"/> |