コード例 #1
0
ファイル: monitor.py プロジェクト: larslevity/CBoardMinimal
 def recv_sample(connection):
     task_raw = connection.recv(4096)
     task = pickler.unpickle_data(task_raw)
     if task[0] == 'sample':
         send_back(connection, 'ACK')
         return task[1]
     elif task[0] == 'Exit':
         return 'Exit'
     else:
         return 0
コード例 #2
0
ファイル: UI_main.py プロジェクト: larslevity/GeckoBot
def main(connection):
    def send_back(data_out):
        data_out_raw = pickler.pickle_data(data_out)
        connection.sendall(data_out_raw)

    exit_flag = False

    while not exit_flag:
        task_raw = connection.recv(4096)
        task = pickler.unpickle_data(task_raw)

        if task[0] == 'get':
            send_back(ui_state.get())
        elif task[0] == 'display':
            msg = task[1]
            lcd.display(msg)
        elif task[0] == 'Exit':
            exit_flag = True
            break
        elif task[0] == 'select from list':
            lis = task[1]
            Q = task[2]
            time_to_answer = task[3]
            with timeout.timeout(time_to_answer):
                try:
                    ans = lcd.select_elem_from_list(lis, Quest=Q)
                except exception.TimeoutError:
                    lcd.display('time out ...')
                    lcd.display('')
                    ans = None
            send_back(ans)

        elif task[0] == 'select from keylist':
            keylist = task[1]
            default = task[2]
            ans = lcd.select_from_keylist(keylist, default)
            send_back(ans)

        time.sleep(.05)
    return 0
コード例 #3
0
 def recieve_data(self):
     ans = pickler.unpickle_data(self.client_socket.recv(4096))
     return ans
コード例 #4
0
    def get_tasks(self):
        data_in_raw = self.connection.recv(4096)
        data_in_list = pickler.unpickle_data(data_in_raw)

        for data_in in data_in_list:
            if 'update' in data_in:
                self.send_back([self.cargo.rec, self.cargo.rec_u,
                                self.cargo.rec_r])

            if 'valve_meta_info' in data_in:
                valve_data = []
                for valve in self.cargo.valve:
                    valve_data.append(valve.name)
                PID_gains = []
                for c in self.cargo.controller:
                    PID_gains.append([c.Kp, c.Ti, c.Td])
                self.send_back([valve_data,
                                self.cargo.maxpressure,
                                self.cargo.maxctrout,
                                self.cargo.sampling_time,
                                PID_gains,
                                self.cargo.wcomm.pattern])

            if 'dvalve_meta_info' in data_in:
                dvalve_data = []
                for dvalve in self.cargo.dvalve:
                    dvalve_data.append(dvalve.name)
                self.send_back(dvalve_data)

            if 'change_state' in data_in:
                candidates = ['PAUSE', 'REFERENCE_TRACKING', 'EXIT',
                              'USER_CONTROL', 'USER_REFERENCE']
                new_state = None
                for candidate in candidates:
                    if candidate in data_in:
                        new_state = candidate
                        print('recieved task to change state to:', new_state)
                if new_state:
                    self.cargo.state = new_state
                    while not self.cargo.actual_state == new_state:
                        time.sleep(self.cargo.sampling_time)
                self.send_back(new_state)

            if 'set_valve' in data_in:
                valve_data = data_in[1]
                for key in valve_data:
                    self.cargo.pwm_task[key] = valve_data[key]

            if 'set_ref' in data_in:
                ref_data = data_in[1]
                for key in ref_data:
                    self.cargo.ref_task[key] = ref_data[key]

            if 'set_dvalve' in data_in:
                dvalve_data = data_in[1]
                for key in dvalve_data:
                    self.cargo.dvalve_task[key] = dvalve_data[key]

            if 'set_pidgain' in data_in:
                idx = data_in[1]
                gain_data = data_in[2]
                if isinstance(self.cargo.controller[idx],
                              ctrlib.PidController):
                    self.cargo.controller[idx].set_gain(gain_data)
                else:
                    raise NotImplementedError(
                        "Controller", self.cargo.controller[idx],
                        "doesn't support gain setting at runtime")
                c = self.cargo.controller[idx]
                gain = [c.Kp, c.Ti, c.Td]
                self.send_back(gain)

            if 'set_maxpressure' in data_in:
                maxpressure = data_in[1]
                if 10 > maxpressure > 0:
                    self.cargo.maxpressure = maxpressure
                    for sensor in self.cargo.sens:
                        sensor.set_maxpressure(maxpressure)
                self.send_back(self.cargo.maxpressure)

            if 'set_maxctrout' in data_in:
                maxctrout = data_in[1]
                if 1. > maxctrout > 0.:
                    self.cargo.maxctrout = maxctrout
                    for ctr in self.cargo.controller:
                        ctr.set_maxoutput(maxctrout)
                self.send_back(self.cargo.maxctrout)

            if 'set_tsampling' in data_in:
                tsampling = data_in[1]
                if 1. > tsampling > 0.:
                    self.cargo.sampling_time = tsampling
                self.send_back(self.cargo.sampling_time)

            if 'set_pattern' in data_in:
                pattern = data_in[1]
                self.cargo.wcomm.pattern = pattern
                self.send_back(self.cargo.wcomm.pattern)

            if 'set_walking' in data_in:
                state = data_in[1]
                self.cargo.wcomm.confirm = state
                self.send_back(self.cargo.wcomm.confirm)
コード例 #5
0
def recieve_data(sock):
    ans = pickler.unpickle_data(sock.recv(4096))
    return ans