Building an ASTM ACK with a Mod-256 Checksum¶
ASTM frames carry a mod-256 checksum encoded as two uppercase hex characters between the ETX (end-of-block) marker and the trailing CR/LF. QIE's Socket (ASTM) Receiver leaves that calculation and the response framing to the channel, so you produce the response bytes in a mapping or destination script and hand them back through qie.postMessageResponse.
Source-side configuration¶
On the Socket (ASTM) Receiver, set Response to From Mapping or Destination node. With this option, QIE sends back only what your script explicitly returns; otherwise it would auto-acknowledge with its defaults.
Checksum helper¶
A standard mod-256 checksum implementation in JavaScript:
function calcASTMChecksum(input) {
var sum = 0;
for (var i = 0; i < input.length; i++) {
sum += input.charCodeAt(i);
if (sum & 0x80) {
sum = (0xff - sum + 1) * -1;
}
}
sum = sum % 256;
if (sum < 0) sum *= -1;
var hex = sum.toString(16).toUpperCase();
return hex.length === 1 ? '0' + hex : hex;
}
The function returns a two-character uppercase hex string suitable for splicing into an ASTM frame between the ETX marker and the CR/LF terminator.
Sending a response¶
Build the response bytes in a mapping or destination script and call qie.postMessageResponse(bytes) to send them back over the open socket. The exact frame layout (STX, frame number, content, ETX/ETB, checksum, CR LF) depends on the analyzer's ASTM implementation. Consult the device's specification, then use the helper above to compute the checksum over the bytes between STX and ETX.
Caveats¶
- Mapping or destination response only. When the source is set to respond from a mapping or destination node, QIE does not send any reply unless your script calls
qie.postMessageResponse. If the script throws before that call, the analyzer may time out. - Mod-256, not CRC. Some lab integrations call their checksum "CRC" colloquially, the ASTM standard uses a plain mod-256 sum, not a CRC polynomial. Use this helper, not a
crc16-style function, unless the analyzer documents a non-standard variant.