From a06e693e694f25968b976d9051c8ee37086da7bc Mon Sep 17 00:00:00 2001 From: Rena kim Date: Wed, 9 May 2018 13:40:12 +0900 Subject: [PATCH] v1.1.0 release --- FWUploadThread.py | 9 +- TCPClientThread.py | 2 - WIZ750CMDSET.py | 4 + WIZ752CMDSET.py | 4 + WIZArgParser.py | 17 +- WIZMSGHandler.py | 132 +++------------ WIZMakeCMD.py | 131 +++++++++++++++ wizconfig.py | 397 +++++++++++++++++++-------------------------- 8 files changed, 349 insertions(+), 347 deletions(-) create mode 100644 WIZMakeCMD.py diff --git a/FWUploadThread.py b/FWUploadThread.py index 9b0a817..5561aca 100644 --- a/FWUploadThread.py +++ b/FWUploadThread.py @@ -42,7 +42,7 @@ def jumpToApp(mac_addr): print('[%s] Jump to app boot mode' % mac_addr) cmd_list.append(["MA", mac_addr]) - cmd_list.append(["PW", " "]) + cmd_list.append(["PW", self.idcode]) cmd_list.append(["AB", ""]) wizmsghangler.makecommands(cmd_list, OP_FWUP) wizmsghangler.sendcommands() @@ -50,7 +50,7 @@ def jumpToApp(mac_addr): class FWUploadThread(threading.Thread): # initialization # def __init__(self, log_level): - def __init__(self): + def __init__(self, idcode): threading.Thread.__init__(self) self.dest_mac = None @@ -62,6 +62,7 @@ def __init__(self): self.istimeout = 0 self.serverip = None self.serverport = None + self.idcode = idcode self.sentbyte = 0 @@ -90,7 +91,7 @@ def jumpToApp(self): print('[%s] Jump to app boot mode' % self.dest_mac) cmd_list.append(["MA", self.dest_mac]) - cmd_list.append(["PW", " "]) + cmd_list.append(["PW", self.idcode]) cmd_list.append(["AB", ""]) self.wizmsghangler.makecommands(cmd_list, OP_FWUP) self.wizmsghangler.sendcommands() @@ -103,7 +104,7 @@ def sendCmd(self, command): # Send FW UPload request message cmd_list.append(["MA", self.dest_mac]) - cmd_list.append(["PW", " "]) + cmd_list.append(["PW", self.idcode]) cmd_list.append([command, str(len(self.data))]) # sys.stdout.write("cmd_list: %s\r\n" % cmd_list) self.wizmsghangler.makecommands(cmd_list, OP_FWUP) diff --git a/TCPClientThread.py b/TCPClientThread.py index 7d9cec6..7583958 100644 --- a/TCPClientThread.py +++ b/TCPClientThread.py @@ -251,7 +251,6 @@ def run(self): lastnumindex = dst_ip.rfind('.') lastnum = int(dst_ip[lastnumindex + 1:len(dst_ip)]) - # filename = strftime("%d-%b-%Y", localtime()) + '_log.txt' # fd = open(filename, 'w') @@ -269,7 +268,6 @@ def run(self): for i in range(len(threads)): end_flag &= not threads[i].is_alive() - except (KeyboardInterrupt, SystemExit): for i in range(dst_num): threads[i].stop() diff --git a/WIZ750CMDSET.py b/WIZ750CMDSET.py index 0e5b093..2ea535a 100644 --- a/WIZ750CMDSET.py +++ b/WIZ750CMDSET.py @@ -22,6 +22,10 @@ def __init__(self, log_level): "ST" : ["Operation status", "", {}, "RO"], "UN" : ["UART Interface(Str)", "", {}, "RO"], "UI" : ["UART Interface(Code)", "", {}, "RO"], + # WIZ750SR: F/W 1.2.0 verison or later + "TR" : ["TCP Retransmission Retry count", + "^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])$", + {}, "RW"], "OP" : ["Network Operation Mode", "^[0-3]$", {"0": "TCP Client mode", "1" : "TCP Server mode", "2" : "TCP Mixed mode", "3" : "UDP mode"}, diff --git a/WIZ752CMDSET.py b/WIZ752CMDSET.py index ed25571..a62f44a 100644 --- a/WIZ752CMDSET.py +++ b/WIZ752CMDSET.py @@ -24,6 +24,10 @@ def __init__(self, log_level): "EN" : ["UART Interface(Str) for channel 1", "", {}, "RO"], "UI" : ["UART Interface(Code) for channel 0", "", {}, "RO"], "EI" : ["UART Interface(Code) for channel 1", "", {}, "RO"], + # WIZ750SR: F/W 1.2.0 verison or later + "TR" : ["TCP Retransmission Retry count", + "^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])$", + {}, "RW"], "OP" : ["Network Operation Mode for channel 0", "^[0-3]$", {"0": "TCP Client mode", "1" : "TCP Server mode", "2" : "TCP Mixed mode", "3" : "UDP mode"}, diff --git a/WIZArgParser.py b/WIZArgParser.py index a4eb20c..6105367 100644 --- a/WIZArgParser.py +++ b/WIZArgParser.py @@ -44,9 +44,12 @@ def config_arg(self): parser.add_argument('-d', '--device', dest='macaddr', help='Device mac address to configuration') parser.add_argument('-a', '--all', action='store_true', help='Configuration about all devices (in mac_list.txt)') parser.add_argument('-c', '--clear', action='store_true', help='Mac list clear') + parser.add_argument('-v', '--version', action='store_true', help='Version information') group = parser.add_argument_group('Configuration') group.add_argument('-s', '--search', action='store_true', help='Search devices (in same network)') + # group.add_argument('-s', '--search', nargs='?', const=True, help='Search the devices. If using search ID code, set parameter.') + group.add_argument('-p', '--password', help='Search Id code (password)') group.add_argument('-r', '--reset', action='store_true', help='Reboot device') group.add_argument('-f', '--factory', action='store_true', help='Factory reset') @@ -100,7 +103,7 @@ def config_arg(self): group.add_argument('--rip1', metavar='IP', help='Remote host IP address / Domain') group.add_argument('--rport1', metavar='PORT', help='Remote host port number') - group.add_argument('--baud1', type=int, help='baud rate (300|600|1200|1800|2400|4800|9600|14400|19200|28800|38400|57600|115200|230400)') + group.add_argument('--baud1', type=int, help='baud rate (300|600|1200|1800|2400|4800|9600|14400|19200|28800|38400|57600|115200|230400|460800)') group.add_argument('--data1', choices=['0','1'], help='data bit (0: 7-bit, 1: 8-bit)') group.add_argument('--parity1', choices=['0','1','2'], help='parity bit (0: NONE, 1: ODD, 2: EVEN)') group.add_argument('--stop1', choices=['0','1'], help='stop bit (0: 1-bit, 1: 2-bit)') @@ -118,6 +121,7 @@ def config_arg(self): help='''TCP Keep-alive packet transmission retry interval value\n(0: Not use / 1~65535: Keep-alive packet transmission retry interval (Unit: millisecond))''') group.add_argument('--rr', metavar='number', help='''TCP client reconnection interval value [TCP client only]\n(0: Not use / 1~65535: TCP client reconnection interval (Unit: millisecond))''') + group.add_argument('--tr', metavar='count', help='TCP Retransmisstion Retry count (1~255)') ## Command mode switch settings group = parser.add_argument_group('UART Command mode switch settings') @@ -131,9 +135,18 @@ def config_arg(self): group.add_argument('--sp', metavar='value', help='Search identification code (string, up to 8 bytes / default: None)') group.add_argument('--dg', choices=['0','1'], help='Serial debug message enable (Debug UART port)') + ## Extention GPIO configs + group = parser.add_argument_group('Extention GPIO configurations (Digital out mode need value)\n\t\t\t(0: Digital in / 1: Digital Out(need value) / 2: Analog in)') + # (0: Digital in / 1: Digital Out / 2: Analog input) + group.add_argument('--ga', nargs='*', metavar='val', help='Expantion GPIO A config') + group.add_argument('--gb', nargs='*', metavar='val', help='Expantion GPIO B config') + group.add_argument('--gc', nargs='*', metavar='val', help='Expantion GPIO C config') + group.add_argument('--gd', nargs='*', metavar='val', help='Expantion GPIO D config') + ## Config from file + group = parser.add_argument_group('Get/Set from file') group.add_argument('--setfile', help='File name to Set') - group.add_argument('--getfile', help='File name to Get info. Refer default command(cmd_oneport.txt or cmd_twoport.txt).') + group.add_argument('--getfile', help='File name to Get info. Refer default command (cmd_oneport.txt or cmd_twoport.txt).') args = parser.parse_args() diff --git a/WIZMSGHandler.py b/WIZMSGHandler.py index 71acb22..6e8c259 100644 --- a/WIZMSGHandler.py +++ b/WIZMSGHandler.py @@ -17,20 +17,13 @@ logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger() -exitflag = 0 - OP_SEARCHALL = 1 -OP_GETCOMMAND = 2 +OP_RESET = 2 OP_SETCOMMAND = 3 OP_SETFILE = 4 OP_GETFILE = 5 OP_FWUP = 6 -def timeout_func(): -# print('timeout') - global exitflag - exitflag = 1 - class WIZMSGHandler: def __init__(self, udpsock): self.sock = udpsock @@ -58,52 +51,19 @@ def __init__(self, udpsock): self.getreply = [] - # self.exitflag = None - def timeout_func(self): # print('timeout') - # self.exitflag = 1 self.istimeout = True def getmacaddr(self, index): if len(self.mac_list) >= (index + 1): mac_addr = self.mac_list[index] - # print (mac_addr) for i in range(5, 1): mac_addr[i*2:] = ":" + mac_addr[i*2:] - # print (mac_addr) return mac_addr else: sys.stdout.write("index is out of range\r\n") return None - - # Get IP address - def getipaddr(self, index): - if len(self.ip_list) >= (index + 1): - ip_addr = self.ip_list[index] - print(ip_addr) - return ip_addr - else: - print('getipaddr: index is out of range') - return None - - def getopmode(self, index): - if len(self.mode_list) >= (index + 1): - opmode = self.mode_list[index] - # print('getopmode:', opmode) - return opmode - else: - print('getopmode: index is out of range') - return None - - def getipmode(self, index): - if len(self.ip_mode) >= (index + 1): - ipmode = self.ip_mode[index] - # print('getipmode:', ipmode) - return ipmode - else: - print('getipmode: index is out of range') - return None def makecommands(self, cmd_list, op_code): self.opcode = op_code @@ -132,34 +92,29 @@ def makecommands(self, cmd_list, op_code): self.msg[self.size:] = str.encode("\r\n") self.size += 2 -# print(self.size, self.msg) - def sendcommands(self): self.sock.sendto(self.msg) - - # Check the response (for setting / reset / factory) + # Check the response def checkresponse(self): readready, writeready, errorready = select.select(self.inputs, self.outputs, self.errors, 1) - configreply = None + self.getreply = None while True: for sock in readready: if sock == self.sock.sock: data = self.sock.recvfrom() - configreply = data.splitlines() + self.getreply = data.splitlines() # print('config reply:', configreply) readready, writeready, errorready = select.select(self.inputs, self.outputs, self.errors, 1) if len(readready) == 0: break - - if configreply is not None: + if self.getreply is not None: return 1 else: return -1 - def parseresponse(self): readready, writeready, errorready = select.select(self.inputs, self.outputs, self.errors, 1) @@ -170,7 +125,7 @@ def parseresponse(self): # t.start() replylists = None - self.getreply = [] + self.getreply = None while True: self.iter += 1 @@ -180,10 +135,6 @@ def parseresponse(self): self.timer1.cancel() self.istimeout = False break - - # if(exitflag) : - # t.cancel() - # # exitflag = 0 for sock in readready: if sock == self.sock.sock : @@ -194,52 +145,14 @@ def parseresponse(self): if self.opcode is OP_SEARCHALL: for i in range(0, len(replylists)): - if b'MC' in replylists[i] : - self.mac_list.append(replylists[i][2:]) - # sys.stdout.write("iter count: %r, %r\r\n" % (self.iter, replylists[i][2:])) - if b'MN' in replylists[i]: - self.devname.append(replylists[i][2:]) - # sys.stdout.write("Device name: %r\r\n" % (replylists[i][2:])) - # if 'MN' in replylists[i] and "WIZ752SR-12x" not in replylists[i][2:] : - # if 'MN' in replylists[i] and "WIZ750SR" not in replylists[i][2:] : - # self.mac_list.pop() - # sys.stdout.write("iter count: %r, %r\r\n" % (self.iter, replylists[i][2:])) - if b'VR' in replylists[i]: - self.version.append(replylists[i][2:]) - - if b'ST' in replylists[i]: - self.devst.append(replylists[i][2:]) - - # if b'VR' in replylists[i] and b"1.1.2dev" in replylists[i][2:] : - # self.mac_list.pop() - # sys.stdout.write("iter count: %r, %r\r\n" % (self.iter, replylists[i][2:])) - if b'OP' in replylists[i]: - self.mode_list.append(replylists[i][2:]) - if b'LI' in replylists[i]: - self.ip_list.append(replylists[i][2:]) - # print('ip_list', self.ip_list) - # sys.stdout.write("iter count: %r, %r\r\n" % (self.iter, replylists[i][2:])) + if b'MC' in replylists[i]: self.mac_list.append(replylists[i][2:]) + if b'MN' in replylists[i]: self.devname.append(replylists[i][2:]) + if b'VR' in replylists[i]: self.version.append(replylists[i][2:]) + if b'ST' in replylists[i]: self.devst.append(replylists[i][2:]) + if b'OP' in replylists[i]: self.mode_list.append(replylists[i][2:]) + if b'LI' in replylists[i]: self.ip_list.append(replylists[i][2:]) if b'IM' in replylists[i]: self.ip_mode.append(replylists[i][2:]) - elif self.opcode is OP_GETCOMMAND: - pass - # for i in range(0, len(replylists)): - # sys.stdout.write("%r\r\n" % replylists[i]) - - elif self.opcode is OP_SETCOMMAND: - pass - # for i in range(0, len(replylists)): - # sys.stdout.write("%r\r\n" % replylists[i]) - - elif self.opcode is OP_SETFILE: - pass - # for i in range(0, len(replylists)): - # sys.stdout.write("%r\r\n" % replylists[i]) - - elif self.opcode is OP_GETFILE: - pass - # for i in range(0, len(replylists)): - # sys.stdout.write("%r\r\n" % replylists[i]) elif self.opcode is OP_FWUP: for i in range(0, len(replylists)): @@ -248,12 +161,9 @@ def parseresponse(self): if b'MA' in replylists[i][:2]: dest_mac = self.dest_mac reply_mac = replylists[i][2:] - # sys.stdout.write('dest_mac: %r\r\n' % dest_mac) - # sys.stdout.write('reply_mac: %r\r\n' % reply_mac) # self.isvalid = True else: self.isvalid = False - # sys.stdout.write("%r\r\n" % replylists[i][:2]) if b'FW' in replylists[i][:2]: @@ -267,8 +177,6 @@ def parseresponse(self): param = replylists[i][2:].split(b':') self.reply = replylists[i][2:] - # sys.stdout.write("%r\r\n" % replylists[i]) - readready, writeready, errorready = select.select(self.inputs, self.outputs, self.errors, 1) if self.opcode is OP_SEARCHALL: @@ -276,27 +184,27 @@ def parseresponse(self): elif self.opcode is OP_SETCOMMAND or self.opcode is OP_SETFILE: if replylists is not None: return True + # return self.getreply else: return -1 elif self.opcode is OP_FWUP: return self.reply # sys.stdout.write("%s\r\n" % self.mac_list) - def get_log(self): - if len(self.getreply) > 0: - print('Configuration result: ') + def get_log(self, mac_addr): + if self.getreply is not None: + print('[%s] Setting result: ' % (mac_addr)) # print('getreply: %s' % self.getreply) cmdsetObj = WIZ752CMDSET(logging.ERROR) for i in range(2, len(self.getreply)): - getcmd = self.getreply[i][:2] - cmd = getcmd.decode('utf-8') - getparam = self.getreply[i][2:] - param = getparam.decode('utf-8') - + cmd = self.getreply[i][:2].decode() + param = self.getreply[i][2:].decode() cmd_desc = cmdsetObj.getcmddescription(cmd) param_desc = cmdsetObj.getparamdescription(cmd, param) conf_info = " %02d) %s: %-17s | %s: %s\r\n" % (i-1, cmd, param, cmd_desc, param_desc) sys.stdout.write('%s' % conf_info) + else: + pass def get_filelog(self, macaddr): filename = None diff --git a/WIZMakeCMD.py b/WIZMakeCMD.py new file mode 100644 index 0000000..9e1bd41 --- /dev/null +++ b/WIZMakeCMD.py @@ -0,0 +1,131 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import socket +import time +import struct +import binascii +import sys +import getopt +import logging +import re +import os +from WIZ750CMDSET import WIZ750CMDSET +from WIZ752CMDSET import WIZ752CMDSET +from WIZUDPSock import WIZUDPSock +from WIZMSGHandler import WIZMSGHandler +from WIZArgParser import WIZArgParser +from FWUploadThread import * +import logging +logging.basicConfig(level=logging.DEBUG) +logger = logging.getLogger() + +OP_SEARCHALL = 1 +OP_RESET = 2 +OP_SETCOMMAND = 3 +OP_SETFILE = 4 +OP_GETFILE = 5 +OP_FWUP = 6 + +DEV_STATE_IDLE = 10 +DEV_STATE_APPBOOT = 11 +DEV_STATE_APPUPDATED = 12 +DEV_STATE_BOOTUP = 13 +DEV_STATE_BOOTUPDATED = 14 + +BAUDRATES = [300, 600, 1200, 1800, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800] + +cmd_getinfo = ['MC','VR','MN','ST','IM','OP','LI','SM','GW'] + +# Command for each device +cmd_ch1 = ['MC','VR','MN','UN','ST','IM','OP','DD','CP','PO','DG','KA','KI','KE','RI','LI','SM','GW','DS','PI','PP','DX','DP','DI','DW','DH','LP','RP','RH','BR','DB','PR','SB','FL','IT','PT','PS','PD','TE','SS','NP','SP','SC'] +cmd_added = ['TR'] # firmware version 1.2.0 or later +cmd_ch2 = ['QS','QO','QH','QP','QL','RV','RA','RE','RR','EN','RS','EB','ED','EP','ES','EF','E0','E1','NT','NS','ND'] + +cmd_gpio = ['CA','CB','CC','CD','GA','GB','GC','GD'] + +class WIZMakeCMD: + def search(self, idcode): + cmd_list = [] + # Search All Devices on the network + # 장치 검색 시 필요 정보 Get + cmd_list.append(["MA", "FF:FF:FF:FF:FF:FF"]) + cmd_list.append(["PW", idcode]) + for cmd in cmd_ch1: + cmd_list.append([cmd, ""]) + return cmd_list + + def get_from_file(self, mac_addr, idcode, filename): + # 파일의 command들에 대한 정보를 가져옴 + cmd_list = [] + f = open(filename, 'r') + cmd_list.append(["MA", mac_addr]) + cmd_list.append(["PW", idcode]) + for line in f: +# print len(line), line.decode('hex') + if len(line) > 2 : + cmd_list.append([line[:2], ""]) + f.close() + return cmd_list + + def set_from_file(self, mac_addr, idcode, filename): + # 파일에서 cmd/parameter set 정보를 불러옴 + cmd_list = [] + getcmd_list = [] + f = open(filename, 'r') + cmd_list.append(["MA", mac_addr]) + cmd_list.append(["PW", idcode]) + for line in f: + if len(line) > 2: + cmd_list.append([line[:2], line[2:]]) + getcmd_list.append(line[:2]) + for cmd in getcmd_list: + cmd_list.append([cmd, ""]) + cmd_list.append(["SV", ""]) + cmd_list.append(["RT", ""]) + f.close() + return cmd_list + + # Get device info + def getcommand(self, macaddr, idcode, command_list): + cmd_list = [] # 초기화 + cmd_list.append(["MA", macaddr]) + cmd_list.append(["PW", idcode]) + # cmd_list.append(["MC", ""]) + for i in range(len(command_list)): + cmd_list.append([command_list[i], ""]) + # cmd_list.append(["RT", ""]) + return cmd_list + + # Set device + def setcommand(self, macaddr, idcode, command_list, param_list): + cmd_list = [] + try: + # print('Macaddr: %s' % macaddr) + cmd_list.append(["MA", macaddr]) + cmd_list.append(["PW", idcode]) + # for set + for i in range(len(command_list)): + cmd_list.append([command_list[i], param_list[i]]) + # for get + for i in range(len(command_list)): + cmd_list.append([command_list[i], ""]) + cmd_list.append(["SV", ""]) # save device setting + cmd_list.append(["RT", ""]) # Device reboot + return cmd_list + except Exception as e: + sys.stdout.write('%r\r\n' % e) + + def reset(self, mac_addr, idcode): + cmd_list = [] + cmd_list.append(["MA", mac_addr]) + cmd_list.append(["PW", idcode]) + cmd_list.append(["RT", ""]) + return cmd_list + + def factory_reset(self, mac_addr, idcode): + cmd_list = [] + cmd_list.append(["MA", mac_addr]) + cmd_list.append(["PW", idcode]) + cmd_list.append(["FR", ""]) + return cmd_list diff --git a/wizconfig.py b/wizconfig.py index 9501ad1..52e99c5 100644 --- a/wizconfig.py +++ b/wizconfig.py @@ -7,7 +7,6 @@ import binascii import sys import getopt -import logging import re import os from WIZ750CMDSET import WIZ750CMDSET @@ -16,12 +15,15 @@ from WIZMSGHandler import WIZMSGHandler from WIZArgParser import WIZArgParser from FWUploadThread import * +from WIZMakeCMD import * import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger() +VERSION = 'v1.1.0' + OP_SEARCHALL = 1 -OP_GETCOMMAND = 2 +OP_RESET = 2 OP_SETCOMMAND = 3 OP_SETFILE = 4 OP_GETFILE = 5 @@ -33,125 +35,13 @@ DEV_STATE_BOOTUP = 13 DEV_STATE_BOOTUPDATED = 14 -BAUDRATES = [300, 600, 1200, 1800, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800] - -cmd_oneport = ['MC','VR','MN','UN','UI','ST','IM','OP','DD','CP','PO','DG','KA','KI','KE','RI','LI','SM','GW','DS','PI','PP','DX','DP','DI','DW','DH','LP','RP','RH','BR','DB','PR','SB','FL','IT','PT','PS','PD','TE','SS','NP','SP'] -cmd_twoport = ['MC','VR','MN','UN','UI','ST','IM','OP','DD','CP','PO','DG','KA','KI','KE','RI','LI','SM','GW','DS','PI','PP','DX','DP','DI','DW','DH','LP','RP','RH','BR','DB','PR','SB','FL','IT','PT','PS','PD','TE','SS','NP','SP','QS','QO','QH','QP','QL','RV','RA','RE','RR','EI','EN','RS','EB','ED','EP','ES','EF','E0','E1','NT','NS','ND'] - -class WIZMakeCMD: - def search(self): - cmd_list = [] - # Search All Devices on the network - # 장치 검색 시 필요 정보 Get - cmd_list.append(["MA", "FF:FF:FF:FF:FF:FF"]) - cmd_list.append(["PW", " "]) - for cmd in cmd_oneport: - cmd_list.append([cmd, ""]) - return cmd_list - - def get_value(self, mac_addr, filename): - # 파일의 command들에 대한 정보를 가져옴 - cmd_list = [] - f = open(filename, 'r') - cmd_list.append(["MA", mac_addr]) - cmd_list.append(["PW", " "]) - for line in f: -# print len(line), line.decode('hex') - if len(line) > 2 : - cmd_list.append([line[:2], ""]) - f.close() - return cmd_list - - def set_value(self, mac_addr, filename): - # 파일에서 cmd/parameter set 정보를 불러옴 - cmd_list = [] - f = open(filename, 'r') - cmd_list.append(["MA", mac_addr]) - cmd_list.append(["PW", " "]) - getcmd_list = [] - for line in f: - if len(line) > 2: - cmd_list.append([line[:2], line[2:]]) - getcmd_list.append(line[:2]) - for cmd in getcmd_list: - cmd_list.append([cmd, ""]) - - cmd_list.append(["SV", ""]) - cmd_list.append(["RT", ""]) - f.close() - return cmd_list - - # Get device info - def getcommand(self, macaddr, command_list): - cmd_list = [] # 초기화 - cmd_list.append(["MA", macaddr]) - cmd_list.append(["PW", " "]) - # cmd_list.append(["MC", ""]) - for i in range(len(command_list)): - cmd_list.append([command_list[i], ""]) - # cmd_list.append(["RT", ""]) - return cmd_list - - # Set device - def setcommand(self, macaddr, command_list, param_list): - cmd_list = [] - try: - # print('Macaddr: %s' % macaddr) - cmd_list.append(["MA", macaddr]) - cmd_list.append(["PW", " "]) - # for set - for i in range(len(command_list)): - cmd_list.append([command_list[i], param_list[i]]) - # for get - # for i in range(len(command_list)): - # cmd_list.append([command_list[i], ""]) - cmd_list.append(["SV", ""]) # save device setting - cmd_list.append(["RT", ""]) # Device reboot - return cmd_list - except Exception as e: - sys.stdout.write('%r\r\n' % e) - - def reset(self, mac_addr): - cmd_list = [] - cmd_list.append(["MA", mac_addr]) - cmd_list.append(["PW", " "]) - cmd_list.append(["RT", ""]) - return cmd_list - - def factory_reset(self, mac_addr): - cmd_list = [] - cmd_list.append(["MA", mac_addr]) - cmd_list.append(["PW", " "]) - cmd_list.append(["FR", ""]) - return cmd_list - - def set_maclist(self, mac_list, devname, version, status, ip_list): - try: - if os.path.isfile('mac_list.txt'): - f = open('mac_list.txt', 'r+') - else: - f = open('mac_list.txt', 'w+') - data = f.readlines() - # print('data', data) - except Exception as e: - sys.stdout.write(e) - for i in range(len(mac_list)): - print('* Device %d: %s [%s] | %s | %s | Version: %s ' % (i+1, mac_list[i].decode(), devname[i].decode(), ip_list[i].decode(), status[i].decode(), version[i].decode())) - # print('%s|%s|%s|%s' % (mac_list[i].decode(), devname[i].decode(), version[i].decode(), ip_list[i].decode())) - info = "%s\n" % (mac_list[i].decode()) - if info in data: - pass - else: - print('New Device: %s' % mac_list[i].decode()) - f.write(info) - f.close() - class UploadThread(threading.Thread): - def __init__(self, mac_addr, file_name): + def __init__(self, mac_addr, idcode, file_name): threading.Thread.__init__(self) self.mac_addr = mac_addr self.filename = file_name + self.idcode = idcode def run(self): thread_list = [] @@ -164,7 +54,7 @@ def run(self): jumpToApp(self.mac_addr) elif update_state is DEV_STATE_APPBOOT: time.sleep(2) - th_fwup = FWUploadThread() + th_fwup = FWUploadThread(self.idcode) th_fwup.setparam(self.mac_addr, self.filename) th_fwup.sendCmd('FW') th_fwup.start() @@ -172,7 +62,7 @@ def run(self): update_state += 1 class MultiConfigThread(threading.Thread): - def __init__(self, mac_addr, cmd_list, op_code): + def __init__(self, mac_addr, id_code, cmd_list, op_code): threading.Thread.__init__(self) conf_sock = WIZUDPSock(5000, 50001) @@ -180,12 +70,13 @@ def __init__(self, mac_addr, cmd_list, op_code): self.wizmsghangler = WIZMSGHandler(conf_sock) self.mac_addr = mac_addr + self.id_code = id_code self.cmd_list = cmd_list self.configresult = None - self.op_code = OP_SETCOMMAND + self.op_code = op_code - def SetMultiIP(self, host_ip): + def set_multiip(self, host_ip): self.host_ip = host_ip dst_port = '5000' @@ -198,10 +89,7 @@ def SetMultiIP(self, host_ip): setcmd['GW'] = target_gw setcmd['LP'] = dst_port setcmd['OP'] = '1' - self.cmd_list = wizmakecmd.setcommand(mac_addr, list(setcmd.keys()), list(setcmd.values())) - - def Checkresult(self): - return self.configresult + self.cmd_list = wizmakecmd.setcommand(mac_addr, self.id_code, list(setcmd.keys()), list(setcmd.values())) def run(self): # print('multiset cmd_list: ', self.cmd_list) @@ -216,7 +104,116 @@ def run(self): if self.configresult < 0: print(' [%s] Configuration failed. Please check the device.' % (self.mac_addr)) else: - print(' [%s] Configuration success!' % (self.mac_addr)) + if self.op_code is OP_RESET: + pass + else: + self.wizmsghangler.get_log(self.mac_addr) + # print(' [%s] Configuration success!' % (self.mac_addr)) + +def make_setcmd(arg): + setcmd = {} + + # General config + if args.alloc: setcmd['IM'] = args.alloc + if args.ip: setcmd['LI'] = args.ip + if args.subnet: setcmd['SM'] = args.subnet + if args.gw: setcmd['GW'] = args.gw + if args.dns: setcmd['DS'] = args.dns + + # Channel 0 config + if args.nmode0: setcmd['OP'] = args.nmode0 + if args.port0: setcmd['LP'] = args.port0 + if args.rip0: setcmd['RH'] = args.rip0 + if args.rport0: setcmd['RP'] = args.rport0 + + if args.baud0: setcmd['BR'] = str(BAUDRATES.index(args.baud0)) + if args.data0: setcmd['DB'] = args.data0 + if args.parity0: setcmd['PR'] = args.parity0 + if args.stop0: setcmd['SB'] = args.stop0 + if args.flow0: setcmd['FL'] = args.flow0 + if args.time0: setcmd['PT'] = args.time0 + if args.size0: setcmd['PS'] = args.size0 + if args.char0: setcmd['PD'] = args.char0 + + if args.it: setcmd['IT'] = args.it + if args.ka: setcmd['KA'] = args.ka + if args.ki: setcmd['KI'] = args.ki + if args.ke: setcmd['KE'] = args.ke + if args.ri: setcmd['RI'] = args.ri + + # Channel 1 config + if args.nmode1: setcmd['QO'] = args.nmode1 + if args.port1: setcmd['QL'] = args.port1 + if args.rip1: setcmd['QH'] = args.rip1 + if args.rport1: setcmd['QP'] = args.rport1 + + if args.baud1: setcmd['EB'] = str(BAUDRATES.index(args.baud1)) + if args.data1: setcmd['ED'] = args.data1 + if args.parity1: setcmd['EP'] = args.parity1 + if args.stop1: setcmd['ES'] = args.stop1 + if args.flow1: setcmd['EF'] = args.flow1 + if args.time1: setcmd['NT'] = args.time1 + if args.size1: setcmd['NS'] = args.size1 + if args.char1: setcmd['ND'] = args.char1 + + if args.rv: setcmd['RV'] = args.rv + if args.ra: setcmd['RA'] = args.ra + if args.rs: setcmd['RS'] = args.rs + if args.re: setcmd['RE'] = args.re + if args.rr: setcmd['RR'] = args.rr + if args.tr: setcmd['TR'] = args.tr + + # Configs + if args.cp: setcmd['CP'] = args.cp + if args.np: setcmd['NP'] = args.np + if args.sp: setcmd['SP'] = args.sp + if args.dg: setcmd['DG'] = args.dg + + # Command mode switch settings + if args.te: setcmd['TE'] = args.te + if args.ss: setcmd['SS'] = args.ss + + # expansion GPIO + if args.ga: + setcmd['CA'] = args.ga[0] + if args.ga[0] == '1' and args.ga[1] is not None: + setcmd['GA'] = args.ga[1] + elif args.gb: + setcmd['CB'] = args.gb[0] + if args.gb[0] == '1' and args.gb[1] is not None: + setcmd['GB'] = args.gb[1] + elif args.gc: + setcmd['CC'] = args.gc[0] + if args.gc[0] == '1' and args.gc[1] is not None: + setcmd['GC'] = args.gc[1] + elif args.gd: + setcmd['CD'] = args.gd[0] + if args.gd[0] == '1' and args.gd[1] is not None: + setcmd['GD'] = args.gd[1] + + # print('%d, %s' % (len(setcmd), setcmd)) + return setcmd + +def make_maclist(mac_list, devname, version, status, ip_list): + try: + if os.path.isfile('mac_list.txt'): + f = open('mac_list.txt', 'r+') + else: + f = open('mac_list.txt', 'w+') + data = f.readlines() + # print('data', data) + except Exception as e: + sys.stdout.write(e) + for i in range(len(mac_list)): + print('* Device %d: %s [%s] | %s | %s | Version: %s ' % (i+1, mac_list[i].decode(), devname[i].decode(), ip_list[i].decode(), status[i].decode(), version[i].decode())) + # print('%s|%s|%s|%s' % (mac_list[i].decode(), devname[i].decode(), version[i].decode(), ip_list[i].decode())) + info = "%s\n" % (mac_list[i].decode()) + if info in data: + pass + else: + print('New Device: %s' % mac_list[i].decode()) + f.write(info) + f.close() if __name__ == '__main__': wizmakecmd = WIZMakeCMD() @@ -240,10 +237,16 @@ def run(self): update_state = DEV_STATE_IDLE # print(args) - if args.search or args.clear: - if len(sys.argv) is not 2: - print('Invalid argument. Please refer to %s -h\n' % sys.argv[0]) - sys.exit(0) + # search id code init + searchcode = ' ' + + if args.search or args.clear or args.version: + if args.search and args.password is not None: + pass + else: + if len(sys.argv) is not 2: + print('Invalid argument. Please refer to %s -h\n' % sys.argv[0]) + sys.exit(0) else: if len(sys.argv) < 3: print('Invalid argument. Please refer to %s -h\n' % sys.argv[0]) @@ -254,8 +257,10 @@ def run(self): f = open('mac_list.txt', 'w') f.close() - ## single or all device set - # elif args.macaddr or args.all or args.search or args.multiset: + if args.version: + print('WIZnet-S2E-Tool %s' % VERSION) + + # Configuration (single or multi) elif args.macaddr or args.all or args.search or args.multiset: if args.macaddr: mac_addr = args.macaddr @@ -265,66 +270,14 @@ def run(self): op_code = OP_SETCOMMAND print('Devcie configuration start...\n') - # General config - - if args.alloc: setcmd['IM'] = args.alloc - if args.ip: setcmd['LI'] = args.ip - if args.subnet: setcmd['SM'] = args.subnet - if args.gw: setcmd['GW'] = args.gw - if args.dns: setcmd['DS'] = args.dns - - # Channel 0 config - if args.nmode0: setcmd['OP'] = args.nmode0 - if args.port0: setcmd['LP'] = args.port0 - if args.rip0: setcmd['RH'] = args.rip0 - if args.rport0: setcmd['RP'] = args.rport0 - - if args.baud0: setcmd['BR'] = str(BAUDRATES.index(args.baud0)) - if args.data0: setcmd['DB'] = args.data0 - if args.parity0: setcmd['PR'] = args.parity0 - if args.stop0: setcmd['SB'] = args.stop0 - if args.flow0: setcmd['FL'] = args.flow0 - if args.time0: setcmd['PT'] = args.time0 - if args.size0: setcmd['PS'] = args.size0 - if args.char0: setcmd['PD'] = args.char0 - - if args.it: setcmd['IT'] = args.it - if args.ka: setcmd['KA'] = args.ka - if args.ki: setcmd['KI'] = args.ki - if args.ke: setcmd['KE'] = args.ke - if args.ri: setcmd['RI'] = args.ri - - # Channel 1 config - if args.nmode1: setcmd['QO'] = args.nmode1 - if args.port1: setcmd['QL'] = args.port1 - if args.rip1: setcmd['QH'] = args.rip1 - if args.rport1: setcmd['QP'] = args.rport1 - - if args.baud1: setcmd['EB'] = str(BAUDRATES.index(args.baud1)) - if args.data1: setcmd['ED'] = args.data1 - if args.parity1: setcmd['EP'] = args.parity1 - if args.stop1: setcmd['ES'] = args.stop1 - if args.flow1: setcmd['EF'] = args.flow1 - if args.time1: setcmd['NT'] = args.time1 - if args.size1: setcmd['NS'] = args.size1 - if args.char1: setcmd['ND'] = args.char1 - - if args.rv: setcmd['RV'] = args.rv - if args.ra: setcmd['RA'] = args.ra - if args.rs: setcmd['RS'] = args.rs - if args.re: setcmd['RE'] = args.re - if args.rr: setcmd['RR'] = args.rr - - # Configs - if args.cp: setcmd['CP'] = args.cp - if args.np: setcmd['NP'] = args.np - if args.sp: setcmd['SP'] = args.sp - if args.dg: setcmd['DG'] = args.dg - - # Command mode switch settings - if args.te: setcmd['TE'] = args.te - if args.ss: setcmd['SS'] = args.ss - # print('%d, %s' % (len(setcmd), setcmd)) + + setcmd = make_setcmd(args) + + # search id code (parameter of 'PW') + if args.password: + searchcode = args.password + else: + searchcode = ' ' # Check parameter setcmd_cmd = list(setcmd.keys()) @@ -359,17 +312,17 @@ def run(self): op_code = OP_FWUP print('[Multi] Device FW upload: device %d, %s' % (i+1, mac_addr)) fwup_name = 'th%d_fwup' % (i) - fwup_name = UploadThread(mac_addr, args.fwfile) + fwup_name = UploadThread(mac_addr, searchcode, args.fwfile) fwup_name.start() else: if args.multiset: th_name = 'th%d_config' % (i) - th_name = MultiConfigThread(mac_addr, cmd_list, OP_SETCOMMAND) - th_name.SetMultiIP(host_ip) + th_name = MultiConfigThread(mac_addr, searchcode, cmd_list, OP_SETCOMMAND) + th_name.set_multiip(host_ip) th_name.start() elif args.getfile: op_code = OP_GETFILE - cmd_list = wizmakecmd.get_value(mac_addr, args.getfile) + cmd_list = wizmakecmd.get_from_file(mac_addr, searchcode, args.getfile) wizmsghangler.makecommands(cmd_list, op_code) wizmsghangler.sendcommands() @@ -377,36 +330,36 @@ def run(self): elif args.setfile: op_code = OP_SETFILE print('[Setfile] Device [%s] Config from \'%s\' file.' % (mac_addr, args.setfile)) - cmd_list = wizmakecmd.set_value(mac_addr, args.setfile) - th_setfile = MultiConfigThread(mac_addr, cmd_list, OP_SETFILE) + cmd_list = wizmakecmd.set_from_file(mac_addr, searchcode, args.setfile) + th_setfile = MultiConfigThread(mac_addr, searchcode, cmd_list, OP_SETFILE) th_setfile.start() else: if args.reset: + op_code = OP_RESET print('[Multi] Reset devices %d: %s' % (i+1, mac_addr)) - cmd_list = wizmakecmd.reset(mac_addr) + cmd_list = wizmakecmd.reset(mac_addr, searchcode) elif args.factory: + op_code = OP_RESET print('[Multi] Factory reset devices %d: %s' % (i+1, mac_addr)) - cmd_list = wizmakecmd.factory_reset(mac_addr) + cmd_list = wizmakecmd.factory_reset(mac_addr, searchcode) else: - # op_code = OP_SETCOMMAND + op_code = OP_SETCOMMAND print('[Multi] Setting devcies %d: %s' % (i+1, mac_addr)) - cmd_list = wizmakecmd.setcommand(mac_addr, list(setcmd.keys()), list(setcmd.values())) - get_cmd_list = wizmakecmd.getcommand(mac_addr, list(setcmd.keys())) + cmd_list = wizmakecmd.setcommand(mac_addr, searchcode, list(setcmd.keys()), list(setcmd.values())) th_name = 'th%d_config' % (i) - th_name = MultiConfigThread(mac_addr, cmd_list, OP_SETCOMMAND) + th_name = MultiConfigThread(mac_addr, searchcode, cmd_list, op_code) th_name.start() - - # print(' op_code %d, cmd_list: %s\n' % (op_code, cmd_list)) + time.sleep(0.3) if args.getfile: print('[Multi][Getfile] Get device [%s] info from \'%s\' commands\n' % (mac_addr, args.getfile)) wizmsghangler.get_filelog(mac_addr) - ## Single device config + # Single device config else: if args.fwfile: op_code = OP_FWUP print('Device %s Firmware upload' % mac_addr) - t_fwup = FWUploadThread() + t_fwup = FWUploadThread(searchcode) t_fwup.setparam(mac_addr, args.fwfile) t_fwup.jumpToApp() time.sleep(2) @@ -415,39 +368,34 @@ def run(self): elif args.search: op_code = OP_SEARCHALL print('Start to Search devices...') - cmd_list = wizmakecmd.search() + cmd_list = wizmakecmd.search(searchcode) elif args.reset: op_code = OP_SETCOMMAND print('Device %s Reset' % mac_addr) - cmd_list = wizmakecmd.reset(mac_addr) + cmd_list = wizmakecmd.reset(mac_addr, searchcode) elif args.factory: op_code = OP_SETCOMMAND print('Device %s Factory reset' % mac_addr) - cmd_list = wizmakecmd.factory_reset(mac_addr) + cmd_list = wizmakecmd.factory_reset(mac_addr, searchcode) elif args.setfile: op_code = OP_SETFILE print('[Setfile] Device [%s] Config from \'%s\' file.' % (mac_addr, args.setfile)) - cmd_list = wizmakecmd.set_value(mac_addr, args.setfile) + cmd_list = wizmakecmd.set_from_file(mac_addr, searchcode, args.setfile) elif args.getfile: op_code = OP_GETFILE print('[Getfile] Get device [%s] info from \'%s\' commands\n' % (mac_addr, args.getfile)) - cmd_list = wizmakecmd.get_value(mac_addr, args.getfile) + cmd_list = wizmakecmd.get_from_file(mac_addr, searchcode, args.getfile) else: op_code = OP_SETCOMMAND print('* Single devcie config: %s' % mac_addr) - cmd_list = wizmakecmd.setcommand(mac_addr, list(setcmd.keys()), list(setcmd.values())) - get_cmd_list = wizmakecmd.getcommand(mac_addr, list(setcmd.keys())) - # print('get_cmd_list', get_cmd_list) + cmd_list = wizmakecmd.setcommand(mac_addr, searchcode, list(setcmd.keys()), list(setcmd.values())) if args.all or args.multiset: if args.fwfile or args.factory or args.reset: pass - else: - print('Configuration result:') elif args.fwfile: pass else: - # print(' op_code %d, cmd_list: %s' % (op_code, cmd_list)) wizmsghangler.makecommands(cmd_list, op_code) wizmsghangler.sendcommands() conf_result = wizmsghangler.parseresponse() @@ -460,25 +408,20 @@ def run(self): dev_version = wizmsghangler.version dev_status = wizmsghangler.devst ip_list = wizmsghangler.ip_list - wizmakecmd.set_maclist(mac_list, dev_name, dev_version, dev_status, ip_list) + make_maclist(mac_list, dev_name, dev_version, dev_status, ip_list) print('\nRefer to \'mac_list.txt\' file') elif not args.all: if op_code is OP_GETFILE: wizmsghangler.get_filelog(mac_addr) elif op_code is OP_SETFILE: print('\nDevice configuration from \'%s\' complete!' % args.setfile) + wizmsghangler.get_log(mac_addr) elif args.multiset or args.factory or args.reset: pass elif op_code is OP_SETCOMMAND: if conf_result < 0: print('\nWarning: No response from the device [%s]. Please check the device\'s status.' % mac_addr) else: - print('\nDevice configuration complete!') - - # print('get_cmd_list: %s' % get_cmd_list) - # wizmsghangler.makecommands(get_cmd_list, OP_GETCOMMAND) - # wizmsghangler.sendcommands() - # wizmsghangler.parseresponse() - - # wizmsghangler.get_log() + print('\nDevice[%s] configuration complete!' % (mac_addr)) + wizmsghangler.get_log(mac_addr) \ No newline at end of file