summaryrefslogtreecommitdiffstats
path: root/recipes-demo/agl-vss-helper/files/agl-vss-helper.py
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2024-01-04 19:26:19 -0500
committerScott Murray <scott.murray@konsulko.com>2024-01-05 16:40:12 +0000
commitae1ebd3ab2b5c3d5ea8ed8fc55915c070e629743 (patch)
tree11ec593ea40e05235f6469161ec609f03c7a9ebd /recipes-demo/agl-vss-helper/files/agl-vss-helper.py
parenta2f890dae4d3b9d49d2921576b04384cef7641d3 (diff)
kuksa-vss-init: rework into agl-vss-helper
Rework/replace the kuksa_vss_init script with a new agl-vss-helper script that uses a configuration file for the list of VSS signals and the values they should be set to. It also will run in daemon mode if the configuration includes a list of signals to perform mocking as an actuator, and push any target values back out as the current value. This avoids needing to perform hacks around directly feeding sensor values from applications for things where we do not have an existing actuator backend (e.g. HMI units values). Bug-AGL: SPEC-5042 Change-Id: I6d1e9d5fb72f7f23a3bb45fcda0a48e1a10c3863 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Reviewed-on: https://gerrit.automotivelinux.org/gerrit/c/AGL/meta-agl-demo/+/29583 ci-image-build: Jenkins Job builder account ci-image-boot-test: Jenkins Job builder account Tested-by: Jenkins Job builder account
Diffstat (limited to 'recipes-demo/agl-vss-helper/files/agl-vss-helper.py')
-rw-r--r--recipes-demo/agl-vss-helper/files/agl-vss-helper.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/recipes-demo/agl-vss-helper/files/agl-vss-helper.py b/recipes-demo/agl-vss-helper/files/agl-vss-helper.py
new file mode 100644
index 000000000..73ac6b9df
--- /dev/null
+++ b/recipes-demo/agl-vss-helper/files/agl-vss-helper.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python3
+# Copyright (c) 2022 Aakash Solanki, tech2aks@gmail.com
+# Copyright (c) 2024 Scott Murray <scott.murray@konsulko.com>
+#
+# SPDX-License-Identifier: MIT
+
+import sys
+from pathlib import Path
+import yaml
+import asyncio
+import concurrent.futures
+from kuksa_client.grpc.aio import VSSClient
+from kuksa_client.grpc import Datapoint
+from systemd.daemon import notify
+
+# Defaults
+hostname = "localhost"
+port = 55555
+config_filename = "/etc/xdg/AGL/agl-vss-helper.yaml"
+token_filename = "/etc/xdg/AGL/agl-vss-helper/agl-vss-helper.token"
+ca_cert_filename = "/etc/kuksa-val/CA.pem"
+tls_server_name = "localhost"
+verbose = False
+
+async def main():
+ client = VSSClient(hostname,
+ port,
+ root_certificates=Path(ca_cert_filename),
+ tls_server_name=tls_server_name,
+ token=token,
+ ensure_startup_connection=True)
+ await client.connect()
+ print(f"Connected to KUKSA.val databroker at {hostname}:{port}")
+ if "initialize" in config and isinstance(config["initialize"], list):
+ for entry in config["initialize"]:
+ if "signal" in entry and "value" in entry:
+ if verbose:
+ print(f"Setting {entry['signal']} to {entry['value']}")
+ await client.set_current_values({ entry["signal"] : Datapoint(entry["value"]) })
+
+ notify("READY=1")
+
+ if "mock" in config and isinstance(config["mock"], list):
+ if len(config["mock"]) != 0:
+ print(f"Mocking actuators:")
+ for signal in config["mock"]:
+ print(f" {signal}")
+ async for updates in client.subscribe_target_values(config["mock"]):
+ for signal in updates:
+ if updates[signal] is not None:
+ if verbose:
+ print(f"Actuating {signal} to {updates[signal].value}")
+ await client.set_current_values({ signal : Datapoint(updates[signal].value) })
+
+
+#
+# Initialization
+#
+
+try:
+ config_file = open(config_filename, "r")
+ config = yaml.safe_load(config_file)
+except yaml.YAMLError as exc:
+ print(f"Could not parse configuration: ${exc}")
+except:
+ print(f"Could not read configuration")
+
+if "verbose" in config and isinstance(config["verbose"], bool):
+ verbose = config["verbose"]
+if "hostname" in config and isinstance(config["hostname"], string):
+ hostname = config["hostname"]
+if "port" in config and isinstance(config["port"], int):
+ port = config["port"]
+if "use-tls" in config and isinstance(config["use-tls"], bool):
+ use_tls = config["use-tls"]
+if "token-file" in config and isinstance(config["token-file"], string):
+ token_filename = config["token-file"]
+if "ca-certificate" in config and isinstance(config["ca-certificate"], string):
+ ca_cert_filename = config["ca-certificate"]
+
+if token_filename != "":
+ if verbose:
+ print(f"Reading authorization token {token_filename}")
+ token_file = open(token_filename, "r")
+ token = token_file.read()
+else:
+ token = ""
+
+print("Starting")
+try:
+ asyncio.run(main())
+except KeyboardInterrupt:
+ print("Exiting")
+
+notify("STOPPING=1")
+sys.exit(0)