logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" Packet Error Rate Test \n") logFile.write("-------------------------------------------------------\n") logFile.write("Channel: " + str(DEFAULT_CHANNEL) + "\n") # Set serial read time-out serialport.setTimeout(SERIAL_PORT_TIMEOUT_ROUTER) # Factory new the controller print '[Factory New]' isFN = 0 serialport.sendBuffer('ATZ\r\n') while (isFN == 0): fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' # Create network sendCommand(serialport, createNwkCmd, channel=DEFAULT_CHANNEL) time.sleep(1) # Enable join sendCommand(serialport, joinEnableCmd, time=PERMIT_JOIN_DURATION) isJoinEnabled = 1 print '[Permit join enabled]' # Start time
logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" Packet Error Rate Test \n") logFile.write("-------------------------------------------------------\n") logFile.write("Channel: " + str(DEFAULT_CHANNEL) + "\n") # Set serial read time-out serialport.setTimeout(SERIAL_PORT_TIMEOUT_ROUTER) # Factory new the controller print '[Factory New]' isFN = 0 serialport.sendBuffer('ATZ\r\n') while(isFN == 0): fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' # Create network sendCommand(serialport, createNwkCmd, channel=DEFAULT_CHANNEL) time.sleep(1) # Enable join sendCommand(serialport, joinEnableCmd, time=PERMIT_JOIN_DURATION) isJoinEnabled = 1 print '[Permit join enabled]' # Start time
def runTest(self, event): # Log file directory if not os.path.exists("log"): os.makedirs("log") os.chdir("log") # Log file name logFileName = "log_" + datetime.now().strftime("%Y%m%d_%H%M%S") + ".txt" if os.path.exists(logFileName): os.remove(logFileName) logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" UART Rx Test \n") logFile.write("-------------------------------------------------------\n") # Serial port time-out serialport.setTimeout(SERIAL_TIMEOUT) # Factory new the controller print '[Factory New]' isFN = 0 while(isFN == 0): serialport.sendBuffer('ATZ\r\n') fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' packetId = 0 lastErrorPacketId = 0 errorCounts = 0 atCommand='ATI2\r\n' for packetId in range(0, 1000): serialport.sendBuffer(atCommand) logFile.write(atCommand) # Log the echo from the controller echo = serialport.readline() print echo logFile.write(echo) response = serialport.readline() responseOK = serialport.readline() logMessage = '[' + str(packetId) + '] ' + response + responseOK print logMessage logFile.write(logMessage) if (response.startswith('ERROR')): errorCounts += 1 logMessage = '[Error occurs after ' + str(packetId - lastErrorPacketId) + ' packets]\n' print logMessage lastErrorPacketId = packetId logFile.write(logMessage) # Print the test result print 'Tried: ' + str(packetId + 1) + '\n' print 'Error Counts: ' + str(errorCounts) + '\n' logFile.write('Tried: ' + str(packetId + 1) + '\n') logFile.write('Error Counts: ' + str(errorCounts) + '\n') logFile.close() return
os.chdir("log") if os.path.exists("deviceInfo.txt"): os.remove("deviceInfo.txt") logFile = open("deviceInfo.txt", "w+") logFile.write("=======================================================\n") logFile.write("[Log created]\n" + datetime.now().strftime("%d %b %Y %H:%M:%S") + "\n") # Join started isStarted = 1 isJoined = 0 while isStarted: duration = elapsedTime(start) / 1000 if (isJoined == 0) and (duration >= PERMIT_JOIN_DURATION): isStarted = 0 resp = serialport.readline() print resp if resp: # Wait for device join if resp.startswith("$NEWDEVU:"): s, info = resp.split(":") nwkAddr, macAddr = info.split(",") acepResp = sendCommandNoResponsePattern(serialport, activeEndpointCmd, shortAddr=int(nwkAddr, base=16)) # Request to leave isJoined = 1 # Disable join sendCommand(serialport, joinEnableCmd, time=PERMIT_JOIN_STOP) print "[Permit join disabled]"
logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" UART Rx Test \n") logFile.write("-------------------------------------------------------\n") #print '[UART RX Test]' # Serial port timeout serialport.setTimeout(SERIAL_TIMEOUT) # Factory new the controller print '[Factory New]' isFN = 0 while (isFN == 0): serialport.sendBuffer('ATZ\r\n') fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' #Create network #sendCommand(serialport, createNwkCmd, channel=0x1A) #time.sleep(1) # Enable join #sendCommand(serialport, joinEnableCmd, time=0xFF) #isJoinEnabled = 1 #print '[Permit join enabled]' packetId = 0
logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" UART Rx Test \n") logFile.write("-------------------------------------------------------\n") #print '[UART RX Test]' # Serial port timeout serialport.setTimeout(SERIAL_TIMEOUT) # Factory new the controller print '[Factory New]' isFN = 0 while(isFN == 0): serialport.sendBuffer('ATZ\r\n') fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' #Create network #sendCommand(serialport, createNwkCmd, channel=0x1A) #time.sleep(1) # Enable join #sendCommand(serialport, joinEnableCmd, time=0xFF) #isJoinEnabled = 1 #print '[Permit join enabled]' packetId = 0
if os.path.exists("deviceInfo.txt"): os.remove("deviceInfo.txt") logFile = open("deviceInfo.txt", "w+") logFile.write("=======================================================\n") logFile.write("[Log created]\n" + datetime.now().strftime("%d %b %Y %H:%M:%S") + "\n") #Join started isStarted = 1 isJoined = 0 while (isStarted): duration = elapsedTime(start) / 1000 if (isJoined == 0) and (duration >= PERMIT_JOIN_DURATION): isStarted = 0 resp = serialport.readline() print resp if resp: # Wait for device join if resp.startswith('$NEWDEVU:'): s, info = resp.split(':') nwkAddr, macAddr = info.split(',') acepResp = sendCommandNoResponsePattern(serialport, activeEndpointCmd, shortAddr=int(nwkAddr, base=16)) # Request to leave isJoined = 1 #Disable join
def runTest(self, event): # Log file directory if not os.path.exists("log"): os.makedirs("log") os.chdir("log") # Log file name logFileName = "log_" + datetime.now().strftime("%Y%m%d_%H%M%S") + ".txt" if os.path.exists(logFileName): os.remove(logFileName) logFile = open(logFileName, "w+") logFile.write("=======================================================\n") logFile.write(" UART Rx Test \n") logFile.write("-------------------------------------------------------\n") # Serial port time-out serialport.setTimeout(SERIAL_TIMEOUT) # Factory new the controller print '[Factory New]' isFN = 0 while (isFN == 0): serialport.sendBuffer('ATZ\r\n') fnResponse = serialport.readline() if fnResponse.startswith('$READY'): isFN = 1 time.sleep(1) print '[Done]' packetId = 0 lastErrorPacketId = 0 errorCounts = 0 atCommand = 'ATI2\r\n' for packetId in range(0, 1000): serialport.sendBuffer(atCommand) logFile.write(atCommand) # Log the echo from the controller echo = serialport.readline() print echo logFile.write(echo) response = serialport.readline() responseOK = serialport.readline() logMessage = '[' + str(packetId) + '] ' + response + responseOK print logMessage logFile.write(logMessage) if (response.startswith('ERROR')): errorCounts += 1 logMessage = '[Error occurs after ' + str( packetId - lastErrorPacketId) + ' packets]\n' print logMessage lastErrorPacketId = packetId logFile.write(logMessage) # Print the test result print 'Tried: ' + str(packetId + 1) + '\n' print 'Error Counts: ' + str(errorCounts) + '\n' logFile.write('Tried: ' + str(packetId + 1) + '\n') logFile.write('Error Counts: ' + str(errorCounts) + '\n') logFile.close() return