MAV'RIC
|
00001 /******************************************************************************* 00002 * Copyright (c) 2009-2016, MAV'RIC Development Team 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of the copyright holder nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software without 00017 * specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00023 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 * POSSIBILITY OF SUCH DAMAGE. 00030 ******************************************************************************/ 00031 00032 /******************************************************************************* 00033 * \file onboard_parameters.hpp 00034 * 00035 * \author MAV'RIC Team 00036 * \author Julien Lecoeur 00037 * 00038 * \brief Onboard parameters 00039 * 00040 ******************************************************************************/ 00041 00042 00043 #ifndef ONBOARD_PARAMETERS_HPP_ 00044 #define ONBOARD_PARAMETERS_HPP_ 00045 00046 #include <cstdbool> 00047 00048 #include "communication/mavlink_stream.hpp" 00049 #include "communication/mavlink_message_handler.hpp" 00050 #include "status/state.hpp" 00051 #include "hal/common/file.hpp" 00052 00053 00060 class Onboard_parameters 00061 { 00062 public: 00063 00067 struct conf_t 00068 { 00069 bool debug; 00070 }; 00071 00072 00078 static inline conf_t default_config(void); 00079 00080 00092 Onboard_parameters(File& file, const State& state, Mavlink_message_handler& message_handler, const Mavlink_stream& mavlink_stream, const conf_t& config); 00093 00102 bool add(uint32_t* val, const char* param_name); 00103 00112 bool add(int32_t* val, const char* param_name); 00113 00122 bool add(float* val, const char* param_name); 00123 00129 bool read_from_storage(); 00130 00136 bool write_to_storage(); 00137 00143 bool send_first_scheduled_parameter(void); 00144 00145 00146 protected: 00147 00151 struct param_entry_t 00152 { 00153 float* param; 00154 char param_name[MAVLINK_MSG_PARAM_SET_FIELD_PARAM_ID_LEN]; 00155 mavlink_message_type_t data_type; 00156 uint8_t param_name_length; 00157 uint8_t param_id; 00158 bool schedule_for_transmission; 00159 }; 00160 00161 00169 virtual uint32_t max_count(void) = 0; 00170 00171 00179 virtual param_entry_t* parameters(void) = 0; 00180 00181 00182 private: 00183 00184 bool debug_; 00185 File& file_; 00186 const State& state_; 00187 const Mavlink_stream& mavlink_stream_; 00188 uint32_t param_count_; 00189 00190 00198 bool send_one_parameter_now(uint32_t index); 00199 00200 00201 /****************************** 00202 * static callback functions * 00203 ******************************/ 00211 static bool send_all_scheduled_parameters(Onboard_parameters* onboard_parameters); 00212 00220 static void schedule_all_parameters(Onboard_parameters* onboard_parameters, uint32_t sysid, const mavlink_message_t* msg); 00221 00229 static void send_parameter(Onboard_parameters* onboard_parameters, uint32_t sysid, const mavlink_message_t* msg); 00230 00238 static void receive_parameter(Onboard_parameters* onboard_parameters, uint32_t sysid, const mavlink_message_t* msg); 00239 00248 static mav_result_t preflight_storage(Onboard_parameters* onboard_parameters, const mavlink_command_long_t* msg); 00249 00250 }; 00251 00257 template<uint32_t N> 00258 class Onboard_parameters_T: public Onboard_parameters 00259 { 00260 public: 00272 Onboard_parameters_T(File& file, const State& state, Mavlink_message_handler& message_handler, const Mavlink_stream& mavlink_stream, const conf_t& config): 00273 Onboard_parameters(file, state, message_handler, mavlink_stream, config) 00274 {} 00275 00276 00277 protected: 00278 00284 uint32_t max_count(void) 00285 { 00286 return N; 00287 } 00288 00289 00295 param_entry_t* parameters(void) 00296 { 00297 return parameters_; 00298 } 00299 00300 00301 private: 00302 param_entry_t parameters_[N]; 00303 }; 00304 00305 00311 Onboard_parameters::conf_t Onboard_parameters::default_config(void) 00312 { 00313 conf_t conf = {}; 00314 conf.debug = false; 00315 return conf; 00316 } 00317 00318 #endif /* ONBOARD_PARAMETERS_HPP_ */