English
AN-26112403 · Parse telemetry, read back parameters and confirm a retry with tklHelper
A CJ188 cold-water meter reports flow on FPort 22 and returns configuration on FPort 214. When the operator sets a 23-minute sampling period, the receiving model must compare the new reading and the requested value in the same unit.
1. Read the meter
The model first validates a measurement frame of at least 23 bytes. The frame tag is 87 03. The following excerpt reads the four little-endian BCD bytes starting at offset 17. The full meter model also handles faults and missing responses.
js
const frameInfo = {
port: 22,
dataLen: -1,
tagList: [{ index: 0, tag: 0x87 }, { index: 1, tag: 0x03 }]
};
const appInfo = [{
field_name: 'totalflow', index: 17, type: 'bcdLE4',
coefficient: 0.01, decimal: 2
}];
const parser = new PayloadParser({ device, msg, frameInfo, appInfo });
const fields = parser.telemetry();
const measurement = parser.telemetryAfter(fields);
return measurement == null ? {} : { telemetry_data: measurement };Keep the parser instance for both calls. The first returns fields and the second assembles the business object. Four zero bytes produce totalflow: 0. Test for missing values with value == null so zero and boolean false remain valid.
2. Read the current sampling period
On FPort 214 the meter returns APP70 as a four-byte little-endian unsigned integer in seconds. The model and RPC agree to compare minutes.
js
const paraInfo = {
app_70: { field_name: 'period', type: 'uint32LE' }
};
const parser = new PayloadParser({ device, msg, paraInfo });
const fields = parser.paras();
const parameters = parser.parasAfter(fields);
if (parameters?.period == null) return {};
return { shared_attrs: { period: parameters.period / 60 } };The wire value 64 05 00 00 is 1380 seconds. Convert it to 23 minutes before returning it in shared_attrs. The full meter model also reports the parameter in telemetry.
3. Match feedback to the active command
| Step | Entry point | Contract |
|---|---|---|
| Internal callback reaches the setting RPC | RetryHelper.dispatch({ device, params, rpcName, logger }) | When handled, return its actions immediately. This callback reuses the original downlink. |
| User requests a change | RPCHelper.makeParaSetPlan(...) | Supply the actual device, RPC and feedback model names, encoded write/read buffer, expected business values, data domain and retry budget. Return the plan’s actions. This example expects minutes in Utils.dataType.shared. |
| Feedback reaches the receiving model | RetryHelper.finishTelemetry(...) | Pass this message’s result, device, message and receiving model name. Return the whole result to retain updates and actions. |
If a command carries additional reply definitions, RetryHelper.getTelemetryContext supplies the current queue head’s parsing context. Parse the packet, then call RetryHelper.parseTelemetry({ context, data, failure }) and include the returned item in the parsedData passed to finishTelemetry. When the current packet already yields the expected mapped values in the requested domain, use them directly. Historical attributes cannot fill a missing field.
The retry count is the number of resends after the initial transmission, from 0 through 5. Class C uses timed checks and one command deadline. Class A waits for an eligible device uplink and has a feedback window for each round. A link ACK alone cannot confirm the setting.
4. Follow one command from request to confirmation
The local replay used cj188_coolwater_set_23103 and cj188_coolwater_para_23103 with a Class C device fixture, two allowed retries, a 5000 ms interval and a 60000 ms deadline. The following payloads are decoded hexadecimal bytes. The platform receives Base64 in msg.userdata.payload.
| Step | Input | Observed result |
|---|---|---|
| 1 | FPort 22, 23 bytes starting with 87 03, followed by zeros | comm_state = OK, totalflow = 0. |
| 2 | Request period = 23 minutes | Initial downlink, then WAIT_FEEDBACK. |
| 3 | FPort 214, 2f032201022f042602e8032f06460417000000 | 23 seconds is 23/60 minutes. The command stays in WAIT_FEEDBACK. |
| 4 | First check at five seconds | One resend. Replaying the same callback produces zero additional downlinks. |
| 5 | FPort 214, 2f032201022f042602e8032f06460464050000 | 1380 seconds is 23 minutes. The remaining target fields also match. The state becomes CONFIRMED_PARAMETER and the retry record is cleared. |
All 14 upstream local replay checks passed. Installation on the target host and physical meter behavior require separate verification.