pez-globo / pufferfish-software

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

Improve some of the driver interfaces for the Nonin sensor #434

Closed rohanpurohit closed 2 years ago

rohanpurohit commented 2 years ago

This PR includes:

In Cpp files resolved most of the unresolved comments from #421 except the refactor for Sensor.cpp which i will also do in this PR itself.

rohanpurohit commented 2 years ago

@ethanjli I was working on the high-level driver and I'm not too sure when we should say the sensor is connected, and unfortunately I broke the connector that connects the nonin module to the MCU breadboard, so I won't be able to test the latest changes until I'm able to get the replacement for the connector wire. sorry about that!

ethanjli commented 2 years ago

Ok, no worries! As for connectivity, I think there are a few levels and we'll need to report the different levels differently. We should consider the module connected to the MCU when we're receiving new packets/samples at the expected interval (I believe it's a few times per second). We should consider the finger sensor connected to the module when the module packets are reporting that the SNSD status flag is false. We should consider the patient's finger connected to the sensor when the module packets are reporting that SpO2 and HR are not at their "missing data" indicator valued (127 and 511, respectively) and simultaneously reporting that the OOT status flag is false.

rohanpurohit commented 2 years ago

Ok, no worries! As for connectivity, I think there are a few levels and we'll need to report the different levels differently. We should consider the module connected to the MCU when we're receiving new packets/samples at the expected interval (I believe it's a few times per second). We should consider the finger sensor connected to the module when the module packets are reporting that the SNSD status flag is false. We should consider the patient's finger connected to the sensor when the module packets are reporting that SpO2 and HR are not at their "missing data" indicator valued (127 and 511, respectively) and simultaneously reporting that the OOT status flag is false.

Thanks! I have made some changes to Sensor.cpp but it's still WIP and we can discuss it in our meeting tomorrow.

rohanpurohit commented 2 years ago

@ethanjli This pr is ready for testing. after which we can do one final review depending on test results

Tests:

anything else you might think of while testing, do let me know! thanks.

ethanjli commented 2 years ago

Here are my results from testing:

Conclusion: just a few small changes and I'm pretty confident that it will work enough for us to merge this PR.

For records-keeping:

  1. This project is licensed under Apache License v2.0 for any software, and Solderpad Hardware License v2.1 for any hardware - do you agree that your contributions to this project will be under these licenses, too?
  2. Were any of these contributions also part of work you did for an employer or a client?
  3. Does this work include, or is it based on, any third-party work which you did not create?
rohanpurohit commented 2 years ago

@ethanjli one interesting thing to note is in the previous code that you wrote for Sensor.cpp, for both HR and SpO2 you checked for 127 which is the missing data for SpO2 Sensor.cpp, and it matches to what we are observing, which would definitely fix that bug! but of course, we'll need to figure out why that happens.

I guess this is the code block that's doing that change PacketReceiver L63 and looks like that is what we want since the LSB is for SpO2

  1. This project is licensed under Apache License v2.0 for any software, and Solderpad Hardware License v2.1 for any hardware - do you agree that your contributions to this project will be under these licenses, too? Yes
  2. Were any of these contributions also part of work you did for an employer or a client? No
  3. Does this work include, or is it based on, any third-party work which you did not create? No
ethanjli commented 2 years ago

TODO for me: test, and see if it's easy to fix the suspicious HR MSB processing at https://github.com/pez-globo/pufferfish-software/blob/95833b1adcf3d9255a406c8b876d4819acc2f9c4/firmware/ventilator-controller-stm32/Core/Inc/Pufferfish/Driver/Serial/Nonin/PacketReceiver.h#L63

TODO for you (this work does not block this PR): investigate whether FrameBuffer should behave more like RingBuffer or more like ChunkSplitter in its interface for reporting input_overwritten (i.e. as a return code or as an output parameter)

ethanjli commented 2 years ago

I've pushed up a commit completing the fix of the HR parsing code, as well as adding definitions to the frontend's logs/constants.ts for handling the new events you added. With these fixes, everything seems to work; there's a very noticeable delay between when I put my finger in the sensor and when the frontend shows numbers, but I haven't checked whether this is the same delay as before or a larger delay.

For records-keeping on my contributions:

  1. This project is licensed under Apache License v2.0 for any software, and Solderpad Hardware License v2.1 for any hardware - do you agree that your contributions to this project will be under these licenses, too? Yes
  2. Were any of these contributions also part of work you did for an employer or a client? No
  3. Does this work include, or is it based on, any third-party work which you did not create? No
ethanjli commented 2 years ago

We concluded that FrameBuffer shouldn't modify any internal state if it's already full, it should just return early. This is like the interface of RingBuffer. By contrast, ChunkSplitter clears the internal buffer if it's full and another input is overwritten. There it's reasonable because dropping one frame doesn't affect the state of the protocol, since the protocol doesn't really have connection state at the levels above frames. For the Nonin sensor, there is connection state at the packet level, because each packet is a sequence of 25 consecutive frames and dropping one will invalidate the packet anyways - so clearing the internal buffer wouldn't help error recovery.