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_EFI/AP_EFI_DroneCAN.cpp
Views: 1798
#include <AP_HAL/AP_HAL.h>12#include "AP_EFI_config.h"34#if AP_EFI_DRONECAN_ENABLED5#include "AP_EFI_DroneCAN.h"67#include <AP_CANManager/AP_CANManager.h>8#include <AP_DroneCAN/AP_DroneCAN.h>9#include <AP_BoardConfig/AP_BoardConfig.h>1011extern const AP_HAL::HAL& hal;1213AP_EFI_DroneCAN *AP_EFI_DroneCAN::driver;1415// constructor16AP_EFI_DroneCAN::AP_EFI_DroneCAN(AP_EFI &_frontend) :17AP_EFI_Backend(_frontend)18{19driver = this;20}2122// links the DroneCAN message to this backend23bool AP_EFI_DroneCAN::subscribe_msgs(AP_DroneCAN *ap_dronecan)24{25const auto driver_index = ap_dronecan->get_driver_index();2627return (Canard::allocate_sub_arg_callback(ap_dronecan, &trampoline_status, driver_index) != nullptr);28}2930// Called from frontend to update with the readings received by handler31void AP_EFI_DroneCAN::update()32{33}3435// EFI message handler36void AP_EFI_DroneCAN::trampoline_status(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const uavcan_equipment_ice_reciprocating_Status &msg)37{38if (driver == nullptr) {39return;40}41driver->handle_status(msg);42}4344/*45handle reciprocating ICE status message from DroneCAN46*/47void AP_EFI_DroneCAN::handle_status(const uavcan_equipment_ice_reciprocating_Status &pkt)48{49auto &istate = internal_state;5051// state maps 1:1 from Engine_State52istate.engine_state = Engine_State(pkt.state);5354if (!(pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_CRANKSHAFT_SENSOR_ERROR_SUPPORTED)) {55istate.crankshaft_sensor_status = Crankshaft_Sensor_Status::NOT_SUPPORTED;56} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_CRANKSHAFT_SENSOR_ERROR) {57istate.crankshaft_sensor_status = Crankshaft_Sensor_Status::ERROR;58} else {59istate.crankshaft_sensor_status = Crankshaft_Sensor_Status::OK;60}6162if (!(pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_SUPPORTED)) {63istate.temperature_status = Temperature_Status::NOT_SUPPORTED;64} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_BELOW_NOMINAL) {65istate.temperature_status = Temperature_Status::BELOW_NOMINAL;66} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_ABOVE_NOMINAL) {67istate.temperature_status = Temperature_Status::ABOVE_NOMINAL;68} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_OVERHEATING) {69istate.temperature_status = Temperature_Status::OVERHEATING;70} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_EGT_ABOVE_NOMINAL) {71istate.temperature_status = Temperature_Status::EGT_ABOVE_NOMINAL;72} else {73istate.temperature_status = Temperature_Status::OK;74}7576if (!(pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_SUPPORTED)) {77istate.fuel_pressure_status = Fuel_Pressure_Status::NOT_SUPPORTED;78} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_BELOW_NOMINAL) {79istate.fuel_pressure_status = Fuel_Pressure_Status::BELOW_NOMINAL;80} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_ABOVE_NOMINAL) {81istate.fuel_pressure_status = Fuel_Pressure_Status::ABOVE_NOMINAL;82} else {83istate.fuel_pressure_status = Fuel_Pressure_Status::OK;84}8586if (!(pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_SUPPORTED)) {87istate.oil_pressure_status = Oil_Pressure_Status::NOT_SUPPORTED;88} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_BELOW_NOMINAL) {89istate.oil_pressure_status = Oil_Pressure_Status::BELOW_NOMINAL;90} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_ABOVE_NOMINAL) {91istate.oil_pressure_status = Oil_Pressure_Status::ABOVE_NOMINAL;92} else {93istate.oil_pressure_status = Oil_Pressure_Status::OK;94}9596if (!(pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DETONATION_SUPPORTED)) {97istate.detonation_status = Detonation_Status::NOT_SUPPORTED;98} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DETONATION_OBSERVED) {99istate.detonation_status = Detonation_Status::OBSERVED;100} else {101istate.detonation_status = Detonation_Status::NOT_OBSERVED;102}103104if (!(pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_MISFIRE_SUPPORTED)) {105istate.misfire_status = Misfire_Status::NOT_SUPPORTED;106} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_MISFIRE_OBSERVED) {107istate.misfire_status = Misfire_Status::OBSERVED;108} else {109istate.misfire_status = Misfire_Status::NOT_OBSERVED;110}111112if (!(pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DEBRIS_SUPPORTED)) {113istate.debris_status = Debris_Status::NOT_SUPPORTED;114} else if (pkt.flags & UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DEBRIS_DETECTED) {115istate.debris_status = Debris_Status::DETECTED;116} else {117istate.debris_status = Debris_Status::NOT_DETECTED;118}119120istate.engine_load_percent = pkt.engine_load_percent;121istate.engine_speed_rpm = pkt.engine_speed_rpm;122istate.spark_dwell_time_ms = pkt.spark_dwell_time_ms;123istate.atmospheric_pressure_kpa = pkt.atmospheric_pressure_kpa;124istate.intake_manifold_pressure_kpa = pkt.intake_manifold_pressure_kpa;125istate.intake_manifold_temperature = pkt.intake_manifold_temperature;126istate.coolant_temperature = pkt.coolant_temperature;127istate.oil_pressure = pkt.oil_pressure;128istate.oil_temperature = pkt.oil_temperature;129istate.fuel_pressure = pkt.fuel_pressure;130istate.fuel_consumption_rate_cm3pm = pkt.fuel_consumption_rate_cm3pm;131istate.estimated_consumed_fuel_volume_cm3 = pkt.estimated_consumed_fuel_volume_cm3;132istate.throttle_position_percent = pkt.throttle_position_percent;133istate.ecu_index = pkt.ecu_index;134135// 1:1 for spark plug usage136istate.spark_plug_usage = Spark_Plug_Usage(pkt.spark_plug_usage);137138// assume max one cylinder status139if (pkt.cylinder_status.len > 0) {140const auto &cs = pkt.cylinder_status.data[0];141auto &c = istate.cylinder_status;142c.ignition_timing_deg = cs.ignition_timing_deg;143c.injection_time_ms = cs.injection_time_ms;144c.cylinder_head_temperature = cs.cylinder_head_temperature;145c.exhaust_gas_temperature = cs.exhaust_gas_temperature;146c.lambda_coefficient = cs.lambda_coefficient;147}148149// Required for healthy message150istate.last_updated_ms = AP_HAL::millis();151152copy_to_frontend();153}154155#endif // AP_EFI_DRONECAN_ENABLED156157158159