def do_show(self): if not sims: return cprint.notice_p("Not any devices") cprint.notice_p("Dev List") for index in range(len(sims)): cprint.notice_p("[index:{0}] [devid:{1}]".format( self.ControlIndex, sims[index].get_item("_deviceID")))
def help_c(self): cprint.notice_p("INPUT: c [3,7] [status]") cprint.notice_p("3 status: 0表示未连接,1表示连接但是未供电,2表示正在供电中") cprint.notice_p("7 status: 0表示未连接,1表示插座、枪已连接好,2表示插座、枪、车已经连接好但是未供电," "3表示插座、枪、车已经连接好且已经给车发送开始充电指令,4表示插座、枪、车已经连接好且正在充电") cprint.notice_p("3孔只能设置[0,1] 7孔只能设置[0,1,2]") cprint.notice_p("设置3孔状态大于1的时候7孔会联动设置为0,反之亦然")
def check_args(self): global ipv4_list if arg_handle.get_args('device_count') > 1 and not arg_handle.get_args('self_IP'): cprint.error_p( "if device count big than 1, self_IP start must assign") sys.exit() elif arg_handle.get_args('device_count') > 1: ipv4s = common_APIs.get_local_ipv4() ip_prefix = '.'.join(arg_handle.get_args( 'self_IP').split('.')[0:-1]) ip_start = arg_handle.get_args('self_IP').split('.')[-1] cprint.notice_p("Start ip: %s" % (ip_start)) ipv4s = [ip for ip in ipv4s if re.search( r'%s' % (ip_prefix), ip) and int(ip.split('.')[-1]) >= int(ip_start)] if len(ipv4s) < arg_handle.get_args('device_count'): cprint.error_p("Local ips: %d not enough" % (len(ipv4s))) sys.exit() else: ipv4_list = ipv4s for ip in ipv4_list: cprint.notice_p("Use Local ip: %s" % (ip)) else: ip = '' if arg_handle.get_args('self_IP'): ip = arg_handle.get_args('self_IP') ipv4_list = [ip]
def do_ctl(self, arg, opt=None): args = arg.split() if len(args) != 1 and not args[0].isdigit(): return self.help_ctl() val = int(args[0]) if (val > len(sims) - 1): return self.do_show() devid = "ALL" if (val != -1): devid = sims[val].get_item("_deviceID") self.ControlIndex = val cprint.notice_p("set ctl index to {0} (devid:{1})".format( self.ControlIndex, devid))
def do_log(self, arg, opts=None): level = { '0': logging.CRITICAL, '1': logging.ERROR, '2': logging.WARNING, '3': logging.INFO, '4': logging.DEBUG, } if int(arg) in range(5): for i in self.sim_objs: cprint.notice_p("=" * 40) self.sim_objs[i].LOG.set_level(level[arg]) else: cprint.warn_p("unknow log level: %s!" % (arg))
def check_args(self): global ipv4_list ipv4_list = [] if arg_handle.get_args('self_IP'): ipv4s = common_APIs.get_local_ipv4() ip_prefix = '.'.join( arg_handle.get_args('self_IP').split('.')[0:-1]) ip_start = int(arg_handle.get_args('self_IP').split('.')[-1]) ipv4_list = [ ip for ip in ipv4s if re.search(r'%s' % (ip_prefix), ip) and int(ip.split('.')[-1]) >= ip_start ] ipv4_list.sort() for ipv4 in ipv4_list: cprint.notice_p("find ip: " + ipv4)
def help_alarm(self): cprint.notice_p("send alarm:") cprint.notice_p("alarm error_code error_status error_level error_msg")
def help_log(self): cprint.notice_p( "change logger level: log {0:critical, 1:error, 2:warning, 3:info, 4:debug}" )
def run(self): self.args = self.parser.parse_args() cprint.notice_p("CMD line: " + str(self.args)) self.check_args()
# sys init sys_init() # multi thread global thread_list thread_list = [] # create clients clients = [] for i in range(1, arg_handle.get_args('client_count') + 1): LOG.yinfo('To create client: %d' % (i)) sim = AirControl(('192.168.10.1', 5100), logger=LOG) thread_list.append([sim.schedule_loop]) thread_list.append([sim.send_data_loop]) thread_list.append([sim.heartbeat_loop]) # run threads sys_proc() # sys_join() # cmd loop signal.signal(signal.SIGINT, lambda signal, frame: cprint.notice_p('Exit SYSTEM: exit')) my_cmd = MyCmd() my_cmd.cmdloop() # sys clean sys_cleanup() sys.exit()
def help_sts(self): cprint.notice_p("show all msgs info!")
def help_record(self): cprint.notice_p("send record:")
def help_set(self): cprint.notice_p("set state")
def help_st(self): cprint.notice_p("show state")
def help_us(self): cprint.notice_p("模拟各种异常事件") cprint.notice_p("INPUT: us [reason] [status] ") cprint.notice_p("reason : [1:模拟急停事件,2:模拟设备故障]") cprint.notice_p("急停status : [0:离开急停状态,1:进入急停状态]") cprint.notice_p("设备故障status : [0:正常 1:过压 2:欠压 3:过流 4:过温 5:漏电]")
def help_show(self): cprint.notice_p("获取当前所有ID和序列号")
def help_ic(self): cprint.notice_p("模拟IC卡充电") cprint.notice_p("INPUT: ic [status] ") cprint.notice_p("status : [0:停止充电,1:开始充电]")
def help_ctl(self): cprint.notice_p("设置要操作的设备序列号") cprint.notice_p("ctl [index]") cprint.notice_p("index默认为-1,意为对所有设备执行同一操作") cprint.notice_p("使用show命令查看当前有的设备序列号和DEV ID以及当前操控的设备序列号")
def do_st(self, arg, opts=None): for i in range(len(self.sim_objs)): cprint.notice_p("-" * 20) self.sim_objs[i].status_show()
# multi thread global thread_list thread_list = [] # create serial objs global coms_list coms_list = {} for com_id in arg_handle.get_args('port_list'): coms_list[com_id] = Air('COM' + com_id, logger=LOG) thread_list.append([coms_list[com_id].schedule_loop]) thread_list.append([coms_list[com_id].send_data_loop]) thread_list.append([coms_list[com_id].recv_data_loop]) # run threads sys_proc() if arg_handle.get_args('cmdloop') or True: # cmd loop signal.signal( signal.SIGINT, lambda signal, frame: cprint.notice_p('Exit SYSTEM: exit')) my_cmd = MyCmd(coms_list, logger=LOG) my_cmd.cmdloop() else: sys_join() # sys clean sys_cleanup() sys.exit()
def help_event(self): cprint.notice_p("send event")
def help_st(self): cprint.notice_p("show air conditioner state")
def do_exit(self, arg, opts=None): cprint.notice_p("Exit CLI, good luck!") sys_cleanup() sys.exit()
def help_send(self): cprint.notice_p("send sting to comx, 'all' mean to all")