STIMA
3
|
#include "i2c-opc.h"
Functions | |
void | setup () |
Arduino setup function. Init watchdog, hardware, debug, buffer and load configuration stored in EEPROM. More... | |
void | loop () |
Arduino loop function. First, initialize tasks and sensors, then execute the tasks and activates the power down if no task is running. More... | |
void | logPrefix (Print *_logOutput) |
void | logSuffix (Print *_logOutput) |
void | init_logging () |
Init logging system. More... | |
void | init_power_down (uint32_t *time_ms, uint32_t debouncing_ms) |
Enter power down mode. More... | |
void | init_wdt (uint8_t wdt_timer) |
Init watchdog. More... | |
void | init_buffers () |
Init buffers. More... | |
void | init_tasks () |
Init tasks variable and state. More... | |
void | init_pins () |
Init hardware pins. More... | |
void | init_wire () |
Init wire (i2c) library and performs checks on the bus. More... | |
void | init_spi () |
Init SPI library. More... | |
void | init_rtc () |
Init RTC module. More... | |
void | init_system () |
Init system. More... | |
void | print_configuration () |
Print current configuration. More... | |
void | save_configuration (bool is_default) |
Save configuration to EEPROM. More... | |
void | load_configuration () |
Load configuration from EEPROM. More... | |
void | init_sensors () |
Create and setup sensors. More... | |
ISR (TIMER1_OVF_vect) | |
void | i2c_request_interrupt_handler () |
I2C request interrupt handler. More... | |
void | i2c_receive_interrupt_handler (int rx_data_length) |
I2C receive interrupt handler. More... | |
template<typename sample_g , typename observation_g , typename values_v , typename value_v > | |
void | addSample (sample_g *sample, observation_g *observation, values_v *values, value_v value) |
template<typename observation_g , typename value_v > | |
value_v | readCurrentObservation (observation_g *buffer) |
template<typename observation_g , typename value_v > | |
void | writeCurrentObservation (observation_g *buffer, value_v value) |
template<typename observation_g , typename length_v > | |
void | resetObservation (observation_g *buffer, length_v length) |
template<typename observation_g , typename length_v > | |
void | resetBackObservation (observation_g *buffer, length_v length) |
template<typename observation_g , typename length_v > | |
void | incrementObservation (observation_g *buffer, length_v length) |
template<typename observation_g , typename length_v , typename value_v > | |
void | addObservation (observation_g *buffer, length_v length, value_v value) |
template<typename observation_g , typename length_v , typename value_v > | |
value_v | readBackObservation (observation_g *buffer, length_v length) |
void | samples_processing (bool is_force_processing) |
Main routine for processing the samples to calculate an observation. More... | |
template<typename sample_g , typename observation_g > | |
bool | make_observation_from_samples (bool is_force_processing, sample_g *sample, observation_g *observation) |
bool | observations_processing () |
Main routine for processing the observations to calculate a value for report. More... | |
template<typename sample_g , typename observation_g , typename value_v , typename val_v > | |
bool | make_value_from_samples_and_observations (sample_g *sample, observation_g *observation, value_v *value) |
void | opc_task () |
Opc setup and reading Task. Read data from OPC. More... | |
void | exchange_buffers () |
Exchange reader and writer pointer to buffer. More... | |
void | reset_samples_buffer () |
Reset samples buffers to default value. More... | |
void | reset_observations_buffer () |
Reset observations buffers to default value. More... | |
void | command_task () |
Command Task. Execute the command received on i2c bus by reading i2c received data buffer. More... | |
void | tests () |
Performs specific operations based on the received command. More... | |
void | commands () |
Performs specific operations based on the received command. More... | |
void command_task | ( | void | ) |
Command Task. Execute the command received on i2c bus by reading i2c received data buffer.
Execute the command received on i2c bus by reading i2c received data buffer.
void commands | ( | void | ) |
Performs specific operations based on the received command.
CONTINUOUS START
CONTINUOUS STOP
CONTINUOUS START-STOP
ONESHOT START
ONESHOT STOP
ONESHOT START-STOP
void exchange_buffers | ( | void | ) |
Exchange reader and writer pointer to buffer.
void i2c_receive_interrupt_handler | ( | int | rx_data_length | ) |
I2C receive interrupt handler.
[in] | rx_data_length | received data length in bytes. |
check crc: ok
void i2c_request_interrupt_handler | ( | void | ) |
I2C request interrupt handler.
write readable_data_length bytes of data stored in readable_data_read_ptr (base) + readable_data_address (offset) on i2c bus
write crc8
void init_buffers | ( | void | ) |
Init buffers.
copy readable_data_2 in readable_data_1
void init_logging | ( | void | ) |
Init logging system.
void init_pins | ( | void | ) |
Init hardware pins.
void init_power_down | ( | uint32_t * | time_ms, |
uint32_t | debouncing_ms | ||
) |
Enter power down mode.
time_ms | pointer to a variable to save the last instant you entered power down. |
debouncing_ms | delay to power down. |
void init_rtc | ( | void | ) |
Init RTC module.
void init_sensors | ( | void | ) |
Create and setup sensors.
void init_spi | ( | void | ) |
Init SPI library.
void init_system | ( | void | ) |
Init system.
main loop state
void init_tasks | ( | void | ) |
Init tasks variable and state.
no tasks ready
reset samples_count value
void init_wdt | ( | uint8_t | wdt_timer | ) |
Init watchdog.
wdt_timer | a time value for init watchdog (WDTO_xxxx). |
void init_wire | ( | void | ) |
Init wire (i2c) library and performs checks on the bus.
ISR | ( | TIMER1_OVF_vect | ) |
Pre-load timer counter register
increment timer_counter by TIMER1_INTERRUPT_TIME_MS
check if SENSORS_SAMPLE_TIME_MS ms have passed since last time. if true and if is in continuous mode and continuous start command It has been received, activate Sensor OPC task
reset timer_counter if it has become larger than TIMER1_VALUE_MAX_MS
void load_configuration | ( | void | ) |
Load configuration from EEPROM.
read configuration from eeprom
void loop | ( | void | ) |
Arduino loop function. First, initialize tasks and sensors, then execute the tasks and activates the power down if no task is running.
bool make_observation_from_samples | ( | bool | is_force_processing, |
sample_g * | sample, | ||
observation_g * | observation | ||
) |
when true, indicates that sufficient samples have been acquired for the calculation of an observation
force processing when total samples count (sample->count + sample->error_count >= (SENSORS_SAMPLE_COUNT_MAX - SENSORS_SAMPLE_COUNT_TOLERANCE))
force processing when total samples count (sample->count + sample->error_count >= (SENSORS_SAMPLE_COUNT_MIN - SENSORS_SAMPLE_COUNT_TOLERANCE))
normal behavior: processing when correct sample count ((sample->count + sample->error_count) == samples_count)
add missing observation to observations buffer
increment ptr for set new calculted observation to observations buffer
bool make_value_from_samples_and_observations | ( | sample_g * | sample, |
observation_g * | observation, | ||
value_v * | value | ||
) |
assign last sample to report value
reset value to default
if true, you can calculate the value for report (there are at least STATISTICAL_DATA_COUNT observations)
good observation counter
error observation counter
current observation's value
minimum value
average value
maximum value
standard deviation value
loop backwards in last STATISTICAL_DATA_COUNT observations array
if it is a good observation, calculate sum, minimum and maximum value. Otherwise increment error counter.
check and assing minimum value
check and assing maximum value
average calculation
standard deviation
calculate report value only if there are enough good observations
assign last observation to report value
average
assign maximum observation to report value
assign minimum observation to report value
calculate standard deviation: make sense for count >=2
assign standard deviation to standard deviation report value
bool observations_processing | ( | void | ) |
Main routine for processing the observations to calculate a value for report.
if true, a new pm1 data report was calculated
if true, a new pm2.5 data report was calculated
if true, a new pm10 data report was calculated
if true, a new bins data report was calculated
void opc_task | ( | void | ) |
Opc setup and reading Task. Read data from OPC.
success
retry
fail
success
retry
fail
success
retry
fail
success
void print_configuration | ( | void | ) |
Print current configuration.
void reset_observations_buffer | ( | void | ) |
Reset observations buffers to default value.
void reset_samples_buffer | ( | void | ) |
Reset samples buffers to default value.
void samples_processing | ( | bool | is_force_processing | ) |
Main routine for processing the samples to calculate an observation.
is_force_processing | if is true, force the calculation of the observation provided there is a minimum number of samples. |
if true, a new bins and pm observation was calculated
assign new value for samples_count
reset samples's buffer values
void save_configuration | ( | bool | is_default | ) |
Save configuration to EEPROM.
is_default | if true save default configuration; if false save current configuration. |
write configuration to eeprom
void setup | ( | ) |
Arduino setup function. Init watchdog, hardware, debug, buffer and load configuration stored in EEPROM.
Arduino setup function. Init watchdog, hardware, debug and load configuration stored in EEPROM.
void tests | ( | void | ) |
Performs specific operations based on the received command.
Performs tests operations based on the received command.