Line data Source code
1 : #pragma once 2 : 3 : #include "AP_Logger_Backend.h" 4 : #include <AP_Rally/AP_Rally.h> 5 : #include <AP_RTC/AP_RTC_config.h> 6 : 7 : class LoggerMessageWriter { 8 : public: 9 : 10 : virtual void reset() = 0; 11 : virtual void process() = 0; 12 308701231 : bool finished() const { return _finished; } 13 : 14 10470 : virtual void set_logger_backend(class AP_Logger_Backend *backend) { 15 10470 : _logger_backend = backend; 16 10470 : } 17 : 18 : bool out_of_time_for_writing_messages() const; 19 : 20 : protected: 21 : bool _finished = false; 22 : AP_Logger_Backend *_logger_backend = nullptr; 23 : }; 24 : 25 : 26 : class LoggerMessageWriter_WriteSysInfo : public LoggerMessageWriter { 27 : public: 28 : 29 : void reset() override; 30 : void process() override; 31 : 32 : private: 33 : enum class Stage : uint8_t { 34 : FIRMWARE_STRING = 0, 35 : GIT_VERSIONS, 36 : VER, // i.e. the "VER" message 37 : SYSTEM_ID, 38 : PARAM_SPACE_USED, 39 : RC_PROTOCOL, 40 : RC_OUTPUT, 41 : #if AP_RTC_LOGGING_ENABLED 42 : LOG_RTC_MSG, 43 : #endif // AP_RTC_LOGGING_ENABLED 44 : }; 45 : Stage stage; 46 : }; 47 : 48 : class LoggerMessageWriter_WriteEntireMission : public LoggerMessageWriter { 49 : public: 50 : 51 : void reset() override; 52 : void process() override; 53 : 54 : private: 55 : enum class Stage { 56 : WRITE_NEW_MISSION_MESSAGE = 0, 57 : WRITE_MISSION_ITEMS, 58 : DONE 59 : }; 60 : 61 : uint16_t _mission_number_to_send; 62 : Stage stage; 63 : }; 64 : 65 : class LoggerMessageWriter_WriteAllRallyPoints : public LoggerMessageWriter { 66 : public: 67 : 68 : void reset() override; 69 : void process() override; 70 : 71 : private: 72 : enum class Stage { 73 : WRITE_NEW_RALLY_MESSAGE = 0, 74 : WRITE_ALL_RALLY_POINTS, 75 : DONE 76 : }; 77 : 78 : uint16_t _rally_number_to_send; 79 : Stage stage = Stage::WRITE_NEW_RALLY_MESSAGE; 80 : }; 81 : 82 : #if HAL_LOGGER_FENCE_ENABLED 83 : class LoggerMessageWriter_Write_Polyfence : public LoggerMessageWriter { 84 : public: 85 : 86 : void reset() override; 87 : void process() override; 88 : 89 : private: 90 : enum class Stage { 91 : WRITE_NEW_FENCE_MESSAGE = 0, 92 : WRITE_FENCE_ITEMS, 93 : DONE 94 : }; 95 : 96 : uint16_t _fence_number_to_send; 97 : Stage stage; 98 : }; 99 : #endif // HAL_LOGGER_FENCE_ENABLED 100 : 101 : class LoggerMessageWriter_DFLogStart : public LoggerMessageWriter { 102 : public: 103 2094 : LoggerMessageWriter_DFLogStart() : 104 2094 : _writesysinfo() 105 : #if AP_MISSION_ENABLED 106 2094 : , _writeentiremission() 107 : #endif 108 : #if HAL_RALLY_ENABLED 109 2094 : , _writeallrallypoints() 110 : #endif 111 : #if HAL_LOGGER_FENCE_ENABLED 112 4188 : , _writeallpolyfence() 113 : #endif 114 : { 115 2094 : } 116 : 117 2094 : void set_logger_backend(class AP_Logger_Backend *backend) override final { 118 2094 : LoggerMessageWriter::set_logger_backend(backend); 119 2094 : _writesysinfo.set_logger_backend(backend); 120 : #if AP_MISSION_ENABLED 121 2094 : _writeentiremission.set_logger_backend(backend); 122 : #endif 123 : #if HAL_RALLY_ENABLED 124 2094 : _writeallrallypoints.set_logger_backend(backend); 125 : #endif 126 : #if HAL_LOGGER_FENCE_ENABLED 127 2094 : _writeallpolyfence.set_logger_backend(backend); 128 : #endif 129 2094 : } 130 : 131 : bool out_of_time_for_writing_messages_df() const; 132 : 133 : void reset() override; 134 : void process() override; 135 4004167 : bool fmt_done() const { return _fmt_done; } 136 : bool params_done() const { return _params_done; } 137 : 138 : // reset some writers so we push stuff out to logs again. Will 139 : // only work if we are in state DONE! 140 : #if AP_MISSION_ENABLED 141 : bool writeentiremission(); 142 : #endif 143 : #if HAL_RALLY_ENABLED 144 : bool writeallrallypoints(); 145 : #endif 146 : #if HAL_LOGGER_FENCE_ENABLED 147 : bool writeallfence(); 148 : #endif 149 : 150 : private: 151 : 152 : // check for using too much time 153 : static bool check_process_limit(uint32_t start_us); 154 : 155 : enum class Stage { 156 : FORMATS = 0, 157 : UNITS, 158 : MULTIPLIERS, 159 : FORMAT_UNITS, 160 : PARMS, 161 : VEHICLE_MESSAGES, 162 : RUNNING_SUBWRITERS, // must be last thing to run as we can redo bits of these 163 : DONE, 164 : }; 165 : 166 : bool _fmt_done; 167 : bool _params_done; 168 : 169 : Stage stage; 170 : 171 : uint16_t next_format_to_send; 172 : 173 : uint8_t _next_unit_to_send; 174 : uint8_t _next_format_unit_to_send; 175 : uint8_t _next_multiplier_to_send; 176 : 177 : AP_Param::ParamToken token; 178 : AP_Param *ap; 179 : float param_default; 180 : enum ap_var_type type; 181 : 182 : 183 : LoggerMessageWriter_WriteSysInfo _writesysinfo; 184 : #if AP_MISSION_ENABLED 185 : LoggerMessageWriter_WriteEntireMission _writeentiremission; 186 : #endif 187 : #if HAL_RALLY_ENABLED 188 : LoggerMessageWriter_WriteAllRallyPoints _writeallrallypoints; 189 : #endif 190 : #if HAL_LOGGER_FENCE_ENABLED 191 : LoggerMessageWriter_Write_Polyfence _writeallpolyfence; 192 : #endif 193 : };