Struct SensorManager

Source
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:

graph LR signal_handler[SignalHandler] --> sensor_manager[SensorManager] sensor_manager[SensorManager] --> signal_handler[SignalHandler] signal_handler[SignalHandler] --> tcp_communication[TcpCommunication] tcp_communication[TcpCommunication] --> signal_handler[SignalHandler]

Fields§

§config: SensorManagerConfig§ambient_temperature: f32

ambient temperature in °C

§ambient_humidity: f32

humidity in %

§water_temperature: f32

water temperature in °C

§conductivity: f32

conductivity in mS

§pH: f32

pH value

§lock_error_channel_receive_termination: bool

inhibition 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: bool

inhibition 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: Instant

Recording when the last measurement took place

§measurement_interval: Duration

Duration in between two requests to either the simulator or the hardware

§lock_error_dht_mutex: bool

inhibition 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: bool

inhibition 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: bool

inhibition 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: bool

inhibition 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: bool

inhibition 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: bool

inhibition 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: bool

inhibition flag to avoid flooding the log file with repeated messages about excessive access time to mutex

§max_mutex_access_duration: Duration

Maximum permissible duration for accessing the mutex

Implementations§

Source§

impl SensorManager

Source

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_temperature in the config is not a valid, known source.
  • source_water_temperature in the config is not a valid, known source.
Source

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 an Option<Sender<InternalCommand>> used for sending commands to the TcpCommunication thread (which acts as the simulator interface).
  • rx_sensor_manager_from_tcp_opt - A reference to an Option<Receiver<Result<f32, TcpCommunicationError>>> used for receiving simulated sensor data from the TcpCommunication thread.
§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.

Source

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 all mpsc channels necessary for inter-thread communication with the TcpCommunication (if in simulator mode) and the SignalHandler.
  • mutexes - A struct containing Arc<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

Source§

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)

Method connects the default trait implementation with the specific implementation setting the warn-lock.

Source§

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

inform the location of the warning for logging purposes

Source§

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

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>

Sends a request to a simulator via a channel and blocks until a response is received. Read more
Source§

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)

Checks for and processes new commands received from the signal handler and an optional messaging channel. Read more
Source§

impl WaitForTerminationTrait for SensorManager

Source§

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

Method connects the default trait implementation with the specific implementation for accessing the error-lock.

Source§

fn wait_for_termination( &mut self, rx_waiting_thread_from_signal_handler: &mut AquaReceiver<InternalCommand>, sleep_duration: Duration, origin: &str, )

Implements the graceful shutdown wait loop for several threads (default implementation). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T