pub struct SensorManager {Show 18 fields
config: SensorManagerConfig,
ambient_temperature: f32,
ambient_humidity: f32,
water_temperature: f32,
conductivity: f32,
pH: f32,
pub lock_error_channel_receive_termination: bool,
pub lock_warn_inapplicable_command_signal_handler: bool,
pub instant_last_measurement: Instant,
pub measurement_interval: Duration,
lock_error_dht_mutex: bool,
lock_error_atlas_scientific_temperature_mutex: bool,
lock_error_atlas_scientific_ph_mutex: bool,
lock_error_atlas_scientific_conductivity_mutex: bool,
lock_error_ds18b20_water_temperature_mutex: bool,
lock_error_ds18b20_ambient_temperature_mutex: bool,
pub lock_warn_max_mutex_access_duration: bool,
pub max_mutex_access_duration: Duration,
}Expand description
Contains the communication with DHT ambient temperature and humidity sensor. Alternatively, TCP communication is used when configured to run with the simulator. Sensor data is read periodically and stored. Requests from data logger and heating control are answered with last measured data. Thread communication of this component is as follows:
Fields§
§config: SensorManagerConfig§ambient_temperature: f32ambient temperature in °C
ambient_humidity: f32humidity in %
water_temperature: f32water temperature in °C
conductivity: f32conductivity in mS
pH: f32pH value
lock_error_channel_receive_termination: boolinhibition flag to avoid flooding the log file with repeated messages about failure to receive termination signal via the channel
lock_warn_inapplicable_command_signal_handler: boolinhibition flag to avoid flooding the log file with repeated messages about having received inapplicable command via the channel from the signal handler thread
instant_last_measurement: InstantRecording when the last measurement took place
measurement_interval: DurationDuration in between two requests to either the simulator or the hardware
lock_error_dht_mutex: boolinhibition flag to avoid flooding the log file with repeated messages about failure to acquire lock on mutex for Dht readings
lock_error_atlas_scientific_temperature_mutex: boolinhibition flag to avoid flooding the log file with repeated messages about failure to acquire lock on mutex for temperature from Atlas Scientific sensor unit
lock_error_atlas_scientific_ph_mutex: boolinhibition flag to avoid flooding the log file with repeated messages about failure to acquire lock on mutex pH value from Atlas Scientific sensor unit
lock_error_atlas_scientific_conductivity_mutex: boolinhibition flag to avoid flooding the log file with repeated messages about failure to acquire lock on mutex for conductivity from Atlas Scientific sensor unit
lock_error_ds18b20_water_temperature_mutex: boolinhibition flag to avoid flooding the log file with repeated messages about failure to acquire lock on mutex for water temperature from Ds18b20 sensor
lock_error_ds18b20_ambient_temperature_mutex: boolinhibition flag to avoid flooding the log file with repeated messages about failure to acquire lock on mutex for ambient temperature from Ds18b20 sensor
lock_warn_max_mutex_access_duration: boolinhibition flag to avoid flooding the log file with repeated messages about excessive access time to mutex
max_mutex_access_duration: DurationMaximum permissible duration for accessing the mutex
Implementations§
Source§impl SensorManager
impl SensorManager
Sourcepub fn new(
config: SensorManagerConfig,
) -> Result<SensorManager, SensorManagerError>
pub fn new( config: SensorManagerConfig, ) -> Result<SensorManager, SensorManagerError>
Creates a new SensorManager control instance.
This constructor initializes the ambient temperature and humidity measurement module.
It sets the initial temperature and humidity values to configured replacement values
and initializes all internal “lock” flags to false. These flags help prevent
log flooding from recurring errors or warnings during operation.
§Returns
A Result containing a new SensorManager instance on success, or a
SensorManagerError if the configuration is invalid.
§Errors
This function will return an error if:
source_ambient_temperaturein the config is not a valid, known source.source_water_temperaturein the config is not a valid, known source.
Sourcefn communicate_with_simulator(
&mut self,
sensor_manager_channels: &mut SensorManagerChannels,
) -> Result<(), SensorManagerError>
fn communicate_with_simulator( &mut self, sensor_manager_channels: &mut SensorManagerChannels, ) -> Result<(), SensorManagerError>
Communicates with a simulator thread via channels to retrieve water temperature, ambient temperature, ambient humidity, pH and conductivity.
This private helper function is used when the SensorManager module is configured
to run in simulation mode. It sends RequestSignal commands to the simulator and
updates the module’s internal fields with the responses.
§Arguments
tx_sensor_manager_to_tcp_opt- A reference to anOption<Sender<InternalCommand>>used for sending commands to theTcpCommunicationthread (which acts as the simulator interface).rx_sensor_manager_from_tcp_opt- A reference to anOption<Receiver<Result<f32, TcpCommunicationError>>>used for receiving simulated sensor data from theTcpCommunicationthread.
§Returns
An empty Result on success, or a SensorManagerError if communication fails.
§Errors
This function will return a SensorManagerError::SimulatorCommunicationError if sending a
request or receiving a response over the channels fails.
§Panics
This function will panic if either tx_sensor_manager_to_tcp_opt or rx_sensor_manager_from_tcp_opt
are None. This case is not possible because the SensorManager module performs checks beforehand to ensure
these channels are Some when running in simulator mode.
Sourcepub fn execute(
&mut self,
sensor_manager_channels: &mut SensorManagerChannels,
mutexes: SensorManagerMutexes,
)
pub fn execute( &mut self, sensor_manager_channels: &mut SensorManagerChannels, mutexes: SensorManagerMutexes, )
Executes the main control loop for the sensor manager.
This function runs continuously, managing the periodic consolidation of sensor data. It operates in two main modes:
- Simulator Mode: Fetches simulated sensor data for all signals via a TCP communication channel.
- Hardware Mode: Reads the latest sensor data from various shared mutexes that are
populated by other dedicated sensor threads (like
Ds18b20,Dht,AtlasScientific).
Based on the configuration, it selects the appropriate data source (e.g., Ds18b20 vs.
Atlas Scientific for water temperature). The consolidated data is then written to the
mutex_sensor_manager_signals mutex, making it available to other application threads.
The loop maintains a measurement interval and remains responsive to Quit and Terminate
commands from the signal handler for graceful shutdown.
§Arguments
sensor_manager_channels- A struct containing allmpscchannels necessary for inter-thread communication with theTcpCommunication(if in simulator mode) and theSignalHandler.mutexes- A struct containingArc<Mutex<...>>handles to all required sensor data sources and the final output signals struct.
§Panics
This function will panic if:
- It’s configured to use the simulator but essential TCP communication channels are missing.
Trait Implementations§
Source§impl CheckMutexAccessDurationTrait for SensorManager
impl CheckMutexAccessDurationTrait for SensorManager
Source§fn get_warn_lock(&self, _key_opt: &Option<&AquariumSignal>) -> bool
fn get_warn_lock(&self, _key_opt: &Option<&AquariumSignal>) -> bool
Method connects the default trait implementation with the specific implementation reading the warn-lock.
Source§fn set_warn_lock(&mut self, _key_opt: &Option<&AquariumSignal>, value: bool)
fn set_warn_lock(&mut self, _key_opt: &Option<&AquariumSignal>, value: bool)
Method connects the default trait implementation with the specific implementation setting the warn-lock.
Source§fn get_max_mutex_access_duration(&self) -> Duration
fn get_max_mutex_access_duration(&self) -> Duration
Method connects the default trait implementation with the specific implementation for getting maximum permissible access duration
Source§fn get_location(&self) -> &str
fn get_location(&self) -> &str
inform the location of the warning for logging purposes
fn check_mutex_access_duration( &mut self, key_opt: Option<&AquariumSignal>, instant_after_locking_mutex: Instant, instant_before_locking_mutex: Instant, )
Source§impl GetResponseFromSimulatorTrait for SensorManager
impl GetResponseFromSimulatorTrait for SensorManager
Source§fn get_response_from_simulator(
requester: String,
tx_to_tcp: &mut AquaSender<InternalCommand>,
rx_from_tcp: &mut AquaReceiver<Result<f32, TcpCommunicationError>>,
internal_command: InternalCommand,
) -> Result<f32, TcpCommunicationError>
fn get_response_from_simulator( requester: String, tx_to_tcp: &mut AquaSender<InternalCommand>, rx_from_tcp: &mut AquaReceiver<Result<f32, TcpCommunicationError>>, internal_command: InternalCommand, ) -> Result<f32, TcpCommunicationError>
Source§impl ProcessExternalRequestTrait for SensorManager
impl ProcessExternalRequestTrait for SensorManager
Source§fn process_external_request(
&mut self,
rx_from_signal_handler: &mut AquaReceiver<InternalCommand>,
rx_from_messaging_opt: Option<&mut AquaReceiver<InternalCommand>>,
) -> (bool, bool, bool)
fn process_external_request( &mut self, rx_from_signal_handler: &mut AquaReceiver<InternalCommand>, rx_from_messaging_opt: Option<&mut AquaReceiver<InternalCommand>>, ) -> (bool, bool, bool)
Source§impl WaitForTerminationTrait for SensorManager
impl WaitForTerminationTrait for SensorManager
Source§fn get_warn_lock_mut(&mut self) -> &mut bool
fn get_warn_lock_mut(&mut self) -> &mut bool
Method connects the default trait implementation with the specific implementation accessing the warn-lock.
Source§fn get_error_lock_mut(&mut self) -> &mut bool
fn get_error_lock_mut(&mut self) -> &mut bool
Method connects the default trait implementation with the specific implementation for accessing the error-lock.