STIMA
3
|
#include <stima_module.h>
#include "stima-config.h"
#include <typedef.h>
#include <registers.h>
#include <registers-master.h>
#include <debug.h>
#include <ArduinoLog.h>
#include <StreamUtils.h>
#include <i2c_config.h>
#include <json_config.h>
#include <ntp_config.h>
#include <constantdata_config.h>
#include <gsm_config.h>
#include <SPI.h>
#include <Wire.h>
#include <pcf8563.h>
#include <rmap_utility.h>
#include <TimeLib.h>
#include <SensorDriver.h>
#include <i2c_utility.h>
#include <arduinoJsonRPC.h>
#include <ethernet_config.h>
#include <Ethernet2.h>
#include <IWatchdog.h>
#include "STM32LowPower.h"
#include <STM32RTC.h>
#include <rtc.h>
Go to the source code of this file.
Classes | |
struct | constantdata_t |
struct | configuration_t |
EEPROM saved configuration. More... | |
Macros | |
#define | WDTO_1S 1 |
#define | SLEEP_MODE_PWR_DOWN 1 |
Enumerations | |
enum | state_t { INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END , REBOOT , INIT , TASKS_EXECUTION , END , INIT , TASKS_EXECUTION , END } |
Main loop finite state machine. More... | |
enum | supervisor_state_t { SUPERVISOR_INIT , SUPERVISOR_CONNECTION_LEVEL_TASK , SUPERVISOR_WAIT_CONNECTION_LEVEL_TASK , SUPERVISOR_TIME_LEVEL_TASK , SUPERVISOR_MANAGE_LEVEL_TASK , SUPERVISOR_TEST_SDCARD , SUPERVISOR_END , SUPERVISOR_WAIT_STATE } |
Supervisor task finite state machine. More... | |
enum | ethernet_state_t { ETHERNET_INIT , ETHERNET_CONNECT , ETHERNET_OPEN_UDP_SOCKET , ETHERNET_END , ETHERNET_WAIT_STATE } |
Ethernet task finite state machine. More... | |
enum | sensors_reading_state_t { SENSORS_READING_INIT , SENSORS_READING_SETUP_CHECK , SENSORS_READING_POWER_OFF , SENSORS_READING_POWER_ON , SENSORS_READING_SETUP , SENSORS_READING_PREPARE , SENSORS_READING_IS_PREPARED , SENSORS_READING_GET , SENSORS_READING_IS_GETTED , SENSORS_READING_READ , SENSORS_READING_NEXT , SENSORS_READING_END , SENSORS_READING_WAIT_STATE , SENSORS_READING_INIT , SENSORS_SETUP_CHECK , SENSORS_READING_PREPARE , SENSORS_READING_IS_PREPARED , SENSORS_READING_GET , SENSORS_READING_IS_GETTED , SENSORS_READING_READ , SENSORS_READING_NEXT , SENSORS_READING_END , SENSORS_READING_WAIT_STATE , SENSORS_READING_INIT , SENSORS_READING_SETUP_CHECK , SENSORS_READING_POWER_OFF , SENSORS_READING_POWER_ON , SENSORS_READING_SETUP , SENSORS_READING_PREPARE , SENSORS_READING_IS_PREPARED , SENSORS_READING_GET , SENSORS_READING_IS_GETTED , SENSORS_READING_READ , SENSORS_READING_NEXT , SENSORS_READING_END , SENSORS_READING_WAIT_STATE , SENSORS_READING_INIT , SENSORS_READING_PREPARE , SENSORS_READING_IS_PREPARED , SENSORS_READING_GET , SENSORS_READING_IS_GETTED , SENSORS_READING_READ , SENSORS_READING_NEXT , SENSORS_READING_END , SENSORS_READING_WAIT_STATE } |
Sensors reading task finite state machine. More... | |
enum | time_state_t { TIME_INIT , TIME_SEND_ONLINE_REQUEST , TIME_WAIT_ONLINE_RESPONSE , TIME_SET_SYNC_NTP_PROVIDER , TIME_SET_SYNC_RTC_PROVIDER , TIME_END , TIME_WAIT_STATE } |
Time task finite state machine. More... | |
enum | rpc_state_t { RPC_INIT , RPC_EXECUTE , RPC_END } |
RPC task finite state machine. More... | |
Functions | |
JsonRPC | streamRpc (false) |
Remote Procedure Call object. | |
void | realreboot () |
time_t | getSystemTime () |
void | init_logging (void) |
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_system (void) |
Init system. More... | |
void | init_rpc (void) |
Register RPC. More... | |
void | init_buffers (void) |
Init buffers. More... | |
void | init_tasks (void) |
Init tasks variable and state. More... | |
void | init_pins (void) |
Init hardware pins. More... | |
void | init_wire (void) |
Init wire (i2c) library and performs checks on the bus. More... | |
void | init_spi (void) |
Init SPI library. More... | |
void | init_rtc (void) |
Init RTC module. More... | |
void | init_timer1 (void) |
Init Timer1 module. More... | |
void | start_timer (void) |
Start Timer1 module. More... | |
void | stop_timer (void) |
Stop Timer1 module. More... | |
void | interrupt_task_1s (void) |
1 seconds task. More... | |
void | init_sensors (void) |
Create and setup sensors. More... | |
void | print_configuration (void) |
Print current configuration. More... | |
void | load_configuration (void) |
Load configuration from EEPROM. More... | |
void | save_configuration (bool) |
Save configuration to EEPROM. More... | |
void | set_default_configuration (void) |
Set default configuration to global configuration variable. More... | |
void | setNextTimeForSensorReading (time_t *next_time, uint16_t time_s) |
bool | extractSensorsParams (JsonObject ¶ms, char *driver, char *type, uint8_t *address, uint8_t *node) |
Extract sensor's parameter. More... | |
int | configure (JsonObject ¶ms, JsonObject &result) |
RPC configuration. More... | |
int | prepare (JsonObject ¶ms, JsonObject &result) |
RPC prepare. More... | |
int | getjson (JsonObject ¶ms, JsonObject &result) |
RPC get json. More... | |
int | prepandget (JsonObject ¶ms, JsonObject &result) |
RPC prepare and get json. More... | |
int | reboot (JsonObject ¶ms, JsonObject &result) |
RPC reboot. More... | |
void | supervisor_task (void) |
Supervisor task. Manage RTC and NTP sync and open/close gsm and ethernet connection. More... | |
void | sensors_reading_task (bool do_prepare=true, bool do_get=true, char *driver=NULL, char *type=NULL, uint8_t address=0, uint8_t node=0, uint8_t *sensor_index=0, uint32_t *wait_time=NULL) |
Sensors reading Task. Read data from sensors. More... | |
void | rtc_task (void) |
Real Time Clock task. Read RTC time and sync system time with it. More... | |
void | time_task (void) |
Time task. Get time from NTP and sync RTC with it. More... | |
void | ethernet_task (void) |
Ethernet task. Manage Ethernet operation. More... | |
void | rtc_interrupt_handler (void) |
Real Time Clock interrupt handler. More... | |
HardwareSerial | Serial1 (PB11, PB10) |
void | wdt_enable (int wdt_timer) |
void | wdt_reset () |
void | wdt_disable () |
void | power_adc_disable () |
void | power_spi_disable () |
void | power_timer0_disable () |
void | power_timer1_disable () |
void | power_timer2_disable () |
void | power_adc_enable () |
void | power_spi_enable () |
void | power_timer0_enable () |
void | power_timer1_enable () |
void | power_timer2_enable () |
void | set_sleep_mode (int SLEEP_MODE_PWR_DOWN) |
void | sleep_enable () |
void | sleep_cpu () |
void | sleep_disable () |
Variables | |
uint8_t | sensors_count = 0 |
bool | is_datetime_set |
A valid date and time is setted and usable by station. | |
bool | have_to_reboot |
Request for a reboot as soon as possible. | |
configuration_t | readable_configuration |
Configuration for this module. | |
configuration_t | writable_configuration |
Configuration for this module. | |
volatile uint8_t | ready_tasks_count |
uint32_t | awakened_event_occurred_time_ms |
EthernetUDP | eth_udp_client |
Ethernet UDP client structure. | |
EthernetClient | eth_tcp_client |
Ethernet TCP client structure. | |
SensorDriver * | sensors [SENSORS_MAX] |
bool | is_first_run |
If true, the first reading of the sensors was performed. | |
bool | do_reset_first_run |
If true, the first reading of the sensors was performed. | |
bool | is_first_test |
If true, the first reading of the sensors was performed. | |
bool | is_test |
bool | is_time_set |
If true, the time was readed from rtc or ntp and was setted in system. | |
bool | is_time_for_sensors_reading_updated |
If true, the next time has been calculated to read the sensors. | |
bool | is_client_connected |
If true, the client (ethernet or gsm) was connected to socket (TCP or UDP). | |
bool | is_client_udp_socket_open |
If true, the client (ethernet or gsm) was opened the UDP socket. | |
bool | is_event_client_executed |
If true, the client has executed its task. | |
bool | is_event_time_executed |
If true, the time task has executed. | |
bool | do_ntp_sync |
If true, you must update the time from ntp. | |
time_t | last_ntp_sync |
Last date and time when ntp sync was performed. | |
char | json_sensors_data [SENSORS_MAX][JSON_BUFFER_LENGTH] |
buffer containing the data read by sensors in json text format. | |
char | json_sensors_data_test [JSON_BUFFER_LENGTH] |
buffer containing the data read by sensors in json text format for test only. | |
volatile time_t | system_time |
System time since 01/01/1970 00:00:00. | |
volatile time_t | next_ptr_time_for_sensors_reading |
Next scheduled time (in seconds since 01/01/1970 00:0:00) for sensors reading. | |
volatile time_t | next_ptr_time_for_testing_sensors |
Next scheduled time (in seconds since 01/01/1970 00:0:00) for sensors reading. | |
uint8_t | sensor_reading_failed_count |
Counter for failed and skipped sensors. | |
volatile tmElements_t | sensor_reading_time |
Date and time corresponding to the last reading of the sensors. | |
time_t | ptr_time_data |
Readed data pointer stored on SD-Card for data send. | |
char | stima_name [20] |
Name of this module. | |
state_t | state |
supervisor_state_t | supervisor_state |
Supervisor task state. | |
ethernet_state_t | ethernet_state |
Ethernet task state. | |
uint8_t | i2c_error |
time_state_t | time_state |
Time task state. | |
sensors_reading_state_t | sensors_reading_state |
rpc_state_t | rpc_state |
RPC task state. | |
bool | is_event_supervisor |
Enable or disable the Supervisor task. | |
volatile bool | is_event_sensors_reading |
bool | is_event_sensors_reading_rpc |
Enable or disable the Sensors reading task from RPC. | |
volatile bool | is_event_rtc |
Enable or disable the Real Time Clock task. | |
volatile bool | is_event_time |
Enable or disable the Time task. | |
bool | is_event_ethernet |
Enable or disable the Ethernet task. | |
bool | is_event_rpc |
Indicate if RPC is active or not. | |
STM32RTC & | rtc = STM32RTC::getInstance() |
enum ethernet_state_t |
enum rpc_state_t |
enum sensors_reading_state_t |
Sensors reading task finite state machine.
enum state_t |
Main loop finite state machine.
enum supervisor_state_t |
Supervisor task finite state machine.
enum time_state_t |
Time task finite state machine.
int configure | ( | JsonObject & | params, |
JsonObject & | result | ||
) |
RPC configuration.
*params | json's params |
&result | json's response |
void ethernet_task | ( | void | ) |
Ethernet task. Manage Ethernet operation.
bool extractSensorsParams | ( | JsonObject & | params, |
char * | driver, | ||
char * | type, | ||
uint8_t * | address, | ||
uint8_t * | node | ||
) |
Extract sensor's parameter.
[in] | *params | json's params |
[out] | *driver | driver |
[out] | *type | type |
[out] | *address | address |
[out] | *node | node |
int getjson | ( | JsonObject & | params, |
JsonObject & | result | ||
) |
RPC get json.
*params | json's params |
&result | json's response |
void init_buffers | ( | ) |
Init buffers.
copy readable_data_2 in readable_data_1
copy readable_data_2 in readable_data_1
copy readable_data_write in readable_data_read
copy readable_data_write in readable_data_read
copy readable_data_2 in readable_data_1
copy readable_data_2 in readable_data_1
copy readable_data_write in readable_data_read
copy readable_data_write in readable_data_read
copy readable_data_write in readable_data_read
copy readable_data_2 in readable_data_1
copy readable_data_write in readable_data_read
copy readable_data_2 in readable_data_1
copy readable_data_2 in readable_data_1
copy readable_data_write in readable_data_read
copy readable_data_write in readable_data_read
copy readable_data_write in readable_data_read
copy readable_data_2 in readable_data_1
copy readable_data_write in readable_data_read
void init_logging | ( | ) |
Init logging system.
void init_pins | ( | ) |
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_rpc | ( | void | ) |
Register RPC.
void init_rtc | ( | ) |
Init RTC module.
void init_sensors | ( | ) |
Create and setup sensors.
void init_spi | ( | ) |
Init SPI library.
void init_system | ( | ) |
Init system.
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
main loop state
void init_tasks | ( | ) |
Init tasks variable and state.
no tasks ready
no tasks ready
reset samples_count value
no tasks ready
no tasks ready
reset samples_count value
no tasks ready
no tasks ready
reset samples_count value
no tasks ready
no tasks ready
reset samples_count value
no tasks ready
no tasks ready
no tasks ready
no tasks ready
no tasks ready
reset samples_count value
no tasks ready
no tasks ready
no tasks ready
no tasks ready
void init_timer1 | ( | void | ) |
Init Timer1 module.
void init_wdt | ( | uint8_t | wdt_timer | ) |
Init watchdog.
wdt_timer | a time value for init watchdog (WDTO_xxxx). |
void init_wire | ( | ) |
Init wire (i2c) library and performs checks on the bus.
clear the I2C bus first before calling Wire.begin()
clear the I2C bus first before calling Wire.begin()
void interrupt_task_1s | ( | void | ) |
1 seconds task.
void load_configuration | ( | ) |
Load configuration from EEPROM.
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
read configuration from eeprom
int prepandget | ( | JsonObject & | params, |
JsonObject & | result | ||
) |
RPC prepare and get json.
*params | json's params |
&result | json's response |
int prepare | ( | JsonObject & | params, |
JsonObject & | result | ||
) |
RPC prepare.
*params | json's params |
&result | json's response |
void print_configuration | ( | ) |
Print current configuration.
int reboot | ( | JsonObject & | params, |
JsonObject & | result | ||
) |
RPC reboot.
*params | json's params |
&result | json's response |
void rtc_interrupt_handler | ( | void | ) |
Real Time Clock interrupt handler.
void rtc_task | ( | void | ) |
Real Time Clock task. Read RTC time and sync system time with it.
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
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
write configuration to eeprom
void sensors_reading_task | ( | bool | do_prepare = true , |
bool | do_get = true , |
||
char * | driver = NULL , |
||
char * | type = NULL , |
||
uint8_t | address = 0 , |
||
uint8_t | node = 0 , |
||
uint8_t * | sensor_index = 0 , |
||
uint32_t * | wait_time = NULL |
||
) |
Sensors reading Task. Read data from sensors.
do_prepare | if true, execute the prepare sensor's procedure |
do_get | if true, execute the get sensor's procedure |
*driver | sensor's driver |
*type | sensor's type |
*address | sensor's address |
*node | sensor's node |
*sensor_index | sensor's index |
*wait_time | sensor's wait time |
void set_default_configuration | ( | void | ) |
Set default configuration to global configuration variable.
void start_timer | ( | void | ) |
Start Timer1 module.
< Normal timer operation
< 1:1024 prescaler
< Pre-load timer counter register
< Clear interrupt overflow flag register
< Enable overflow interrupt
void stop_timer | ( | void | ) |
Stop Timer1 module.
< Stop
< Disable overflow interrupt
< Clear interrupt overflow flag register
< Pre-load timer counter register
void supervisor_task | ( | void | ) |
Supervisor task. Manage RTC and NTP sync and open/close gsm and ethernet connection.
void time_task | ( | void | ) |
Time task. Get time from NTP and sync RTC with it.