Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

99 health query format #106

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EosLib/format/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from EosLib.format.formats import telemetry_data, position, empty_format, cutdown, ping_format, valve, e_field, \
science_data, field_mill
from EosLib.format.formats.health import driver_health_report, health_response
from EosLib.format.formats.health import driver_health_report, health_query, health_response
from EosLib.format.definitions import Type as Type
1 change: 1 addition & 0 deletions EosLib/format/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ class Type(IntEnum):
SCIENCE_DATA = 13
DRIVER_HEALTH_REPORT = 14
FIELDMILL = 15
HEALTH_QUERY = 16
HEALTH_RESPONSE = 17
ERROR = 255
67 changes: 67 additions & 0 deletions EosLib/format/formats/health/health_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from abc import abstractmethod
from dataclasses import dataclass
from enum import IntEnum, unique
from typing_extensions import Self
import struct

from EosLib.device import Device
from EosLib.format.base_format import BaseFormat
from EosLib.format.definitions import Type

@unique
class QueryType(IntEnum):
DEVICE = 0
DEVICE_HISTORY = 1
LOGS = 2
@dataclass
class HealthQuery(BaseFormat):

def __init__(self, device_id: Device, query_type: QueryType):
self.device_id = device_id
self.query_type = query_type
self.valid = self.get_validity()

@staticmethod
def get_format_string(self) -> str:
return "!" \
"B" \
"B"

@staticmethod
def _i_promise_all_abstract_methods_are_implemented() -> bool:
""" This method exists because if you use a dataclass-based format ABC gets mad because it can't figure out
that the dataclass implements __init__, __eq__, etc.
:return: True if isabstract check should be bypassed, otherwise False
"""
return True

@staticmethod
@abstractmethod
def get_format_type() -> Type:
return Type.HEALTH_QUERY
# raise NotImplementedError

@abstractmethod
def encode(self) -> bytes:
return struct.pack(self.get_format_string(),
self.device_id,
self.query_type
)
# raise NotImplementedError

@classmethod
@abstractmethod
def decode(cls, data: bytes) -> Self:
unpacked_data = struct.unpack(cls.get_format_string(), data)
return HealthQuery(unpacked_data[0], unpacked_data[1])
# raise NotImplementedError

@abstractmethod
def get_validity(self) -> bool:
return (
0 <= self.device_id <= len(Device)
and 0 <= self.query_type <= len(QueryType)
)
# raise NotImplementedError
Loading