pez-globo / pufferfish-software

All software for the Pufferfish ventilator.
Apache License 2.0
0 stars 1 forks source link

Backend should translate the firmware's clock to the wall clock time #311

Closed ethanjli closed 3 years ago

ethanjli commented 3 years ago

Currently all logged events have their time displayed as occuring around 1969 or 1970. This is because the firmware's timestamps are directly being displayed in the firmware. The backend needs to convert firmware timestamps (for which time 0 is the time the MCU started running) into Unix timestamps (for which time 0 is January 1, 1970). We could achieve this by adding another message type where the firmware reports its clock time. The backend initializes an initial time to this, and then it keeps track of deltas between messages which have a time field (which I think is all or almost all messages) to increment its Unix timestamp clock. Then it translates all time field values in its messages and log events into Unix timestamps before putting them into its state store.

It'd be great to figure out a way we can keep track of time deltas to be robust to uint32_t rollover (which is ~49 days), though if this is too difficult, for the HFNC-only release we could just instruct hospitals to restart their ventilators at least once every 40 days. Perhaps what we could just do is reset the "initial time" variable in the backend if the time from the microcontroller decreases, as that time should only decrease on rollover.

ethanjli commented 3 years ago

Because rollover can only be detected in a general case by a timestamp decreasing, it's important not to feed decreasing timestamps from the MCU except in a rollover event. This means that each message type should have its own ventserver.protocols.application.ClockSynchronizer in the backend, as different messages have update timestamps at different times relative to each other.