goToMain / libosdp

Implementation of IEC 60839-11-5 OSDP (Open Supervised Device Protocol); provides a C library with support for C++, Rust and Python3
https://libosdp.sidcha.dev
Apache License 2.0
140 stars 73 forks source link

pd_app.py example does not result in a functioning PD by OSDP Spec #173

Closed KaiAmelung closed 7 months ago

KaiAmelung commented 7 months ago

Describe the bug This appears to be an issue to me, but would appreciate insight if it is not:

The example Python pd_app.py includes the following pySerial usage:

class SerialChannel(Channel):
    def __init__(self, device: str, speed: int):
        self.dev = serial.Serial(device, speed, timeout=1)

    def read(self, max: int):
        return self.dev.read(max)

OSDP CPs require a response within 200ms according the OSDP spec. timeout is set to 1 meaning the PD will wait up to 1 second if it does not read the max amount of bytes. max is always set to 64 by libosdp, so if a command comes through which is 32 bytes, for instance, the PD can take up to 1 second to respond.

Expected behavior When using the example app, a correctly functioning PD should be simulated i.e. it should reply to commands within 200ms.

Observed behavior The 1 second timeout means that commands which do not sum up to a multiple of 64 bytes can take up to 1 second to read, meaning a sub-200ms response is not always possible.

Notes Switching the timeout to zero appears to solve the issue as the library will wait for a complete message.

sidcha commented 7 months ago

Thanks for reporting the issue. You are right, it should be set to 0.