代码拉取完成,页面将自动刷新
using ItenestLibrary;
using ItenestLibrary.bean;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static ItenestLibrary.CommonEnum;
namespace WifiRfTest
{
public partial class TestForm : Form
{
public TestForm()
{
InitializeComponent();
}
int connId = -1;
private void connectBtn_Click(object sender, EventArgs e)
{
Console.WriteLine("ip: " + ipTxt.Text);
string ipAddr = ipTxt.Text;
//获取极致汇仪的连接状态
StringBuilder buffer = new StringBuilder(256);
Common.WT_GetTesterConnStataus(ipAddr, buffer);
//连接极致汇仪
if (buffer.ToString().Equals("IDLE:"))
{
int code = Common.WT_Connect(ipAddr, ref connId);
if (code == 0)
{
Console.WriteLine("连接成功");
connectBtn.Enabled = false;
disConnectBtn.Enabled = true;
ipTxt.Enabled = false;
panel2.Enabled = true;
}
else
{
MessageBox.Show("连接失败");
}
}
else
{
MessageBox.Show("连接失败: " + buffer.ToString());
}
}
private void disConnectBtn_Click(object sender, EventArgs e)
{
//断开连接
Common.WT_DisConnect(connId);
//释放DLL资源
ITestUtils.WT_DLLTerminate();
disConnectBtn.Enabled = false;
connectBtn.Enabled = true;
ipTxt.Enabled = true;
panel2.Enabled = false;
}
private void comBox_DropDown(object sender, EventArgs e)
{
// 获取并打印所有可用串口名称
string[] portNames = SerialPort.GetPortNames();
comBox.Items.Clear();
foreach (string portName in portNames)
{
comBox.Items.Add(portName);
}
}
private PortUtils portUtils;
private string message;
private void openBtn_Click(object sender, EventArgs e)
{
if (portUtils == null)
{
portUtils = new PortUtils(comBox.Text, 115200);
}
if (!portUtils.isOpen())
{
bool result = portUtils.Open();
if (result)
{
showMessage("串口打开成功");
portUtils.DataReceived += Port_DataReceived;
openBtn.Enabled = false;
closeBtn.Enabled = true;
message = "";
messageTxt.Clear();
panel1.Enabled = true;
comBox.Enabled = false;
//send("AT+VER");
//showMessage("接收:" + portUtils.GetData() + "\r\n");
}
else
{
MessageBox.Show("串口打开失败");
}
}
else
{
MessageBox.Show("串口已打开");
}
}
private void closeBtn_Click(object sender, EventArgs e)
{
Console.WriteLine("串口状态: " + portUtils.isOpen());
portUtils.Close();
openBtn.Enabled = true;
closeBtn.Enabled = false;
panel1.Enabled = false;
comBox.Enabled = true;
}
private void Port_DataReceived(object sender, string e)
{
Console.WriteLine($"Received: {e}");
showMessage("接收:" + e + "\r\n");
//showMessage(e);
}
private void showMessage(string msg)
{
message += msg;
Invoke(new Action(() =>
{
messageTxt.AppendText(msg);
}));
}
private void send(string msg)
{
showMessage("发送:" + msg);
portUtils.Send(msg);
//showMessage("接收:" + portUtils.GetData() + "\r\n");
}
private void sendBtn_Click(object sender, EventArgs e)
{
send(cmdTxt.Text + "\r\n");
}
private void unloadBtn_Click(object sender, EventArgs e)
{
send("cd /lib/modules/4.9.84 \r\n");
send("rmmod aic8800_fdrv && rmmod aic_load_fw && rmmod aic_btusb \r\n");
}
private void testmodeBtn_Click(object sender, EventArgs e)
{
send("insmod aic_load_fw.ko testmode=1 && insmod aic8800_fdrv.ko && ifconfig wlan0 up && cd /customer \r\n");
}
private void cmdComBox_DropDownClosed(object sender, EventArgs e)
{
cmdTxt.Text = cmdComBox.Text;
}
private void cmdComBox_DropDown(object sender, EventArgs e)
{
//cmdComBox.Items.Clear();
//string[] cmds = {
// "./wifi_test wlan0 set_tx 1 0 0 0 1500",
// "./wifi_test wlan0 set_tx 1 0 0 3 1500",
// "cd /customer",
// "./wifi_test wlan0 set_txstop",
//};
//foreach (string cmd in cmds)
//{
// cmdComBox.Items.Add(cmd);
//}
}
private void TestForm_Load(object sender, EventArgs e)
{
//初始化指令集
cmdComBox.Items.Clear();
string[] cmds = {
"./wifi_test wlan0 set_tx 1 0 0 0 1500",
"./wifi_test wlan0 set_tx 1 0 0 3 1500",
"cd /customer",
"./wifi_test wlan0 set_txstop",
};
foreach (string cmd in cmds)
{
cmdComBox.Items.Add(cmd);
}
//初始化极致汇仪的DLL
CommonUtils.Copy_Run_Exe();
ITestUtils.WT_DLLInitialize();
//下拉值赋值
// 将枚举值作为下拉框的填充值
//rfPort
var enumRFValues = Enum.GetValues(typeof(WT_PORT_ENUM)).Cast<WT_PORT_ENUM>();
var dataSource1 = enumRFValues.Select(e => new KeyValuePair<WT_PORT_ENUM, string>(e, e.ToString())).ToList();
comboBox1.DataSource = dataSource1;
comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";
//trigType
var enumTrigTypeValues = Enum.GetValues(typeof(WT_TRIG_TYPE_ENUM)).Cast<WT_TRIG_TYPE_ENUM>();
var dataSource2 = enumTrigTypeValues.Select(e => new KeyValuePair<WT_TRIG_TYPE_ENUM, string>(e, e.ToString())).ToList();
comboBox2.DataSource = dataSource2;
comboBox2.DisplayMember = "Value";
comboBox2.ValueMember = "Key";
//demod
var enumDemodValues = Enum.GetValues(typeof(WT_DEMOD_ENUM)).Cast<WT_DEMOD_ENUM>();
var dataSource3 = enumDemodValues.Select(e => new KeyValuePair<WT_DEMOD_ENUM, string>(e, e.ToString())).ToList();
comboBox3.DataSource = dataSource3;
comboBox3.DisplayMember = "Value";
comboBox3.ValueMember = "Key";
}
private void getBasicBtn_Click(object sender, EventArgs e)
{
//获取测试仪的版本以及测试仪类型
int testerType = (int)WT_TESTER_TYPE.WT208C;
TesterInfo testerInfo = new TesterInfo();
Common.WT_GetTesterVersion(connId, ref testerInfo, ref testerType);
showITestMsg(testerInfo.ToString());
}
private void showITestMsg(string msg)
{
Invoke(new Action(() =>
{
iTestMsgTxt.Text = msg;
}));
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private bool loopVsa = true;
private Thread thread;
private string vsaLog = ""; // 存储VSA日志的字符串
private void openVsaBtn_Click(object sender, EventArgs e)
{
VsaParameter vsaParameter = new VsaParameter();
VsgParameter vsgParameter = new VsgParameter();
//获取默认配置参数
Common.WT_GetDefaultParameter(ref vsaParameter, ref vsgParameter);
//线损补偿值设置:如果外部线衰减值是 10dB,则设定 extGain 的值为-10;
double extGain = 0;
Console.WriteLine("WT_SetExternalGain: " + ITestUtils.WT_SetExternalGain(connId, extGain));
//设置 VSA 参数
vsaParameter.freq = int.Parse(textBox2.Text) * 1e6;
vsaParameter.max_power = int.Parse(textBox3.Text);
vsaParameter.smp_time = int.Parse(textBox4.Text);
vsaParameter.rfPort = (int)comboBox1.SelectedValue;
vsaParameter.trig_type = (int)comboBox2.SelectedValue;
//vsaParameter.demod = (int)CommonEnum.WT_DEMOD_ENUM.WT_DEMOD_ZIGBEE;
vsaParameter.demod = (int)comboBox3.SelectedValue;
vsaParameter.trig_timeout = 20;
//Console.WriteLine("cc: " + vsaParameter.ToString());
Console.WriteLine("WT_SetVSA: " + ITestUtils.WT_SetVSA(connId, ref vsaParameter));
Console.WriteLine("WT_SetVSA: " + vsaParameter.ToString());
Console.WriteLine("WT_SetVSA_AutoRange: " + ITestUtils.WT_SetVSA_AutoRange(connId, ref vsaParameter));
Console.WriteLine("WT_SetVSA_AutoRange: " + vsaParameter.ToString());
loopVsa = true;
thread = new Thread(RunLoop);
thread.Start();
}
private void RunLoop()
{
// 循环操作
while (loopVsa)
{
//按照设定的 VSA 参数进行数据抓取
Console.WriteLine("C-returnCode: " + ITestUtils.WT_DataCapture(connId));
//解析VSA数据
//string anaParamString = CommonConstant.WT_RES_POWER_PEAK_DB;
double result = -1;
StringBuilder description = new StringBuilder(256);
StringBuilder unit = new StringBuilder(256);
//发射功率平均值
Console.WriteLine("WT_RES_POWER_FRAME_DB: " + ITestUtils.WT_GetResult(connId, CommonConstant.WT_RES_POWER_FRAME_DB, ref result, description, unit));
Set_Vsa_Log("WT_RES_POWER_FRAME_DB: " + description + ":" + result.ToString("F3") + " " + unit);
StringBuilder description_1 = new StringBuilder(256);
StringBuilder unit_1 = new StringBuilder(256);
double result_1 = -1;
//
//Console.WriteLine("WT_GetResult: " + ITestUtils.WT_GetResult(connID, CommonConstant.WT_RES_POWER_ALL_DB, ref result_1, description_1, unit_1));
//Set_Vsa_Log("WT_RES_POWER_ALL_DB: " + description_1 + ":" + result_1.ToString("F3") + ":" + unit);
StringBuilder description_2 = new StringBuilder(256);
StringBuilder unit_2 = new StringBuilder(256);
double result_2 = -1;
//Console.WriteLine("WT_GetResult: " + ITestUtils.WT_GetResult(connID, CommonConstant.WT_RES_FRAME_EVM_ALL, ref result, description_2, unit_2));
//Set_Vsa_Log("WT_RES_FRAME_EVM_ALL: " + description_2 + ":" + result_2.ToString("F3") + ":" + unit_2);
StringBuilder description_3 = new StringBuilder(256);
StringBuilder unit_3 = new StringBuilder(256);
double result_3 = -1;
Console.WriteLine("WT_RES_FRAME_EVM_PEAK: " + ITestUtils.WT_GetResult(connId, CommonConstant.WT_RES_FRAME_EVM_PEAK, ref result_3, description_3, unit_3));
Set_Vsa_Log(" WT_RES_FRAME_EVM_PEAK: " + description_3 + ":" + result_3.ToString("F3") + " " + unit_3);
StringBuilder description_4 = new StringBuilder(256);
StringBuilder unit_4 = new StringBuilder(256);
double result_4 = -1;
Console.WriteLine("WT_RES_FRAME_FREQ_ERR: " + ITestUtils.WT_GetResult(connId, CommonConstant.WT_RES_FRAME_FREQ_ERR, ref result_4, description_4, unit_4));
Set_Vsa_Log(" WT_RES_FRAME_FREQ_ERR: " + description_4 + ":" + result_4.ToString("F3") + " " + unit_4);
StringBuilder description_5 = new StringBuilder(256);
StringBuilder unit_5 = new StringBuilder(256);
double result_5 = -1;
Console.WriteLine("WT_RES_SPECTRUM_MASK_ERR_PERCENT: " + ITestUtils.WT_GetResult(connId, CommonConstant.WT_RES_SPECTRUM_MASK_ERR_PERCENT, ref result_5, description_5, unit_5));
Set_Vsa_Log(" WT_RES_SPECTRUM_MASK_ERR_PERCENT: " + description_5 + ":" + result_5 + " " + unit_5);
Set_Vsa_Log("\n");
Console.WriteLine("D-returnCode: " + ITestUtils.WT_StopDataCapture(connId));
//检查的结果参数列表
List<string> resultParams = new List<string>();
resultParams.Add(CommonConstant.WT_RES_SPECTRUM_PEAK_POW_FREQ);
resultParams.Add(CommonConstant.WT_RES_FRAME_FREQ_ERR);
resultParams.Add(CommonConstant.WT_RES_POWER_ALL_DB);
foreach (string param in resultParams)
{
StringBuilder desc = new StringBuilder(256);
StringBuilder unitValue = new StringBuilder(256);
double resultValue = -1;
Console.WriteLine(ITestUtils.WT_GetResult(connId, param, ref resultValue, desc, unitValue));
if(resultValue != 0)
{
Console.WriteLine("出现频偏了: " + param);
Console.WriteLine(desc + ":" + resultValue + " " + unitValue);
}
Set_Vsa_Log(desc + ":" + resultValue/1000 + " " + unitValue);
Set_Vsa_Log("\n");
}
Invoke((MethodInvoker)delegate
{
// 滚动到最后一行并选中
iTestMsgTxt.Text = Get_Vsa_Log();
//iTestMsgTxt.SelectionStart = iTestMsgTxt.Text.Length;
//iTestMsgTxt.ScrollToCaret();
});
Thread.Sleep(500);
}
}
public string Get_Vsa_Log()
{
return vsaLog; // 返回当前VSA日志字符串
}
public void Set_Vsa_Log(string message)
{
if (vsaLog.Length > 100000)
{
vsaLog = "";
}
if (!"\n".Equals(message))
{
vsaLog += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + message + "\n"; // 在当前时间前面添加日志信息并换行
}
else
{
vsaLog += message;
}
}
private void stopVsaBtn_Click(object sender, EventArgs e)
{
Console.WriteLine("D-returnCode: " + ITestUtils.WT_StopDataCapture(connId));
loopVsa = false;
}
private void loginBtn_Click(object sender, EventArgs e)
{
send("root\r\n");
Thread.Sleep(500);
send("admin\r\n");
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。