Skip to content
Open
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
4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ class Client extends EventEmitter {
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
invokeId: options.invokeId || this._getInvokeId(),
arrayIndex: options.arrayIndex || baEnum.ASN1_ARRAY_ALL
arrayIndex: options.arrayIndex !== undefined ? options.arrayIndex : baEnum.ASN1_ARRAY_ALL
};
const buffer = this._getBuffer();
baNpdu.encode(buffer, baEnum.NpduControlPriority.NORMAL_MESSAGE | baEnum.NpduControlBits.EXPECTING_REPLY, address, null, DEFAULT_HOP_COUNT, baEnum.NetworkLayerMessageType.WHO_IS_ROUTER_TO_NETWORK, 0);
Expand Down Expand Up @@ -618,7 +618,7 @@ class Client extends EventEmitter {
maxSegments: options.maxSegments || baEnum.MaxSegmentsAccepted.SEGMENTS_65,
maxApdu: options.maxApdu || baEnum.MaxApduLengthAccepted.OCTETS_1476,
invokeId: options.invokeId || this._getInvokeId(),
arrayIndex: options.arrayIndex || baEnum.ASN1_ARRAY_ALL,
arrayIndex: options.arrayIndex !== undefined ? options.arrayIndex : baEnum.ASN1_ARRAY_ALL,
priority: options.priority
};
const buffer = this._getBuffer();
Expand Down
2 changes: 1 addition & 1 deletion lib/services/read-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports.encode = (buffer, objectType, objectInstance, propertyId, arrayIn
baAsn1.encodeContextEnumerated(buffer, 1, propertyId);
}
if (arrayIndex !== baEnum.ASN1_ARRAY_ALL) {
baAsn1.encodeContextUnsigned(buffer, 2, arrayIndex || baEnum.ASN1_ARRAY_ALL);
baAsn1.encodeContextUnsigned(buffer, 2, arrayIndex);
}
};

Expand Down
11 changes: 11 additions & 0 deletions test/unit/service-read-property.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ describe('bacstack - Services layer ReadProperty unit', () => {
property: {id: 85, index: 2}
});
});

it('should successfully encode and decode with array index 0', () => {
const buffer = utils.getBuffer();
baServices.readProperty.encode(buffer, 4, 630, 85, 0);
const result = baServices.readProperty.decode(buffer.buffer, 0, buffer.offset);
delete result.len;
expect(result).toEqual({
objectId: {type: 4, instance: 630},
property: {id: 85, index: 0}
});
});
});

describe('ReadPropertyAcknowledge', () => {
Expand Down