from SecondLayerHLAs import SecondLayerAnalyzer
from saleae.analyzers import AnalyzerFrame


# SDR High level analyzer must subclass the Second Layer HLA class
class DefaultHla(SecondLayerAnalyzer.SecondLayerHLA):

    def __init__(self):
        pass

    def updateCCC(self, ccc_dict: dict) -> None:
        pass

    def update_result_types(self, result_types: dict) -> None:
        pass

    def instruction_decoder(self, frame:AnalyzerFrame) -> AnalyzerFrame:
        return frame

    #Returns the correct analyzer frame for each abort case possible
    def handle_abort_message(self, temp_frame: AnalyzerFrame,end_time) -> AnalyzerFrame:
        #Change to the abort version of the original message
        if temp_frame.type  == "Message":
            aux_frame = AnalyzerFrame('Message Aborted', temp_frame.start_time, end_time, {
                "Data": temp_frame.data["Data"],
                "Length": temp_frame.data["Length"],
                "Address": temp_frame.data["Address"]
            })
        elif temp_frame.type  == "I3C Direct CCC Transaction":
            aux_frame = AnalyzerFrame('Aborted I3C Direct CCC Transaction', temp_frame.start_time, end_time, {
                "Info": temp_frame.data["Info"],
                "Address": temp_frame.data["Address"],
                "Length": temp_frame.data["Length"],
                "Data": temp_frame.data["Data"]
            })
        elif temp_frame.type  == "I3C IBI Transaction":
            aux_frame = AnalyzerFrame('Aborted I3C IBI Transaction', temp_frame.start_time, end_time, {
                "Address": temp_frame.data["Address"],
                "Length": temp_frame.data["Length"],
                "Data": temp_frame.data["Data"]
            })
        elif temp_frame.type  == "I3C Transaction":
            aux_frame = AnalyzerFrame('Aborted I3C Transaction', temp_frame.start_time, end_time, {
                "Address": temp_frame.data["Address"],
                "Length": temp_frame.data["Length"],
                "Data": temp_frame.data["Data"]
            })

        return aux_frame

