17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-29 06:57:29 +01:00

zmq: read simulator state from the shared TrainState registry

The zmq interface kept its own copy of the state field list, its own name
table and its own packer. All three are now the shared registry, which
resolves the same channel names and returns the same values, so the wire
format is unchanged. New state exposed to external interfaces is added in
one place from now on.

The registry reports the raw velocity rather than zeroing it while the
simulation is paused, and a symbol which doesn't apply to the current
vehicle keeps its measurement and says so through its quality flag.
This commit is contained in:
2026-09-05 20:41:59 +00:00
parent 6bfd21d135
commit 40df8e84f6
4 changed files with 20 additions and 166 deletions

View File

@@ -12,7 +12,6 @@ http://mozilla.org/MPL/2.0/.
#include "simulation/simulation.h"
#include "simulation/simulationtime.h"
#include "utilities/Globals.h"
namespace hardware
{
@@ -29,8 +28,10 @@ state_value make_value( state_snapshot const &Snapshot, value_type const Type, d
false == Snapshot.available ? value_quality::unavailable :
false == Applicable ? value_quality::not_applicable :
value_quality::valid );
if( result.quality != value_quality::valid )
if( result.quality == value_quality::unavailable )
{
// there's nothing to report; a value which merely doesn't apply keeps whatever the
// simulator holds, the quality flag is what tells the device not to trust it
result.numeric = 0.0;
}
return result;
@@ -115,7 +116,7 @@ state_registry::state_registry()
add( "radio_channel", value_type::uint8, "", 0.0, 15.0, []( state_snapshot const &s ) { return make_value( s, value_type::uint8, s.train.radio_channel ); } );
// measurements, in engineering units
add( "velocity", value_type::float32, "km/h", 0.0, 400.0, []( state_snapshot const &s ) { return make_value( s, value_type::float32, Global.iPause ? 0.0 : s.train.velocity ); } );
add( "velocity", value_type::float32, "km/h", 0.0, 400.0, []( state_snapshot const &s ) { return make_value( s, value_type::float32, s.train.velocity ); } );
add( "reservoir_pressure", value_type::float32, "bar", 0.0, 16.0, []( state_snapshot const &s ) { return make_value( s, value_type::float32, s.train.reservoir_pressure ); } );
add( "pipe_pressure", value_type::float32, "bar", 0.0, 16.0, []( state_snapshot const &s ) { return make_value( s, value_type::float32, s.train.pipe_pressure ); } );
add( "brake_pressure", value_type::float32, "bar", 0.0, 16.0, []( state_snapshot const &s ) { return make_value( s, value_type::float32, s.train.brake_pressure ); } );