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_NWPMU.cpp
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415#include "AP_EFI_config.h"1617#if AP_EFI_NWPWU_ENABLED1819#include <AP_HAL/AP_HAL.h>2021#include <AP_Common/AP_Common.h>22#include <AP_HAL/utility/sparse-endian.h>23#include <AP_Math/AP_Math.h>24#include <GCS_MAVLink/GCS.h>2526#include "AP_EFI_NWPMU.h"2728extern const AP_HAL::HAL& hal;2930AP_EFI_NWPMU::AP_EFI_NWPMU(AP_EFI &_frontend) :31CANSensor("NWPMU"),32AP_EFI_Backend(_frontend)33{34register_driver(AP_CAN::Protocol::EFI_NWPMU);35}3637void AP_EFI_NWPMU::handle_frame(AP_HAL::CANFrame &frame)38{39const uint32_t id = frame.id & AP_HAL::CANFrame::MaskExtID;4041WITH_SEMAPHORE(get_sem());4243switch ((NWPMU_ID)id) {44case NWPMU_ID::ECU_1: {45internal_state.last_updated_ms = AP_HAL::millis();46struct ecu_1 data;47memcpy(&data, frame.data, sizeof(data));48internal_state.engine_speed_rpm = data.rpm;49internal_state.throttle_position_percent = data.tps * 0.1f;50internal_state.cylinder_status.ignition_timing_deg = data.ignition_angle * 0.1f;51break;52}5354case NWPMU_ID::ECU_2: {55internal_state.last_updated_ms = AP_HAL::millis();56struct ecu_2 data;57memcpy(&data, frame.data, sizeof(data));58switch ((NWPMU_PRESSURE_TYPE)data.pressure_type) {59case NWPMU_PRESSURE_TYPE::kPa:60internal_state.atmospheric_pressure_kpa = data.baro * 0.01f;61internal_state.intake_manifold_pressure_kpa = data.baro * 0.01f;62break;63case NWPMU_PRESSURE_TYPE::psi:64internal_state.atmospheric_pressure_kpa = data.baro * 0.0689476f;65internal_state.intake_manifold_pressure_kpa = data.baro * 0.0689476f;66break;67default:68break;69}70internal_state.cylinder_status.lambda_coefficient = data.lambda * 0.01f;71break;72}7374case NWPMU_ID::ECU_4: {75internal_state.last_updated_ms = AP_HAL::millis();76struct ecu_4 data;77memcpy(&data, frame.data, sizeof(data));78// remap the analog input for fuel pressure, 0.5 V == 0 PSI, 4.5V == 100 PSI79internal_state.fuel_pressure = linear_interpolate(0, 689.476,80data.analog_fuel_pres * 0.001,810.5f,4.5f);82break;83}8485case NWPMU_ID::ECU_5: {86internal_state.last_updated_ms = AP_HAL::millis();87struct ecu_5 data;88memcpy(&data, frame.data, sizeof(data));89switch((NWPMU_TEMPERATURE_TYPE)data.temp_type) {90case NWPMU_TEMPERATURE_TYPE::C:91internal_state.coolant_temperature = C_TO_KELVIN(data.coolant_temp * 0.1f);92internal_state.cylinder_status.cylinder_head_temperature = C_TO_KELVIN(data.coolant_temp * 0.1f);93break;94case NWPMU_TEMPERATURE_TYPE::F:95internal_state.coolant_temperature = F_TO_KELVIN(data.coolant_temp * 0.1f);96internal_state.cylinder_status.cylinder_head_temperature = F_TO_KELVIN(data.coolant_temp * 0.1f);97break;98default:99break;100}101break;102}103104case NWPMU_ID::ECU_6: {105internal_state.last_updated_ms = AP_HAL::millis();106struct ecu_6 data;107memcpy(&data, frame.data, sizeof(data));108if (!_emitted_version && (AP_HAL::millis() > 10000)) { // don't emit a version early in the boot process109GCS_SEND_TEXT(MAV_SEVERITY_INFO, "NWPMU Version: %d.%d.%d",110data.firmware_major,111data.firmware_minor,112data.firmware_build);113_emitted_version = true;114}115break;116}117case NWPMU_ID::GCU:118case NWPMU_ID::ECU_3:119case NWPMU_ID::ECU_7:120case NWPMU_ID::ECU_8:121case NWPMU_ID::ECU_9:122case NWPMU_ID::ECU_10:123case NWPMU_ID::ECU_11:124case NWPMU_ID::ECU_12:125break;126}127}128129void AP_EFI_NWPMU::update()130{131// copy the data to the front end132copy_to_frontend();133}134135#endif // AP_EFI_NWPWU_ENABLED136137138