dufourgilles / knx-ip

KNX IP Gateway protocol implementation
30 stars 9 forks source link

writeAsync force sixBits to false #20

Closed RealByron closed 7 months ago

RealByron commented 1 year ago

Hi there, Thank you for your project . I didn't find a way to specify how to construct a KNXDataBuffer for values less or more that 6 bits values I would like to force value to be xrite in additionnal byte like DPT5 for example

Could you give me some hints ?

    buf = new KNXDataBuffer(Buffer.from([32]));
    await knxClient.writeAsync(dstAddress, buf);
    >IN   8/1/2023 10:59:06.3 [470       ]  BC 01.01.100 24/4/004 E1 00  A0  : 

    buf = new KNXDataBuffer(Buffer.from([64]));
    await knxClient.writeAsync(dstAddress, buf);
    >IN   8/1/2023 10:59:18.6 [470       ]  BC 01.01.100 24/4/004 E2 00  80 40  : 
dufourgilles commented 1 year ago

Hi,

thanks for your previous commit. I'm on vacations and don't have full access to my system to respond to this question. But I'll get back to you mid august.

Gilles

RealByron commented 1 year ago

No worry, enjoy your vacations

dufourgilles commented 11 months ago

Indeed this is not obvious. Actually, you would have to set the 6bits flag of the KNXDataBuffer so that the message is correctly formatted. Currently, this flag is only set if no type specified or type 1

sixBits(): boolean {
    if (this.info == null) { return true; }
    return this.info.type.type === '1';
}

Then when constructing the NPDU we check the 6bits flag and the length of the message should be 1

    if (data.sixBits() && data.length === 1 && data.value.readUInt8(0) < 0x3F) {
        this.apci = (this.apci & 0xC0) | data.value.readUInt8(0);
        this._data = null;
        return;
    }

So, to answer your question you should construct a buffer with a single byte and the value should be less than 0x3F.

Gilles.