2020-06-17 19:16:29 -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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/utility/sparse-endian.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
|
|
|
|
#include "AP_EFI_NWPMU.h"
|
|
|
|
|
|
|
|
#if HAL_EFI_NWPWU_ENABLED
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
AP_EFI_NWPMU::AP_EFI_NWPMU(AP_EFI &_frontend) :
|
2021-07-22 13:52:17 -03:00
|
|
|
CANSensor("NWPMU"),
|
2020-06-17 19:16:29 -03:00
|
|
|
AP_EFI_Backend(_frontend)
|
|
|
|
{
|
2021-07-22 13:52:17 -03:00
|
|
|
register_driver(AP_CANManager::Driver_Type_EFI_NWPMU);
|
2020-06-17 19:16:29 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AP_EFI_NWPMU::handle_frame(AP_HAL::CANFrame &frame)
|
|
|
|
{
|
|
|
|
const uint32_t id = frame.id & AP_HAL::CANFrame::MaskExtID;
|
|
|
|
|
|
|
|
WITH_SEMAPHORE(sem);
|
|
|
|
|
|
|
|
switch ((NWPMU_ID)id) {
|
|
|
|
case NWPMU_ID::ECU_1: {
|
|
|
|
internal_state.last_updated_ms = AP_HAL::millis();
|
2021-07-12 13:43:26 -03:00
|
|
|
struct ecu_1 data;
|
|
|
|
memcpy(&data, frame.data, sizeof(data));
|
|
|
|
internal_state.engine_speed_rpm = data.rpm;
|
|
|
|
internal_state.throttle_position_percent = data.tps * 0.1f;
|
|
|
|
internal_state.cylinder_status[0].ignition_timing_deg = data.ignition_angle * 0.1f;
|
2020-06-17 19:16:29 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NWPMU_ID::ECU_2: {
|
|
|
|
internal_state.last_updated_ms = AP_HAL::millis();
|
2021-07-12 13:43:26 -03:00
|
|
|
struct ecu_2 data;
|
|
|
|
memcpy(&data, frame.data, sizeof(data));
|
|
|
|
switch ((NWPMU_PRESSURE_TYPE)data.pressure_type) {
|
2020-06-17 19:16:29 -03:00
|
|
|
case NWPMU_PRESSURE_TYPE::kPa:
|
2021-07-12 13:43:26 -03:00
|
|
|
internal_state.atmospheric_pressure_kpa = data.baro * 0.01f;
|
|
|
|
internal_state.intake_manifold_pressure_kpa = data.baro * 0.01f;
|
2020-06-17 19:16:29 -03:00
|
|
|
break;
|
|
|
|
case NWPMU_PRESSURE_TYPE::psi:
|
2021-07-12 13:43:26 -03:00
|
|
|
internal_state.atmospheric_pressure_kpa = data.baro * 0.0689476f;
|
|
|
|
internal_state.intake_manifold_pressure_kpa = data.baro * 0.0689476f;
|
2020-06-17 19:16:29 -03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-07-12 13:43:26 -03:00
|
|
|
internal_state.cylinder_status[0].lambda_coefficient = data.lambda * 0.01f;
|
2020-06-17 19:16:29 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NWPMU_ID::ECU_4: {
|
|
|
|
internal_state.last_updated_ms = AP_HAL::millis();
|
2021-07-12 13:43:26 -03:00
|
|
|
struct ecu_4 data;
|
|
|
|
memcpy(&data, frame.data, sizeof(data));
|
2020-06-17 19:16:29 -03:00
|
|
|
// remap the analog input for fuel pressure, 0.5 V == 0 PSI, 4.5V == 100 PSI
|
|
|
|
internal_state.fuel_pressure = linear_interpolate(0, 689.476,
|
2021-07-12 13:43:26 -03:00
|
|
|
data.analog_fuel_pres * 0.001,
|
2020-06-17 19:16:29 -03:00
|
|
|
0.5f,4.5f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NWPMU_ID::ECU_5: {
|
|
|
|
internal_state.last_updated_ms = AP_HAL::millis();
|
2021-07-12 13:43:26 -03:00
|
|
|
struct ecu_5 data;
|
|
|
|
memcpy(&data, frame.data, sizeof(data));
|
|
|
|
switch((NWPMU_TEMPERATURE_TYPE)data.temp_type) {
|
2020-06-17 19:16:29 -03:00
|
|
|
case NWPMU_TEMPERATURE_TYPE::C:
|
2022-01-12 08:03:24 -04:00
|
|
|
internal_state.coolant_temperature = C_TO_KELVIN(data.coolant_temp * 0.1f);
|
|
|
|
internal_state.cylinder_status[0].cylinder_head_temperature = C_TO_KELVIN(data.coolant_temp * 0.1f);
|
2020-06-17 19:16:29 -03:00
|
|
|
break;
|
|
|
|
case NWPMU_TEMPERATURE_TYPE::F:
|
2022-01-12 18:02:37 -04:00
|
|
|
internal_state.coolant_temperature = F_TO_KELVIN(data.coolant_temp * 0.1f);
|
|
|
|
internal_state.cylinder_status[0].cylinder_head_temperature = F_TO_KELVIN(data.coolant_temp * 0.1f);
|
2020-06-17 19:16:29 -03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NWPMU_ID::ECU_6: {
|
|
|
|
internal_state.last_updated_ms = AP_HAL::millis();
|
2021-07-12 13:43:26 -03:00
|
|
|
struct ecu_6 data;
|
|
|
|
memcpy(&data, frame.data, sizeof(data));
|
2020-06-17 19:16:29 -03:00
|
|
|
if (!_emitted_version && (AP_HAL::millis() > 10000)) { // don't emit a version early in the boot process
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "NWPMU Version: %d.%d.%d",
|
2021-07-12 13:43:26 -03:00
|
|
|
data.firmware_major,
|
|
|
|
data.firmware_minor,
|
|
|
|
data.firmware_build);
|
2020-06-17 19:16:29 -03:00
|
|
|
_emitted_version = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NWPMU_ID::GCU:
|
|
|
|
case NWPMU_ID::ECU_3:
|
|
|
|
case NWPMU_ID::ECU_7:
|
|
|
|
case NWPMU_ID::ECU_8:
|
|
|
|
case NWPMU_ID::ECU_9:
|
|
|
|
case NWPMU_ID::ECU_10:
|
|
|
|
case NWPMU_ID::ECU_11:
|
|
|
|
case NWPMU_ID::ECU_12:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AP_EFI_NWPMU::update()
|
|
|
|
{
|
|
|
|
// copy the data to the front end
|
|
|
|
copy_to_frontend();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAL_EFI_NWPWU_ENABLED
|