Commit c93b03fb authored by lyong's avatar lyong

fix:更换wifi测试方案

parent ea58ae9d
...@@ -67,22 +67,25 @@ function doVersion(fd) { ...@@ -67,22 +67,25 @@ function doVersion(fd) {
} }
function doDutStart(fd, recvBuf) { function doDutStart(fd, recvBuf) {
console.log("doDutStart"); console.log("doDutStart");
if (doDutStart._scanTimerOut === undefined) {
doDutStart._scanTimerOut = null;
}
if (doDutStart._scanTimerOut != null) {
clearTimeout(doDutStart._scanTimerOut);
doDutStart._scanTimerOut = null;
}
autoUtil.startWifiScan(); autoUtil.startWifiScan();
autoUtil.AnalyzeATSearchSsid(recvBuf); autoUtil.setSsid(recvBuf);
send(fd, '+OK'); doDutStart._scanTimerOut = setTimeout(function () {
send(fd, '+OK');
}, 5000);
} }
function doScan(fd) { function doScan(fd, recvBuf) {
var value = autoUtil.getWifiScan() || ""; // if (value != "null") { var chekssid = autoUtil.getssid()
var value = autoUtil.getWifiScan(chekssid); // if (value != "null") {
// var value = "01,name:Midea_test,rssi:-43,mac:02-b1-f7-70-1d-a2;02,name:HUAWEI_B311_A736,rssi:-41,mac:42-53-0f-36-a7-3d;03,name:MIDEA_B311_A74E,rssi:-47,mac:02-8e-97-4e-a7-3d;" var scanList = "+" + value;
// 02,name:HUAWEI_B311_A736,rssi:-41,mac:42-53-0f-36-a7-3d;03,name:MIDEA_B311_A74E,rssi:-47,mac:02-8e-97-4e-a7-3d;04,name:360\xe5\x85\x8d\xe8\xb4\xb9WiFi-8A,rssi:-39,mac:b2-95-9d-82-0b-28;05,name:HUAWEI-888,rssi:-48,mac:22-7e-45-7e-03-a4" send(fd, scanList);
// 06,name:\x00\x00\x00\x00\x00\x00\x00\x00,rssi:-52,mac:b4-86-55-1e-e9-2d;07,name:BYT_HS,rssi:-48,mac:30-89-d3-2f-a5-a3;08,name:\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00,rssi:-50,mac:fc-60-9b-7a-8e-50;09,name:Midea_test,rssi:-49,mac:8e-21-70-c1-69-c8;10,name:HUAWEI-0E1G4D,rssi:-51,mac:d4-8f-a2-42-26-90;"
var scanList = "+" + value ;
// console.log("scanList: " + scanList);
send(fd, scanList);
// }
} }
function doOtg(fd) { function doOtg(fd) {
if (autoUtil.checkUsbDeviceExist() == true) { if (autoUtil.checkUsbDeviceExist() == true) {
...@@ -131,8 +134,8 @@ function doGetCrc(fd) { ...@@ -131,8 +134,8 @@ function doGetCrc(fd) {
function doEnd(fd) { function doEnd(fd) {
send(fd, '+OK'); send(fd, '+OK');
autoUtil.exitAutoFactoryPage(); // autoUtil.exitAutoFactoryPage();
exitAutoFactory(); // exitAutoFactory();
} }
function doWriteMac(fd, recvBuf) { function doWriteMac(fd, recvBuf) {
...@@ -318,7 +321,7 @@ function getCountdownStatus() { ...@@ -318,7 +321,7 @@ function getCountdownStatus() {
} }
function send(fd, cmd) { function send(fd, cmd) {
var cmdBuf = cmd + "\r\r\n\n"; var cmdBuf = cmd + "\r\n";
var len = cmdBuf.length; // 返回 8 var len = cmdBuf.length; // 返回 8
console.log("!!TX:" + cmdBuf + "(len):" + cmdBuf.length); console.log("!!TX:" + cmdBuf + "(len):" + cmdBuf.length);
return uart.uart_send(fd, cmdBuf, len); return uart.uart_send(fd, cmdBuf, len);
......
...@@ -8,7 +8,7 @@ var handleSNDataBinFile = require("handleSNDataBinFile.js"); ...@@ -8,7 +8,7 @@ var handleSNDataBinFile = require("handleSNDataBinFile.js");
var router = require("@system.router"); var router = require("@system.router");
var bglight = require("bglight.js"); var bglight = require("bglight.js");
var envTemp = require("environmentTemperature.js"); var envTemp = require("environmentTemperature.js");
var resultsWifiList = "null"; var resultsWifiList = [];
var SECURE_APP_PATH = "/mnt/app/eOpteeCtrl" var SECURE_APP_PATH = "/mnt/app/eOpteeCtrl"
var that; var that;
var scanFlag = true; var scanFlag = true;
...@@ -46,7 +46,7 @@ function checkUsbDeviceExist() { ...@@ -46,7 +46,7 @@ function checkUsbDeviceExist() {
// /sys/devices/platform/soc@3000000/4200000.ehci1-controller/usb1/1-1doOtg // /sys/devices/platform/soc@3000000/4200000.ehci1-controller/usb1/1-1doOtg
var usbPath = "/sys/devices/platform/soc@3000000/4200000.ehci1-controller/usb1/1-1" var usbPath = "/sys/devices/platform/soc@3000000/4200000.ehci1-controller/usb1/1-1"
var ret = devExist(usbPath); var ret = devExist(usbPath);
// console.log("checkUsbDeviceExist ret: " + ret) // console.log("checkUsbDeviceExist ret: " + ret)
if (devExist(usbPath)) return true if (devExist(usbPath)) return true
return false; return false;
} }
...@@ -100,46 +100,36 @@ function startWifiScan() { ...@@ -100,46 +100,36 @@ function startWifiScan() {
} }
var checkSsidName = "null" var checkSsidName = "null"
function getCheckSsid() {
return checkSsidName
function setSsid(value) {
checkSsidName = value
} }
function setCheckSsid(value) { function getssid() {
checkSsidName = value; return checkSsidName;
} }
function AnalyzeATSearchSsid(value) { function AnalyzeATSearchSsid(value) {
// AT+DUT_START=Midea_test\r\r\n\n if (!value) return '';
let line = value; // 1. 只取第一行
const firstLine = value.split(/[\r\n]/)[0];
/* 1. 只有出现 \r 或 \n 时才去删,否则保持原样 */ // 2. 去掉首尾不可见字符
if (/(?:\r|\n)/.test(line)) { const line = firstLine.replace(/[^\x20-\x7E]/g, '').trim();
line = line.replace(/[\r\n]/g, '');
}
/* 2. 取 SSID */
const prefix = 'AT+DUT_START='; const prefix = 'AT+DUT_START=';
const idx = line.indexOf(prefix); const idx = line.indexOf(prefix);
if (idx === -1) return; // 格式不对直接放弃 if (idx === -1) return '';
return line.slice(idx + prefix.length).trim();
const ssid = line.slice(idx + prefix.length).trim();
setCheckSsid(ssid);
} }
function getWifiScan(value) {
if (!Array.isArray(resultsWifiList) || resultsWifiList.length < 1)
function getWifiScan() { return "FAIL";
// console.log("getWifiScan")
if (resultsWifiList == "null" || resultsWifiList.length == 0)
return "null";
// console.log("getWifiScan--------2")
var result = JSON.stringify(resultsWifiList); var result = JSON.stringify(resultsWifiList);
console.log(result) console.log("getWifiScan" + result)
// var rel = resultsWifiList.map(ap => `${ap.idx},name:${ap.name},rssi:${ap.rssi},mac:${ap.mac}`) console.log("value:" + value)
// .join(';'); var ssid = AnalyzeATSearchSsid(value);
// console.log("!getWifiScan:"+ rel) console.log("check ssid :" + ssid + "------")
// return rel; var found = resultsWifiList.find(ap => ap.name == ssid);
const first = resultsWifiList.find(ap => ap.name == getCheckSsid()); if (found) {
if (first) { return `name:${found.name},rssi:${found.rssi},mac:${found.mac}`;
/* 只要 01 号这一条 */
return `01,name:${first.name},rssi:${first.rssi},mac:${first.mac}`;
} }
else { else {
return "FAIL"; return "FAIL";
...@@ -495,6 +485,7 @@ module.exports = { ...@@ -495,6 +485,7 @@ module.exports = {
initUartPWM: initUartPWM, initUartPWM: initUartPWM,
devExist: devExist, devExist: devExist,
checkUsbDeviceExist: checkUsbDeviceExist, checkUsbDeviceExist: checkUsbDeviceExist,
AnalyzeATSearchSsid: AnalyzeATSearchSsid, getRtcTimer: getRtcTimer,
getRtcTimer: getRtcTimer setSsid: setSsid,
getssid: getssid
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment