Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 17 additions & 30 deletions src/adapter/deconz/driver/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -997,14 +997,10 @@ class Driver extends events.EventEmitter {

const payload = Buffer.alloc(7);
let pos = 0;
payload.writeUInt8(zdpSeq, pos);
pos += 1;
payload.writeUInt32LE(scanChannels, pos);
pos += 4;
payload.writeUInt8(scanDuration, pos);
pos += 1;
payload.writeUInt8(this.paramNwkUpdateId, pos);
pos += 1;
pos = payload.writeUInt8(zdpSeq, pos);
pos = payload.writeUInt32LE(scanChannels, pos);
pos = payload.writeUInt8(scanDuration, pos);
pos = payload.writeUInt8(this.paramNwkUpdateId, pos);

const req: ApsDataRequest = {
requestId: this.nextTransactionID(),
Expand Down Expand Up @@ -1099,45 +1095,36 @@ class Driver extends events.EventEmitter {

const buf = Buffer.alloc(128);
let pos = 0;
buf.writeUInt8(FirmwareCommand.WriteParameter, pos);
pos += 1;
buf.writeUInt8(seqNumber, pos);
pos += 1;
buf.writeUInt8(0, pos); // status: not used
pos += 1;
pos = buf.writeUInt8(FirmwareCommand.WriteParameter, pos);
pos = buf.writeUInt8(seqNumber, pos);
pos = buf.writeUInt8(0, pos); // status: not used

const posFrameLength = pos; // remember
buf.writeUInt16LE(0, pos); // dummy frame length
pos += 2;

pos = buf.writeUInt16LE(0, pos); // dummy frame length
// -------------- actual data ---------------------------------------
const posPayloadLength = pos; // remember
buf.writeUInt16LE(0, pos); // dummy payload length
pos += 2;
buf.writeUInt8(parameterId, pos);
pos += 1;

pos = buf.writeUInt16LE(0, pos); // dummy payload length
pos = buf.writeUInt8(parameterId, pos);

if (value instanceof Buffer) {
for (let i = 0; i < value.length; i++) {
buf.writeUInt8(value[i], pos);
pos += 1;
pos = buf.writeUInt8(value[i], pos);
}
} else if (typeof value === "number") {
if (param.type === DataType.U8) {
buf.writeUInt8(value, pos);
pos += 1;
pos = buf.writeUInt8(value, pos);
} else if (param.type === DataType.U16) {
buf.writeUInt16LE(value, pos);
pos += 2;
pos = buf.writeUInt16LE(value, pos);
} else if (param.type === DataType.U32) {
buf.writeUInt32LE(value, pos);
pos += 4;
pos = buf.writeUInt32LE(value, pos);
} else {
throw new Error("tried to write unknown parameter number type");
}
} else if (typeof value === "bigint") {
if (param.type === DataType.U64) {
buf.writeBigUInt64LE(value, pos);
pos += 8;
pos = buf.writeBigUInt64LE(value, pos);
} else {
throw new Error("tried to write unknown parameter number type");
}
Expand Down
12 changes: 5 additions & 7 deletions src/adapter/ember/adapter/tokensManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,9 @@ export class EmberTokensManager {

if (tiStatus === SLStatus.OK) {
const outputToken = Buffer.alloc(4 + 1 + 1 + tokenInfo.size * tokenInfo.arraySize);
outputToken.writeUInt32LE(tokenInfo.nvm3Key, writeOffset); // 4 bytes
writeOffset += 4;
outputToken.writeUInt8(tokenInfo.size, writeOffset++); // 1 byte
outputToken.writeUInt8(tokenInfo.arraySize, writeOffset++); // 1 byte
writeOffset = outputToken.writeUInt32LE(tokenInfo.nvm3Key, writeOffset); // 4 bytes
writeOffset = outputToken.writeUInt8(tokenInfo.size, writeOffset); // 1 byte
writeOffset = outputToken.writeUInt8(tokenInfo.arraySize, writeOffset); // 1 byte

for (let arrayIndex = 0; arrayIndex < tokenInfo.arraySize; arrayIndex++) {
const [tdStatus, tokenData] = await ezsp.ezspGetTokenData(tokenInfo.nvm3Key, arrayIndex);
Expand Down Expand Up @@ -391,12 +390,11 @@ export class EmberTokensManager {
tokenData.data.equals(BLANK_EUI64_BUF)
) {
// Special case : Save the node EUI64 on the restoredEui64 token while saving.
tokenData.data.set(localEui64);
localEui64.copy(tokenData.data);
logger.debug("[TOKENS] Saved node EUI64 in place of blank RESTORED EUI64.", NS);
}

outputToken.set(tokenData.data, writeOffset);
writeOffset += tokenData.size;
writeOffset += tokenData.data.copy(outputToken, writeOffset);
} else {
logger.error(`[TOKENS] Failed to get token data at index ${arrayIndex} with status=${SLStatus[tdStatus]}.`, NS);
}
Expand Down
6 changes: 2 additions & 4 deletions src/adapter/zigate/adapter/patchZdoBuffaloBE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import {BuffaloZdo} from "../../../zspec/zdo/buffaloZdo";

class ZiGateZdoBuffalo extends BuffaloZdo {
public override writeUInt16(value: number): void {
this.buffer.writeUInt16BE(value, this.position);
this.position += 2;
this.position = this.buffer.writeUInt16BE(value, this.position);
}

public override writeUInt32(value: number): void {
this.buffer.writeUInt32BE(value, this.position);
this.position += 4;
this.position = this.buffer.writeUInt32BE(value, this.position);
}

public override writeIeeeAddr(value: string /*TODO: EUI64*/): void {
Expand Down
6 changes: 2 additions & 4 deletions src/adapter/zigate/driver/buffaloZiGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ class BuffaloZiGate extends Buffalo {
return value;
}
public writeUInt16BE(value: number): void {
this.buffer.writeUInt16BE(value, this.position);
this.position += 2;
this.position = this.buffer.writeUInt16BE(value, this.position);
}

public readUInt32BE(): number {
Expand All @@ -181,8 +180,7 @@ class BuffaloZiGate extends Buffalo {
return value;
}
public writeUInt32BE(value: number): void {
this.buffer.writeUInt32BE(value, this.position);
this.position += 4;
this.position = this.buffer.writeUInt32BE(value, this.position);
}

public readListUInt16BE(length: number): number[] {
Expand Down
58 changes: 20 additions & 38 deletions src/buffalo/buffalo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export class Buffalo {
}

public writeUInt8(value: number): void {
this.buffer.writeUInt8(value, this.position);
this.position++;
this.position = this.buffer.writeUInt8(value, this.position);
}

public readUInt8(): number {
Expand All @@ -46,8 +45,7 @@ export class Buffalo {
}

public writeUInt16(value: number): void {
this.buffer.writeUInt16LE(value, this.position);
this.position += 2;
this.position = this.buffer.writeUInt16LE(value, this.position);
}

public readUInt16(): number {
Expand All @@ -57,8 +55,7 @@ export class Buffalo {
}

public writeUInt24(value: number): void {
this.buffer.writeUIntLE(value, this.position, 3);
this.position += 3;
this.position = this.buffer.writeUIntLE(value, this.position, 3);
}

public readUInt24(): number {
Expand All @@ -68,8 +65,7 @@ export class Buffalo {
}

public writeUInt32(value: number): void {
this.buffer.writeUInt32LE(value, this.position);
this.position += 4;
this.position = this.buffer.writeUInt32LE(value, this.position);
}

public readUInt32(): number {
Expand All @@ -79,8 +75,7 @@ export class Buffalo {
}

public writeUInt40(value: number): void {
this.buffer.writeUIntLE(value, this.position, 5);
this.position += 5;
this.position = this.buffer.writeUIntLE(value, this.position, 5);
}

public readUInt40(): number {
Expand All @@ -90,8 +85,7 @@ export class Buffalo {
}

public writeUInt48(value: number): void {
this.buffer.writeUIntLE(value, this.position, 6);
this.position += 6;
this.position = this.buffer.writeUIntLE(value, this.position, 6);
}

public readUInt48(): number {
Expand All @@ -101,9 +95,8 @@ export class Buffalo {
}

public writeUInt56(value: bigint): void {
this.buffer.writeUIntLE(Number(value & 0xffffffffffffn), this.position, 6);
this.buffer.writeUInt8(Number(value >> 48n), this.position + 6);
this.position += 7;
this.position = this.buffer.writeUIntLE(Number(value & 0xffffffffffffn), this.position, 6);
this.position = this.buffer.writeUInt8(Number(value >> 48n), this.position);
}

public readUInt56(): bigint {
Expand All @@ -114,8 +107,7 @@ export class Buffalo {
}

public writeUInt64(value: bigint): void {
this.buffer.writeBigUInt64LE(value, this.position);
this.position += 8;
this.position = this.buffer.writeBigUInt64LE(value, this.position);
}

public readUInt64(): bigint {
Expand All @@ -125,8 +117,7 @@ export class Buffalo {
}

public writeInt8(value: number): void {
this.buffer.writeInt8(value, this.position);
this.position++;
this.position = this.buffer.writeInt8(value, this.position);
}

public readInt8(): number {
Expand All @@ -136,8 +127,7 @@ export class Buffalo {
}

public writeInt16(value: number): void {
this.buffer.writeInt16LE(value, this.position);
this.position += 2;
this.position = this.buffer.writeInt16LE(value, this.position);
}

public readInt16(): number {
Expand All @@ -147,8 +137,7 @@ export class Buffalo {
}

public writeInt24(value: number): void {
this.buffer.writeIntLE(value, this.position, 3);
this.position += 3;
this.position = this.buffer.writeIntLE(value, this.position, 3);
}

public readInt24(): number {
Expand All @@ -158,8 +147,7 @@ export class Buffalo {
}

public writeInt32(value: number): void {
this.buffer.writeInt32LE(value, this.position);
this.position += 4;
this.position = this.buffer.writeInt32LE(value, this.position);
}

public readInt32(): number {
Expand All @@ -169,8 +157,7 @@ export class Buffalo {
}

public writeInt40(value: number): void {
this.buffer.writeIntLE(value, this.position, 5);
this.position += 5;
this.position = this.buffer.writeIntLE(value, this.position, 5);
}

public readInt40(): number {
Expand All @@ -180,8 +167,7 @@ export class Buffalo {
}

public writeInt48(value: number): void {
this.buffer.writeIntLE(value, this.position, 6);
this.position += 6;
this.position = this.buffer.writeIntLE(value, this.position, 6);
}

public readInt48(): number {
Expand All @@ -192,9 +178,8 @@ export class Buffalo {

public writeInt56(value: bigint): void {
const unsignedValue = value < 0n ? (1n << 56n) + value : value;
this.buffer.writeUIntLE(Number(unsignedValue & 0xffffffffffffn), this.position, 6);
this.buffer.writeUInt8(Number(unsignedValue >> 48n), this.position + 6);
this.position += 7;
this.position = this.buffer.writeUIntLE(Number(unsignedValue & 0xffffffffffffn), this.position, 6);
this.position = this.buffer.writeUInt8(Number(unsignedValue >> 48n), this.position);
}

public readInt56(): bigint {
Expand All @@ -209,8 +194,7 @@ export class Buffalo {
}

public writeInt64(value: bigint): void {
this.buffer.writeBigInt64LE(value, this.position);
this.position += 8;
this.position = this.buffer.writeBigInt64LE(value, this.position);
}

public readInt64(): bigint {
Expand All @@ -220,8 +204,7 @@ export class Buffalo {
}

public writeFloatLE(value: number): void {
this.buffer.writeFloatLE(value, this.position);
this.position += 4;
this.position = this.buffer.writeFloatLE(value, this.position);
}

public readFloatLE(): number {
Expand All @@ -231,8 +214,7 @@ export class Buffalo {
}

public writeDoubleLE(value: number): void {
this.buffer.writeDoubleLE(value, this.position);
this.position += 8;
this.position = this.buffer.writeDoubleLE(value, this.position);
}

public readDoubleLE(): number {
Expand Down
3 changes: 1 addition & 2 deletions src/zspec/zcl/buffaloZcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,7 @@ export class BuffaloZcl extends Buffalo {
}

private writeBigEndianUInt24(value: number): void {
this.buffer.writeUIntBE(value, this.position, 3);
this.position += 3;
this.position = this.buffer.writeUIntBE(value, this.position, 3);
}

private readBigEndianUInt24(): number {
Expand Down