fix: 配置页频率/峰峰值前端显示与DB原始值双向转换
根据 DPG430 串口协议: - 频率 f(Hz) = 10 * X, X 为 DB/设备原始值 - 峰峰值 V = ((X*3.3)/4095)*4, X 为正整数 前端 fixture.js 和 vehicle_base_test.js 增加转换层: - 显示: raw X → f(Hz) / V(V)(fillFormFromParam、renderTable、openModal) - 保存: f(Hz)/V(V) → raw X(getFormParams、saveRecord) DB 已存原始值无需迁移,后端 build_4b_packet 透传原始值无需改。
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
// 工装配置页
|
||||
|
||||
// ─── 频率/峰峰值转换常量 ─────────────────────
|
||||
// 协议: 工作频率 f(Hz) = 10 * X, X 为 DB/设备中存储和传输的原始值
|
||||
// 协议: 峰峰值 V = ((X * 3.3) / 4095) * 4, X 为 DB/设备中存储和传输的原始值(正整数)
|
||||
const FREQ_SCALE = 10;
|
||||
const PEAK_SCALE = 4095 / (4 * 3.3); // ≈ 310.227
|
||||
|
||||
function rawFreqToHz(x) { return x * FREQ_SCALE; }
|
||||
function hzToRawFreq(hz) { return Math.round(hz / FREQ_SCALE); }
|
||||
function rawPeakToV(x) { return parseFloat(((x * 3.3) / 4095 * 4).toFixed(2)); }
|
||||
function vToRawPeak(v) { return Math.round(v * PEAK_SCALE); }
|
||||
|
||||
let baseTests = []; // 所有车检器基准参数
|
||||
let selectedBaseTest = null;
|
||||
let pollTimer4C = null; // 0x4C 参数查询轮询
|
||||
@@ -82,8 +93,8 @@ function renderBaseTestTable() {
|
||||
<td>${t.type_num}</td>
|
||||
<td>${esc(t.dev_name)}</td>
|
||||
<td>${t.SensMin}~${t.SensMax}</td>
|
||||
<td>${t.FreMin}~${t.FreMax}</td>
|
||||
<td>${t.PeakMin}~${t.PeakMax}</td>
|
||||
<td>${rawFreqToHz(t.FreMin)}~${rawFreqToHz(t.FreMax)}</td>
|
||||
<td>${rawPeakToV(t.PeakMin)}~${rawPeakToV(t.PeakMax)}</td>
|
||||
</tr>
|
||||
`).join("");
|
||||
}
|
||||
@@ -108,10 +119,10 @@ function fillFromBaseTest(t) {
|
||||
document.getElementById("param-dev-type").value = t.type_num;
|
||||
document.getElementById("param-sens-min").value = t.SensMin;
|
||||
document.getElementById("param-sens-max").value = t.SensMax;
|
||||
document.getElementById("param-fre-min").value = t.FreMin;
|
||||
document.getElementById("param-fre-max").value = t.FreMax;
|
||||
document.getElementById("param-peak-min").value = t.PeakMin;
|
||||
document.getElementById("param-peak-max").value = t.PeakMax;
|
||||
document.getElementById("param-fre-min").value = rawFreqToHz(t.FreMin);
|
||||
document.getElementById("param-fre-max").value = rawFreqToHz(t.FreMax);
|
||||
document.getElementById("param-peak-min").value = rawPeakToV(t.PeakMin);
|
||||
document.getElementById("param-peak-max").value = rawPeakToV(t.PeakMax);
|
||||
}
|
||||
|
||||
function onDevTypeChange() {
|
||||
@@ -202,10 +213,10 @@ function fillFormFromParam(param) {
|
||||
document.getElementById("param-dev-type").value = param.DevType || 0;
|
||||
document.getElementById("param-sens-min").value = param.SensMin || 0;
|
||||
document.getElementById("param-sens-max").value = param.SensMax || 0;
|
||||
document.getElementById("param-fre-min").value = param.FreMin || 0;
|
||||
document.getElementById("param-fre-max").value = param.FreMax || 0;
|
||||
document.getElementById("param-peak-min").value = param.PeakMin || 0;
|
||||
document.getElementById("param-peak-max").value = param.PeakMax || 0;
|
||||
document.getElementById("param-fre-min").value = rawFreqToHz(param.FreMin || 0);
|
||||
document.getElementById("param-fre-max").value = rawFreqToHz(param.FreMax || 0);
|
||||
document.getElementById("param-peak-min").value = rawPeakToV(param.PeakMin || 0);
|
||||
document.getElementById("param-peak-max").value = rawPeakToV(param.PeakMax || 0);
|
||||
document.getElementById("param-far-tol").value = (param.FarTol || 0) * 10;
|
||||
document.getElementById("param-near-tol").value = (param.NearTol || 0) * 10;
|
||||
document.getElementById("param-step-tol").value = (param.StepTol || 0) * 10;
|
||||
@@ -299,10 +310,10 @@ function getFormParams() {
|
||||
minus_dis: Math.round((parseInt(document.getElementById("param-minus-dis").value) || 0) / 10),
|
||||
sens_min: parseInt(document.getElementById("param-sens-min").value) || 0,
|
||||
sens_max: parseInt(document.getElementById("param-sens-max").value) || 0,
|
||||
fre_min: parseInt(document.getElementById("param-fre-min").value) || 0,
|
||||
fre_max: parseInt(document.getElementById("param-fre-max").value) || 0,
|
||||
peak_min: parseInt(document.getElementById("param-peak-min").value) || 0,
|
||||
peak_max: parseInt(document.getElementById("param-peak-max").value) || 0,
|
||||
fre_min: hzToRawFreq(parseFloat(document.getElementById("param-fre-min").value) || 0),
|
||||
fre_max: hzToRawFreq(parseFloat(document.getElementById("param-fre-max").value) || 0),
|
||||
peak_min: vToRawPeak(parseFloat(document.getElementById("param-peak-min").value) || 0),
|
||||
peak_max: vToRawPeak(parseFloat(document.getElementById("param-peak-max").value) || 0),
|
||||
far_tol: Math.round((parseInt(document.getElementById("param-far-tol").value) || 0) / 10),
|
||||
near_tol: Math.round((parseInt(document.getElementById("param-near-tol").value) || 0) / 10),
|
||||
step_tol: Math.round((parseInt(document.getElementById("param-step-tol").value) || 0) / 10),
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
// 车检器测试基准参数管理
|
||||
|
||||
// ─── 频率/峰峰值转换常量 ─────────────────────
|
||||
// 协议: 工作频率 f(Hz) = 10 * X, X 为 DB/设备中存储和传输的原始值
|
||||
// 协议: 峰峰值 V = ((X * 3.3) / 4095) * 4, X 为 DB/设备中存储和传输的原始值(正整数)
|
||||
const FREQ_SCALE = 10;
|
||||
const PEAK_SCALE = 4095 / (4 * 3.3); // ≈ 310.227
|
||||
|
||||
function rawFreqToHz(x) { return x * FREQ_SCALE; }
|
||||
function hzToRawFreq(hz) { return Math.round(hz / FREQ_SCALE); }
|
||||
function rawPeakToV(x) { return parseFloat(((x * 3.3) / 4095 * 4).toFixed(2)); }
|
||||
function vToRawPeak(v) { return Math.round(v * PEAK_SCALE); }
|
||||
|
||||
let editId = null; // null=新增, number=编辑
|
||||
|
||||
// ─── Toast ───────────────────────────────────
|
||||
@@ -36,8 +47,8 @@ function renderTable(data) {
|
||||
<td>${t.type_num}</td>
|
||||
<td>${esc(t.dev_name)}</td>
|
||||
<td>${t.SensMin} ~ ${t.SensMax}</td>
|
||||
<td>${t.FreMin} ~ ${t.FreMax}</td>
|
||||
<td>${t.PeakMin} ~ ${t.PeakMax}</td>
|
||||
<td>${rawFreqToHz(t.FreMin)} ~ ${rawFreqToHz(t.FreMax)}</td>
|
||||
<td>${rawPeakToV(t.PeakMin)} ~ ${rawPeakToV(t.PeakMax)}</td>
|
||||
<td>${esc(t.remark || '-')}</td>
|
||||
<td>
|
||||
<button class="btn-edit" onclick="openModal(${t.id})">编辑</button>
|
||||
@@ -63,10 +74,10 @@ function openModal(id = null) {
|
||||
document.getElementById("edit-dev-name").value = data.dev_name;
|
||||
document.getElementById("edit-sens-min").value = data.SensMin;
|
||||
document.getElementById("edit-sens-max").value = data.SensMax;
|
||||
document.getElementById("edit-fre-min").value = data.FreMin;
|
||||
document.getElementById("edit-fre-max").value = data.FreMax;
|
||||
document.getElementById("edit-peak-min").value = data.PeakMin;
|
||||
document.getElementById("edit-peak-max").value = data.PeakMax;
|
||||
document.getElementById("edit-fre-min").value = rawFreqToHz(data.FreMin);
|
||||
document.getElementById("edit-fre-max").value = rawFreqToHz(data.FreMax);
|
||||
document.getElementById("edit-peak-min").value = rawPeakToV(data.PeakMin);
|
||||
document.getElementById("edit-peak-max").value = rawPeakToV(data.PeakMax);
|
||||
document.getElementById("edit-remark").value = data.remark || "";
|
||||
});
|
||||
} else {
|
||||
@@ -96,10 +107,10 @@ async function saveRecord() {
|
||||
dev_name: document.getElementById("edit-dev-name").value.trim(),
|
||||
SensMin: parseInt(document.getElementById("edit-sens-min").value) || 0,
|
||||
SensMax: parseInt(document.getElementById("edit-sens-max").value) || 0,
|
||||
FreMin: parseInt(document.getElementById("edit-fre-min").value) || 0,
|
||||
FreMax: parseInt(document.getElementById("edit-fre-max").value) || 0,
|
||||
PeakMin: parseInt(document.getElementById("edit-peak-min").value) || 0,
|
||||
PeakMax: parseInt(document.getElementById("edit-peak-max").value) || 0,
|
||||
FreMin: hzToRawFreq(parseFloat(document.getElementById("edit-fre-min").value) || 0),
|
||||
FreMax: hzToRawFreq(parseFloat(document.getElementById("edit-fre-max").value) || 0),
|
||||
PeakMin: vToRawPeak(parseFloat(document.getElementById("edit-peak-min").value) || 0),
|
||||
PeakMax: vToRawPeak(parseFloat(document.getElementById("edit-peak-max").value) || 0),
|
||||
remark: document.getElementById("edit-remark").value.trim(),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user