summaryrefslogtreecommitdiffstats
path: root/vehicle-signals/VehicleSignalsConfig.cpp
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2023-08-24 15:21:40 -0400
committerScott Murray <scott.murray@konsulko.com>2023-08-24 15:58:58 -0400
commite6e998428529bb788e2412e84757ad9a0b71fb32 (patch)
tree732447f581be177a0b181cb1de00c481b82bbda6 /vehicle-signals/VehicleSignalsConfig.cpp
parent1234b2771bc45a885df54a779dfb8a125f315f93 (diff)
Rework vehicle signals support to use KUKSA.val databroker
Rework the VehicleSignals class and its use in the Navigation and Hvac classes to switch from using the original KUKSA.val server via WebSockets to the KUKSA.val databroker's gRPC "VAL" API. Notable changes: - The VehicleSignals API has changed a bit with respect to setting signals, callers now need to pass the new value as the type that matches the signal as opposed to always passing a string, and optionally indicate if an actuator's target or value is being set. Subscribe operations now also allow subscribing for either actuator targets or values. - It is possible that the values returned by get and subscribe operations will be changed to using QVariant instead of QStrings in a future follow up, but that has not been done in these changes. - The connected signal from VehicleSignals still has roughly the same meaning, but the authorize function and authorized signals are to some degree redundant now. They have been kept for compatibility, but may be removed in a follow up set of changes. - The section header in the .ini files expected by the VehicleSignalsConfig class has been changed from "vis-client" to "kuksa-client" since the databroker is not a VIS server, and to some degree forcing an update on the part of clients is useful since their authorization tokens also need to change. - The client key and certificate support has been removed from the VehicleSignalsConfig class, as they are no longer used in either the server or databroker as of KUKSA.val 0.4.0. A new optional parameter, "tls-server-name", has been added to work with the new TLS support behavior. It can be used to override the expected host name for connecting to a non-local databroker instance. - The Navigation constructor now takes an additional parameter to indicate whether the instance acts as a router or a client. The underlying need for this stems from an application acting as a router needing to subscribe to the destination setting actuator targets. Bug-AGL: SPEC-4762 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: I253480ae2abf068dc6e41a495454960ed5c0feaf
Diffstat (limited to 'vehicle-signals/VehicleSignalsConfig.cpp')
-rw-r--r--vehicle-signals/VehicleSignalsConfig.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/vehicle-signals/VehicleSignalsConfig.cpp b/vehicle-signals/VehicleSignalsConfig.cpp
new file mode 100644
index 0000000..c72c2cd
--- /dev/null
+++ b/vehicle-signals/VehicleSignalsConfig.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2023 Konsulko Group
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <QDebug>
+#include <QSettings>
+#include <QUrl>
+#include <QFile>
+// ?
+//#include <QSslKey>
+//#include <QTimer>
+
+#include "VehicleSignalsConfig.h"
+
+#define DEFAULT_CLIENT_KEY_FILE "/etc/kuksa-val/Client.key"
+#define DEFAULT_CLIENT_CERT_FILE "/etc/kuksa-val/Client.pem"
+#define DEFAULT_CA_CERT_FILE "/etc/kuksa-val/CA.pem"
+
+VehicleSignalsConfig::VehicleSignalsConfig(const QString &hostname,
+ const unsigned port,
+ const QByteArray &caCert,
+ const QString &tlsServerName,
+ const QString &authToken) :
+ m_hostname(hostname),
+ m_port(port),
+ m_caCert(caCert),
+ m_tlsServerName(tlsServerName),
+ m_authToken(authToken),
+ m_verbose(0),
+ m_valid(true)
+{
+ // Potentially could do some certificate validation here...
+}
+
+VehicleSignalsConfig::VehicleSignalsConfig(const QString &appname)
+{
+ m_valid = false;
+
+ QSettings *pSettings = new QSettings("AGL", appname);
+ if (!pSettings)
+ return;
+
+ m_hostname = pSettings->value("kuksa-client/server", "localhost").toString();
+ if (m_hostname.isEmpty()) {
+ qCritical() << "Invalid server hostname";
+ return;
+ }
+
+ m_port = pSettings->value("kuksa-client/port", 55555).toInt();
+ if (m_port == 0) {
+ qCritical() << "Invalid server port";
+ return;
+ }
+
+ QString caCertFileName = pSettings->value("kuksa-client/ca-certificate", DEFAULT_CA_CERT_FILE).toString();
+ if (caCertFileName.isEmpty()) {
+ qCritical() << "Invalid CA certificate filename";
+ return;
+ }
+ QFile caCertFile(caCertFileName);
+ if (!caCertFile.open(QIODevice::ReadOnly)) {
+ qCritical() << "Could not open CA certificate file";
+ return;
+ }
+ QByteArray caCertData = caCertFile.readAll();
+ if (caCertData.isEmpty()) {
+ qCritical() << "Invalid CA certificate file";
+ return;
+ }
+ m_caCert = caCertData;
+
+ m_tlsServerName = pSettings->value("kuksa-client/tls-server-name", "").toString();
+
+ QString authTokenFileName = pSettings->value("kuksa-client/authorization").toString();
+ if (authTokenFileName.isEmpty()) {
+ qCritical() << "Invalid authorization token filename";
+ return;
+ }
+ QFile authTokenFile(authTokenFileName);
+ if (!authTokenFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ qCritical() << "Could not open authorization token file";
+ return;
+ }
+ QTextStream in(&authTokenFile);
+ QString authToken = in.readLine();
+ if (authToken.isEmpty()) {
+ qCritical() << "Invalid authorization token file";
+ return;
+ }
+ m_authToken = authToken;
+
+ m_verbose = 0;
+ QString verbose = pSettings->value("kuksa-client/verbose").toString();
+ if (!verbose.isEmpty()) {
+ if (verbose == "true" || verbose == "1")
+ m_verbose = 1;
+ if (verbose == "2")
+ m_verbose = 2;
+ }
+
+ m_valid = true;
+}