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
134 stars 71 forks source link

Retain PD in online state for up to 8 seconds before marking it offline #189

Closed sidcha closed 1 month ago

sidcha commented 2 months ago

Discussed in https://github.com/goToMain/libosdp/discussions/186

Originally posted by **Master8oy** June 26, 2024 I'm testing this library and I discovered one thing. When the PD does not send back a response, e.g. due to a failure or packet loss, the AC immediately marks the device as OFFLINE and starts communicating with the device as it did when it was first started. According to the standard, the AC should keep this PD in ONLINE state for 8 seconds and only then switch to OFFLINE state if it does not respond. Does this mean that this is not implemented in the library or can it be set somewhere?
sidcha commented 1 month ago

This issue been addressed in 182f049e0791b73a886b494a77f3b6551da18610:

    cp: Introduce "probe" state for PDs that don't respond

    When a PD does not respond, CP pushes it to offline state and then
    retries after a timeout. This timeout is exponentially increased to not
    POLL devices that have been plugged out of the socket entirely. This was
    working fine but some users don't like the random SC discards due to
    some PDs not responding withing the 200ms time frame per-packet. This is
    especially pronounced when there is a file transfer operation in-flight.

    Apart form those details, the OSDP Specification says the CP has to
    maintain the PD to be online for up to 8 seconds or inactivity before
    marking the PD as unresponsive.

    This patch adds support for a new state in which a PD can be: probe. In
    this state, the CP is probing to see if the PD will become active again
    by sending the last command repeatedly for 8 seconds and then gives up
    and marks the PD as offline. This also means that we can get rid of the
    exponential back-off that was employed in this path before.