Commit 4ec9f1b9 authored by waterword's avatar waterword

feat(factoryTest): 添加软件版本检查功能

- 新增 softVersionEvent 函数用于检查软件版本
- 添加 compareVersionStrings 函数用于比较版本号
- 实现 checkSoftVersion 函数以检查 U 盘中的版本是否更新
- 在 updateSystemInfo 中调用 softVersionEvent 函数
- 优化了部分代码格式和注释
parent e6b6d821
...@@ -4,6 +4,7 @@ var userData = _userdata.userData; ...@@ -4,6 +4,7 @@ var userData = _userdata.userData;
const fs = require("@system.fs"); const fs = require("@system.fs");
var systemCtrl = require("systemCtrl.js"); var systemCtrl = require("systemCtrl.js");
var process = require("@system.process"); var process = require("@system.process");
var file = require("file.js");
var that; var that;
var systemInfoTimer = null; var systemInfoTimer = null;
var systemInfo = {}; var systemInfo = {};
...@@ -15,7 +16,7 @@ function getSystemInfo() { ...@@ -15,7 +16,7 @@ function getSystemInfo() {
// 统一设置颜色 // 统一设置颜色
const textValueKeys = [ const textValueKeys = [
"crtsystemId1_TextValue1", "crtsystemId1_TextValue1",
"crtsystemId1_TextValue2", // "crtsystemId1_TextValue2",
"crtsystemId1_TextValue3", "crtsystemId1_TextValue3",
"crtsystemId1_TextValue4", "crtsystemId1_TextValue4",
"crtsystemId1_TextValue5", "crtsystemId1_TextValue5",
...@@ -35,7 +36,7 @@ const textValueKeys = [ ...@@ -35,7 +36,7 @@ const textValueKeys = [
]; ];
// function setTextColorByValue(that, fullKey, value) { // function setTextColorByValue(that, fullKey, value) {
// const color = (value === "NG") ? "#ff0000" : "#00ff00"; // const color = (value == "NG") ? "#ff0000" : "#00ff00";
// const key = fullKey.replace(/^crt/, ""); // 去掉前缀 "crt" // const key = fullKey.replace(/^crt/, ""); // 去掉前缀 "crt"
// that.$setTextColor(key, color); // that.$setTextColor(key, color);
// } // }
...@@ -48,20 +49,20 @@ let ngCount = 0; ...@@ -48,20 +49,20 @@ let ngCount = 0;
function setTextColorByValue(that, fullKey, value) { function setTextColorByValue(that, fullKey, value) {
// 1. 设置颜色 // 1. 设置颜色
const color = (value === "NG") ? "#ff0000" : "#00ff00"; const color = (value == "NG") ? "#ff0000" : "#00ff00";
const key = fullKey.replace(/^crt/, ""); const key = fullKey.replace(/^crt/, "");
that.$setTextColor(key, color); that.$setTextColor(key, color);
// 2. 更新计数 // 2. 更新计数
checkedCount++; checkedCount++;
if (value === "NG") ngCount++; if (value == "NG") ngCount++;
// 3. 等所有项都检测完再写全局变量 // 3. 等所有项都检测完再写全局变量
//console.log("textValueKeys.length: " + textValueKeys.length + ", checkedCount: " + checkedCount + ", ngCount: " + ngCount) //console.log("textValueKeys.length: " + textValueKeys.length + ", checkedCount: " + checkedCount + ", ngCount: " + ngCount)
//console.log("factoryTestSystemCheck: " + that.factoryTestSystemCheck) //console.log("factoryTestSystemCheck: " + that.factoryTestSystemCheck)
if (checkedCount === textValueKeys.length) { if (checkedCount == textValueKeys.length) {
that.factoryTestSystemCheck = (ngCount === 0) ? 1 : 2; that.factoryTestSystemCheck = (ngCount == 0) ? 1 : 2;
// 重置计数器,方便下次调用 // 重置计数器,方便下次调用
checkedCount = 0; checkedCount = 0;
ngCount = 0; ngCount = 0;
...@@ -147,6 +148,7 @@ function updateSystemInfo() { ...@@ -147,6 +148,7 @@ function updateSystemInfo() {
that.crtsystemId3_TextValue4 = systemInfo.wifiIp; that.crtsystemId3_TextValue4 = systemInfo.wifiIp;
// that.crtsystemId3_TextValue5: "NG", // that.crtsystemId3_TextValue5: "NG",
softVersionEvent();
textValueKeys.forEach(key => { textValueKeys.forEach(key => {
const value = that[key]; const value = that[key];
if (value !== undefined) { if (value !== undefined) {
...@@ -155,24 +157,37 @@ function updateSystemInfo() { ...@@ -155,24 +157,37 @@ function updateSystemInfo() {
}); });
// console.log(` // console.log(`
// 系统信息已更新: // 系统信息已更新:
// 固件版本: ${systemInfo.softwareVersion} // 固件版本: ${systemInfo.softwareVersion}
// 硬件版本: ${systemInfo.hardwareVersion} // 硬件版本: ${systemInfo.hardwareVersion}
// 产测版本: ${systemInfo.factorywareVersion} // 产测版本: ${systemInfo.factorywareVersion}
// CPU温度: ${systemInfo.cpuTemperature} ℃ // CPU温度: ${systemInfo.cpuTemperature} ℃
// CPU频率: ${systemInfo.cpuFrequency} MHz // CPU频率: ${systemInfo.cpuFrequency} MHz
// 存储总容量: ${systemInfo.storageInfo.totalSizeMB} MB // 存储总容量: ${systemInfo.storageInfo.totalSizeMB} MB
// 存储剩余空间: ${systemInfo.storageInfo.totalAvailableMB} MB // 存储剩余空间: ${systemInfo.storageInfo.totalAvailableMB} MB
// WiFi MAC地址: ${systemInfo.wifiMac} // WiFi MAC地址: ${systemInfo.wifiMac}
// SN序列号: ${systemInfo.sn} // SN序列号: ${systemInfo.sn}
// TP固件版本: ${systemInfo.tpVersion} // TP固件版本: ${systemInfo.tpVersion}
// 屏厂家名: ${systemInfo.screenVendor} // 屏厂家名: ${systemInfo.screenVendor}
// WiFi型号: ${systemInfo.wifiModel} // WiFi型号: ${systemInfo.wifiModel}
// License注册状态: ${systemInfo.licenseRegistered} // License注册状态: ${systemInfo.licenseRegistered}
// `); // `);
} }
function softVersionEvent() {
var color = "#ff0000";
var state = checkSoftVersion();
if (!state) {
ngCount++;
color = "#ff0000";
}
else {
color = "#00ff00";
}
console.log("color==" + color)
that.$setTextColor("systemId1_TextValue2", color);
}
// 启动定时器 // 启动定时器
function startSystemInfoTimer(obj) { function startSystemInfoTimer(obj) {
that = obj; that = obj;
...@@ -196,8 +211,40 @@ function stopSystemInfoTimer() { ...@@ -196,8 +211,40 @@ function stopSystemInfoTimer() {
//console.log("定时器未启动"); //console.log("定时器未启动");
} }
} }
function compareVersionStrings(str1, str2) {
// 从字符串中提取数字部分
var num1 = str1.substring(1).split('.').map(Number);
var num2 = str2.substring(1).split('.').map(Number);
console.log("num1=" + num1);
console.log("num2=" + num2);
for (let i = 0; i < num1.length; i++) {
if (num1[i] > num2[i]) {
return 1;
} else if (num1[i] < num2[i]) {
return -1;
}
}
return 0;
}
function checkSoftVersion() {
var obj = file.readBasicPath("../../../../../mnt/exUDISK/swuUpdate/swuVersion.json", "json");
if (obj == undefined) {
console.log("swuVersion.json is not exist!");
return 1;
}
console.log("obj.version=" + obj.version);
var comparativeResult = compareVersionStrings(obj.version, systemInfo.softwareVersion);
console.log("comparativeResult=" + comparativeResult);
if (comparativeResult == 1) {
return 0;//表示U盘里的baner版本号比当前版本号大
}
else {
return 1;
}
}
...@@ -216,7 +263,7 @@ function getWifiInfo(options) { ...@@ -216,7 +263,7 @@ function getWifiInfo(options) {
const line = statusLines[i].trim(); const line = statusLines[i].trim();
if (line.startsWith(switchOption)) { if (line.startsWith(switchOption)) {
const state = line.split('=')[1]; const state = line.split('=')[1];
// if (state === "COMPLETED") { // if (state == "COMPLETED") {
// isConnected = true; // isConnected = true;
// break; // break;
// } // }
...@@ -255,7 +302,7 @@ function getTotalStorageInfo() { ...@@ -255,7 +302,7 @@ function getTotalStorageInfo() {
for (let i = 1; i < lines.length; i++) { // 跳过表头 for (let i = 1; i < lines.length; i++) { // 跳过表头
const line = lines[i].trim(); const line = lines[i].trim();
if (line === "") continue; if (line == "") continue;
const parts = line.split(/\s+/); const parts = line.split(/\s+/);
if (parts.length < 6) continue; if (parts.length < 6) continue;
...@@ -341,7 +388,7 @@ function getScreenVendor() { ...@@ -341,7 +388,7 @@ function getScreenVendor() {
const vendorStr = fs.read("/tmp/tp_id.txt", "r"); const vendorStr = fs.read("/tmp/tp_id.txt", "r");
if (vendorStr) { if (vendorStr) {
const trimmedVendorStr = vendorStr.trim(); const trimmedVendorStr = vendorStr.trim();
console.log(`Screen Vendor: ${trimmedVendorStr}`); console.log(`Screen Vendor: ${trimmedVendorStr}`);
return trimmedVendorStr; return trimmedVendorStr;
} else { } else {
......
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