def scan(): devs_id = loadDeviceID(file_deviceid) if not devs_id: outputInfo("Error: No device id.") return None printInerface.init(len(devs_id), time_interval) printInerface.printOutput("Start Test!") # return socket_broadcast = getBroadcastSocket(host, portS) # socket_udp = getUDPSocket(host, portC) cnt_test = 0 dict_devinfo = {} for dev_id in devs_id: dict_devinfo[dev_id] = None while True: cnt_test += 1 printInerface.printTitle(len(devs_id), time_interval, cnt_test) for index, dev_id in enumerate(devs_id): outputInfo ("[%02d] device ID : %s %s" % (cnt_test, dev_id, time.strftime("%Y-%m-%d %H:%M:%S", \ time.localtime()))) dev_info = getDeviceInfo(socket_broadcast, dev_id) state = verifyDeviceInfo(dev_info, dict_devinfo[dev_id]) printInerface.printInfo(dev_id, devinfoToStr(dev_info), index, state) dict_devinfo[dev_id] = dev_info time.sleep(0.01) time.sleep(time_interval)
def start(): cnt_test = 0 socket_broadcast = getBroadcastSocket(host, portS) list_id_old = [] unknow_ip_old = [] printInerface.init(0, 0, time_interval, 0) while True: cnt_test += 1 list_id, dict_ip = scan(socket_broadcast, cnt_test) dict_dev = {} know_ip = [] for index, dev_id in enumerate(list_id): outputInfo ("[%02d] device ID : %s %s" % (cnt_test, dev_id, time.strftime("%Y-%m-%d %H:%M:%S", \ time.localtime()))) dev_info, list_ip = getDeviceInfo(socket_broadcast, dev_id) know_ip += list_ip state = verifyDeviceInfo(dev_info, dev_id, list_id_old) dict_dev[dev_id] = (devinfoToStr(dev_info), index, state) # printInerface.printInfo(dev_id, devinfoToStr(dev_info), index, state) time.sleep(0.01) unknow_ip = getUnknowIP(know_ip, dict_ip) if len(list_id)+len(unknow_ip) != len(list_id_old)+len(unknow_ip_old): printInerface.init(len(list_id), len(unknow_ip), time_interval, cnt_test) else: printInerface.init(len(list_id), len(unknow_ip), time_interval, cnt_test, False) printInerface.printDevInfo(dict_dev) printInerface.printUnknowIP(unknow_ip, len(list_id)) list_id_old = list_id unknow_ip_old = unknow_ip
def testStart(): global cnt_test global cnt_error socket_broadcast = getBroadcastSocket(host, portS) socket_udp = getUDPSocket(host, portC) dev_id = devices_id[0] value_left = None value_right = None while True: cnt_test += 1 outputInfo ("[%02d] device ID : %s %s" % (cnt_test, dev_id, time.strftime("%Y-%m-%d %H:%M:%S", \ time.localtime()))) result = testOneDevice(socket_broadcast, socket_udp, cnt_test, dev_id) dev_info = None if result: dev_info = result["dev_info"] value_left = result["res_powermater"]["value_left"] value_right = result["res_powermater"]["value_right"] else: cnt_error += 1 printInerface.printTitle(dev_id, time_interval, cnt_error, cnt_test) printInerface.printInfo(value_left, value_right) time.sleep(time_interval) if __name__ == '__main__': printInerface.init(devices_id[0], time_interval) testStart()
import sys global device_id global device_ip global scan_info if len(sys.argv) == 1: print "Error: No argument." exit(1) elif len(sys.argv) == 2: device_id = sys.argv[1] scan_info = True else: device_id = sys.argv[1] device_ip = sys.argv[2] scan_info = False if re.match('^EP[\d]{6}$', device_id): return if re.match('^[\d]{6}$', device_id): device_id = 'EP' + device_id else: print "Error: device_id[%s] invalid." % device_id exit(1) if __name__ == '__main__': global device_id global device_ip checkArg() printInerface.init(device_id, time_interval) testStart()
def testStart(): global cnt_test global cnt_error socket_broadcast = getBroadcastSocket(host, portS) socket_udp = getUDPSocket(host, portC) dev_id = devices_id[0] value_left = None value_right = None while True: cnt_test += 1 outputInfo ("[%02d] device ID : %s %s" % (cnt_test, dev_id, time.strftime("%Y-%m-%d %H:%M:%S", \ time.localtime()))) result = testOneDevice(socket_broadcast, socket_udp, cnt_test, dev_id) dev_info = None if result: dev_info = result["dev_info"] value_left = result["res_powermater"]["value_left"] value_right = result["res_powermater"]["value_right"] else: cnt_error += 1 printInerface.printTitle(dev_id, time_interval, cnt_error, cnt_test) printInerface.printInfo(value_left, value_right) time.sleep(time_interval) if __name__ == '__main__': printInerface.init(devices_id[0], time_interval) testStart()
import sys global device_id global device_ip global scan_info if len(sys.argv) == 1: print "Error: No argument." exit(1) elif len(sys.argv) == 2: device_id = sys.argv[1] scan_info = True else: device_id = sys.argv[1] device_ip = sys.argv[2] scan_info = False if re.match('^EP[\d]{6}$', device_id): return if re.match('^[\d]{6}$', device_id): device_id = 'EP' + device_id else: print "Error: device_id[%s] invalid." % device_id exit(1) if __name__ == '__main__': global device_id global device_ip checkArg() printInerface.init(device_id, time_interval) testStart()