From 083dd4495fe4225811f603462833fef2beaa1492 Mon Sep 17 00:00:00 2001 From: Rena kim Date: Mon, 5 Feb 2018 17:06:34 +0900 Subject: [PATCH] modify wizconfig 1. modify firmware upload 2. add&modify argument/parameter for 2 port s2e 3. update readme --- FWUploadThread.py | 161 ++++++++++++++++++++++++++++------------- README.md | 157 ++++++++++++++++++++++++---------------- WIZArgParser.py | 51 ++++++------- WIZMSGHandler.py | 17 ++--- wizconfig.py | 39 ++++++---- wizsocket/TCPClient.py | 52 ++++++++++++- 6 files changed, 310 insertions(+), 167 deletions(-) diff --git a/FWUploadThread.py b/FWUploadThread.py index d2f441e..d26a3d1 100644 --- a/FWUploadThread.py +++ b/FWUploadThread.py @@ -9,9 +9,10 @@ import logging import threading import getopt +import os logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger() - +import binascii from WIZMSGHandler import WIZMSGHandler from WIZUDPSock import WIZUDPSock from wizsocket.TCPClient import TCPClient @@ -48,6 +49,8 @@ def __init__(self): self.serverip = None self.serverport = None + self.sentbyte = 0 + def setparam(self, dest_mac, binaryfile): self.dest_mac = dest_mac self.bin_filename = binaryfile @@ -79,12 +82,25 @@ def run(self): wizmsghangler.sendcommands() resp = wizmsghangler.parseresponse() - resp = resp.decode('utf-8') - # print('resp', resp) - params = resp.split(':') - sys.stdout.write('Dest IP: %r, Dest Port num: %r\r\n' % (params[0], int(params[1]))) - self.serverip = params[0] - self.serverport = int(params[1]) + if resp is not '': + resp = resp.decode('utf-8') + # print('resp', resp) + params = resp.split(':') + sys.stdout.write('Dest IP: %s, Dest Port num: %r\r\n' % (params[0], int(params[1]))) + self.serverip = params[0] + self.serverport = int(params[1]) + + # network reachable check + ping_reponse = os.system("ping " + ("-n 2 " if sys.platform.lower()=="win32" else "-c 1 ") + self.serverip) + # ping_reponse = os.system('ping -n 1 ' + params[0]) + if ping_reponse == 0: + print('Device[%s] network OK' % self.dest_mac) + else: + print(': Device[%s]: %s is unreachable.\n\tRefer --multiset or --ip options to set IP address.' % (self.dest_mac, self.serverip)) + sys.exit(0) + else: + print('No response from device. Check the network or device status.') + sys.exit(0) try: self.client = TCPClient(2, params[0], int(params[1])) @@ -99,73 +115,120 @@ def run(self): if self.timer1 is not None: self.timer1.cancel() cur_state = self.client.state - self.client.open() - # sys.stdout.write('1 : %r\r\n' % self.client.getsockstate()) - # sys.stdout.write("%r\r\n" % self.client.state) - if self.client.state is SOCK_OPEN_STATE: - sys.stdout.write('[%r] is OPEN\r\n' % (self.serverip)) - # sys.stdout.write('[%r] client.working_state is %r\r\n' % (self.serverip, self.client.working_state)) - time.sleep(1) + try: + self.client.open() + # sys.stdout.write('1 : %r\r\n' % self.client.getsockstate()) + # sys.stdout.write("%r\r\n" % self.client.state) + if self.client.state is SOCK_OPEN_STATE: + sys.stdout.write('[%r] is OPEN\r\n' % (self.serverip)) + # sys.stdout.write('[%r] client.working_state is %r\r\n' % (self.serverip, self.client.working_state)) + # time.sleep(1) + except Exception as e: + sys.stdout.write('%r\r\n' % e) elif self.client.state is SOCK_OPEN_STATE: cur_state = self.client.state - self.client.connect() - # sys.stdout.write('2 : %r' % self.client.getsockstate()) - if self.client.state is SOCK_CONNECT_STATE: - sys.stdout.write('[%r] is CONNECTED\r\n' % (self.serverip)) - # sys.stdout.write('[%r] client.working_state is %r\r\n' % (self.serverip, self.client.working_state)) - time.sleep(1) - + # time.sleep(2) + try: + self.client.connect() + # sys.stdout.write('2 : %r' % self.client.getsockstate()) + if self.client.state is SOCK_CONNECT_STATE: + sys.stdout.write('[%r] is CONNECTED\r\n' % (self.serverip)) + # sys.stdout.write('[%r] client.working_state is %r\r\n' % (self.serverip, self.client.working_state)) + # time.sleep(1) + except Exception as e: + sys.stdout.write('%r\r\n' % e) elif self.client.state is SOCK_CONNECT_STATE: - if self.client.working_state == idle_state: + # if self.client.working_state == idle_state: # sys.stdout.write('3 : %r' % self.client.getsockstate()) - try: - while self.remainbytes is not 0: + try: + while self.remainbytes is not 0: + if self.client.working_state == idle_state: if self.remainbytes >= 1024: msg = bytearray(1024) msg[:] = self.data[self.curr_ptr:self.curr_ptr+1024] self.client.write(msg) + self.sentbyte = 1024 # sys.stdout.write('1024 bytes sent from at %r\r\n' % (self.curr_ptr)) + sys.stdout.write('[%s] 1024 bytes sent from at %r\r\n' % (self.serverip, self.curr_ptr)) self.curr_ptr += 1024 self.remainbytes -= 1024 else : msg = bytearray(self.remainbytes) msg[:] = self.data[self.curr_ptr:self.curr_ptr+self.remainbytes] self.client.write(msg) - sys.stdout.write('...\nLast %r byte sent from at %r \r\n' % (self.remainbytes, self.curr_ptr)) - sys.stdout.write('Device [%s] firmware upload success!\r\n' % (self.dest_mac)) + # sys.stdout.write('Last %r byte sent from at %r \r\n' % (self.remainbytes, self.curr_ptr)) + sys.stdout.write('[%s] Last %r byte sent from at %r \r\n' % (self.serverip, self.remainbytes, self.curr_ptr)) self.curr_ptr += self.remainbytes self.remainbytes = 0 + self.sentbyte = self.remainbytes + + self.client.working_state = datasent_state + + self.timer1 = threading.Timer(2.0, self.myTimer) + self.timer1.start() + elif self.client.working_state == datasent_state: + # sys.stdout.write('4 : %r' % self.client.getsockstate()) + response = self.client.readbytes(2) + # print('response: %r' % response) + if response is not None: + if int(binascii.hexlify(response), 16): + self.client.working_state = idle_state + self.timer1.cancel() + self.istimeout = 0 + else: + print('ERROR: No response from device. Stop FW upload...') + self.client.close() + sys.exit(0) - self.client.working_state = datasent_state + # if (response != ""): + # self.timer1.cancel() + # self.istimeout = 0 - self.timer1 = threading.Timer(2.0, self.myTimer) - self.timer1.start() + # time.sleep(0.1) + # self.client.working_state = idle_state + # self.client.close() + + if self.istimeout is 1: + # self.timer1.cancel() + self.istimeout = 0 + self.client.working_state = idle_state + self.client.close() + sys.exit(0) + + # sys.stdout.write('Device [%s] firmware upload success!\r\n' % (self.dest_mac)) + + + # self.client.working_state = datasent_state + + # self.timer1 = threading.Timer(2.0, self.myTimer) + # self.timer1.start() # sys.stdout.write('timer 1 started\r\n') - except Exception as e: - sys.stdout.write('%r\r\n' % e) - elif self.client.working_state == datasent_state: - sys.stdout.write('4 : %r' % self.client.getsockstate()) - response = self.client.read() - if (response != ""): - self.timer1.cancel() - self.istimeout = 0 - - time.sleep(0.1) - self.client.working_state = idle_state - self.client.close() - - if self.istimeout is 1: - # self.timer1.cancel() - self.istimeout = 0 - self.client.working_state = idle_state - self.client.close() + except Exception as e: + sys.stdout.write('%r\r\n' % e) + # elif self.client.working_state == datasent_state: + # sys.stdout.write('4 : %r' % self.client.getsockstate()) + # response = self.client.read() + # if (response != ""): + # self.timer1.cancel() + # self.istimeout = 0 + # time.sleep(0.1) + # self.client.working_state = idle_state + # self.client.close() + + # if self.istimeout is 1: + # # self.timer1.cancel() + # self.istimeout = 0 + # self.client.working_state = idle_state + # self.client.close() + # self.client.close() response = "" break - except: - pass + sys.stdout.write('Device [%s] firmware upload success!\r\n' % (self.dest_mac)) + except (KeyboardInterrupt, SystemExit): + sys.stdout.write('%r\r\n' % e) finally: pass diff --git a/README.md b/README.md index 96a0b2e..b179b03 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,13 @@ # OVERVIEW WIZnet-S2E-Tool is module Configuration & Test Tool for WIZnet S2E devices. \ -Python interpreter based and it is platform independent. -It works on version 2.7 python current. - +Python interpreter based and it is platform independent. \ +It works on version 2.7 and 3.6 python. # SUPPORT DEVICES ## 1 Port Serial to Ethernet Module - [WIZ750SR](http://wizwiki.net/wiki/doku.php?id=products:wiz750sr:start) - - [WIZ750SR Github](https://github.com/Wiznet/WIZ750SR) + - [WIZ750SR Github page](https://github.com/Wiznet/WIZ750SR) - [WIZ750SR-100](http://wizwiki.net/wiki/doku.php?id=products:wiz750sr-100:start) - [WIZ750SR-105](http://wizwiki.net/wiki/doku.php?id=products:wiz750sr-105:start) - [WIZ750SR-110](http://wizwiki.net/wiki/doku.php?id=products:wiz750sr-110:start) @@ -36,54 +35,52 @@ It works on version 2.7 python current. ## CLI Configuration Tool -### Pre-Required -#### 1) Python +### Pre-Check +#### Python -WIZnet-S2E-Tool works on Python version 2.7. +WIZnet-S2E-Tool works on Python version 2.7 and 3.6. If you don't have Python, refer to https://www.python.org/ If python already installed, check the version as follow. $ python --version Python 2.7.X +or -#### 2) pySerial -Next, you have to install **pySerial** module as follow. - - $ pip install pyserial -If you want more detail, refer to https://github.com/pyserial/pyserial - + $ python --version + Python 3.6.X ---- -### Option -#### optional arguments: +### Options + +#### Optional arguments: -h, --help show this help message and exit -d MACADDR, --device MACADDR Device mac address to configuration -a, --all Configuration about all devices (in mac_list.txt) + -c, --clear Mac list clear -#### Firmware Upload: - -u FWFILE, --upload FWFILE - Firmware upload from file - -#### No parameter Options: +#### Configuration: -s, --search Search devices (in same network) - -c, --clear Mac list clear -r, --reset Reboot device -f, --factory Factory reset - -#### Network Configuration: - --nmode {0,1,2,3} Network operation mode (0: tcpclient, 1: tcpserver, 2: mixed, 3: udp) + -m ipaddr, --multiset ipaddr + Set IP address for all devices in 'mac_list.txt'. Parameter is first address. + -u FWFILE, --upload FWFILE + Firmware upload from file + +#### General Options: --alloc {0,1} IP address allocation method (0: Static, 1: DHCP) --ip IP Local ip address --subnet SUBNET Subnet mask --gw GW Gateway address --dns DNS DNS server address - --port PORT Local port number - --rip IP Remote host IP address / Domain - --rport PORT Remote host port number -#### UART #0 Configurations: +#### Channel #0 Options: + --port0 PORT0 Local port number + --nmode0 {0,1,2,3} Network operation mode (0: tcpclient, 1: tcpserver, 2: mixed, 3: udp) + --rip0 IP Remote host IP address / Domain + --rport0 PORT Remote host port number --baud0 BAUD0 baud rate (300|600|1200|1800|2400|4800|9600|14400|19200|28800|38400|57600|115200|230400) --data0 {0,1} data bit (0: 7-bit, 1: 8-bit) --parity0 {0,1,2} parity bit (0: NONE, 1: ODD, 2: EVEN) @@ -102,7 +99,11 @@ If you want more detail, refer to https://github.com/pyserial/pyserial --ri number TCP client reconnection interval value [TCP client only] (0: Not use / 1~65535: TCP client reconnection interval (Unit: millisecond)) -#### UART #1 Configurations: +#### Channel #1 Options: + --port1 PORT1 Local port number + --nmode1 {0,1,2,3} Network operation mode (0: tcpclient, 1: tcpserver, 2: mixed, 3: udp) + --rip1 IP Remote host IP address / Domain + --rport1 PORT Remote host port number --baud1 BAUD1 baud rate (300|600|1200|1800|2400|4800|9600|14400|19200|28800|38400|57600|115200|230400) --data1 {0,1} data bit (0: 7-bit, 1: 8-bit) --parity1 {0,1,2} parity bit (0: NONE, 1: ODD, 2: EVEN) @@ -125,7 +126,7 @@ If you want more detail, refer to https://github.com/pyserial/pyserial --te {0,1} Serial command mode switch code enable --ss 3-byte hex Serial command mode switch code (default: 2B2B2B) -#### Configs: +#### ETC options: --cp {0,1} TCP connection password enable [TCP server mode only] --np pw TCP connection password (string, up to 8 bytes / default: None) [TCP server mode only] --sp value Search identification code (string, up to 8 bytes / default: None) @@ -135,10 +136,6 @@ If you want more detail, refer to https://github.com/pyserial/pyserial --setfile SETFILE File name to Set --getfile GETFILE File name to Get info. Refer default command(cmd_oneport.txt or cmd_twoport.txt). -#### Set IP address for multi devices: - -m ipaddr, --multiset ipaddr - Set IP address for all device in 'mac_list.txt'. Parameter is first address. - ---- ### Usage @@ -147,19 +144,16 @@ You can see detail description as following command. $ python wizconfig.py -h -When config the serial port, refer below. - -- ***Warning*** -The *UART #1 Configurations* is for 2 port S2E devices. refer to below. +****** - 1 Port S2E devices - WIZ750SR Series - - Use **UART #0 Configurations** only. + - Use [Channel #0 Options](#channel-#0-options:) only. - 2 Port S2E devices - WIZ752SR Series - - Use **UART #0 Configurations** & **UART #1 Configurations** both. + - Use [Channel #0 Options](#channel-#0-options:) & [Channel #1 Options](#channel-#1-options) both. -And all other options are common for 1 port & 2 port S2E devices. +And **all other options are common** for 1 port & 2 port S2E devices. ---- @@ -169,6 +163,8 @@ First, you could search devices use '-s' or '--search' option. $ python wizconfig.py -s And then **mac_list.txt** is created, there are MAC address information of each devices. +
+ #### 2. Configuration * Single Device @@ -178,19 +174,19 @@ And then **mac_list.txt** is created, there are MAC address information of each $ python wizconfig.py -a [Options ...] +**Example** -*Set example* + Set baud rate to 115200 of 1 port S2E device. (use --baud0 option) -Set baud rate to 115200 of 1 port S2E device. - -If device's mac address is '00:08:DC:AA:BB:CC', you can set like this. + If device's mac address is '00:08:DC:AA:BB:CC', you can set like this. $ python wizconfig.py -d 00:08:DC:AA:BB:CC --baud0 115200 -If you want to set baud rate for all devices on the network, do like this. + If you want to set baud rate for all devices on the network, do like this. $ python wizconfig.py -a --baud0 115200 +
#### 3. Firmware Upload @@ -202,12 +198,14 @@ So first, use **-m/--multiset** option for **set ip address to the same network- $ python wizconfig.py -m ##### Step 2 - Firmware upload -Next, prepare the fireware file. You must use **App part firmware** file when do this. +Next, prepare the fireware file. You must use **App Boot firmware** file when do this. -To download firmware file, visit below link. +To download firmware file, refer below link. - https://github.com/Wiznet/WIZ750SR/releases - https://github.com/Wiznet/WIZ750SR/tree/master/Projects/S2E_App/bin +If file is ready, perform the F/W update with the following command: + * Single device $ python wizconfig.py -d 00:08:DC:XX:XX:XX -u @@ -216,6 +214,27 @@ To download firmware file, visit below link. $ python wizconfig.py -a -u +**Example** + +Confirm your host's network band and set IP address for multiple devices. \ +And need to perform -s/--search option before this because -m/--multiset command use 'mac_list.txt'.\ +If your host PC use IP '192.168.0.X', + + $ python wizconfig.py -s + $ python wizconfig.py -m 192.168.0.100 + + This is just example. You can any address that not use, instead of '100'. + + Single device F/W upload (if mac address is '00:08:DC:AA:BB:CC') + + $ python wizconfig.py -d 00:08:DC:AA:BB:CC -u W7500x_S2E_App.bin + + All device F/W upload (in mac_list.txt) + + $ python wizconfig.py -a -u W7500x_S2E_App.bin + +
+ #### 4. Get/Set configs Use File ##### Getfile @@ -225,21 +244,25 @@ You can use example files named **cmd_oneport.txt** and **cmd_twoport.txt**. * Single device - // One port devices - $ python wizconfig.py -d 00:08:DC:XX:XX:XX --getfile cmd_oneport.txt + * One port devices + + $ python wizconfig.py -d 00:08:DC:XX:XX:XX --getfile cmd_oneport.txt - // Two port devices - $ python wizconfig.py -d 00:08:DC:XX:XX:XX --getfile cmd_twoport.txt + * Two port devices + + $ python wizconfig.py -d 00:08:DC:XX:XX:XX --getfile cmd_twoport.txt * ALL devices - // One port devices - $ python wizconfig.py -a --getfile cmd_oneport.txt + * One port devices + + $ python wizconfig.py -a --getfile cmd_oneport.txt - // Two port devices - $ python wizconfig.py -a --getfile cmd_twoport.txt + * Two port devices -It will create log file named **getfile_0008DCXXXXXX.log** that contains information about the device. + $ python wizconfig.py -a --getfile cmd_twoport.txt + +It will create log file(s) named **getfile_0008DCXXXXXX.log** that contains information about the device. ##### Setfile You can save the settings you want to keep to a file and set them with the --setfile option. It can be used as macro. @@ -280,19 +303,27 @@ This tool is perform simple loopback test for functional verification of WIZ75XS ### Usage $ python wiz75x_loopback_test.py -h -
optional arguments:
-  -h, --help                         show this help message and exit
-  -s {1,2}, --select {1,2}           Select number of serial port (1: 1 Port S2E, 2: 2 Port S2E)
-  -t TARGETIP, --targetip TARGETIP   Target IP address
-  -r RETRY, --retry RETRY            Test retry number (default: 5)
+ optional arguments: + -h, --help show this help message and exit + -s {1,2}, --select {1,2} Select number of serial port (1: 1 Port S2E, 2: 2 Port S2E) + -t TARGETIP, --targetip TARGETIP Target IP address + -r RETRY, --retry RETRY Test retry number (default: 5) -t/--targetip option is for set IP address to the same network-band as host. $ python wiz75x_loopback_test.py -s -t 192.168.X.X - +**Example** + + -r/--retry is optional, and -s/--select and -t/--targetip is essential. + + If host IP address is 192.168.0.50 and device is 1 port S2E, + + $ python wiz75x_loopback_test.py -s 1 -t 192.168.0.100 + If device is 2 port S2E, + $ python wiz75x_loopback_test.py -s 2 -t 192.168.0.100 # FAQ If you have any problems, please visit [WIZnet Forum](https://forum.wiznet.io/). diff --git a/WIZArgParser.py b/WIZArgParser.py index 1fed6c4..28acc48 100644 --- a/WIZArgParser.py +++ b/WIZArgParser.py @@ -44,34 +44,33 @@ def config_arg(self): formatter_class=argparse.RawTextHelpFormatter) 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') - ## FW upload - group = parser.add_argument_group('Firmware Upload') - group.add_argument('-u', '--upload', dest='fwfile', help='Firmware upload from file') - - group = parser.add_argument_group('No parameter Options') + group = parser.add_argument_group('Configuration') group.add_argument('-s', '--search', action='store_true', help='Search devices (in same network)') - group.add_argument('-c', '--clear', action='store_true', help='Mac list clear') group.add_argument('-r', '--reset', action='store_true', help='Reboot device') group.add_argument('-f', '--factory', action='store_true', help='Factory reset') + # multi ip set + group.add_argument('-m', '--multiset', metavar='ipaddr', help='Set IP address for all devices in \'mac_list.txt\'. Parameter is first address.') + # F/W upload + group.add_argument('-u', '--upload', dest='fwfile', help='Firmware upload from file') ## Network config - group = parser.add_argument_group('Network Configuration') - # exclusive_group = group.add_mutually_exclusive_group() - group.add_argument('--nmode', choices=['0', '1', '2', '3'], - help='Network operation mode (0: tcpclient, 1: tcpserver, 2: mixed, 3: udp)') - group.add_argument('--alloc', choices=['0', '1'], - help='IP address allocation method (0: Static, 1: DHCP)') + group = parser.add_argument_group('General Options') + group.add_argument('--alloc', choices=['0', '1'], help='IP address allocation method (0: Static, 1: DHCP)') group.add_argument('--ip', help='Local ip address') group.add_argument('--subnet', help='Subnet mask') group.add_argument('--gw', help='Gateway address') group.add_argument('--dns', help='DNS server address') - group.add_argument('--port', help='Local port number') - group.add_argument('--rip', metavar='IP', help='Remote host IP address / Domain') - group.add_argument('--rport', metavar='PORT', help='Remote host port number') + + ### Channel 0 options + group = parser.add_argument_group('Channel #0 Options') + group.add_argument('--port0', help='Local port number') + group.add_argument('--nmode0', choices=['0', '1', '2', '3'], + help='Network operation mode (0: tcpclient, 1: tcpserver, 2: mixed, 3: udp)') + group.add_argument('--rip0', metavar='IP', help='Remote host IP address / Domain') + group.add_argument('--rport0', metavar='PORT', help='Remote host port number') - ## UART 0 Options - group = parser.add_argument_group('UART #0 Configurations') group.add_argument('--baud0', type=int, help='baud rate (300|600|1200|1800|2400|4800|9600|14400|19200|28800|38400|57600|115200|230400)') group.add_argument('--data0', choices=['0','1'], help='data bit (0: 7-bit, 1: 8-bit)') group.add_argument('--parity0', choices=['0','1','2'], help='parity bit (0: NONE, 1: ODD, 2: EVEN)') @@ -93,8 +92,14 @@ def config_arg(self): help='''TCP client reconnection interval value [TCP client only]\n(0: Not use / 1~65535: TCP client reconnection interval (Unit: millisecond))''') # group.add_argument('--ec', choices=['0','1'], help='UART Echoback function enable (Data UART port)') - ## UART 1 Options - group = parser.add_argument_group('UART #1 Configurations') + ## Channel 1 options + group = parser.add_argument_group('Channel #1 Options') + group.add_argument('--port1', help='Local port number') + group.add_argument('--nmode1', choices=['0', '1', '2', '3'], + help='Network operation mode (0: tcpclient, 1: tcpserver, 2: mixed, 3: udp)') + 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('--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)') @@ -119,8 +124,8 @@ def config_arg(self): group.add_argument('--te', choices=['0','1'], help='Serial command mode switch code enable') group.add_argument('--ss', metavar='3-byte hex', help='Serial command mode switch code (default: 2B2B2B)') - ## Configs - group = parser.add_argument_group('Configs') + ## etc options + group = parser.add_argument_group('ETC options') group.add_argument('--cp', choices=['0','1'], help='TCP connection password enable [TCP server mode only]') group.add_argument('--np', metavar='pw', help='TCP connection password (string, up to 8 bytes / default: None) [TCP server mode only]') group.add_argument('--sp', metavar='value', help='Search identification code (string, up to 8 bytes / default: None)') @@ -132,9 +137,5 @@ def config_arg(self): 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).') - ## Set multiIP - group = parser.add_argument_group('\nSet IP address for multi devices') - # group.add_argument('-m', '--multiset', action='store_true', help='Set multi IP for all device (in mac_list.txt)') - group.add_argument('-m', '--multiset', metavar='ipaddr', help='''Set IP address for all device in 'mac_list.txt'. Parameter is first address.''') args = parser.parse_args() return args \ No newline at end of file diff --git a/WIZMSGHandler.py b/WIZMSGHandler.py index 26977f3..4c54a95 100644 --- a/WIZMSGHandler.py +++ b/WIZMSGHandler.py @@ -53,6 +53,7 @@ def __init__(self, udpsock): self.ip_mode = [] self.mode_list = [] self.devname = [] + self.version = [] self.getreply = [] @@ -84,15 +85,6 @@ def getipaddr(self, index): else: print('getipaddr: index is out of range') return None - - def getdevname(self, index): - if len(self.devname) >= (index + 1): - devname = self.devname[index] - print('devname:' + devname) - return devname - else: - print('getdevname: index is out of range') - return None def getopmode(self, index): if len(self.mode_list) >= (index + 1): @@ -188,9 +180,10 @@ def parseresponse(self): # 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 'VR' in replylists[i] and "1.0.0" not in replylists[i][2:] : - if b'VR' in replylists[i] and b"1.1.2dev" in replylists[i][2:] : - self.mac_list.pop() + if b'VR' in replylists[i]: + self.version.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:]) diff --git a/wizconfig.py b/wizconfig.py index 6e0af1a..f717ee6 100644 --- a/wizconfig.py +++ b/wizconfig.py @@ -186,18 +186,20 @@ def isvalid(self, mac_addr): op_code = OP_SETCOMMAND print('Devcie configuration start...\n') - # Network config - if args.nmode: setcmd['OP'] = args.nmode + # 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 - if args.port: setcmd['LP'] = args.port - if args.rip: setcmd['RH'] = args.rip - if args.rport: setcmd['RP'] = args.rport + + # 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 - # UART0 config if args.baud0: setcmd['BR'] = str(BAUDRATES.index(args.baud0)) if args.data0: setcmd['DB'] = args.data0 if args.parity0: setcmd['PR'] = args.parity0 @@ -206,7 +208,19 @@ def isvalid(self, mac_addr): if args.time0: setcmd['PT'] = args.time0 if args.size0: setcmd['PS'] = args.size0 if args.char0: setcmd['PD'] = args.char0 - # UART1 config + + 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 @@ -215,20 +229,13 @@ def isvalid(self, mac_addr): if args.time1: setcmd['NT'] = args.time1 if args.size1: setcmd['NS'] = args.size1 if args.char1: setcmd['ND'] = args.char1 - - # UART0 Config - 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 - # UART1 Config + 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 diff --git a/wizsocket/TCPClient.py b/wizsocket/TCPClient.py index 25807db..f19f7f0 100644 --- a/wizsocket/TCPClient.py +++ b/wizsocket/TCPClient.py @@ -106,7 +106,7 @@ def readline(self): self.buflen += len(tmpbuf) # self.logger.debug("2 buflen: %d\r\n" % self.buflen) - index = self.rcvbuf.find("\r", 0, self.buflen) + index = self.rcvbuf.find(b"\r", 0, self.buflen) if index != -1: # sys.stdout.write("index %d\r\n" % index) retval = self.rcvbuf[0:index+1] @@ -132,7 +132,55 @@ def readline(self): self.time = time.time() return "" - + + def readbytes(self, length): + if self.buflen > 0: + if self.buflen >= length: + retbuf = self.rcvbuf[:length] + self.rcvbuf[0:] = self.rcvbuf[length:] + self.buflen -= length + else: + retbuf = self.rcvbuf[:self.buflen] + self.buflen = 0 + + return retbuf + else: + inputready, outputready, exceptready = select.select([self.sock], [], [], 0) + +# sys.stdout.write("%r\r\n" % inputready) +# sys.stdout.write("%r\r\n" % self.sock) + for i in inputready: + if i == self.sock: +# sys.stdout.write("select activated\r\n") + try: + tmpbuf = self.sock.recv(MAXBUFLEN - self.buflen) + except socket.error: + self.sock = None + self.state = CLOSE_STATE + self.working_state = idle_state + self.buflen = 0 + return None + +# sys.stdout.write("tmpbuf: ") +# sys.stdout.write(tmpbuf) +# sys.stdout.flush() + self.rcvbuf[self.buflen:] = tmpbuf + self.buflen += len(tmpbuf) + +# if len(self.rcvbuf) > 0: +# retval = "%c" % self.rcvbuf[0] +# # sys.stdout.write("rcvbuf: ") +# # sys.stdout.write(self.rcvbuf) +# self.rcvbuf[0:] = self.rcvbuf[1:] +# # sys.stdout.write("rcvbuf: ") +# # sys.stdout.write(self.rcvbuf) +# # sys.stdout.flush() +# self.buflen -= 1 + + # return retval + return None + + def read(self): if self.buflen > 0: retval = "%c" % self.rcvbuf[0]