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/Tools/AP_Periph/efi.cpp
Views: 1798
#include "AP_Periph.h"12#ifdef HAL_PERIPH_ENABLE_EFI34/*5EFI support6*/78#include <dronecan_msgs.h>910#ifndef AP_PERIPH_EFI_MAX_RATE11// default to 2x the AP_Vehicle rate12#define AP_PERIPH_EFI_MAX_RATE 100U13#endif1415/*16update CAN EFI17*/18void AP_Periph_FW::can_efi_update(void)19{20if (!efi.enabled()) {21return;22}2324#if AP_PERIPH_EFI_MAX_RATE > 025const uint32_t now_ms = AP_HAL::millis();26if (now_ms - last_efi_update_ms < (1000U / AP_PERIPH_EFI_MAX_RATE)) {27return;28}29last_efi_update_ms = now_ms;30#endif3132efi.update();33const uint32_t update_ms = efi.get_last_update_ms();34if (!efi.is_healthy() || efi_update_ms == update_ms) {35return;36}37efi_update_ms = update_ms;38EFI_State state;39efi.get_state(state);4041{42/*43send status packet44*/45uavcan_equipment_ice_reciprocating_Status pkt {};4647// state maps 1:1 from Engine_State48pkt.state = uint8_t(state.engine_state);4950switch (state.crankshaft_sensor_status) {51case Crankshaft_Sensor_Status::NOT_SUPPORTED:52break;53case Crankshaft_Sensor_Status::OK:54pkt.flags |= UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_CRANKSHAFT_SENSOR_ERROR_SUPPORTED;55break;56case Crankshaft_Sensor_Status::ERROR:57pkt.flags |=58UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_CRANKSHAFT_SENSOR_ERROR_SUPPORTED |59UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_CRANKSHAFT_SENSOR_ERROR;60break;61}6263switch (state.temperature_status) {64case Temperature_Status::NOT_SUPPORTED:65break;66case Temperature_Status::OK:67pkt.flags |= UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_SUPPORTED;68break;69case Temperature_Status::BELOW_NOMINAL:70pkt.flags |=71UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_SUPPORTED |72UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_BELOW_NOMINAL;73break;74case Temperature_Status::ABOVE_NOMINAL:75pkt.flags |=76UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_SUPPORTED |77UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_ABOVE_NOMINAL;78break;79case Temperature_Status::OVERHEATING:80pkt.flags |=81UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_SUPPORTED |82UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_OVERHEATING;83break;84case Temperature_Status::EGT_ABOVE_NOMINAL:85pkt.flags |=86UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_SUPPORTED |87UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_TEMPERATURE_EGT_ABOVE_NOMINAL;88break;89}9091switch (state.fuel_pressure_status) {92case Fuel_Pressure_Status::NOT_SUPPORTED:93break;94case Fuel_Pressure_Status::OK:95pkt.flags |= UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_SUPPORTED;96break;97case Fuel_Pressure_Status::BELOW_NOMINAL:98pkt.flags |=99UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_SUPPORTED |100UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_BELOW_NOMINAL;101break;102case Fuel_Pressure_Status::ABOVE_NOMINAL:103pkt.flags |=104UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_SUPPORTED |105UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_FUEL_PRESSURE_ABOVE_NOMINAL;106break;107}108109switch (state.oil_pressure_status) {110case Oil_Pressure_Status::NOT_SUPPORTED:111break;112case Oil_Pressure_Status::OK:113pkt.flags |= UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_SUPPORTED;114break;115case Oil_Pressure_Status::BELOW_NOMINAL:116pkt.flags |=117UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_SUPPORTED |118UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_BELOW_NOMINAL;119break;120case Oil_Pressure_Status::ABOVE_NOMINAL:121pkt.flags |=122UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_SUPPORTED |123UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_OIL_PRESSURE_ABOVE_NOMINAL;124break;125}126127switch (state.detonation_status) {128case Detonation_Status::NOT_SUPPORTED:129break;130case Detonation_Status::NOT_OBSERVED:131pkt.flags |=132UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DETONATION_SUPPORTED;133break;134case Detonation_Status::OBSERVED:135pkt.flags |=136UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DETONATION_SUPPORTED |137UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DETONATION_OBSERVED;138break;139}140141switch (state.misfire_status) {142case Misfire_Status::NOT_SUPPORTED:143break;144case Misfire_Status::NOT_OBSERVED:145pkt.flags |=146UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_MISFIRE_SUPPORTED;147break;148case Misfire_Status::OBSERVED:149pkt.flags |=150UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_MISFIRE_SUPPORTED |151UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_MISFIRE_OBSERVED;152break;153}154155switch (state.debris_status) {156case Debris_Status::NOT_SUPPORTED:157break;158case Debris_Status::NOT_DETECTED:159pkt.flags |=160UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DEBRIS_SUPPORTED;161break;162case Debris_Status::DETECTED:163pkt.flags |=164UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DEBRIS_SUPPORTED |165UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_FLAG_DEBRIS_DETECTED;166break;167}168169pkt.engine_load_percent = state.engine_load_percent;170pkt.engine_speed_rpm = state.engine_speed_rpm;171pkt.spark_dwell_time_ms = state.spark_dwell_time_ms;172pkt.atmospheric_pressure_kpa = state.atmospheric_pressure_kpa;173pkt.intake_manifold_pressure_kpa = state.intake_manifold_pressure_kpa;174pkt.intake_manifold_temperature = state.intake_manifold_temperature;175pkt.coolant_temperature = state.coolant_temperature;176pkt.oil_pressure = state.oil_pressure;177pkt.oil_temperature = state.oil_temperature;178pkt.fuel_pressure = state.fuel_pressure;179pkt.fuel_consumption_rate_cm3pm = state.fuel_consumption_rate_cm3pm;180pkt.estimated_consumed_fuel_volume_cm3 = state.estimated_consumed_fuel_volume_cm3;181pkt.throttle_position_percent = state.throttle_position_percent;182pkt.ecu_index = state.ecu_index;183pkt.spark_plug_usage = uint8_t(state.spark_plug_usage);184185// assume single set of cylinder status186pkt.cylinder_status.len = 1;187auto &c = pkt.cylinder_status.data[0];188const auto &state_c = state.cylinder_status;189c.ignition_timing_deg = state_c.ignition_timing_deg;190c.injection_time_ms = state_c.injection_time_ms;191c.cylinder_head_temperature = state_c.cylinder_head_temperature;192c.exhaust_gas_temperature = state_c.exhaust_gas_temperature;193c.lambda_coefficient = state_c.lambda_coefficient;194195uint8_t buffer[UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_MAX_SIZE];196const uint16_t total_size = uavcan_equipment_ice_reciprocating_Status_encode(&pkt, buffer, !canfdout());197198canard_broadcast(UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_SIGNATURE,199UAVCAN_EQUIPMENT_ICE_RECIPROCATING_STATUS_ID,200CANARD_TRANSFER_PRIORITY_LOW,201&buffer[0],202total_size);203}204}205206#endif // HAL_PERIPH_ENABLE_EFI207208209