Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.cpp
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415#include "AP_ESC_Telem_Backend.h"16#include "AP_ESC_Telem.h"17#include <AP_HAL/AP_HAL.h>1819#if HAL_WITH_ESC_TELEM2021#include <AP_Math/AP_Math.h>22#include <AP_Vehicle/AP_Vehicle_Type.h>2324extern const AP_HAL::HAL& hal;2526AP_ESC_Telem_Backend::AP_ESC_Telem_Backend() {27_frontend = AP_ESC_Telem::_singleton;28#if !APM_BUILD_TYPE(APM_BUILD_UNKNOWN)29// we allow for no frontend in example fw and tools to make it30// possible to run them on hardware with IOMCU31if (_frontend == nullptr) {32AP_HAL::panic("No ESC frontend");33}34#endif35}3637// callback to update the rpm in the frontend, should be called by the driver when new data is available38void AP_ESC_Telem_Backend::update_rpm(const uint8_t esc_index, const float new_rpm, const float error_rate) {39_frontend->update_rpm(esc_index, new_rpm, error_rate);40}4142// callback to update the data in the frontend, should be called by the driver when new data is available43void AP_ESC_Telem_Backend::update_telem_data(const uint8_t esc_index, const TelemetryData& new_data, const uint16_t data_present_mask) {44_frontend->update_telem_data(esc_index, new_data, data_present_mask);45}4647/*48return true if the data is stale49*/50bool AP_ESC_Telem_Backend::TelemetryData::stale(uint32_t now_ms) const volatile51{52return last_update_ms == 0 || now_ms - last_update_ms > ESC_TELEM_DATA_TIMEOUT_MS;53}5455/*56return true if the requested types of data are available and not stale57*/58bool AP_ESC_Telem_Backend::TelemetryData::valid(const uint16_t type_mask) const volatile59{60if ((types & type_mask) == 0) {61// Requested type not available62return false;63}64return !stale(AP_HAL::millis());65}6667#endif686970