Пример #1
0
    def read_matrix_inp_resp_initial(self, chain_serial, msg):
        """Read initial matrix switch states.

        Args:
            chain_serial: Serial of the chain which received the message.
            msg: Message to parse.
        """
        # Verify the CRC8 is correct
        if len(msg) < 11:
            raise AssertionError(
                "Received too short initial input response: " +
                "".join(" 0x%02x" % b for b in msg))
        crc8 = OppRs232Intf.calc_crc8_part_msg(msg, 0, 10)
        if msg[10] != ord(crc8):
            self.bad_crc += 1
            self.log.warning("Msg contains bad CRC:%s.",
                             "".join(" 0x%02x" % b for b in msg))
        else:
            if chain_serial + '-' + str(
                    msg[0]) not in self.matrix_inp_addr_dict:
                self.log.warning(
                    "Got input response for invalid matrix card at initial request: %s. Msg: %s.",
                    msg[0], "".join(" 0x%02x" % b for b in msg))
                return
            opp_inp = self.matrix_inp_addr_dict[chain_serial + '-' +
                                                str(msg[0])]
            opp_inp.old_state = ((msg[2] << 56) | (msg[3] << 48) |
                                 (msg[4] << 40) | (msg[5] << 32) |
                                 (msg[6] << 24) | (msg[7] << 16) |
                                 (msg[8] << 8) | msg[9])
Пример #2
0
    def read_gen2_inp_resp_initial(self, chain_serial, msg):
        """Read initial switch states.

        Args:
            chain_serial: Serial of the chain which received the message.
            msg: Message to parse.
        """
        # Verify the CRC8 is correct
        if len(msg) < 7:
            raise AssertionError("Received too short initial input response: " + "".join(" 0x%02x" % b for b in msg))
        crc8 = OppRs232Intf.calc_crc8_part_msg(msg, 0, 6)
        if msg[6] != ord(crc8):
            self.badCRC += 1
            self.log.warning("Msg contains bad CRC:%s.", "".join(" 0x%02x" % b for b in msg))
        else:
            if chain_serial + '-' + str(msg[0]) not in self.inpAddrDict:
                self.log.warning("Got input response for invalid card at initial request: %s. Msg: %s.", msg[0],
                                 "".join(" 0x%02x" % b for b in msg))
                return

            opp_inp = self.inpAddrDict[chain_serial + '-' + str(msg[0])]
            new_state = (msg[2] << 24) | \
                (msg[3] << 16) | \
                (msg[4] << 8) | \
                msg[5]

            opp_inp.oldState = new_state
Пример #3
0
    def vers_resp(self, chain_serial, msg):
        """Process version response.

        Args:
            chain_serial: Serial of the chain which received the message.
            msg: Message to parse.
        """
        # Multiple get version responses can be received at once
        self.log.debug("Received Version Response:%s",
                       "".join(" 0x%02x" % b for b in msg))
        curr_index = 0
        while True:
            # check that message is long enough, must include crc8
            if len(msg) < curr_index + 7:
                self.log.warning("Msg is too short: %s.",
                                 "".join(" 0x%02x" % b for b in msg))
                self.opp_connection[chain_serial].lost_synch()
                break
            # Verify the CRC8 is correct
            crc8 = OppRs232Intf.calc_crc8_part_msg(msg, curr_index, 6)
            if msg[curr_index + 6] != ord(crc8):
                self.badCRC += 1
                self.log.warning("Msg contains bad CRC:%s.",
                                 "".join(" 0x%02x" % b for b in msg))
                break
            version = (msg[curr_index + 2] << 24) | \
                (msg[curr_index + 3] << 16) | \
                (msg[curr_index + 4] << 8) | \
                msg[curr_index + 5]
            self.log.debug("Firmware version: %d.%d.%d.%d",
                           msg[curr_index + 2], msg[curr_index + 3],
                           msg[curr_index + 4], msg[curr_index + 5])
            if msg[curr_index] not in self.gen2AddrArr[chain_serial]:
                self.log.warning(
                    "Got firmware response for %s but not in inventory at %s",
                    msg[curr_index], chain_serial)
            else:
                self.gen2AddrArr[chain_serial][msg[curr_index]] = version

            if version < self.minVersion:
                self.minVersion = version
            if version == BAD_FW_VERSION:
                raise AssertionError(
                    "Original firmware sent only to Brian before adding "
                    "real version numbers. The firmware must be updated before "
                    "MPF will work.")
            if (len(msg) > curr_index + 7) and (msg[curr_index + 7] == ord(
                    OppRs232Intf.EOM_CMD)):
                break
            elif (len(msg) > curr_index + 8) and (msg[curr_index + 8] == ord(
                    OppRs232Intf.GET_VERS_CMD)):
                curr_index += 7
            else:
                self.log.warning("Malformed GET_VERS_CMD response:%s.",
                                 "".join(" 0x%02x" % b for b in msg))
                self.opp_connection[chain_serial].lost_synch()
                break
Пример #4
0
    def read_matrix_inp_resp(self, chain_serial, msg):
        """Read matrix switch changes.

        Args:
            chain_serial: Serial of the chain which received the message.
            msg: Message to parse.
        """
        # Single read gen2 input response.  Receive function breaks them down

        # Verify the CRC8 is correct
        if len(msg) < 11:
            self.log.warning("Msg too short: %s.",
                             "".join(" 0x%02x" % b for b in msg))
            self.opp_connection[chain_serial].lost_synch()
            return

        crc8 = OppRs232Intf.calc_crc8_part_msg(msg, 0, 10)
        if msg[10] != ord(crc8):
            self.badCRC += 1
            self.log.warning("Msg contains bad CRC:%s.",
                             "".join(" 0x%02x" % b for b in msg))
        else:
            if chain_serial + '-' + str(msg[0]) not in self.matrixInpAddrDict:
                self.log.warning(
                    "Got input response for invalid matrix card: %s. Msg: %s.",
                    msg[0], "".join(" 0x%02x" % b for b in msg))
                return
            opp_inp = self.matrixInpAddrDict[chain_serial + '-' + str(msg[0])]
            new_state = [
                (msg[2] << 24) | (msg[3] << 16) | (msg[4] << 8) | msg[5],
                (msg[6] << 24) | (msg[7] << 16) | (msg[8] << 8) | msg[9]
            ]

            # Using a bank so 32 bit python works properly
            for bank in range(0, 2):
                changes = opp_inp.oldState[bank] ^ new_state[bank]
                if changes != 0:
                    curr_bit = 1
                    for index in range(0, 32):
                        if (curr_bit & changes) != 0:
                            if (curr_bit & new_state[bank]) == 0:
                                self.machine.switch_controller.process_switch_by_num(
                                    state=1,
                                    num=opp_inp.chain_serial + '-' +
                                    opp_inp.cardNum + '-' + str(index),
                                    platform=self)
                            else:
                                self.machine.switch_controller.process_switch_by_num(
                                    state=0,
                                    num=opp_inp.chain_serial + '-' +
                                    opp_inp.cardNum + '-' + str(index),
                                    platform=self)
                        curr_bit <<= 1
                opp_inp.oldState[bank] = new_state[bank]

        # we can continue to poll
        self._poll_response_received[chain_serial].set()
Пример #5
0
    def read_gen2_inp_resp(self, chain_serial, msg):
        """Read switch changes.

        Args:
            chain_serial: Serial of the chain which received the message.
            msg: Message to parse.
        """
        # Single read gen2 input response.  Receive function breaks them down

        # Verify the CRC8 is correct
        if len(msg) < 7:
            self.log.warning("Msg too short: %s.",
                             "".join(" 0x%02x" % b for b in msg))
            self.opp_connection[chain_serial].lost_synch()
            return

        crc8 = OppRs232Intf.calc_crc8_part_msg(msg, 0, 6)
        if msg[6] != ord(crc8):
            self.badCRC += 1
            self.log.warning("Msg contains bad CRC:%s.",
                             "".join(" 0x%02x" % b for b in msg))
        else:
            if chain_serial + '-' + str(msg[0]) not in self.inpAddrDict:
                self.log.warning(
                    "Got input response for invalid card: %s. Msg: %s.",
                    msg[0], "".join(" 0x%02x" % b for b in msg))
                return

            opp_inp = self.inpAddrDict[chain_serial + '-' + str(msg[0])]
            new_state = (msg[2] << 24) | \
                (msg[3] << 16) | \
                (msg[4] << 8) | \
                msg[5]

            # Update the state which holds inputs that are active
            changes = opp_inp.oldState ^ new_state
            if changes != 0:
                curr_bit = 1
                for index in range(0, 32):
                    if (curr_bit & changes) != 0:
                        if (curr_bit & new_state) == 0:
                            self.machine.switch_controller.process_switch_by_num(
                                state=1,
                                num=opp_inp.chain_serial + '-' +
                                opp_inp.cardNum + '-' + str(index),
                                platform=self)
                        else:
                            self.machine.switch_controller.process_switch_by_num(
                                state=0,
                                num=opp_inp.chain_serial + '-' +
                                opp_inp.cardNum + '-' + str(index),
                                platform=self)
                    curr_bit <<= 1
            opp_inp.oldState = new_state

        # we can continue to poll
        self._poll_response_received[chain_serial].set()
Пример #6
0
    def get_gen2_cfg_resp(self, chain_serial, msg):
        """Process cfg response.

        Args:
            chain_serial: Serial of the chain which received the message.
            msg: Message to parse.
        """
        # Multiple get gen2 cfg responses can be received at once
        self.log.debug("Received Gen2 Cfg Response:%s",
                       "".join(" 0x%02x" % b for b in msg))
        curr_index = 0
        read_input_msg = bytearray()
        while True:
            # check that message is long enough, must include crc8
            if len(msg) < curr_index + 7:
                self.log.warning("Msg is too short: %s.",
                                 "".join(" 0x%02x" % b for b in msg))
                self.opp_connection[chain_serial].lost_synch()
                break
            # Verify the CRC8 is correct
            crc8 = OppRs232Intf.calc_crc8_part_msg(msg, curr_index, 6)
            if msg[curr_index + 6] != ord(crc8):
                self.badCRC += 1
                self.log.warning("Msg contains bad CRC:%s.",
                                 "".join(" 0x%02x" % b for b in msg))
                break
            self._parse_gen2_board(chain_serial,
                                   msg[curr_index:curr_index + 6],
                                   read_input_msg)

            if (len(msg) > curr_index + 7) and (msg[curr_index + 7] == ord(
                    OppRs232Intf.EOM_CMD)):
                break
            elif (len(msg) > curr_index + 8) and (msg[curr_index + 8] == ord(
                    OppRs232Intf.GET_GEN2_CFG)):
                curr_index += 7
            else:
                self.log.warning("Malformed GET_GEN2_CFG response:%s.",
                                 "".join(" 0x%02x" % b for b in msg))
                self.opp_connection[chain_serial].lost_synch()
                break

        read_input_msg.extend(OppRs232Intf.EOM_CMD)
        self.read_input_msg[chain_serial] = bytes(read_input_msg)
        self._poll_response_received[chain_serial] = asyncio.Event(
            loop=self.machine.clock.loop)
        self._poll_response_received[chain_serial].set()
Пример #7
0
    def vers_resp(self, chain_serial, msg):
        """Process version response.

        Args:
            chain_serial: Serial of the chain which received the message.
            msg: Message to parse.
        """
        # Multiple get version responses can be received at once
        self.log.debug("Received Version Response:%s",
                       "".join(" 0x%02x" % b for b in msg))
        end = False
        curr_index = 0
        while not end:
            # Verify the CRC8 is correct
            crc8 = OppRs232Intf.calc_crc8_part_msg(msg, curr_index, 6)
            if msg[curr_index + 6] != ord(crc8):
                self.badCRC += 1
                hex_string = "".join(" 0x%02x" % b for b in msg)
                self.log.warning("Msg contains bad CRC:%s.", hex_string)
                end = True
            else:
                version = (msg[curr_index + 2] << 24) | \
                    (msg[curr_index + 3] << 16) | \
                    (msg[curr_index + 4] << 8) | \
                    msg[curr_index + 5]
                self.log.debug("Firmware version: %d.%d.%d.%d",
                               msg[curr_index + 2], msg[curr_index + 3],
                               msg[curr_index + 4], msg[curr_index + 5])
                if version < self.minVersion:
                    self.minVersion = version
                if version == BAD_FW_VERSION:
                    raise AssertionError(
                        "Original firmware sent only to Brian before adding "
                        "real version numbers. The firmware must be updated before "
                        "MPF will work.")
            if not end:
                if msg[curr_index + 7] == ord(OppRs232Intf.EOM_CMD):
                    end = True
                elif msg[curr_index + 8] == ord(OppRs232Intf.GET_GET_VERS_CMD):
                    curr_index += 7
                else:
                    hex_string = "".join(" 0x%02x" % b for b in msg)
                    self.log.warning("Malformed GET_VERS_CMD response:%s.",
                                     hex_string)
                    end = True
                    self.opp_connection[chain_serial].lost_synch()
Пример #8
0
    def read_matrix_inp_resp_initial(self, chain_serial, msg):
        """Read initial matrix switch states.

        Args:
            chain_serial: Serial of the chain which received the message.
            msg: Message to parse.
        """
        # Verify the CRC8 is correct
        if len(msg) < 11:
            raise AssertionError(
                "Received too short initial input response: " +
                "".join(" 0x%02x" % b for b in msg))
        crc8 = OppRs232Intf.calc_crc8_part_msg(msg, 0, 10)
        if msg[10] != ord(crc8):
            self.badCRC += 1
            self.log.warning("Msg contains bad CRC:%s.",
                             "".join(" 0x%02x" % b for b in msg))
        else:
            opp_inp = self.matrixInpAddrDict[chain_serial + '-' + str(msg[0])]
            opp_inp.oldState[0] = (msg[2] << 24) | (msg[3] << 16) | (
                msg[4] << 8) | msg[5]
            opp_inp.oldState[1] = (msg[6] << 24) | (msg[7] << 16) | (
                msg[8] << 8) | msg[9]
Пример #9
0
 def _crc_message(self, msg, term=True):
     crc_msg = msg + OppRs232Intf.calc_crc8_part_msg(msg, 0, len(msg))
     if term:
         crc_msg += b'\xff'
     return crc_msg