Ejemplo n.º 1
0
 def get_block(self, code_word, count):
     d = []
     tmk.bcputw(0, code_word)
     for i in range(count):
         tmk.bcputw(i + 1, 0)
     self.logfun(tmk.bcstart, 0, 0, tmk.DATA_RT_BC)
     sleep(0.01)
     for i in range(count):
         d.append(tmk.bcgetw(i + 2))
     return tuple(d)
Ejemplo n.º 2
0
    def upload_plavun(self, data, address):
        up = False
        crc = 0xFFFF
        for i in range(12):
            crc ^= data[i] & 0xFF
            for _ in range(8):
                crc = (crc >> 1) & 0x7FFF
                if crc & 1:
                    crc = crc ^ 0xA001
                else:
                    crc = (crc >> 1) & 0x7FFF

        data = data[:12] + (crc,)
        for i in range(2):
            if up:
                break
            self.logfun(tmk.bcdefbus, 0, i)
            self.log("Передача по МПИ {}".format(("осн.", "рез.")[i]))

            for attempt in range(2):
                sleep(0.1)
                self.send_block(self.make_code_word(Tmk.SEND, address, 3, 13), data)
                sleep(0.1)
                aw = tmk.bcgetw(14)
                if aw != 0:
                    self.log("Неправильное ОС(0x{:x})".format(aw), self.log.ERROR)
                    break

                rdata = self.get_block(self.make_code_word(Tmk.RECEIVE, address, 6, 1), 1)
                if rdata == (0x5555,):
                    self.log("Получена решётка 0x{:x}".format(rdata[0]), self.log.BORRING)
                elif rdata == (0xAAAA,):
                    self.log("Получена решётка 0x{:x}".format(rdata[0]), self.log.BORRING)
                    up = True
                    break
                else:
                    self.log("Получен неправильный ответ 0x{:x}".format(rdata[0]), self.log.ERROR)
                    break
        if up:
            self.log("Ввод прошёл")
        else:
            self.log("Ввод не прошёл", self.log.ERROR)