diff --git a/viscaoveriplib/controleur.py b/viscaoveriplib/controleur.py index 8df431f242b53e4b2a6148a5a8a16c5ac71a0f6e..31b66f1f5ddb3e8777a47771ae18fbcfbf82eb9a 100644 --- a/viscaoveriplib/controleur.py +++ b/viscaoveriplib/controleur.py @@ -3,25 +3,42 @@ from viscaoveriplib.listener import Listener import viscaoveriplib.inquiry_responds_library as inq_resp import viscaoveriplib.responds_messages as default_resp + class Controller: def __init__(self, c: Camera, l: Listener): self.camera = c self.listener = l - def decompose_reception(self): - reception = self.listener.message + @staticmethod + def decompose_reception(reception: str): + """ + decomposes the hex received messaged + + :param reception: str hex eg '01110003000085029051ff' + :return: list of str hex [payload_type, payload_length, sequence_number, payload] eg ['0111', '0003', '00008502', '9051ff'] + """ payload_type = reception[0:4] payload_length = reception[4:8] sequence_number = reception[8:16] payload = reception[16:] return [payload_type, payload_length, sequence_number, payload] - def payload2meaning(self, payload: str, comandetype="default"): - #TODO - if comandetype in inq_resp.inq_list: - return inq_resp.inq_list.get(comandetype).get(payload) - + @staticmethod + def payload2meaning(payload: str, command_type="default"): + """ + Reveal the meaning of the visca respond + :param payload: payload recieved in str hex eg '9051ff' + :param command_type: type of command, the respond's meaning depends on the inquiry/command + :return: the meaning in str + """ + meaning = "Not known" + if command_type in inq_resp.inq_list: + # if payload is not in the dictionary meaning = None + meaning = inq_resp.inq_list.get(command_type).get(payload) else: - return default_resp.liste_respond.get(payload) + meaning = default_resp.liste_respond.get(payload) + if meaning is None: + meaning = "Respond not understood" + return meaning diff --git a/viscaoveriplib/inquiry_responds_library.py b/viscaoveriplib/inquiry_responds_library.py index 53899cccb7e49bbac6cdbbc0a1a8fb8b5f0020a5..2f61d736ce6e8e06d5c6c57b16412d9afd72433b 100644 --- a/viscaoveriplib/inquiry_responds_library.py +++ b/viscaoveriplib/inquiry_responds_library.py @@ -1,4 +1,6 @@ -# liste de dico non exaustif +""" +Dictionary of responds depending on the inquiry command +""" respond = {'y05002FF': "On", 'y05003FF': "Off", "y05000FF": "auto/standard"} diff --git a/viscaoveriplib/responds_messages.py b/viscaoveriplib/responds_messages.py index a0a6626a584b7a5dd508e84b4d73170c8df68357..f7341983b1e4a566f7d4ac21bcf9582c22278d21 100644 --- a/viscaoveriplib/responds_messages.py +++ b/viscaoveriplib/responds_messages.py @@ -1,3 +1,3 @@ -liste_respond = {'904yff': "Ackknowledge", '905yff': "Completion", "006002ff": "Syntax Error", - "906003ff": "Command Buffer Full", "906y04ff": "Command Conceled", "906y05ff": "No Socket", +liste_respond = {'904yff': "Acknowledge", '905yff': "Completion", "006002ff": "Syntax Error", + "906003ff": "Command Buffer Full", "906y04ff": "Command Canceled", "906y05ff": "No Socket", "906y41ff": "Command Not Executable"}