Closed rohanpurohit closed 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!
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.
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.
@ethanjli This pr is ready for testing. after which we can do one final review depending on test results
Tests:
NaN
instead.Nonin sensor disconnected
on disconnecting the sensor from mcu.finger sensor disconnected
.out_of_track
and sensor_alarm
which are unlikely and mostly when the sensor is incapable of providing good measurements.anything else you might think of while testing, do let me know! thanks.
Here are my results from testing:
post_setup_reset
method, and the other for prev_state_ = InitializableState::failed
inside the output
method, then I see that I first hit the prev_state_ = InitializableState::failed
before I hit the breakpoint inside post_setup_reset
. This would suggest that we're calling the output
method as part of the main function's Setup loop, i.e. after the Nonin Sensor has completed its setup
routine but before the other sensors have completed their setup
routines (during which they may sleep for > 2 ms), the Nonin Sensor::output
method is being called. It turns out that this is caused by the main function's "Configure the simulators" section, specifically https://github.com/pez-globo/pufferfish-software/blob/10cabafc474ea24cc2d6da6d12a0f698a7a6c1f0/firmware/ventilator-controller-stm32/Core/Src/main.cpp#L621 , being before the "Reset nonin timer" section. If I swap the order of the two sections, then I am able to get some data from the Nonin sensor. The rest of this test report is made after applying this fix.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:
@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
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)
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:
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.
This PR includes:
Device.h
FrameBuffer.h
BufferInputStatus
andBufferOutputStatus
output_ready
status forinput
FrameReceiver.h
start_of_frame_status_
toat_start_of_frame
validate_start_of_frame
intovalidate_frame_header
andvalidate_frame_checksum
Types.h
header,status,pleth,data,checksum
status
byte mentioned asSYNC
in datasheet inStatusMasks
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.