Exemplo n.º 1
0
def start(main_controller_connection):
    signal.signal(signal.SIGTERM, signal_handler)
    logger.info("Starting gpio_controller")

    while True:
        # Check GPIO
        if not GPIO.input(4):
            command = None
            presstime = 0
            for _ in range(50):
                if not GPIO.input(4):
                    presstime += 1
                else:
                    command = State.reboot_system
                    break
                if presstime > 20:
                    command = State.shutdown_system
                    break
                time.sleep(0.1)

            ipcon.connect('localhost', 4223)
            time.sleep(1.0)
            master_brick = BrickMaster('6QHvJ1', ipcon)
            master_brick.reset()
            if command is State.reboot_system:
                subprocess.call(["sudo", "reboot"])
            elif command is State.shutdown_system:
                subprocess.call(["sudo", "shutdown", "-h", "now"])

        time.sleep(0.3)
Exemplo n.º 2
0
def relay_flash(baudrate, tty, firmware, uid_iqr, uid_master):
    ipcon = IPConnection()
    iqr = BrickletIndustrialQuadRelay(uid_iqr, ipcon)
    master = BrickMaster(uid_master, ipcon)

    ipcon.connect('localhost', 4223)

    #    reset_usb()
    #    time.sleep(1)

    i = 10
    while True:
        if i == 10:
            master.get_chibi_error_log()
            iqr.set_value(MASK_DATA)
            time.sleep(0.2)
            iqr.set_value(MASK_POWER | MASK_DATA)
            i = 0

        i += 1
        try:
            time.sleep(0.01)
            xmc_flash(baudrate, tty, firmware)
            break
        except Exception as e:
            print(str(e))

    iqr.set_value(MASK_POWER)

    master.reset()

    ipcon.disconnect()
Exemplo n.º 3
0
class TFSerial:
    def __init__(self, _):
        self.ipcon = IPConnection()  # Create IP connection
        self.master = BrickMaster(UID, self.ipcon)  # Create device object
        self.ipcon.connect(HOST, PORT)
        self.timeout = 1
        self.read_buffer = []
        self.baudrate = None
        time.sleep(1)

    # Implement Serial functions that we don't need
    def setDTR(self, _):
        pass

    def flushInput(self):
        pass

    def flushOutput(self):
        pass

    # We misuse the setRTS call to start the bootloader mode (flush everyting etc)
    def setRTS(self, value):
        if value:
            self.master.start_wifi2_bootloader()

    def write(self, data):
        try:
            data = map(ord, data)
            while data != []:
                data_chunk = data[:60]
                length = len(data_chunk)
                data_chunk.extend([0] * (60 - length))
                ret = self.master.write_wifi2_flash(data_chunk, length)
                data = data[60:]
        except:
            traceback.print_exc()

        print "write", length, data

    def read(self, length):
        if len(self.read_buffer) >= length:
            ret = self.read_buffer[:length]
            self.read_buffer = self.read_buffer[length:]
            return ''.join(map(chr, ret))

        try:
            length_read = 0
            t = time.time()
            while len(self.read_buffer) < length:
                data, l = self.master.read_wifi2_flash(60)
                data = data[:l]
                self.read_buffer.extend(data)
                if len(self.read_buffer) < length:
                    time.sleep(0.1)
                if time.time() - t > self.timeout:
                    break

            print "read", l, "of", length, data
            ret = ''.join(map(chr, data[:l]))
        except:
            traceback.print_exc()

        ret = self.read_buffer[:length]
        self.read_buffer = self.read_buffer[length:]
        return ''.join(map(chr, ret))

    def done(self):
        self.master.reset()
Exemplo n.º 4
0
class TFSerial:
    def __init__(self, _):
        self.ipcon = IPConnection() # Create IP connection
        self.master = BrickMaster(UID, self.ipcon) # Create device object
        self.ipcon.connect(HOST, PORT)
        self.timeout = 1
        self.read_buffer = []
        self.baudrate = None
        time.sleep(1)

    # Implement Serial functions that we don't need
    def setDTR(self, _): pass
    def flushInput(self): pass
    def flushOutput(self): pass

    # We misuse the setRTS call to start the bootloader mode (flush everyting etc) 
    def setRTS(self, value):
        if value:
            self.master.start_wifi2_bootloader()

    def write(self, data):
        try:
            data = map(ord, data)
            while data != []:
                data_chunk = data[:60]
                length = len(data_chunk)
                data_chunk.extend([0]*(60-length))
                ret = self.master.write_wifi2_flash(data_chunk, length)
                data = data[60:]
        except:
            traceback.print_exc()

        print "write", length, data 

    def read(self, length):
        if len(self.read_buffer) >= length:
            ret = self.read_buffer[:length]
            self.read_buffer = self.read_buffer[length:]
            return ''.join(map(chr, ret))

        try:
            length_read = 0
            t = time.time()
            while len(self.read_buffer) < length:
                data, l = self.master.read_wifi2_flash(60)
                data = data[:l]
                self.read_buffer.extend(data)
                if len(self.read_buffer) < length:
                    time.sleep(0.1)
                if time.time() - t > self.timeout:
                    break

            print "read", l, "of", length, data
            ret = ''.join(map(chr, data[:l]))
        except:
            traceback.print_exc()

        ret = self.read_buffer[:length]
        self.read_buffer = self.read_buffer[length:]
        return ''.join(map(chr, ret))

    def done(self):
        self.master.reset()