ardupilot/libraries/AP_EFI/AP_EFI.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

153 lines
3.6 KiB
C
Raw Permalink Normal View History

2018-03-28 20:37:58 -03:00
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
2022-07-15 20:38:26 -03:00
#include "AP_EFI_config.h"
#if HAL_EFI_ENABLED
2018-03-28 20:37:58 -03:00
#include <AP_Common/AP_Common.h>
#include <AP_Param/AP_Param.h>
2022-02-25 01:06:28 -04:00
#include <GCS_MAVLink/GCS_MAVLink.h>
#include "AP_EFI_ThrottleLinearisation.h"
2018-03-28 20:37:58 -03:00
#include "AP_EFI_Backend.h"
#include "AP_EFI_State.h"
/*
* This library aims to read data from Electronic Fuel Injection
* or Engine Control units. It is focused around the generic
* internal combustion engine state message provided by the
* UAVCAN protocol due to its comprehensiveness, but is extensible
* to use other forms of data transfer besides UAVCAN.
*
*
*
* Authors: Sriram Sami and David Ingraham
* With direction from Andrew Tridgell, Robert Lefebvre, Francisco Ferreira and
* Pavel Kirienko.
* Thanks to Yonah, SpektreWorks Inc, and HFE International.
*/
class AP_EFI {
public:
friend class AP_EFI_Backend;
// For parameter initialization
AP_EFI();
// Initializes backend
void init(void);
// Requests backend to update the frontend. Should be called at 10Hz.
void update();
// Returns the RPM
uint32_t get_rpm() const { return state.engine_speed_rpm; }
// returns enabled state of EFI
2020-08-07 01:04:06 -03:00
bool enabled() const { return type != Type::NONE; }
2018-03-28 20:37:58 -03:00
bool is_healthy() const;
// return timestamp of last update
uint32_t get_last_update_ms(void) const {
return state.last_updated_ms;
}
// get a copy of state structure
void get_state(EFI_State &state);
2018-03-28 20:37:58 -03:00
// Parameter info
static const struct AP_Param::GroupInfo var_info[];
// Backend driver types
2020-08-07 01:04:06 -03:00
enum class Type : uint8_t {
NONE = 0,
2023-06-21 08:09:25 -03:00
#if AP_EFI_SERIAL_MS_ENABLED
2020-08-07 01:04:06 -03:00
MegaSquirt = 1,
2023-06-21 08:09:25 -03:00
#endif
#if AP_EFI_NWPWU_ENABLED
2022-09-04 04:15:49 -03:00
NWPMU = 2,
2023-06-21 08:09:25 -03:00
#endif
#if AP_EFI_SERIAL_LUTAN_ENABLED
2022-09-04 04:15:49 -03:00
Lutan = 3,
2023-06-21 08:09:25 -03:00
#endif
// LOWEHEISER = 4,
2023-06-21 08:09:25 -03:00
#if AP_EFI_DRONECAN_ENABLED
2022-06-03 19:09:58 -03:00
DroneCAN = 5,
2023-06-21 08:09:25 -03:00
#endif
#if AP_EFI_CURRAWONG_ECU_ENABLED
CurrawongECU = 6,
2023-06-21 08:09:25 -03:00
#endif
#if AP_EFI_SCRIPTING_ENABLED
2022-09-04 04:15:49 -03:00
SCRIPTING = 7,
2023-06-21 08:09:25 -03:00
#endif
#if AP_EFI_SERIAL_HIRTH_ENABLED
Hirth = 8,
#endif
2023-06-27 05:02:59 -03:00
MAV = 9,
2018-03-28 20:37:58 -03:00
};
static AP_EFI *get_singleton(void) {
return singleton;
}
// send EFI_STATUS
void send_mavlink_status(mavlink_channel_t chan);
2022-09-04 04:15:49 -03:00
#if AP_SCRIPTING_ENABLED
AP_EFI_Backend* get_backend(uint8_t idx) { return idx==0?backend:nullptr; }
2022-09-04 04:15:49 -03:00
#endif
2023-06-27 05:02:59 -03:00
void handle_EFI_message(const mavlink_message_t &msg);
2018-03-28 20:37:58 -03:00
protected:
// Back end Parameters
AP_Float coef1;
AP_Float coef2;
AP_Float ecu_fuel_density;
2018-03-28 20:37:58 -03:00
EFI_State state;
#if AP_EFI_THROTTLE_LINEARISATION_ENABLED
AP_EFI_ThrLin throttle_linearisation;
#endif
2018-03-28 20:37:58 -03:00
private:
// Front End Parameters
2020-08-07 01:04:06 -03:00
AP_Enum<Type> type;
2018-03-28 20:37:58 -03:00
// Tracking backends
AP_EFI_Backend *backend;
static AP_EFI *singleton;
// Semaphore for access to shared frontend data
HAL_Semaphore sem;
2018-03-28 20:37:58 -03:00
// write to log
void log_status();
};
namespace AP {
AP_EFI *EFI();
};
2021-06-08 01:16:33 -03:00
#endif // HAL_EFI_ENABLED