星期一, 20. 八月 2018 01:53上午 - beautifulzzzz
1、前言
做类似zigbee、ble mesh...无线网络节点性能测试的时候,手动操作然后看表象往往很难找出真正的原因,而且有些深层次问题隐藏在弱网环境中、或大量测试中,因在上位机上用脚本实现自动化挂机测试便显得尤为重要。
本文介绍一种用python写的基于串口通信的上位机自动测试程序框架(简陋框架)。
2、代码框架介绍
如下:整个代码包含两层app+bsp,其中:
bsp层放硬件相关的代码(比如linux系统用python2.7写的串口驱动类);
app层中包含两个应用程序app_app_auto_test_0xda_0xdb_adapter和app_app_auto_test_off_line;
其中应用程序是基于bsp中的代码实现的,进入每个独立的应用程序文件夹,运行make all则可以运行~
➜ mesh_test_toos git:(master) ✗ tree
.
├── app
│ ├── app_app_auto_test_0xda_0xdb_adapter
│ │ ├── app_auto_test.py
│ │ ├── app_frame.py
│ │ ├── main.py
│ │ └── makefile
│ └── app_app_auto_test_off_line
│ ├── app_frame.py
│ ├── app_frame.pyc
│ ├── main.py
│ └── makefile
└── bsp
├── bsp_serial.py
├── bsp_serial.pyc
├── bsp_system.py
└── bsp_system.pyc
4 directories, 12 files
3、bsp代码介绍
bsp_system.py:该文件目前只放了一个获取当前时间戳的函数,精确到毫秒:
#!/usr/bin/env python
# coding=utf-8
import time
def get_time_stamp():
ct = time.time()
local_time = time.localtime(ct)
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
data