AP_EFI: add EFI scripting driver

This commit is contained in:
Joshua Henderson 2022-09-04 03:15:49 -04:00 committed by Randy Mackay
parent 24962be00b
commit 15314b8ed6
5 changed files with 71 additions and 3 deletions

View File

@ -22,6 +22,8 @@
#include "AP_EFI_NWPMU.h" #include "AP_EFI_NWPMU.h"
#include "AP_EFI_DroneCAN.h" #include "AP_EFI_DroneCAN.h"
#include "AP_EFI_Currawong_ECU.h" #include "AP_EFI_Currawong_ECU.h"
#include "AP_EFI_Scripting.h"
#include <AP_Logger/AP_Logger.h> #include <AP_Logger/AP_Logger.h>
#if HAL_MAX_CAN_PROTOCOL_DRIVERS #if HAL_MAX_CAN_PROTOCOL_DRIVERS
@ -35,7 +37,7 @@ const AP_Param::GroupInfo AP_EFI::var_info[] = {
// @Param: _TYPE // @Param: _TYPE
// @DisplayName: EFI communication type // @DisplayName: EFI communication type
// @Description: What method of communication is used for EFI #1 // @Description: What method of communication is used for EFI #1
// @Values: 0:None,1:Serial-MS,2:NWPMU,3:Serial-Lutan,5:DroneCAN,6:Currawong-ECU // @Values: 0:None,1:Serial-MS,2:NWPMU,3:Serial-Lutan,5:DroneCAN,6:Currawong-ECU,7:Scripting
// @User: Advanced // @User: Advanced
// @RebootRequired: True // @RebootRequired: True
AP_GROUPINFO_FLAGS("_TYPE", 1, AP_EFI, type, 0, AP_PARAM_FLAG_ENABLE), AP_GROUPINFO_FLAGS("_TYPE", 1, AP_EFI, type, 0, AP_PARAM_FLAG_ENABLE),
@ -103,6 +105,11 @@ void AP_EFI::init(void)
case Type::CurrawongECU: case Type::CurrawongECU:
#if HAL_EFI_CURRAWONG_ECU_ENABLED #if HAL_EFI_CURRAWONG_ECU_ENABLED
backend = new AP_EFI_Currawong_ECU(*this); backend = new AP_EFI_Currawong_ECU(*this);
#endif
break;
case Type::SCRIPTING:
#if AP_EFI_SCRIPTING_ENABLED
backend = new AP_EFI_Scripting(*this);
#endif #endif
break; break;
default: default:
@ -271,6 +278,19 @@ void AP_EFI::get_state(EFI_State &_state)
_state = state; _state = state;
} }
#if AP_EFI_SCRIPTING_ENABLED && AP_SCRIPTING_ENABLED
void AP_EFI::handle_scripting(const EFI_State &efi_state)
{
if (!backend || (Type(type.get()) != Type::SCRIPTING)) {
return;
}
backend->handle_scripting(efi_state);
}
#endif
namespace AP { namespace AP {
AP_EFI *EFI() AP_EFI *EFI()
{ {

View File

@ -84,6 +84,7 @@ public:
// LOWEHEISER = 4, // LOWEHEISER = 4,
DroneCAN = 5, DroneCAN = 5,
CurrawongECU = 6, CurrawongECU = 6,
SCRIPTING = 7,
}; };
static AP_EFI *get_singleton(void) { static AP_EFI *get_singleton(void) {
@ -93,6 +94,11 @@ public:
// send EFI_STATUS // send EFI_STATUS
void send_mavlink_status(mavlink_channel_t chan); void send_mavlink_status(mavlink_channel_t chan);
#if AP_SCRIPTING_ENABLED
// Ingest EFI_State from scripting driver
void handle_scripting(const EFI_State &efi_state);
#endif
protected: protected:
// Back end Parameters // Back end Parameters

View File

@ -31,6 +31,10 @@ public:
// Update the state structure // Update the state structure
virtual void update() = 0; virtual void update() = 0;
#if AP_SCRIPTING_ENABLED
virtual void handle_scripting(const EFI_State &efi_state) { return; }
#endif
protected: protected:
// Copies internal state to the frontend state // Copies internal state to the frontend state
void copy_to_frontend(); void copy_to_frontend();

View File

@ -0,0 +1,18 @@
#include "AP_EFI_Scripting.h"
#if AP_EFI_SCRIPTING_ENABLED
// Called from frontend to update with the readings received by handler
void AP_EFI_Scripting::update()
{
// Nothing to do here
}
// handle EFI message from scripting
void AP_EFI_Scripting::handle_scripting(const EFI_State &efi_state)
{
internal_state = efi_state;
copy_to_frontend();
}
#endif // AP_EFI_SCRIPTING_ENABLED

View File

@ -0,0 +1,20 @@
#pragma once
#include "AP_EFI.h"
#include "AP_EFI_Backend.h"
#ifndef AP_EFI_SCRIPTING_ENABLED
#define AP_EFI_SCRIPTING_ENABLED (HAL_EFI_ENABLED && AP_SCRIPTING_ENABLED)
#endif
#if AP_EFI_SCRIPTING_ENABLED
class AP_EFI_Scripting : public AP_EFI_Backend {
public:
using AP_EFI_Backend::AP_EFI_Backend;
void update() override;
void handle_scripting(const EFI_State &efi_state) override;
};
#endif // AP_EFI_SCRIPTING_ENABLED