-
Notifications
You must be signed in to change notification settings - Fork 825
feat: added firmware checks and warning #2856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR implements firmware version checks by extending the low-level packet handler to retrieve firmware versions, integrating the check into the board state provider (triggering a notifier when legacy firmware is detected), and displaying a warning dialog in the instruments screen, alongside updating localization resources for the new alert messages. Sequence diagram for firmware version check and legacy warningsequenceDiagram
participant App as InstrumentsScreen
participant Board as BoardStateProvider
participant SciLab as ScienceLab
participant Packet as PacketHandler
participant User as actor User
App->>Board: initialize()
Board->>SciLab: initialize()
Board->>SciLab: openDevice()
Board->>Board: setPSLabVersionIDs()
Board->>Board: fetchFirmwareVersion()
Board->>SciLab: getFirmwareVersion()
SciLab->>Packet: mPacketHandler.getFirmwareVersion()
Packet->>Packet: sendByte(common)
Packet->>Packet: sendByte(getFwVersion)
Packet->>Packet: _commonRead(fwVersionLength)
Packet-->>SciLab: firmwareVersion
SciLab-->>Board: firmwareVersion
Board->>Board: Check firmwareVersion < 3
Board->>App: legacyFirmwareNotifier triggers
App->>User: Show legacy firmware warning dialog
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `lib/providers/board_state_provider.dart:102` </location>
<code_context>
+ pslabFirmwareVersion =
+ await getIt.get<ScienceLab>().mPacketHandler.getFirmwareVersion();
+ }
+ if (pslabFirmwareVersion < 3 && pslabFirmwareVersion != 0) {
+ legacyFirmwareNotifier.value = "LegacyFirmwareDetected";
+ }
</code_context>
<issue_to_address>
Edge case: firmware version 0 may indicate an error, but is excluded from legacy detection.
Version 0 may represent a failed read or uninitialized state. Please handle this explicitly to prevent silent failures or missed alerts.
</issue_to_address>
### Comment 2
<location> `lib/communication/packet_handler.dart:142` </location>
<code_context>
+ sendByte(_mCommandsProto.common);
+ sendByte(_mCommandsProto.getFwVersion);
+ int numBytesRead = await _commonRead(fwVersionLength);
+ if (numBytesRead == 1) {
+ return 2;
+ } else {
+ return _buffer[0];
</code_context>
<issue_to_address>
Returning a hardcoded value (2) for numBytesRead == 1 may be unclear.
Please add a comment explaining why 2 is returned when numBytesRead is 1, or refactor to make the logic clearer.
Suggested implementation:
```
if (numBytesRead == 1) {
// If only one byte is read, it indicates a legacy device or error state.
// Returning 2 as a sentinel value to signal this special case.
return 2;
} else {
return _buffer[0];
```
For even greater clarity, you could define a named constant at the top of the file or class, e.g.:
```dart
static const int legacyDeviceSentinel = 2;
```
and use `return legacyDeviceSentinel;` instead of `return 2;`.
</issue_to_address>
### Comment 3
<location> `lib/communication/packet_handler.dart:147` </location>
<code_context>
+ } else {
+ return _buffer[0];
+ }
+ } catch (e) {
+ logger.e(e);
+ }
+ return 0;
</code_context>
<issue_to_address>
Consider providing more context in error logging for firmware version fetch.
Include details about the operation and relevant parameters in the log to aid debugging and traceability.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
} catch (e) {
logger.e(e);
}
return 0;
=======
} catch (e) {
logger.e(
'Error fetching firmware version: '
'command=${_mCommandsProto.getFwVersion}, '
'fwVersionLength=$fwVersionLength, '
'exception=$e'
);
}
return 0;
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Build StatusBuild successful. APKs to test: https://github.com/fossasia/pslab-app/actions/runs/17189400070/artifacts/3837871033. Screenshots |
@AsCress Yes, I can do that, just need to find my PICKit... 🙈 |
marcnause
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to test successfully with both the v5 board and the v6 board.







-1_instruments_screen.png?raw=true)
-2_nav_drawer.png?raw=true)
-3_accelerometer.png?raw=true)
-4_power_source.png?raw=true)
-5_multimeter.png?raw=true)
-6_wave_generator.png?raw=true)
-7_oscilloscope.png?raw=true)
Adds firmware checks for the legacy firmware and a warning dialog if the user is running the legacy firmware.
Screenshots / Recordings
Screen_recording_20250817_223553.mp4
Screen_recording_20250817_224100.mp4
@marcnause Could you please verify that this works with the V5 board ? Thanks.
Summary by Sourcery
Add firmware version detection and user warning for legacy firmware support.
New Features:
Enhancements: