work1

Dependencies:   mbed MAX44009 mbed-os Si7021

Committer:
danaeb
Date:
Wed May 27 12:34:37 2020 +0000
Revision:
1:3656b45f17a8
app_create

Who changed what in which revision?

UserRevisionLine numberNew contents of line
danaeb 1:3656b45f17a8 1 #ifndef TASK_MAIN_H
danaeb 1:3656b45f17a8 2 #define TASK_MAIN_H
danaeb 1:3656b45f17a8 3
danaeb 1:3656b45f17a8 4 #include "mbed.h"
danaeb 1:3656b45f17a8 5 #include "liboo/types.h"
danaeb 1:3656b45f17a8 6 #include "AppMain.h"
danaeb 1:3656b45f17a8 7 #include "AppLora.h"
danaeb 1:3656b45f17a8 8 #include "Button.h"
danaeb 1:3656b45f17a8 9 #include "Sensor.h"
danaeb 1:3656b45f17a8 10 #include "SensorManager.h"
danaeb 1:3656b45f17a8 11 #include "CommandSample.h"
danaeb 1:3656b45f17a8 12 #include "CommandSampleSelector.h"
danaeb 1:3656b45f17a8 13 //#include "Latch.h"
danaeb 1:3656b45f17a8 14
danaeb 1:3656b45f17a8 15 #include "Calendar.h"
danaeb 1:3656b45f17a8 16
danaeb 1:3656b45f17a8 17 #define COMMAND_COUNT 5
danaeb 1:3656b45f17a8 18 #define COMMAND_PAYLOAD_SIZE 255
danaeb 1:3656b45f17a8 19
danaeb 1:3656b45f17a8 20 #define DEBUG_MEMORY_START 2048
danaeb 1:3656b45f17a8 21 #define DEBUG_MEMORY_SIZE 128
danaeb 1:3656b45f17a8 22
danaeb 1:3656b45f17a8 23 using namespace liboo;
danaeb 1:3656b45f17a8 24 using namespace events;
danaeb 1:3656b45f17a8 25 class AppMain{
danaeb 1:3656b45f17a8 26 public:
danaeb 1:3656b45f17a8 27 typedef enum{
danaeb 1:3656b45f17a8 28 GLOBAL_STATE_STOP,
danaeb 1:3656b45f17a8 29 GLOBAL_STATE_JOIN,
danaeb 1:3656b45f17a8 30 GLOBAL_STATE_RUN,
danaeb 1:3656b45f17a8 31 GLOBAL_STATE_DISCONNECTING,
danaeb 1:3656b45f17a8 32 }GLOBAL_STATE;
danaeb 1:3656b45f17a8 33
danaeb 1:3656b45f17a8 34 typedef enum{
danaeb 1:3656b45f17a8 35 EVENT_SHORT_PUSH,
danaeb 1:3656b45f17a8 36 EVENT_LONG_PUSH,
danaeb 1:3656b45f17a8 37 EVENT_JOIN_SUCCESS,
danaeb 1:3656b45f17a8 38 EVENT_DISCONNECTED,
danaeb 1:3656b45f17a8 39 EVENT_JOIN_FAILED,
danaeb 1:3656b45f17a8 40 EVENT_CONNECTION_ERROR,
danaeb 1:3656b45f17a8 41 EVENT_MINUTE_ELAPSED,
danaeb 1:3656b45f17a8 42 EVENT_DAILY_SEND,
danaeb 1:3656b45f17a8 43
danaeb 1:3656b45f17a8 44 EVENT_TX_DONE,
danaeb 1:3656b45f17a8 45 EVENT_TX_ERROR,
danaeb 1:3656b45f17a8 46 EVENT_RX_ERROR,
danaeb 1:3656b45f17a8 47 }EVENT;
danaeb 1:3656b45f17a8 48
danaeb 1:3656b45f17a8 49 typedef enum{
danaeb 1:3656b45f17a8 50 RUN_STATE_READY,
danaeb 1:3656b45f17a8 51 RUN_STATE_WAIT_SEND_COMPLETE,
danaeb 1:3656b45f17a8 52 }RUN_STATE;
danaeb 1:3656b45f17a8 53
danaeb 1:3656b45f17a8 54 static void initialize(EventQueue *queue);
danaeb 1:3656b45f17a8 55 static void incoming_lora_message_callback(void);
danaeb 1:3656b45f17a8 56 static void set_history_size(u8 history_size);
danaeb 1:3656b45f17a8 57
danaeb 1:3656b45f17a8 58
danaeb 1:3656b45f17a8 59 private:
danaeb 1:3656b45f17a8 60 AppMain(){}; // private constructor that prevent anyone from
danaeb 1:3656b45f17a8 61 // creating the instance
danaeb 1:3656b45f17a8 62 static void _create_sensors(void);
danaeb 1:3656b45f17a8 63 static void _button_callback_handler(Button::ACTION action);
danaeb 1:3656b45f17a8 64 static void _lora_callback_handler(AppLora::EVENT event);
danaeb 1:3656b45f17a8 65 static void _minute_elapsed_callback_handler(void);
danaeb 1:3656b45f17a8 66 static void _daily_send_callback_handler(void);
danaeb 1:3656b45f17a8 67
danaeb 1:3656b45f17a8 68 static void _global_event_handler_from_interrupt(AppMain::EVENT event);
danaeb 1:3656b45f17a8 69 static void _global_event_handler(AppMain::EVENT event);
danaeb 1:3656b45f17a8 70 static void _run_event_handler(AppMain::EVENT event);
danaeb 1:3656b45f17a8 71
danaeb 1:3656b45f17a8 72 static void _minutes_elapsed(void);
danaeb 1:3656b45f17a8 73 static void _enter_global_state_stop(void);
danaeb 1:3656b45f17a8 74 static void _enter_global_state_join(void);
danaeb 1:3656b45f17a8 75 static void _enter_global_state_run(void);
danaeb 1:3656b45f17a8 76 static void _enter_global_state_disconnecting(void);
danaeb 1:3656b45f17a8 77 static void _compute_random_number(void);
danaeb 1:3656b45f17a8 78 static void _trigger_latch(bool sens);
danaeb 1:3656b45f17a8 79
danaeb 1:3656b45f17a8 80 //debug
danaeb 1:3656b45f17a8 81 static void _write_time(char* buffer);
danaeb 1:3656b45f17a8 82
danaeb 1:3656b45f17a8 83 static s8 _send_empty(void);
danaeb 1:3656b45f17a8 84 static void _scheduled_send(bool is_hourly_send);
danaeb 1:3656b45f17a8 85 static s8 _send_samples(bool is_hourly_send);
danaeb 1:3656b45f17a8 86
danaeb 1:3656b45f17a8 87 static SensorData _sensor_data;
danaeb 1:3656b45f17a8 88 static Sensor *_sensor_array[CONFIG_SENSOR_COUNT];
danaeb 1:3656b45f17a8 89 static CommandSample *_command_sample_array[COMMAND_COUNT];
danaeb 1:3656b45f17a8 90 static u8 _command_payload[COMMAND_PAYLOAD_SIZE];
danaeb 1:3656b45f17a8 91 static EventQueue *_queue;
danaeb 1:3656b45f17a8 92 //static PCAL6416 *_gpio_exp;
danaeb 1:3656b45f17a8 93 static LedBlinker *_led_blinker;
danaeb 1:3656b45f17a8 94 static Button *_button;
danaeb 1:3656b45f17a8 95 static SensorManager *_sensor_manager;
danaeb 1:3656b45f17a8 96 static Calendar *_calendar;
danaeb 1:3656b45f17a8 97 static MemoryDeviceEeprom *_memory_device_calendar;
danaeb 1:3656b45f17a8 98 //static Latch *_latch;
danaeb 1:3656b45f17a8 99 static CommandSampleSelector _command_selector;
danaeb 1:3656b45f17a8 100
danaeb 1:3656b45f17a8 101 /*
danaeb 1:3656b45f17a8 102 static SensorBattery *_sensor_battery;
danaeb 1:3656b45f17a8 103 static SensorTensiometer *_sensor_tensiometer_1;
danaeb 1:3656b45f17a8 104 static SensorTensiometer *_sensor_tensiometer_2;
danaeb 1:3656b45f17a8 105 static SensorTensiometer *_sensor_tensiometer_3;
danaeb 1:3656b45f17a8 106 static SensorPressure *_sensor_pressure_1;
danaeb 1:3656b45f17a8 107 static SensorPressure *_sensor_pressure_2;
danaeb 1:3656b45f17a8 108 static SensorPressure *_sensor_pressure_3;
danaeb 1:3656b45f17a8 109 static SensorPressure *_sensor_pressure_pipe;
danaeb 1:3656b45f17a8 110 static SensorSoilTemperature *sensor_soil_temperature;
danaeb 1:3656b45f17a8 111 //static SensorBoardTempRH *sensor_board_temp_rh;
danaeb 1:3656b45f17a8 112 */
danaeb 1:3656b45f17a8 113
danaeb 1:3656b45f17a8 114 static GLOBAL_STATE _global_state;
danaeb 1:3656b45f17a8 115 static RUN_STATE _run_state;
danaeb 1:3656b45f17a8 116 //static bool _forced_timestamp; // all frame must be timestamp until
danaeb 1:3656b45f17a8 117 // the server answer
danaeb 1:3656b45f17a8 118 //static bool _next_frame_timestamped; // every day a frame
danaeb 1:3656b45f17a8 119 // must be timestamped
danaeb 1:3656b45f17a8 120 static u32 _daily_send_s;
danaeb 1:3656b45f17a8 121 static u8 _remaining_join_tries;
danaeb 1:3656b45f17a8 122 static u8 _remaining_sample_before_send; // number of time the sensor have
danaeb 1:3656b45f17a8 123 // sampled. When this number reach 5
danaeb 1:3656b45f17a8 124 // a transmition is scheduled
danaeb 1:3656b45f17a8 125 static u8 _transmit_count_before_alternate; // every 6 transmit we
danaeb 1:3656b45f17a8 126 // must use alternate
danaeb 1:3656b45f17a8 127 // command
danaeb 1:3656b45f17a8 128 static u8 _send_delay;
danaeb 1:3656b45f17a8 129 static u8 _history_size;
danaeb 1:3656b45f17a8 130 static char _time_buffer[24];
danaeb 1:3656b45f17a8 131
danaeb 1:3656b45f17a8 132 static void _software_watchdog_increment();
danaeb 1:3656b45f17a8 133 static void _software_watchdog_reset();
danaeb 1:3656b45f17a8 134 static void _software_watchdog_enable();
danaeb 1:3656b45f17a8 135 static void _software_watchdog_disable();
danaeb 1:3656b45f17a8 136 static u8 _software_watchdog_time;
danaeb 1:3656b45f17a8 137 static bool _software_watchdog_is_enable;
danaeb 1:3656b45f17a8 138
danaeb 1:3656b45f17a8 139 };
danaeb 1:3656b45f17a8 140
danaeb 1:3656b45f17a8 141 #endif
danaeb 1:3656b45f17a8 142