Skip to content

feat(protocol): Add input validation for voltage and current setpoints#270

Open
avion23 wants to merge 1 commit intokanflo:masterfrom
avion23:safety-input-validation
Open

feat(protocol): Add input validation for voltage and current setpoints#270
avion23 wants to merge 1 commit intokanflo:masterfrom
avion23:safety-input-validation

Conversation

@avion23
Copy link
Copy Markdown
Contributor

@avion23 avion23 commented Jun 29, 2025

Input Validation for Safety

Adds validation to prevent out-of-range values from being written to hardware DACs.

Changes

  • protocol_handler.c: Validate parsed command values before processing
  • pwrctl.c: Add bounds checking (65V max input, 60V max output, 20A max current)
  • opendps.c: Validate calibration coefficients (current ADC gain: 0.1-100.0f)

Behavior

  • Invalid commands return error response
  • Hardware limits prevent unsafe DAC writes
  • Device maintains last valid state on invalid input

Prevents potential hardware damage from malformed commands or invalid calibration data.

@avion23 avion23 force-pushed the safety-input-validation branch 2 times, most recently from ccbbe65 to 99c65f1 Compare June 29, 2025 18:08
@avion23 avion23 force-pushed the safety-input-validation branch from 99c65f1 to ee5c343 Compare July 14, 2025 21:04
static command_status_t handle_change_screen(frame_t *frame)
{
emu_printf("%s\n", __FUNCTION__);
uint8_t cmd, screen_id;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While my way of dealing with the protocol might be considered slight overkill, this should be a separate PR I think.

@kanflo
Copy link
Copy Markdown
Owner

kanflo commented Feb 14, 2026

While I am all for input validation, I would like to have all protocol handling changes in a separate PR.

@avion23 avion23 force-pushed the safety-input-validation branch from ee5c343 to 44ef935 Compare February 15, 2026 05:44
…n values

Adds validation to prevent out-of-range values from being written to hardware
or stored as calibration coefficients.

Changes:
- pwrctl.c: Add sanity limits (65V max input, 60V max output, 20A max current)
- opendps.c: Validate calibration coefficients with reasonable bounds

Invalid values are rejected, maintaining the last valid state.
Prevents potential hardware damage from invalid ADC readings or calibration data.
@avion23 avion23 force-pushed the safety-input-validation branch from 44ef935 to fc27bd4 Compare February 15, 2026 05:46
@avion23
Copy link
Copy Markdown
Contributor Author

avion23 commented Feb 15, 2026

Thanks for merging the first one.
I reduced this to only some validations, completely removed protocol changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants