aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-06-27 14:18:47 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-06-27 14:18:47 +0900
commit7607dc1bb93a4df66f1416c1a1a662840fc02e5e (patch)
tree316afc2d131eb05d40f763b639a0368e88202b9a
parentc8193621f75bcf66720cd8bccedd55a00d4e0e24 (diff)
change for Vui icon display error
-rw-r--r--homescreen/homescreen.pro6
-rw-r--r--homescreen/qml/main.qml31
-rw-r--r--homescreen/src/homescreenconnect.cpp267
-rw-r--r--homescreen/src/homescreenconnect.h71
-rw-r--r--homescreen/src/homescreenvoice.cpp2
-rw-r--r--homescreen/src/main.cpp5
-rw-r--r--package/config.xml2
7 files changed, 375 insertions, 9 deletions
diff --git a/homescreen/homescreen.pro b/homescreen/homescreen.pro
index 923c961..8f1ac59 100644
--- a/homescreen/homescreen.pro
+++ b/homescreen/homescreen.pro
@@ -34,7 +34,8 @@ SOURCES += \
src/homescreenhandler.cpp \
src/toucharea.cpp \
src/shortcutappmodel.cpp \
- src/homescreenvoice.cpp
+ src/homescreenvoice.cpp \
+ src/homescreenconnect.cpp
HEADERS += \
src/statusbarmodel.h \
@@ -44,7 +45,8 @@ HEADERS += \
src/homescreenhandler.h \
src/toucharea.h \
src/shortcutappmodel.h \
- src/homescreenvoice.h
+ src/homescreenvoice.h \
+ src/homescreenconnect.h
OTHER_FILES += \
README.md
diff --git a/homescreen/qml/main.qml b/homescreen/qml/main.qml
index 6ca2b5d..bfe27af 100644
--- a/homescreen/qml/main.qml
+++ b/homescreen/qml/main.qml
@@ -142,15 +142,17 @@ Window {
container.state = 'fullscreen'
touchArea.switchArea(1)
homescreenHandler.tapShortcut(appName, true)
- container.visible = false
+ container.opacity = 0.0
voiceBtn.visible = false
} else {
image.source = './images/normal.png'
container.state = 'normal'
touchArea.switchArea(0)
homescreenHandler.tapShortcut(appName, false)
- container.visible = true
- voiceBtn.visible = true
+ container.opacity = 1.0
+ if(voiceBtn.enableVoiceBtn == true){
+ voiceBtn.visible = true
+ }
}
}
}
@@ -191,7 +193,9 @@ Window {
image.visible = true
touchArea.switchArea(0)
container.opacity = 1.0
- voiceBtn.visible = true
+ if(voiceBtn.enableVoiceBtn == true){
+ voiceBtn.visible = true
+ }
}
}
@@ -252,6 +256,15 @@ Window {
}
}
+ Connections {
+ target: homescreenConnect
+ onShowInformation: {
+ bottomText.text = info
+ bottomInformation.visible = true
+ informationTimer.restart()
+ }
+ }
+
Timer {
id:notificationTimer
interval: 3000
@@ -310,7 +323,14 @@ Window {
Connections {
target: homescreenVoice
onStatusChanged: {
- voiceBtn.visible = status
+ voiceBtn.enableVoiceBtn = status
+ if(voiceBtn.enableVoiceBtn == true){
+ if (container.state === 'normal') {
+ voiceBtn.visible = true
+ }
+ }else{
+ voiceBtn.visible = false
+ }
}
}
@@ -323,6 +343,7 @@ Window {
anchors.bottomMargin: 50
anchors.rightMargin: 0
visible: false
+ property bool enableVoiceBtn: false
Image {
id: voiceimage
anchors.left: parent.left
diff --git a/homescreen/src/homescreenconnect.cpp b/homescreen/src/homescreenconnect.cpp
new file mode 100644
index 0000000..19ccc08
--- /dev/null
+++ b/homescreen/src/homescreenconnect.cpp
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2017, 2018, 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <QFileInfo>
+#include "homescreenconnect.h"
+#include <functional>
+#include <QProcess>
+#include <dirent.h>
+#include <stdio.h>
+#include <qstring.h>
+#include <thread>
+#include "hmi-debug.h"
+#include <unistd.h>
+#include <qdebug.h>
+
+static const char API[] = "alexa-voiceagent";
+static const char CARLACLIENTAPI[] = "carlaclient";
+const string vshl_core_event = "{\"events\": []}";
+const string vshl_core_refreshevent = "{\"refresh_token\": \"ws\"}";
+
+const std::vector<std::string> HomescreenConnect::event_lists {
+ std::string("alexa-voiceagent/voice_cbl_codepair_received_event"),
+};
+
+static void _on_hangup_static(void *closure, struct afb_wsj1 *wsj)
+{
+ static_cast<HomescreenConnect*>(closure)->on_hangup(NULL,wsj);
+}
+
+static void _on_call_static(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
+{
+ /* HomescreenConnect is not called from other process */
+}
+
+static void _on_event_static(void* closure, const char* event, struct afb_wsj1_msg *msg)
+{
+ static_cast<HomescreenConnect*>(closure)->on_event(NULL,event,msg);
+}
+
+static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
+{
+ static_cast<HomescreenConnect*>(closure)->on_reply(NULL,msg);
+}
+
+static void event_loop_run(struct sd_event* loop){
+ sd_event_loop(loop);
+ sd_event_unref(loop);
+}
+
+HomescreenConnect::HomescreenConnect(QObject *parent) :
+ QObject(parent)
+{
+ timer = new QTimer(this);
+}
+
+HomescreenConnect::~HomescreenConnect()
+{
+ if(sp_websock != NULL)
+ {
+ afb_wsj1_unref(sp_websock);
+ }
+ if(mploop)
+ {
+ sd_event_exit(mploop, 0);
+ }
+}
+
+int HomescreenConnect::init(int port, const string& token)
+{
+ int ret = 0;
+
+ connect(timer,SIGNAL(timeout()),this,SLOT(subscribe()));
+ connect(this,SIGNAL(stopTimer()),this,SLOT(stopGetCode()));
+ if(port > 0 && token.size() > 0)
+ {
+ mport = port;
+ mtoken = token;
+ }
+ else
+ {
+ HMI_ERROR("HomescreenConnect","port and token should be > 0, Initial port and token uses.");
+ }
+
+ ret = initialize_websocket();
+ if(ret != 0 )
+ {
+ HMI_ERROR("HomescreenConnect","Failed to initialize websocket");
+ }
+ else{
+
+ HMI_DEBUG("HomescreenConnect","Initialized");
+ timer->setSingleShot(true);
+ timer->start(3000);
+ }
+
+ return ret;
+}
+
+int HomescreenConnect::initialize_websocket(void)
+{
+ HMI_DEBUG("HomescreenConnect"," initialize_websocket called");
+ mploop = NULL;
+ int ret = sd_event_new(&mploop);
+ if(ret < 0)
+ {
+ HMI_ERROR("HomescreenConnect","Failed to create event loop");
+ return -1;
+ }
+
+ {
+ // enforce context to avoid initialization/goto error
+ std::thread th(event_loop_run, mploop);
+ th.detach();
+ }
+
+ /* Initialize interface from websocket */
+ minterface.on_hangup = _on_hangup_static;
+ minterface.on_call = _on_call_static;
+ minterface.on_event = _on_event_static;
+ muri += "ws://localhost:" + to_string(mport) + "/api?token=" + mtoken; /*To be modified*/
+ sp_websock = afb_ws_client_connect_wsj1(mploop, muri.c_str(), &minterface, this);
+
+ if(sp_websock == NULL)
+ {
+ HMI_ERROR("HomescreenConnect","Failed to create websocket connection");
+ return -1;
+ }
+
+ return 0;
+}
+
+void HomescreenConnect::subscribe(void)
+{
+ HMI_DEBUG("HomescreenConnect"," subscribe called");
+ if(!sp_websock)
+ {
+ return;
+ }
+
+ json_object* j_obj = json_tokener_parse(vshl_core_event.c_str());
+
+ int ret = afb_wsj1_call_j(sp_websock, API, "subscribeToCBLEvents", j_obj, _on_reply_static, this);
+ if (ret < 0) {
+ HMI_ERROR("HomescreenConnect","Failed to call subscribeToCBLEvents verb");
+ }
+
+ json_object* j_obj1 = json_tokener_parse(vshl_core_refreshevent.c_str());
+ ret = afb_wsj1_call_j(sp_websock, API, "setRefreshToken", j_obj1, _on_reply_static, this);
+ if (ret < 0) {
+ HMI_ERROR("HomescreenConnect","Failed to call setRefreshToken verb");
+ }
+
+ HMI_DEBUG("HomescreenConnect"," subscribe OK");
+ return;
+}
+
+/************* Callback Function *************/
+
+void HomescreenConnect::on_hangup(void *closure, struct afb_wsj1 *wsj)
+{
+ HMI_DEBUG("HomescreenConnect"," on_hangup called");
+}
+
+void HomescreenConnect::on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg)
+{
+ HMI_DEBUG("HomescreenConnect"," on_call called");
+}
+
+/*
+* event is like "homescreen/hvac"
+* msg is like {"event":"homescreen\/hvac","data":{"type":"tap_shortcut"},"jtype":"afb-event"}
+* so you can get
+ event name : struct json_object obj = json_object_object_get(msg,"event")
+*/
+void HomescreenConnect::on_event(void *closure, const char *event, struct afb_wsj1_msg *msg)
+{
+ HMI_DEBUG("HomescreenConnect","on_event event: (%s) msg: (%s).", event, afb_wsj1_msg_object_s(msg));
+
+ if (strstr(event, API) == NULL) {
+ return;
+ }
+
+ struct json_object* ev_contents = afb_wsj1_msg_object_j(msg);
+ struct json_object *json_event_str;
+
+ if(!json_object_object_get_ex(ev_contents, "event", &json_event_str)) {
+ HMI_ERROR("HomescreenConnect", "got json_event_str error.");
+ return;
+ }
+ const char* eventinfo = json_object_get_string(json_event_str);
+ if(strcasecmp(eventinfo, HomescreenConnect::event_lists[0].c_str()) == 0){
+ struct json_object *json_data_str;
+ if(!json_object_object_get_ex(ev_contents, "data", &json_data_str)) {
+ HMI_ERROR("HomescreenConnect", "got json_data_str error.");
+ return;
+ }
+
+ struct json_object *json_payload;
+ if(!json_object_object_get_ex(json_data_str, "payload", &json_payload)) {
+ HMI_ERROR("HomescreenConnect", "got json_payload error.");
+ return;
+ }
+
+ struct json_object *json_code;
+ struct json_object *json_data = json_tokener_parse(json_object_get_string(json_payload));
+ const char* code = json_object_get_string(json_data);
+ QString str = QString::fromLocal8Bit(code);
+ const char* warnginfo = "Connectting to Alexa.";
+ int index = str.indexOf("\"code\"");
+ if( index != -1 ){
+ QString codestr1 = str.right(str.length()-index-7);
+ const QString pos = "\"";
+ int index1 = codestr1.indexOf(pos);
+ if( index1 != -1 ){
+ QString codestr2 = codestr1.right(codestr1.length()-index1-1);
+ QString codestr = codestr2.left(6);
+ emit showInformation(QString(QLatin1String(warnginfo)));
+ std::string str = codestr.toStdString();
+ if(send_code(str.c_str())){
+ HMI_ERROR("HomescreenConnect", "send_code error.");
+ }
+ emit stopTimer();
+ }
+ }
+ }
+}
+
+int HomescreenConnect::send_code(const char *str)
+{
+ HMI_DEBUG("HomescreenConnect"," SendCode,%s",str);
+ struct json_object* obj = json_object_new_object();
+ json_object_object_add(obj, "amazon_code", json_object_new_string(str));
+
+ int ret = afb_wsj1_call_j(sp_websock, CARLACLIENTAPI, "set_amazon_code", obj, _on_reply_static, this);
+ if (ret < 0) {
+ HMI_ERROR("HomescreenConnect","Failed to call set_amazon_code verb");
+ }
+
+ return ret;
+}
+
+void HomescreenConnect::stopGetCode(void)
+{
+ timer->stop();
+}
+
+/**
+ * msg is like ({"response":{"verb":"subscribe","error":0},"jtype":"afb-reply","request":{"status":"success","info":"homescreen binder subscribe event name [on_screen_message]"}})
+ * msg is like ({"response":{"verb":"tap_shortcut","error":0},"jtype":"afb-reply","request":{"status":"success","info":"afb_event_push event [tap_shortcut]"}})
+ */
+void HomescreenConnect::on_reply(void *closure, struct afb_wsj1_msg *msg)
+{
+ HMI_DEBUG("HomescreenConnect"," on_reply called,%s",afb_wsj1_msg_object_s(msg));
+}
diff --git a/homescreen/src/homescreenconnect.h b/homescreen/src/homescreenconnect.h
new file mode 100644
index 0000000..badc86a
--- /dev/null
+++ b/homescreen/src/homescreenconnect.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HOMESCREENCONNECT_H
+#define HOMESCREENCONNECT_H
+
+#include <QObject>
+#include <qlibwindowmanager.h>
+#include <string>
+#include <functional>
+#include <json-c/json.h>
+#include <systemd/sd-event.h>
+#include <QTimer>
+extern "C"
+{
+#include <afb/afb-wsj1.h>
+#include <afb/afb-ws-client.h>
+}
+
+using namespace std;
+
+class HomescreenConnect : public QObject
+{
+ Q_OBJECT
+public:
+ explicit HomescreenConnect(QObject *parent = 0);
+ ~HomescreenConnect();
+ static const std::vector<std::string> state_lists;
+ static const std::vector<std::string> event_lists;
+
+ int init(int port, const string& token);
+ void on_hangup(void *closure, struct afb_wsj1 *wsj);
+ void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
+ void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
+ void on_reply(void *closure, struct afb_wsj1_msg *msg);
+
+signals:
+ void statusChanged(bool status);
+ void showInformation(QString info);
+ void stopTimer(void);
+private slots:
+ void subscribe(void);
+ void stopGetCode(void);
+
+private:
+ int initialize_websocket(void);
+ int send_code(const char *str);
+
+ struct afb_wsj1* sp_websock;
+ struct afb_wsj1_itf minterface;
+ sd_event* mploop;
+ std::string muri;
+ int mport = 2000;
+ std::string mtoken = "hs";
+ QTimer *timer;
+};
+
+#endif // HOMESCREENCONNECT_H
diff --git a/homescreen/src/homescreenvoice.cpp b/homescreen/src/homescreenvoice.cpp
index 0c08b5f..edf0654 100644
--- a/homescreen/src/homescreenvoice.cpp
+++ b/homescreen/src/homescreenvoice.cpp
@@ -223,7 +223,6 @@ void HomescreenVoice::on_event(void *closure, const char *event, struct afb_wsj1
const char* info = json_object_get_string(json_state);
const char* eventinfo = json_object_get_string(json_event_str);
- const char* warnginfo = "Alexa disconnect!";
if(strcasecmp(eventinfo, HomescreenVoice::event_lists[0].c_str()) == 0){
if (strcasecmp(info, HomescreenVoice::state_lists[0].c_str()) == 0) {
if(connect){
@@ -242,7 +241,6 @@ void HomescreenVoice::on_event(void *closure, const char *event, struct afb_wsj1
if (strcasecmp(info, HomescreenVoice::connect_lists[0].c_str()) == 0) {
HMI_DEBUG("HomescreenVoice", "connect false!");
connect = false;
- emit showInformation(QString(QLatin1String(warnginfo)));
}
else if (strcasecmp(info, HomescreenVoice::connect_lists[1].c_str()) == 0){
connect = true;
diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp
index c7c343e..edcc8a7 100644
--- a/homescreen/src/main.cpp
+++ b/homescreen/src/main.cpp
@@ -33,6 +33,7 @@
#include "mastervolume.h"
#include "homescreenhandler.h"
#include "homescreenvoice.h"
+#include "homescreenconnect.h"
#include "toucharea.h"
#include "shortcutappmodel.h"
#include "hmi-debug.h"
@@ -102,6 +103,7 @@ int main(int argc, char *argv[])
HomescreenHandler* homescreenHandler = new HomescreenHandler();
ShortcutAppModel* shortcutAppModel = new ShortcutAppModel();
HomescreenVoice* homescreenVoice = new HomescreenVoice();
+ HomescreenConnect* homescreenConnect = new HomescreenConnect();
if(layoutHandler->init(port,token) != 0){
exit(EXIT_FAILURE);
@@ -126,6 +128,7 @@ int main(int argc, char *argv[])
TouchArea* touchArea = new TouchArea();
homescreenHandler->init(port, token.toStdString().c_str(), layoutHandler, graphic_role);
homescreenVoice->init(port, token.toStdString().c_str());
+ homescreenConnect->init(port, token.toStdString().c_str());
// mail.qml loading
QQmlApplicationEngine engine;
@@ -133,6 +136,7 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("layoutHandler", layoutHandler);
engine.rootContext()->setContextProperty("homescreenHandler", homescreenHandler);
engine.rootContext()->setContextProperty("homescreenVoice", homescreenVoice);
+ engine.rootContext()->setContextProperty("homescreenConnect", homescreenConnect);
engine.rootContext()->setContextProperty("touchArea", touchArea);
engine.rootContext()->setContextProperty("shortcutAppModel", shortcutAppModel);
engine.rootContext()->setContextProperty("launcher", launcher);
@@ -188,6 +192,7 @@ int main(int argc, char *argv[])
QObject::connect(homescreenHandler, SIGNAL(shortcutChanged(QString, QString, QString)), shortcutAppModel, SLOT(changeShortcut(QString, QString, QString)));
QObject::connect(shortcutAppModel, SIGNAL(shortcutUpdated(QString, struct json_object*)), homescreenHandler, SLOT(updateShortcut(QString, struct json_object*)));
+ QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface()));
return a.exec();
}
diff --git a/package/config.xml b/package/config.xml
index 540fbdf..f928151 100644
--- a/package/config.xml
+++ b/package/config.xml
@@ -14,6 +14,8 @@
<param name="windowmanager" value="ws" />
<param name="ahl-4a" value="ws" />
<param name="vshl-core" value="ws" />
+ <param name="alexa-voiceagent" value="ws" />
+ <param name="192.168.123.11:4000/carlaclient" value="tcp" />
</feature>
<feature name="urn:AGL:widget:required-permission">
<param name="urn:AGL:permission::public:no-htdocs" value="required" />