179 lines
4.1 KiB
Python
179 lines
4.1 KiB
Python
|
|
||
|
# coding:utf-8
|
||
|
import argparse
|
||
|
import os
|
||
|
import sys
|
||
|
import inspect
|
||
|
import serial
|
||
|
import serial.tools.list_ports
|
||
|
import time
|
||
|
import random
|
||
|
import datetime
|
||
|
import threading
|
||
|
|
||
|
sys.path.append('./base')
|
||
|
import autotest_time as at_time
|
||
|
import autotest_usart as at_usart
|
||
|
|
||
|
sys.path.append('./inst')
|
||
|
import power_agilent_scpi as ag_power
|
||
|
import power_dpm8600_modbus as dpm_power
|
||
|
import temp_modbus as temp_modbus
|
||
|
|
||
|
sys.path.append('./case')
|
||
|
import case_parser as caseparser
|
||
|
|
||
|
TEMP_PORT='COM45'
|
||
|
TEMP_BANDRATE='9600'
|
||
|
|
||
|
DPM8600_PORT='COM46'
|
||
|
DPM8600_BANDRATE='9600'
|
||
|
DPM8600_CHANNEL=1
|
||
|
|
||
|
AG_POWER_PORT='COM47'
|
||
|
AG_POWER_BANDRATE='9600'
|
||
|
|
||
|
__version__ = "1.0"
|
||
|
PYTHON2 = sys.version_info[0] < 3 # True if on pre-Python 3
|
||
|
|
||
|
DEFAULT_BAUD='115200'
|
||
|
DEFAULT_PORT='COM10'
|
||
|
|
||
|
class FatalError(RuntimeError):
|
||
|
def __init__(self, message):
|
||
|
RuntimeError.__init__(self, message)
|
||
|
|
||
|
@staticmethod
|
||
|
def WithResult(message, result):
|
||
|
"""
|
||
|
Return a fatal error object that appends the hex values of
|
||
|
'result' as a string formatted argument.
|
||
|
"""
|
||
|
message += " (result was %s)" % hex(result)
|
||
|
return FatalError(message)
|
||
|
|
||
|
pasttime=datetime.datetime.now()
|
||
|
nowtime=datetime.datetime.now()
|
||
|
|
||
|
def err_exit(args):
|
||
|
nowtime=datetime.datetime.now()
|
||
|
print("test start time :"+pasttime.strftime('%Y-%m-%d %H:%M:%S'))
|
||
|
print("test end time:"+nowtime.strftime('%Y-%m-%d %H:%M:%S'))
|
||
|
print(str(nowtime-pasttime))
|
||
|
sys.exit(args)
|
||
|
|
||
|
def arg_auto_int(x):
|
||
|
return int(x, 0)
|
||
|
|
||
|
def version(args):
|
||
|
print(__version__)
|
||
|
|
||
|
def list_com(args):
|
||
|
at_usart.list_com()
|
||
|
|
||
|
def ret_cmd(ser,cmd):
|
||
|
ser.write(cmd)
|
||
|
s=ser.readline()
|
||
|
print(bytes.decode(s))
|
||
|
return bytes.decode(s)
|
||
|
|
||
|
def no_ret_cmd(ser,cmd):
|
||
|
ser.write(cmd)
|
||
|
|
||
|
def reset(ser):
|
||
|
ser.close()
|
||
|
ser.rts=1
|
||
|
ser.open()
|
||
|
time.sleep(2)
|
||
|
ser.close()
|
||
|
ser.rts=0
|
||
|
ser.open()
|
||
|
def testcase2(ser):
|
||
|
print('run testcase AT+CESQ=?;+CFUN=0; +COPS=3,2,”00103”; +CSQ=?')
|
||
|
ret_cmd(ser,b'AT+CESQ=?;+CFUN=0; +COPS=3,2,”00103”; +CSQ=?\r\n')
|
||
|
str=ser.readline()
|
||
|
if str==b'OK\r\n':
|
||
|
print('test AT+CESQ=?;+CFUN=0; +COPS=3,2,”00103”; +CSQ=? Pass!')
|
||
|
return True
|
||
|
else:
|
||
|
print('test AT+CESQ=?;+CFUN=0; +COPS=3,2,”00103”; +CSQ=? Fail!')
|
||
|
return False
|
||
|
|
||
|
def testcase3(ser):
|
||
|
print('run testcase AT+CESQ=?;+CFUN=0;+COPS=3,2,"00103";+CSQ=?')
|
||
|
ret_cmd(ser,b'AT+CESQ=?;+CFUN=0;+COPS=3,2,"00103";+CSQ=?\r\n')
|
||
|
str=ser.readline()
|
||
|
if str==b'OK\r\n':
|
||
|
print('test AT+CESQ=?;+CFUN=0;+COPS=3,2,"00103";+CSQ=? Pass!')
|
||
|
return True
|
||
|
else:
|
||
|
print('test AT+CESQ=?;+CFUN=0;+COPS=3,2,"00103";+CSQ=? Fail!')
|
||
|
return False
|
||
|
|
||
|
|
||
|
def test(args):
|
||
|
ser = serial.Serial(args.port, args.baud, bytesize=8, parity='N', stopbits=1, timeout=5)
|
||
|
reset(ser)
|
||
|
print("*** Auto Test ***\n")
|
||
|
print("* Board Connected. *")
|
||
|
print("*------------------------*")
|
||
|
testcase2(ser)
|
||
|
testcase3(ser)
|
||
|
|
||
|
def main():
|
||
|
print("Start time:"+at_time.get_time_stamp())
|
||
|
parser = argparse.ArgumentParser(description='autotest.py v%s - Auto Testing Utility' % __version__, prog='autotest')
|
||
|
|
||
|
parser.add_argument(
|
||
|
'--port', '-p',
|
||
|
help='Serial port device',
|
||
|
default=DEFAULT_PORT)
|
||
|
|
||
|
parser.add_argument(
|
||
|
'--baud', '-b',
|
||
|
help='Serial port baud rate used when flashing/reading',
|
||
|
type=arg_auto_int,
|
||
|
default=DEFAULT_BAUD)
|
||
|
|
||
|
subparsers = parser.add_subparsers(
|
||
|
dest='operation',
|
||
|
help='Run autotest {command} -h for additional help')
|
||
|
|
||
|
parser_basic = subparsers.add_parser(
|
||
|
'test',
|
||
|
help='auto test test.')
|
||
|
|
||
|
parser_list_com = subparsers.add_parser(
|
||
|
'list_com',
|
||
|
help='list all useful com ports.')
|
||
|
|
||
|
args = parser.parse_args()
|
||
|
print("------------------------------------------------------")
|
||
|
print(' Autotest Testing Utility v%s' % __version__)
|
||
|
print("------------------------------------------------------")
|
||
|
print("")
|
||
|
|
||
|
if args.operation is None:
|
||
|
parser.print_help()
|
||
|
err_exit(1)
|
||
|
|
||
|
operation_func = globals()[args.operation]
|
||
|
|
||
|
if PYTHON2:
|
||
|
# This function is depreciated in Python3
|
||
|
operation_args = inspect.getargspec(operation_func).args
|
||
|
else:
|
||
|
operation_args = inspect.getfullargspec(operation_func).args
|
||
|
|
||
|
operation_func(args)
|
||
|
|
||
|
def _main():
|
||
|
try:
|
||
|
main()
|
||
|
except FatalError as e:
|
||
|
print('\n A fatal error occurred: %s' % e)
|
||
|
err_exit(2)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
_main()
|