def handleTestSwitchLeftMidRightAction(client, action): if config.device.testswitchleftmidright() is False: data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onswitchleftmidright", data) client.sendAction(actionReply)
def handleOnSecondPowerAction(client, action): if config.device.testsecondpower() is False: data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onsecondpower",data) client.sendAction(actionReply)
def handleTestSwitchMiddleAction(client, action): if config.device.testswitchmiddle() is False: data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "ontestswitchmiddle",data) client.sendAction(actionReply)
def handleOnDieAction(client, action): if config.device.offline() is False: # 这个函数未定义 data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "ondie",data) client.sendAction(actionReply)
def handleOnGpioFiveAction(client, action): if config.device.testfivegpio() is False: data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "ongpiofive",data) client.sendAction(actionReply)
def handleOnPowerAction(client, action): if config.device.control_power(action.count) is False: # 这个只需要调用这个函数 data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onpower",data) client.sendAction(actionReply)
def handleOnMeshsetAction(client, action): if config.device.meshset() is False: # 调用 meshset、check_exp、connect_device、connect_telnet_host data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onmeshset",data) client.sendAction(actionReply)
def handleOnFirstOkAction(client, action): # 只能同时只能打开一个终端 if config.device.firstok() is False: # firstok、check_cmd_exp、do_telnet、command data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onfirstok",data) client.sendAction(actionReply)
def handleOnCheckFirstAction(client, action): if config.device.checkfirst() is False: # checkfirst、check_cmd_exp、do_telnet、command data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "oncheckfirst",data) client.sendAction(actionReply)
def handleOnTestSd(client, action): if config.device.test3g() is False: # test3g、check_cmd_exp、do_telnet、command data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "ontest3g",data) client.sendAction(actionReply)
def handleOnTestUsbAction(client, action): if config.device.testusb() is False: # testusb、check_exp、connect_device、connect_telnet_host data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "ontestusb",data) client.sendAction(actionReply)
def handleTestDownTestAction(client, action): if config.device.buletoothtest() is False: data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onbluetooth", data) client.sendAction(actionReply)
def handleOnConnectAction(client, action): config.device = SystemF(action) # 根据前端传递过来的action对象来创建实例化对象, if config.device.ping_start is False: # 判断是否ping通,并将结果传递给前端 data = demjson.encode({'status': 0}) else: data = demjson.encode({'status': 1}) actionReply = Action.buildReplyAction(action, "onconnect", data) client.sendAction(actionReply)
def handleOnMacCompareAction(client, action): if config.device.maccompare() is False: """ maccompare、check_resp、do_ssh、command、computmac maccompare、check_resp、do_telnet、command、computmac """ data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onmacpare",data) client.sendAction(actionReply)
def handleOnFirstOkAction(client, action): if config.device.coreok() is False: """ 1、coreok、check_cmd_exp、do_telnet、command 2、coreok、check_cmd、do_telnet、command """ data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "oncoreok",data) client.sendAction(actionReply)
def handleOnSpeedTxAction(client, action): speed = config.device.speed_tx() """ 1、speed_tx、wait_wget_success、check_resp、do_ssh、command speed_tx、wait_wget_success、check_resp、do_telnet、command """ if speed is False: data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'speed_tx': speed, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onspeedtx",data) client.sendAction(actionReply)
def handleOnResetAction(client, action): if config.device.gpio() is False: # gpio、check_cmd、do_telnet、command """ 1.command 这个函数是使用subprocess多进程来远程登陆路由器,并且执行shell脚本命令。 2.do_telnet 这个函数是来执行提供shell脚本语句 3.check_cmd 是用来直接调用do_telnet函数的 4.gpio 这个函数是用来传递需要执行的语句的 """ data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "ongpio",data) client.sendAction(actionReply)
def handleOnResetAction(client, action): # 流程是测试员按下了按钮,就会像后端发送这个action对象,后端来检验这个路由器是否做出了相应的响应 if config.device.reset() is False: # 调用reset、check_exp、connect_device、connect_telnet_host一共需要四个函数。 """ 1.connect_telnet_host 这个函数是是用来远程登陆路由器的,一旦登陆就意味着监听路 由器的reset按钮的状态,这个函数是来返回tn对象的。 2.connect_device 这个函数是用来获取tn对象的 3.check_exp 这个函数一是调用上面的函数来获取tn对象的,二是监听路由器是否 被人按下,发出一个字符串的信号,同时根据是否监听到想要的内容,来响应相应的Bool值 4.reset函数根据上一个函数的响应结果来返回相应的值来传给这里来。 """ data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onreset",data) client.sendAction(actionReply)
def handleOnPreTreatAction(client, action): if config.device.pretreat(action.mac_address) is False: """ 1、pretreat、set_ssid、set_ssid_of_name pretreat、set_ssid、joinwifi、 2、pretreat、wait_ping_ip_start 3、pretreat、check_resp、do_ssh、command pretreat、check_resp、do_telnet、command 4、pretreat、wait_ping_ssh pretreat、connect_device_tel、 """ data = demjson.encode({'status': 0, 'index': action.index}) else: data = demjson.encode({'status': 1, 'index': action.index}) actionReply = Action.buildReplyAction(action, "onpretreat",data) client.sendAction(actionReply)
def handleOnLiveAction(client, action): # 这里action是一个前端传过来的包含有很多信息的对象 logging.info("handleOneLiveAction()") data = demjson.encode({'status': 1}) # 这个就是将字典打包为json格式的字符串 actionReply = Action.buildReplyAction(action, "onlive", data) # 获得了重构后的action实例对象,因为这个实例对象现在需要反向发送了,所以发送与接受方需要对换,同时增加data状态信息 client.sendAction(actionReply) # 这个就是物联网的通信协议