Expand description
bhtune tune/bhtune simulate: runs a full MRFT test end-to-end — resolving a template,
deriving tags, transitioning the loop to Manual, polling the driver and driving a real
[bhtune_core::MrftEngine], persisting every tick and the final calculated results, then
restoring the loop and optionally writing back the chosen PID constants.
The separate bhtune check preflight validates the same request inputs and reads
controller state without preparing or persisting a run. It uses a read-only database
connection and ReadOnlyDriver so it cannot mutate the database or controller.
Mirrors the legacy MRFTstart/ReadInitialOPCvalues/ChangeControllerModeToMan/
ResetOPC sequence from OPCClass.cs. The mode-transition and write-back steps
automatically no-op for the simulator driver, since its [bhtune_core::LoopTags] has no
setpoint/mode/mode-attribute/PID-constant tags at all (see build_loop_tags below) — no
separate “is this the simulator?” branching is needed in that logic.
Structs§
- PidWrite
Preview - Presentation of one raw result’s controller target, including precision failures that do not change the recorded calculation status.
- Preflight
Check - One named preflight check and its operator-facing detail.
- Preflight
Report - Read-only results for a tune request.
- Preflight
TagRead - The value, quality, and validation result for one derived OPC tag.
- Prepared
Tune - Everything
prepareresolves before a tune’s long-running polling phase can start: the already-validatedValidatedTuneRequest, the resolved template and derived tags, a connected driver, the built [LoopConfig], the run’s start time, and the response level (if any) to write back at the end – plus thetune_runsrow’s assigned id. - Recovery
Step Report - Restore
Loop Report - Restore
Loop Request - Startup
Orphan Sweep Report - Tune
Request - Transport-neutral inputs for a tune run.
- Tune
Request Validation Error - A common tune-request field failed runtime validation.
- Tune
RunReport - Unsupported
Driver Kind - Validated
Tune Request - A transport-neutral tune request that has passed common input validation.
Enums§
- Abort
Reason - Driver
Kind - PidWrite
Outcome - The result of
write_pid_values– deliberately simpler thanWriteBackOutcomebelow, which layers CLI-only concerns (aSkippedvariant covering unconfigured tags, no recorded results, or an interactive skip) on top of this.write_pid_valuesonly ever runs once a specific, available target has already been chosen, so there is nothing left to “skip” by the time it’s called. Named distinctly frombhtune_driver::WriteOutcome(that one describes a single raw tag write’s own outcome; this one describes the full pre-read/write/verify/rollback/audit sequence across all three PID constants). - Preflight
Check Status - Severity assigned to an individual preflight result.
- Recovery
Step Status - RunOutcome
- Tune
Outcome - Write
Back Outcome - Write
Back Selection - Write
Back Skip Reason
Constants§
- DEFAULT_
SIM_ DEAD_ TIME - Default simulator dead time in seconds.
- DEFAULT_
SIM_ GAIN - Default simulator process gain used by every tune-request adapter.
- DEFAULT_
SIM_ INITIAL_ VALUE - Default simulator initial PV and MV.
- DEFAULT_
SIM_ NOISE - Default simulator measurement-noise amplitude.
- DEFAULT_
SIM_ SEED - Default simulator random-number-generator seed.
- DEFAULT_
SIM_ TAU - Default simulator process time constant in seconds.
- MV_
ACTUATION_ CONFIRMATION_ SECS - Maximum interval from an accepted OPC DA MV write to its mandatory confirmation check.
Traits§
- Write
Back Handler - Optional adapter hook for response-level selection and progress reporting.
Functions§
- controller_
pid_ for_ result - The shared new-write validity/precision gate. Restore and revert paths deliberately do not call this: their recorded targets must retain their original precision.
- drive
- Runs an already-prepared tune without an interactive selector and returns its coarse outcome. An unrequested write-back is skipped.
- drive_
report - Runs an already-prepared tune and returns the detailed runtime outcome for adapters that report it to a user. An optional handler may select an interactive PID response level and observe write-back progress; it never replaces runtime validation or safety checks.
- pid_
parameters_ for_ result - Validates a persisted result’s raw, full-precision PID parameters.
- pid_
write_ preview - preflight
- Checks a request without invoking tune preparation, the polling loop, or any database mutation. An existing database is queried only through a read-only pool; when it is absent, the current built-in and configured catalog templates provide the lookup data.
- prepare
- Validates a tune request and prepares the driver and persisted run record.
- prepare_
owned - Prepare a simulator tune and bind its history to a demo session before the background execution is started. Live OPC DA preparation is intentionally rejected by this helper.
- recover_
startup_ orphans - Full-mode startup records every affected row before retiring a dead live owner. Holding the process-shared database lock distinguishes a killed process from a paused one whose heartbeat may be stale but whose controller operation is still live.
- restore_
loop - Restores an interrupted live run only after its original database/resource owner is atomically replaced and a durable evidence export exists.
- sample_
quality_ from_ driver - Maps the driver’s live
bhtune_driver::Qualityto the database’s persistedSampleQuality– two separate enums (rather than one shared type) becausebhtune-driverandbhtune-dbare sibling crates that each depend only onbhtune-core, not on each other; only a crate depending on both needs this mapping, so it lives here rather than forcing a new cross-dependency onto either crate.pub(not just used by [run_polling_loop] below) becausebhtune-server’sroutes::opcreuses it verbatim forGET /api/opc/read’s quality field, rather than a second copy of the same three-arm match. - tune_
outcome_ for_ run - validate_
finite_ f32 - Rejects a non-finite
f32request value and identifies its field. - validate_
positive_ u32 - Rejects a zero
u32value where the request requires a positive count. - validate_
restore_ timeout_ secs - Validates the restore budget shared by CLI and HTTP-started tunes.
- write_
pid_ values - Pre-reads the existing Proportional/Integral/Derivative values, writes and verifies
target(Proportional then Integral then Derivative, stopping at the first failure), rolls back to the pre-read values on partial failure (only forkind =WriteKind::Write-- [WriteKind::Revert] never does, so a revert can't chase its own failure with a nested rollback; see [WriteKind]'s own doc comment), and records exactly one [TuneWriteRow`] audit row for the attempt, success or not. - write_
pid_ values_ with_ owner - Performs an already-owned PID write sequence.
drivermust be theAuditedDriverfor the same guard so each write intent is persisted before I/O.