Пример #1
0
    def __parse_info(cls, command):
        """
        Extract the frequency and mode from the IF command.

        The format of the incoming command is the following:
        IF[f]*****+yyyyrx*00tmvspbd1*; where the fields are defined as follows:

        [f]     Operating frequency, excluding any RIT/XIT offset (11 digits; see FA command format)
        *       represents a space (BLANK, or ASCII 0x20)
        +       either "+" or "-" (sign of RIT/XIT offset)
        yyyy    RIT/XIT offset in Hz (range is -9999 to +9999 Hz when computer-controlled)
        r       1 if RIT is on, 0 if off
        x       1 if XIT is on, 0 if off
        t       1 if the K3 is in transmit mode, 0 if receive
        m       operating mode (see MD command)
        v       receive-mode VFO selection, 0 for VFO A, 1 for VFO B
        s       1 if scan is in progress, 0 otherwise
        p       1 if the transceiver is in split mode, 0 otherwise
        b       Basic RSP format: always 0; K2 Extended RSP format (K22): 1 if present IF response is due to a band change; 0 otherwise
        d       Basic RSP format: always 0; K3 Extended RSP format (K31): DATA sub-mode, if applicable (0=DATA A, 1=AFSK A, 2= FSK D, 3=PSK D)

        :param command: String containing the "IF" command
        :type command: str
        :return: The dict with the parsed data
        :rtype: dict
        """
        result = dict()
        ###   command IF00000000000+yyyyrx*00tmvspbd1*;
        ###   index   0123456789012345678901234567890
        mode = cls.__mode_from_byte_to_string(int(command[24]))
        vfo  = command[25]
        freq = command[2:13]
        DecodedTransaction.insertFreq(result, freq.lstrip('0'), vfo)
        DecodedTransaction.insertMode(result, mode, vfo)
        return result
Пример #2
0
    def __parse(cls, trans):
        """
        Parses the string data into a meaningful JSON block containing the command coming from the radio

        This function actually calls the responsible parser depending on the incoming command code

        :param data: A single transaction string coming from the radio that we have to parse to a meaningful JSON block
        :type data: str
        :return: JSON formatted block containing the parsed data
        :rtype: str
        """
        logger.debug("input data: {0}".format(trans))

        result_dic = None
        for s in cls.parsers:
            if trans.startswith(s):  # if we have parser for the current command...
                fn = cls.parsers[s]
                result_dic = getattr(fn, '__func__')(cls, trans) # call the responsible parser
                break

        logger.debug(result_dic.__str__())

        if result_dic is None:
            result_dic = dict()
            DecodedTransaction.insertNotSupported(result_dic, trans)

        result_json = DecodedTransaction.toJson(result_dic)
        logger.debug(result_json.__str__())
        logger.debug("parsed result: {0}".format(result_json))
        return result_json
Пример #3
0
    def __parse_frequency_vfo_b(cls, command):
        """
        Extracts the Frequency value from the command

        :param command: String starting of the type "FB00007000000;"
        :type command: str
        :return: The dict with the parsed data
        :rtype: dict
        """
        result = dict()
        DecodedTransaction.insertFreq(result, command[2:-1].lstrip('0'), vfo=Radio.VFO_B)
        return result
Пример #4
0
    def __parse_mode(cls, command):
        """
        Extracts the Mode value from the command

        :param command: String starting of the type "MD1;" or "MD$1;"
        :type command: str
        :return: The dict with the parsed data
        :rtype: dict
        """
        result = dict()

        if command[2] != '$':
            m = cls.__mode_from_byte_to_string(int(command[2]))
            DecodedTransaction.insertMode(result, m, vfo=Radio.VFO_A)
        else:
            m = cls.__mode_from_byte_to_string(int(command[3]))
            DecodedTransaction.insertMode(result, m, vfo=Radio.VFO_B)

        return result
Пример #5
0
    def decode(cls, data):
        """
        Extracts and decodes the first Icom command found within the supplied buffer.

        :param data: Series of bytes from which we must extract the incoming command. There is no guarantee
        that the first byte is the beginning of the transaction (i.e. there might be some trash in the beginning).
        :type data: array
        :return: Object containing the transaction and some additional control information
        :rtype: DecodedTransaction
        """

        trans = bytearray(data)

        # Find the beginning of the transaction
        trans_start_index = trans.find(cls.TRANS_START)
        if trans_start_index == -1:
            return DecodedTransaction(None, 0)

        # Find the end of the transaction (must be after trans_start_index)
        trans_end_index = trans.find(cls.TRANS_END, trans_start_index)
        if trans_end_index == -1:
            return DecodedTransaction(None, 0)

        cmd_idx = trans_start_index + 4  # get the index of the command

        result_dic = dict()

        if trans[cmd_idx] == cls.CFM_POSITIVE:      # <------------------------- positive confirm
            DecodedTransaction.insertPositiveCfm(result_dic)

        elif trans[cmd_idx] == cls.CFM_NEGATIVE:    # <------------------------- negative confirm
            DecodedTransaction.insertNegativeCfm(result_dic)

        elif trans[cmd_idx] == cls.SEND_FREQ:       # <------------------------- frequency
            freq = cls.__frequency_from_bcd_to_string(trans[(cmd_idx + 1):trans_end_index])
            DecodedTransaction.insertFreq(result_dic, freq)

        elif trans[cmd_idx] == cls.SEND_MODE:       # <------------------------- mode
            mode = cls.__mode_from_byte_to_string(trans[cmd_idx+1])
            DecodedTransaction.insertMode(result_dic, mode)

        else:                                       # <------------------------- not-supported
            DecodedTransaction.insertNotSupported(result_dic, misc_utils.getListInHex(trans[trans_start_index:trans_end_index+1]))

        # Convert to JSON string
        result_json = DecodedTransaction.toJson(result_dic)

        logger.debug("input bytes: {0}".format(misc_utils.getListInHex(bytearray(data))))
        logger.debug("returns: {0}; bytes removed: {1}".format(result_json, trans_end_index+1))

        # return the object with the decoded transaction and the amount of bytes that we have read from the supplied buffer(string)
        return DecodedTransaction(result_json, trans_end_index+1)