Exemple #1
0
def make_event_list(row_value, prev_row_value, column_bit):
    event_list = []
    for i in xrange(8):
        row_bit = repr_binary(row_value)[::-1][i]
        prev_row_bit = repr_binary(prev_row_value)[::-1][i]
        if row_bit != prev_row_bit and row_bit != '0':
            event_list.append([column_bit, i])  # if value is 1 add the address of the bit to the list
    return event_list
Exemple #2
0
def compare_devices_regs(device1, device2,
                         regs=register_addresses.keys()):  # todo: debug
    device1_regs = dict()
    device2_regs = dict()

    for reg in regs:
        device1_regs[reg] = read_byte(device1, reg)
        device2_regs[reg] = read_byte(device2, reg)

    print("[+]registries comparison")
    for reg in regs:
        # device1_reg, device2_reg in zip(device1_regs.iteritems(), device2_regs.iteritems()):
        if device1_regs[reg] == device2_regs[reg]:
            print("[=]" + reg + ": " + repr_binary(device1[reg]))
        else:
            print("[!=]" + device1 + ": " + repr_binary(device1_regs[reg]))
            print("[!=]" + device2 + ": " + repr_binary(device2_regs[reg]))
Exemple #3
0
    def shift_out(self, number):
        latch_value = 0b10000000
        clock_value = 0b01000000
        serial_value = 0b00100000

        # write 2 bytes to shift register
        for bit in repr_binary(self.number_values[number]):
            control_byte = clock_value + (serial_value if bit == '1' else 0) # add serial bit, if the number_value bit is 1
            self.write_port(self.control_port, control_byte)
            self.write_port(self.control_port, control_byte - clock_value) # set clock low
        self.write_port(self.control_port, latch_value) # set latch high !!! moet hier wel een clock bij?
Exemple #4
0
 def check_port(self, port):
     data = self.read_port(port)
     if data != 0:
         try:
             self.set_io_mode('output', ['A', 'B'])
         except Exception as ex:
             logger.debug(ex)
         start_time = dt.datetime.now()
         logger.info("watchdog: port {} is turned on: {}".format(port, repr_binary(data)))
         try:
             # wait time untill output is set low (value should probably not be higher than 1)
             sleep(0.5)
             # if interference with other solenoids is detected, try adding a read statement here
             self.write_port(port, 0)
         except Exception:
             logger.critical("watchdog: write error on port: {}".format(port))
         end_time = dt.datetime.now()
         elapsed_milliseconds = (end_time - start_time).microseconds / 1000
         logger.info("watchdog: port {} turned off in: {}ms".format(port, elapsed_milliseconds))
Exemple #5
0
def listen(device_address):
    device = device_factory(device_address)
    change = False
    drive = 'B'
    inp = 'A'
    prev_column_data = 0
    prev_row_data = 0

    device.set_io_mode('output', drive)
    device.set_io_mode('input', inp)

    while True:
        if change:
            print("[+] input detected: row: {}| column: {}".format(repr_binary(row_data), repr_binary(column_data)))
            change = False
        column_data = device.read_port(drive)
        row_data = device.read_port(inp)
        if column_data != prev_column_data or row_data != prev_row_data:
            change = True
            prev_column_data = column_data
            prev_row_data = row_data
        time.sleep(0.1)
Exemple #6
0
def read_byte(device_addr, reg):
    device = device_factory(device_addr)
    reg = register_lookup(reg)
    data = device.read_byte(reg)
    print("[+]read: " + register_names[reg] + ": " + repr_binary(data))
    return data