diff options
author | Scott Murray <scott.murray@konsulko.com> | 2022-06-06 20:40:19 -0400 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2022-07-04 21:21:37 +0000 |
commit | 607f2b680891c25b51917d5b7f20bc3a3ffc6a65 (patch) | |
tree | 3c0853006bac0dd1c1b6e382fcc60124decc2541 /vehicle-signals/vehiclesignals.h | |
parent | 1332cc7d0a618ee88b4d19813340665332d406ca (diff) |
Add VIS vehicle signal support
Add vehicle-signals library that exposes configuration and interface
objects to use Vehicle Information Service (VIS) signals from a VIS
server such as KUKSA.val. In this initial version Qt signals to
expose some of the low level VIS errors to clients have not been
implemented, as it is not immediately obvious how they could be
leveraged in the AGL demo usecases. If the Qt demos continue to be
used for past the Needlefish release this may warrant revisiting.
Bug-AGL: SPEC-4408
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Change-Id: I05d2bfdd09d090e3ed13ba4e4c2d1d205357d6e4
(cherry picked from commit b34fae267102d374bcc9ab7a6ff6a259515bb6bf)
Diffstat (limited to 'vehicle-signals/vehiclesignals.h')
-rw-r--r-- | vehicle-signals/vehiclesignals.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/vehicle-signals/vehiclesignals.h b/vehicle-signals/vehiclesignals.h new file mode 100644 index 0000000..fd5fe9c --- /dev/null +++ b/vehicle-signals/vehiclesignals.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2022 Konsulko Group + * + * 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 VEHICLESIGNALS_H +#define VEHICLESIGNALS_H + +#include <QObject> +#include <QWebSocket> + +// Class to read/hold VIS server configuration + +class VehicleSignalsConfig +{ +public: + explicit VehicleSignalsConfig(const QString &hostname, + const unsigned port, + const QByteArray &clientKey, + const QByteArray &clientCert, + const QByteArray &caCert, + const QString &authToken, + bool verifyPeer = true); + explicit VehicleSignalsConfig(const QString &appname); + ~VehicleSignalsConfig() {}; + + QString hostname() { return m_hostname; }; + unsigned port() { return m_port; }; + QByteArray clientKey() { return m_clientKey; }; + QByteArray clientCert() { return m_clientCert; }; + QByteArray caCert() { return m_caCert; }; + QString authToken() { return m_authToken; }; + bool verifyPeer() { return m_verifyPeer; }; + bool valid() { return m_valid; }; + unsigned verbose() { return m_verbose; }; + +private: + QString m_hostname; + unsigned m_port; + QByteArray m_clientKey; + QByteArray m_clientCert; + QByteArray m_caCert; + QString m_authToken; + bool m_verifyPeer; + bool m_valid; + unsigned m_verbose; +}; + +// VIS signaling interface class + +class VehicleSignals : public QObject +{ + Q_OBJECT + +public: + explicit VehicleSignals(const VehicleSignalsConfig &config, QObject * parent = Q_NULLPTR); + virtual ~VehicleSignals(); + + Q_INVOKABLE void connect(); + Q_INVOKABLE void authorize(); + + Q_INVOKABLE void get(const QString &path); + Q_INVOKABLE void set(const QString &path, const QString &value); + Q_INVOKABLE void subscribe(const QString &path); + +signals: + void connected(); + void authorized(); + void getSuccessResponse(QString path, QString value, QString timestamp); + void signalNotification(QString path, QString value, QString timestamp); + void disconnected(); + +private slots: + void onConnected(); + void onError(QAbstractSocket::SocketError error); + void reconnect(); + void onDisconnected(); + void onTextMessageReceived(QString message); + +private: + VehicleSignalsConfig m_config; + QWebSocket m_websocket; + std::atomic<unsigned int> m_request_id; + + bool parseData(const QJsonObject &response, QString &path, QString &value, QString ×tamp); +}; + +#endif // VEHICLESIGNALS_H |