Skip to content

Refactor random data sender into CLI with Measurement dataclass - #85

Open
nk25719 wants to merge 6 commits into
SpikeKrakeAlarmMQTTfrom
codex/clean-up-code
Open

Refactor random data sender into CLI with Measurement dataclass#85
nk25719 wants to merge 6 commits into
SpikeKrakeAlarmMQTTfrom
codex/clean-up-code

Conversation

@nk25719

@nk25719 nk25719 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Motivation

  • Modernize and clean up the old procedural script to be Python 3 friendly and easier to test and reuse.
  • Remove import-time socket activity and global mutable state so the module can be imported safely.
  • Make PIRDS measurement encoding explicit and maintain backward compatibility with existing callers.

Description

  • Replace the ad-hoc script with a documented CLI module and a frozen @dataclass Measurement that implements as_bytes() for the 12-byte PIRDS frame.
  • Extracted focused helpers: terminate_with_newline, random_measurement, send_random_measurements, and parse_args, and added a main() entry point guarded by if __name__ == "__main__".
  • Keep compatibility wrappers asBytes() and printMeasurement() that delegate to the new snake_case methods.
  • Add constants for DEVICE_TYPES/MEASUREMENT_TYPES and a DEFAULT_SAMPLE_COUNT to replace many implicit globals.

Testing

  • Ran python3 -m compileall data_server which succeeded.
  • Executed inline assertions that instantiate Measurement('T','B',25,123456789,-7) and verified m.asBytes() == m.as_bytes(), the 13-byte payload length with newline, header bytes, and that the measurement value decodes as -7, which all passed.
  • Confirmed the module imports without executing socket activity and the CLI entrypoint returns SystemExit(main()) when run as a script.

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant