draft commit to make null is possible to send

This commit is contained in:
2026-07-06 11:04:30 +05:00
parent 3c94cd92c1
commit fe9e7b5438
2 changed files with 6 additions and 22 deletions

View File

@@ -36,10 +36,10 @@ type Edge5ModbusV3Metric = {
edge: string edge: string
timestamp: string timestamp: string
tag: string tag: string
value: number value: number | null
} }
function toFloatCDAB(reg0: number, reg1: number): number { function toFloatCDAB(reg0: number, reg1: number): number | null {
const buf = Buffer.allocUnsafe(4) const buf = Buffer.allocUnsafe(4)
buf.writeUInt16BE(reg1, 0) buf.writeUInt16BE(reg1, 0)
buf.writeUInt16BE(reg0, 2) buf.writeUInt16BE(reg0, 2)
@@ -63,16 +63,7 @@ function toMetrics(values: number[], timestamp: string): Edge5ModbusV3Metric[] {
for (let i = 0; i < values.length; i += 2) { for (let i = 0; i < values.length; i += 2) {
const tag = TAGS[i / 2] const tag = TAGS[i / 2]
const value = toFloatCDAB(values[i], values[i + 1]) const value = toFloatCDAB(values[i], values[i + 1]); // null is possible to send
if (isNaN(value)) {
if (CLOUD_INGEST_TAGS.has(tag)) {
log(
`edge5.modbus.v3: не удалось собрать число для ${tag}, ` +
`исходные values[${i}]=${values[i]}, values[${i + 1}]=${values[i + 1]}, пропуск`,
)
}
continue
}
metrics.push({ metrics.push({
edge: EDGE, edge: EDGE,

View File

@@ -9,10 +9,10 @@ type Edge5iiModbusMetric = {
edge: string edge: string
timestamp: string timestamp: string
tag: string tag: string
value: number value: number | null
}; };
function toFloatCDAB(reg0: number, reg1: number): number { function toFloatCDAB(reg0: number, reg1: number): number | null {
const buf = Buffer.allocUnsafe(4) const buf = Buffer.allocUnsafe(4)
buf.writeUInt16BE(reg1, 0) buf.writeUInt16BE(reg1, 0)
buf.writeUInt16BE(reg0, 2) buf.writeUInt16BE(reg0, 2)
@@ -36,14 +36,7 @@ function toMetrics(values: number[], timestamp: string): Edge5iiModbusMetric[] {
for (let i = 0; i < values.length; i += 2) { for (let i = 0; i < values.length; i += 2) {
const tag = `register-${String(i).padStart(3, '0')}` const tag = `register-${String(i).padStart(3, '0')}`
const value = toFloatCDAB(values[i], values[i + 1]) const value = toFloatCDAB(values[i], values[i + 1]); // null is possible to send
if (isNaN(value)) {
log(
`${EDGE}.modbus: не удалось собрать число для ${tag}, ` +
`исходные values[${i}]=${values[i]}, values[${i + 1}]=${values[i + 1]}, пропуск`,
)
continue
};
metrics.push({ metrics.push({
edge: EDGE, edge: EDGE,