Skip to content

Commit

Permalink
Implement robot telemetry exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Apr 10, 2024
1 parent a9760a2 commit de41708
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/robot_interface/telemetry/mqtt_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import time
from abc import ABCMeta, abstractmethod
from queue import Queue
from typing import Callable, Tuple
from typing import Callable, Tuple, Type
from datetime import datetime
import json

from robot_interface.models.exceptions.robot_exceptions import (
RobotTelemetryException,
)
from robot_interface.telemetry.payloads import CloudHealthPayload
from robot_interface.utilities.json_service import EnhancedJSONEncoder


class MqttClientInterface(metaclass=ABCMeta):
Expand Down Expand Up @@ -61,17 +65,23 @@ def __init__(
self.retain: bool = retain

def run(self, isar_id: str, robot_name: str) -> None:
self.cloud_healt_topic: str = f"isar/{isar_id}/cloud_health"
topic: str
payload: str

while True:
try:
payload: str = self.telemetry_method(
isar_id=isar_id, robot_name=robot_name
)
payload = self.telemetry_method(isar_id=isar_id, robot_name=robot_name)
topic = self.topic
except RobotTelemetryException:
continue
payload = json.dumps(
CloudHealthPayload(isar_id, robot_name, datetime.utcnow()),
cls=EnhancedJSONEncoder,
)
topic = self.cloud_healt_topic

self.publish(topic=topic, payload=payload, qos=self.qos, retain=self.retain)

self.publish(
topic=self.topic, payload=payload, qos=self.qos, retain=self.retain
)
time.sleep(self.interval)

def publish(
Expand Down
7 changes: 7 additions & 0 deletions src/robot_interface/telemetry/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ class TelemetryPayload:
timestamp: datetime


@dataclass
class CloudHealthPayload:
isar_id: str
robot_name: str
timestamp: datetime


@dataclass
class TelemetryPosePayload(TelemetryPayload):
pose: Pose
Expand Down

0 comments on commit de41708

Please sign in to comment.