CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.cpp
Views: 1798
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
16
#include "AP_ESC_Telem_Backend.h"
17
#include "AP_ESC_Telem.h"
18
#include <AP_HAL/AP_HAL.h>
19
20
#if HAL_WITH_ESC_TELEM
21
22
#include <AP_Math/AP_Math.h>
23
#include <AP_Vehicle/AP_Vehicle_Type.h>
24
25
extern const AP_HAL::HAL& hal;
26
27
AP_ESC_Telem_Backend::AP_ESC_Telem_Backend() {
28
_frontend = AP_ESC_Telem::_singleton;
29
#if !APM_BUILD_TYPE(APM_BUILD_UNKNOWN)
30
// we allow for no frontend in example fw and tools to make it
31
// possible to run them on hardware with IOMCU
32
if (_frontend == nullptr) {
33
AP_HAL::panic("No ESC frontend");
34
}
35
#endif
36
}
37
38
// callback to update the rpm in the frontend, should be called by the driver when new data is available
39
void AP_ESC_Telem_Backend::update_rpm(const uint8_t esc_index, const float new_rpm, const float error_rate) {
40
_frontend->update_rpm(esc_index, new_rpm, error_rate);
41
}
42
43
// callback to update the data in the frontend, should be called by the driver when new data is available
44
void AP_ESC_Telem_Backend::update_telem_data(const uint8_t esc_index, const TelemetryData& new_data, const uint16_t data_present_mask) {
45
_frontend->update_telem_data(esc_index, new_data, data_present_mask);
46
}
47
48
/*
49
return true if the data is stale
50
*/
51
bool AP_ESC_Telem_Backend::TelemetryData::stale(uint32_t now_ms) const volatile
52
{
53
return last_update_ms == 0 || now_ms - last_update_ms > ESC_TELEM_DATA_TIMEOUT_MS;
54
}
55
56
/*
57
return true if the requested types of data are available and not stale
58
*/
59
bool AP_ESC_Telem_Backend::TelemetryData::valid(const uint16_t type_mask) const volatile
60
{
61
if ((types & type_mask) == 0) {
62
// Requested type not available
63
return false;
64
}
65
return !stale(AP_HAL::millis());
66
}
67
68
#endif
69
70