icom-wlan-node
Version:
Icom WLAN (CI‑V, audio) protocol implementation for Node.js/TypeScript.
57 lines (56 loc) • 1.84 kB
JavaScript
;
// Byte order helpers for Icom packet formats
// Note: These now use CORRECT naming (be = Big-Endian, le = Little-Endian)
Object.defineProperty(exports, "__esModule", { value: true });
exports.le32 = exports.le16 = exports.be32 = exports.be16 = void 0;
exports.shortToBytesLE = shortToBytesLE;
exports.shortToBytesBE = shortToBytesBE;
exports.intToBytesLE = intToBytesLE;
exports.intToBytesBE = intToBytesBE;
exports.strToFixedBytes = strToFixedBytes;
exports.hex = hex;
exports.be16 = {
read: (buf, off) => buf.readUInt16BE(off), // Big-Endian: high byte first
write: (buf, off, v) => buf.writeUInt16BE(v & 0xffff, off)
};
exports.be32 = {
read: (buf, off) => buf.readUInt32BE(off), // Big-Endian: high byte first
write: (buf, off, v) => buf.writeUInt32BE(v >>> 0, off)
};
exports.le16 = {
read: (buf, off) => buf.readUInt16LE(off), // Little-Endian: low byte first
write: (buf, off, v) => buf.writeUInt16LE(v & 0xffff, off)
};
exports.le32 = {
read: (buf, off) => buf.readUInt32LE(off), // Little-Endian: low byte first
write: (buf, off, v) => buf.writeUInt32LE(v >>> 0, off)
};
function shortToBytesLE(n) {
const b = Buffer.alloc(2);
exports.le16.write(b, 0, n);
return b;
}
function shortToBytesBE(n) {
const b = Buffer.alloc(2);
exports.be16.write(b, 0, n);
return b;
}
function intToBytesLE(n) {
const b = Buffer.alloc(4);
exports.le32.write(b, 0, n);
return b;
}
function intToBytesBE(n) {
const b = Buffer.alloc(4);
exports.be32.write(b, 0, n);
return b;
}
function strToFixedBytes(str, len) {
const out = Buffer.alloc(len, 0);
const src = Buffer.from(str, 'utf8');
src.copy(out, 0, 0, Math.min(len, src.length));
return out;
}
function hex(buf) {
return [...buf].map(b => b.toString(16).padStart(2, '0')).join(' ');
}