Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
release
  • Loading branch information
renakim committed May 9, 2018
1 parent ce13c4a commit a06e693
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 347 deletions.
9 changes: 5 additions & 4 deletions FWUploadThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ 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()

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
Expand All @@ -62,6 +62,7 @@ def __init__(self):
self.istimeout = 0
self.serverip = None
self.serverport = None
self.idcode = idcode

self.sentbyte = 0

Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions TCPClientThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions WIZ750CMDSET.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
4 changes: 4 additions & 0 deletions WIZ752CMDSET.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
17 changes: 15 additions & 2 deletions WIZArgParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)')
Expand All @@ -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')
Expand All @@ -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()

Expand Down
132 changes: 20 additions & 112 deletions WIZMSGHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -170,7 +125,7 @@ def parseresponse(self):
# t.start()

replylists = None
self.getreply = []
self.getreply = None

while True:
self.iter += 1
Expand All @@ -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 :
Expand All @@ -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)):
Expand All @@ -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]:
Expand All @@ -267,36 +177,34 @@ 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:
return len(self.mac_list)
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
Expand Down
Loading

0 comments on commit a06e693

Please sign in to comment.