aboutsummaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
Diffstat (limited to 'extras')
-rw-r--r--extras/FeedCAN.py10
-rw-r--r--extras/FeedKuksa.py6
-rw-r--r--extras/Kuksa_Instance.py41
-rw-r--r--extras/config.py12
4 files changed, 43 insertions, 26 deletions
diff --git a/extras/FeedCAN.py b/extras/FeedCAN.py
index 92649f4..9cd01d5 100644
--- a/extras/FeedCAN.py
+++ b/extras/FeedCAN.py
@@ -15,6 +15,7 @@
"""
import can
+import logging
def send_can_signal(frame):
"""
@@ -25,8 +26,13 @@ def send_can_signal(frame):
None
"""
msg = separate_can_frame(frame)
- bus = can.interface.Bus(channel='can0', bustype='socketcan')
- #msg = can.Message(arbitration_id=can_id, data=data, is_extended_id=False)
+
+ try:
+ bus = can.interface.Bus(channel='can0', bustype='socketcan')
+ except Exception as e:
+ logging.error(f"Failed to initialize bus with channel 'can0': {e}")
+ return
+
try:
bus.send(msg)
print("CAN signal sent successfully:")
diff --git a/extras/FeedKuksa.py b/extras/FeedKuksa.py
index 903b442..56e902e 100644
--- a/extras/FeedKuksa.py
+++ b/extras/FeedKuksa.py
@@ -57,6 +57,7 @@ class FeedKuksa(QThread):
Stops the thread.
"""
self.stop_flag = True
+
logging.info("Stopping thread")
def set_instance(self):
@@ -64,7 +65,7 @@ class FeedKuksa(QThread):
Sets the instance of the Kuksa client.
"""
self.kuksa = kuksa_instance.KuksaClientSingleton.instance()
- self.client = self.kuksa.client
+ self.client = self.kuksa.get_client()
def send_values(self, path=None, value=None, attribute=None):
"""
@@ -94,6 +95,9 @@ class FeedKuksa(QThread):
except Exception as e:
logging.error(f"Error sending values to kuksa {e}")
self.set_instance()
+ else:
+ logging.error("Kuksa client is not connected, try reconnecting")
+ self.set_instance()
else:
logging.error("Kuksa client is None, try reconnecting")
time.sleep(2)
diff --git a/extras/Kuksa_Instance.py b/extras/Kuksa_Instance.py
index 49662bd..500e039 100644
--- a/extras/Kuksa_Instance.py
+++ b/extras/Kuksa_Instance.py
@@ -30,7 +30,7 @@ class KuksaClientSingleton:
Attributes:
_instance (Optional[KuksaClientSingleton]): The instance of the class.
_lock (threading.Lock): A lock to ensure thread-safety.
- config (dict): The configuration for KuksaClientThread.
+ kuksa_config (dict): The configuration for KuksaClientThread.
token (str): The path to the token file.
client (KuksaClientThread): The instance of KuksaClientThread.
@@ -73,12 +73,19 @@ class KuksaClientSingleton:
if KuksaClientSingleton._instance is not None:
raise Exception("This class is a singleton!")
- self.config = config.KUKSA_CONFIG
- self.token = config.TOKEN_PATH
+ self.kuksa_config = config.KUKSA_CONFIG
+ self.ws_token = config.WS_TOKEN
+ self.grpc_token = config.GRPC_TOKEN
+
+ if self.kuksa_config["protocol"] == 'ws':
+ self.token = self.ws_token
+ if self.kuksa_config["protocol"] == 'grpc':
+ self.token = self.grpc_token
try:
- self.client = kuksa.KuksaClientThread(self.config)
+ self.client = kuksa.KuksaClientThread(self.kuksa_config)
self.client.authorize(self.token)
+ self.client.start()
time.sleep(2)
if not self.client.checkConnection():
self.client = None
@@ -87,7 +94,7 @@ class KuksaClientSingleton:
KuksaClientSingleton._instance = self
- def reconnect(self, config, token):
+ def reconnect(self, config):
"""
Reconnects the client with the given configuration and token.
@@ -100,8 +107,17 @@ class KuksaClientSingleton:
"""
if self.client:
self.client.stop()
- self.client = kuksa.KuksaClientThread(config)
- self.client.authorize(token)
+
+ if self.kuksa_config["protocol"] == 'ws':
+ self.token = self.ws_token
+ self.kuksa_config["port"] = "8090"
+ if self.kuksa_config["protocol"] == 'grpc':
+ self.token = self.grpc_token
+ self.kuksa_config["port"] = "55555"
+
+ self.client = kuksa.KuksaClientThread(self.kuksa_config)
+ self.client.authorize(self.token)
+ self.client.start()
return self.client
def get_client(self):
@@ -123,16 +139,7 @@ class KuksaClientSingleton:
Returns:
dict: The configuration for KuksaClientThread.
"""
- return self.config
-
- def get_token(self):
- """
- Returns the path to the token file.
-
- Returns:
- str: The path to the token file.
- """
- return self.token
+ return self.kuksa_config
def status(self):
"""
diff --git a/extras/config.py b/extras/config.py
index cc61c57..2ea749c 100644
--- a/extras/config.py
+++ b/extras/config.py
@@ -19,16 +19,16 @@ import platform
python_version = f"python{'.'.join(platform.python_version_tuple()[:2])}"
-CA = os.path.abspath(os.path.join(os.path.dirname(__file__), "../assets/CA.pem"))
+CA = os.path.abspath(os.path.join(os.path.dirname(__file__), "../assets/cert/CA.pem"))
KUKSA_CONFIG = {
- "ip": 'localhost',
- "port": "8090",
- 'protocol': 'ws',
+ "ip": '10.42.0.95',
+ "port": "55555",
+ 'protocol': 'grpc',
'insecure': False,
'cacertificate': CA,
'tls_server_name': "Server",
}
-TOKEN_PATH = os.path.join(os.path.expanduser("~"),
- f".local/lib/{python_version}/site-packages/kuksa_certificates/jwt/super-admin.json.token")
+WS_TOKEN = os.path.join(os.path.expanduser("~"), f".local/lib/{python_version}/site-packages/kuksa_certificates/jwt/super-admin.json.token")
+GRPC_TOKEN = os.path.abspath(os.path.join(os.path.dirname(__file__), "../assets/token/grpc/actuate-provide-all.token")) \ No newline at end of file