def deinit_servo(): print("DEINIT SERVO, SET TO {} and DEINIT".format(SERVO_CENTER_VAL)) args = base_cmd() + [ 'servo', 'Servo {}'.format(SERVO_CENTER_VAL), '<a>', 'servo', 'Servo_deinit' ] socketClient.run(args)
def app(iteration=60): global DEVICE, BASE_CMD, CMD_PIPE_SEP for _ in range(iteration): piped_commands = [] args = BASE_CMD + ['servo', 'Servo(40)'] print("CMD: {}".format(args)) args.append(CMD_PIPE_SEP) piped_commands += args for _ in range(randint(1, 6)): duty = randint(50, 110) args = ['servo', 'Servo({duty})'.format(duty=duty)] print("\tCMD: {}".format(args)) args.append(CMD_PIPE_SEP) piped_commands += args args = ['servo', 'Servo(120)'] print("\tCMD: {}".format(args)) args.append(CMD_PIPE_SEP) piped_commands += args args = ['servo', 'Servo(80)'] print("CMD: {}".format(args)) args.append(CMD_PIPE_SEP) piped_commands += args print("CMD PIPE: {}".format(piped_commands)) socketClient.run(piped_commands) args = BASE_CMD + ['servo', 'Servo_deinit'] socketClient.run(args)
def app(): global DEVICE, BASE_CMD while True: args = BASE_CMD + ['air dht_measure <a> air getMQ135GasPPM'] try: socketClient.run(args) time.sleep(5) except KeyboardInterrupt: break
def app(devfid=None): global DEVICE if devfid is not None: DEVICE = devfid # EDIT YOUR COMMAND args = base_cmd() + ['help', 'version'] status, answer = socketClient.run(args)
def app(devfid=None, test_cycle=64): global DEVICE if devfid is not None: DEVICE = devfid err_cnt = 0 for cycle in range(1, test_cycle + 1): red = random.randint(0, 1000) green = random.randint(0, 1000) blue = random.randint(0, 1000) # EDIT YOUR COMMAND args = base_cmd() + ['light', 'rgb {} {} {}'.format(red, green, blue)] status, answer = socketClient.run(args) if status == 0 or 'R{}G{}B{}'.format(red, green, blue) in answer: print("[OK][{}/{}][{}] {}".format(cycle, test_cycle, err_cnt, answer)) else: print("[ERROR][{}/30][{}] {}".format(cycle, test_cycle, err_cnt, answer)) err_cnt += 1 if err_cnt == 0: print("RESULT: 100% success rate") else: print("RESULT: {}% success rate".format( (((test_cycle - err_cnt) / test_cycle) * 100)))
def app(devfid=None, test_cycle=32): global DEVICE if devfid is not None: DEVICE = devfid err_cnt = 0 for cycle in range(1, test_cycle + 1): cw = random.randint(0, 1000) ww = random.randint(0, 1000) # EDIT YOUR COMMAND if SMOOTH: args = base_cmd() + [ 'cct', 'white {} {} True >json'.format(cw, ww) ] else: args = base_cmd() + [ 'cct', 'white {} {} False >json'.format(cw, ww) ] status, answer = socketClient.run(args) if status == 0 or f'"CW": {cw}' in answer and f'"WW": {ww}' in answer: print("[OK][{}/{}][{}] {}".format(cycle, test_cycle, err_cnt, answer)) else: print("[ERROR][{}/30][{}] {}".format(cycle, test_cycle, err_cnt, answer)) err_cnt += 1 if err_cnt == 0: print("RESULT: 100% success rate") else: print("RESULT: {}% success rate".format( (((test_cycle - err_cnt) / test_cycle) * 100)))
def app(devfid=None, test_cycle=32): global DEVICE if devfid is not None: DEVICE = devfid err_cnt = 0 for cycle in range(1, test_cycle + 1): red = random.randint(0, 1000) green = random.randint(0, 1000) blue = random.randint(0, 1000) # EDIT YOUR COMMAND if SMOOTH: args = base_cmd() + [ 'rgb', 'rgb {} {} {} True >json'.format(red, green, blue) ] else: args = base_cmd() + [ 'rgb', 'rgb {} {} {} False >json'.format(red, green, blue) ] status, answer = socketClient.run(args) if status == 0 or f'"R": {red}' in answer and f'"G": {green}' in answer and f'"B": {blue}' in answer: print("[OK][{}/{}][{}] {}".format(cycle, test_cycle, err_cnt, answer)) else: print("[ERROR][{}/30][{}] {}".format(cycle, test_cycle, err_cnt, answer)) err_cnt += 1 if err_cnt == 0: print("RESULT: 100% success rate") else: print("RESULT: {}% success rate".format( (((test_cycle - err_cnt) / test_cycle) * 100)))
def app(devfid=None): global DEVICE if devfid is not None: DEVICE = devfid # EDIT YOUR COMMAND args = base_cmd() + ['version'] status, answer = socketClient.run(args) print("[micrOS] {}: {}".format(DEVICE, answer).upper())
def app(devfid=None): """ devfid: selected device input send command(s) over socket connection [socketClient.run(args)] <a> command separator in single connection """ global DEVICE if devfid is not None: DEVICE = devfid # EDIT YOUR COMMAND args = base_cmd() + ['help', '<a>', 'version'] status, answer = socketClient.run(args)
def play_game(iteration=30, devfid=None): global CMD_PIPE_SEP for _ in range(iteration): piped_commands = [] args = base_cmd() + ['servo', 'Servo {} '.format(SERVO_CENTER_VAL)] print("CMD: {}".format(args)) args.append(CMD_PIPE_SEP) piped_commands += args for _ in range(randint(1, 6)): duty = randint(55, 100) args = ['servo', 'Servo {duty} '.format(duty=duty)] print("\tCMD: {}".format(args)) args.append(CMD_PIPE_SEP) piped_commands += args args += ['servo', 'Servo {}'.format(SERVO_CENTER_VAL)] print("CMD: {}".format(args)) piped_commands += args print("CMD PIPE: {}".format(piped_commands)) socketClient.run(piped_commands)
def get_status_callback(self): # Get stored devices conn_data = self.socket_data_obj conn_data.read_micrOS_device_cache() for uid in conn_data.MICROS_DEV_IP_DICT.keys(): devip = conn_data.MICROS_DEV_IP_DICT[uid][0] fuid = conn_data.MICROS_DEV_IP_DICT[uid][2] if fuid.startswith('__') or fuid.endswith('__'): continue status, version = socketClient.run( ['--dev', fuid.strip(), 'version']) hwuid = 'None' if status: _status, hello = socketClient.run( ['--dev', fuid.strip(), 'hello']) if _status: hwuid = hello.strip().split(':')[2] status = '🟢' if status else '🔴' msg = f"{status}{hwuid}📍{devip}🏷{fuid} v:️{version}" self.parent_obj.console.append_output(msg) self.parent_obj.console.append_output( f'ALL: {len(conn_data.MICROS_DEV_IP_DICT.keys())}')
def app(devfid=None): global DEVICE if devfid is not None: DEVICE = devfid for k in range(0, 20): args = base_cmd() + ['bme280 measure'] try: status, answer = socketClient.run(args) if status: print("|- [{}/20] OK".format(k + 1)) else: print("|- [{}/20] ERR".format(k + 1)) time.sleep(3) except KeyboardInterrupt: break
def app(test_cycle=64): global BASE_CMD for _ in range(0, test_cycle): red = random.randint(0, 255) green = random.randint(0, 255) blue = random.randint(0, 255) print("===========================") print("R: {}, G: {} B: {}".format(red, green, blue)) command = BASE_CMD + ['neopixel', 'neopixel({}, {}, {})'.format(red, green, blue)] print("CMD: {}".format(command)) status, answer = socketClient.run(command) evaluate_test_data(answer, test_cycle) time.sleep(0.1) print("[i] Communication stability test with Lamp parameter configurations.") print("ERR: {} / ALL {} {}% success rate.".format(TestData.ERR_CNT, TestData.EXEC_CNT, round(100*(1-(TestData.ERR_CNT/TestData.EXEC_CNT)))))
def app(test_cycle=32, devfid=None): global DEVICE if devfid is not None: DEVICE = devfid for _ in range(0, test_cycle): red = random.randint(0, 255) green = random.randint(0, 255) blue = random.randint(0, 255) print("===========================") print("R: {}, G: {} B: {}".format(red, green, blue)) command = base_cmd() + [ 'neopixel', 'neopixel {} {} {} >json'.format(red, green, blue) ] print("CMD: {}".format(command)) status, answer = socketClient.run(command) evaluate_test_data(answer, red, green, blue, test_cycle) time.sleep(0.1) print( "[i] Communication stability test with Lamp parameter configurations.") print("ERR: {} / ALL {} {}% success rate.".format( TestData.ERR_CNT, TestData.EXEC_CNT, round(100 * (1 - (TestData.ERR_CNT / TestData.EXEC_CNT)))))
def app(devfid=None): """ devfid: selected device input send command(s) over socket connection [socketClient.run(args)] <a> command separator in single connection """ global DEVICE if devfid is not None: DEVICE = devfid def home(): args = base_cmd() + ['roboarm', 'control 75 70'] status, answer = socketClient.run(args) test_eval(status, answer) home() args = base_cmd() + ['roboarm', 'control 40 40 s=10'] status, answer = socketClient.run(args) test_eval(status, answer) home() args = base_cmd() + ['roboarm', 'control 115 115'] status, answer = socketClient.run(args) test_eval(status, answer) args = base_cmd() + ['roboarm', 'control 40 115'] status, answer = socketClient.run(args) test_eval(status, answer) args = base_cmd() + ['roboarm', 'control 115 40'] status, answer = socketClient.run(args) test_eval(status, answer) args = base_cmd() + ['roboarm', 'control 40 40'] status, answer = socketClient.run(args) test_eval(status, answer) # Move back to home pos args = base_cmd() + ['roboarm', 'control 75 70 s=5'] status, answer = socketClient.run(args) test_eval(status, answer) print("[Roboarm] success rate: {} %".format(round(__TEST_DATA['ok']/(__TEST_DATA['ok']+__TEST_DATA['err'])*100), 2))
def execute(cmd_list): cmd_args = base_cmd() + cmd_list print("DIMMER TEST: {}".format(cmd_args)) socketClient.run(cmd_args)
def home(): args = base_cmd() + ['roboarm', 'control 75 70'] status, answer = socketClient.run(args) test_eval(status, answer)
def node_status(): socketClient.run(arg_list=['--stat'])
def connect(args=None): if args is not None and len(args) != 0: socketClient.run(arg_list=args.split(' ')) else: socketClient.run(arg_list=[])
def execute(cmd_list): cmd_args = base_cmd() + cmd_list print("[ST] test cmd: {}".format(cmd_args)) return socketClient.run(cmd_args)
def app(): global DEVICE, BASE_CMD # EDIT YOUR COMMAND args = BASE_CMD + ['help'] socketClient.run(args)