logging cleanup 2: sensors, pid, etb, etc (#2567)

* ts logger

* sensors

* wideband too

* missed one

* init

* motors, pid, etc

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-04-18 17:02:32 -07:00 committed by GitHub
parent 177f3afd05
commit 992c16b4af
35 changed files with 103 additions and 120 deletions

View File

@ -113,9 +113,9 @@ void setDcMotorDuty(size_t index, float duty) {
} }
void showDcMotorInfo(Logging* logger, int i) { void showDcMotorInfo(int i) {
DcHardware *dc = &dcHardware[i]; DcHardware *dc = &dcHardware[i];
scheduleMsg(logger, " motor: dir=%d DC=%f", dc->dcMotor.isOpenDirection(), dc->dcMotor.get()); efiPrintf(" motor: dir=%d DC=%f", dc->dcMotor.isOpenDirection(), dc->dcMotor.get());
} }

View File

@ -11,7 +11,6 @@
#include "global.h" #include "global.h"
class DcMotor; class DcMotor;
class Logger;
DcMotor* initDcMotor(const dc_io& io, size_t index, bool useTwoWires DECLARE_ENGINE_PARAMETER_SUFFIX); DcMotor* initDcMotor(const dc_io& io, size_t index, bool useTwoWires DECLARE_ENGINE_PARAMETER_SUFFIX);
@ -19,5 +18,5 @@ DcMotor* initDcMotor(const dc_io& io, size_t index, bool useTwoWires DECLARE_ENG
void setDcMotorFrequency(size_t index, int hz); void setDcMotorFrequency(size_t index, int hz);
void setDcMotorDuty(size_t index, float duty); void setDcMotorDuty(size_t index, float duty);
void showDcMotorInfo(Logging* logger, int i); void showDcMotorInfo(int i);

View File

@ -225,8 +225,8 @@ void EtbController::onConfigurationChange(pid_s* previousConfiguration) {
} }
} }
void EtbController::showStatus(Logging* logger) { void EtbController::showStatus() {
m_pid.showPidStatus(logger, "ETB"); m_pid.showPidStatus("ETB");
} }
expected<percent_t> EtbController::observePlant() const { expected<percent_t> EtbController::observePlant() const {
@ -540,7 +540,7 @@ void EtbController::update() {
m_pid.iTermMax = engineConfiguration->etb_iTermMax; m_pid.iTermMax = engineConfiguration->etb_iTermMax;
if (engineConfiguration->isVerboseETB) { if (engineConfiguration->isVerboseETB) {
m_pid.showPidStatus(&logger, "ETB"); m_pid.showPidStatus("ETB");
} }
// Update local state about autotune // Update local state about autotune
@ -714,7 +714,7 @@ static void showEthInfo(void) {
scheduleMsg(&logger, " dir2=%s", hwPortname(CONFIG(etbIo[i].directionPin2))); scheduleMsg(&logger, " dir2=%s", hwPortname(CONFIG(etbIo[i].directionPin2)));
scheduleMsg(&logger, " control=%s", hwPortname(CONFIG(etbIo[i].controlPin1))); scheduleMsg(&logger, " control=%s", hwPortname(CONFIG(etbIo[i].controlPin1)));
scheduleMsg(&logger, " disable=%s", hwPortname(CONFIG(etbIo[i].disablePin))); scheduleMsg(&logger, " disable=%s", hwPortname(CONFIG(etbIo[i].disablePin)));
showDcMotorInfo(&logger, i); showDcMotorInfo(i);
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */

View File

@ -23,8 +23,6 @@
#define ETB_LOOP_FREQUENCY 500 #define ETB_LOOP_FREQUENCY 500
#define DEFAULT_ETB_PWM_FREQUENCY 800 #define DEFAULT_ETB_PWM_FREQUENCY 800
class Logging;
class EtbController : public IEtbController { class EtbController : public IEtbController {
public: public:
bool init(etb_function_e function, DcMotor *motor, pid_s *pidParameters, const ValueProvider3D* pedalMap, bool initializeThrottles) override; bool init(etb_function_e function, DcMotor *motor, pid_s *pidParameters, const ValueProvider3D* pedalMap, bool initializeThrottles) override;
@ -40,7 +38,7 @@ public:
void onConfigurationChange(pid_s* previousConfiguration); void onConfigurationChange(pid_s* previousConfiguration);
// Print this throttle's status. // Print this throttle's status.
void showStatus(Logging* logger); void showStatus();
// Helpers for individual parts of throttle control // Helpers for individual parts of throttle control
expected<percent_t> observePlant() const override; expected<percent_t> observePlant() const override;

View File

@ -142,11 +142,11 @@ static void showIdleInfo(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
scheduleMsg(logger, "Coil A:"); scheduleMsg(logger, "Coil A:");
scheduleMsg(logger, " pin1=%s", hwPortname(CONFIG(stepperDcIo[0].directionPin1))); scheduleMsg(logger, " pin1=%s", hwPortname(CONFIG(stepperDcIo[0].directionPin1)));
scheduleMsg(logger, " pin2=%s", hwPortname(CONFIG(stepperDcIo[0].directionPin2))); scheduleMsg(logger, " pin2=%s", hwPortname(CONFIG(stepperDcIo[0].directionPin2)));
showDcMotorInfo(logger, 2); showDcMotorInfo(2);
scheduleMsg(logger, "Coil B:"); scheduleMsg(logger, "Coil B:");
scheduleMsg(logger, " pin1=%s", hwPortname(CONFIG(stepperDcIo[1].directionPin1))); scheduleMsg(logger, " pin1=%s", hwPortname(CONFIG(stepperDcIo[1].directionPin1)));
scheduleMsg(logger, " pin2=%s", hwPortname(CONFIG(stepperDcIo[1].directionPin2))); scheduleMsg(logger, " pin2=%s", hwPortname(CONFIG(stepperDcIo[1].directionPin2)));
showDcMotorInfo(logger, 3); showDcMotorInfo(3);
} else { } else {
scheduleMsg(logger, "directionPin=%s reactionTime=%.2f", hwPortname(CONFIG(idle).stepperDirectionPin), scheduleMsg(logger, "directionPin=%s reactionTime=%.2f", hwPortname(CONFIG(idle).stepperDirectionPin),
engineConfiguration->idleStepperReactionTime); engineConfiguration->idleStepperReactionTime);
@ -167,7 +167,7 @@ static void showIdleInfo(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
} }
if (engineConfiguration->idleMode == IM_AUTO) { if (engineConfiguration->idleMode == IM_AUTO) {
getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->showPidStatus(logger, "idle"); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->showPidStatus("idle");
} }
} }
@ -479,8 +479,8 @@ static percent_t automaticIdleController(float tpsPos, float rpm, int targetRpm,
engine->engineState.isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO; engine->engineState.isAutomaticIdle = tps.Valid && engineConfiguration->idleMode == IM_AUTO;
if (engineConfiguration->isVerboseIAC && engine->engineState.isAutomaticIdle) { if (engineConfiguration->isVerboseIAC && engine->engineState.isAutomaticIdle) {
scheduleMsg(logger, "Idle state %s", getIdle_state_e(engine->engineState.idle.idleState)); efiPrintf("Idle state %s", getIdle_state_e(engine->engineState.idle.idleState));
getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->showPidStatus(logger, "idle"); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->showPidStatus("idle");
} }
finishIdleTestIfNeeded(); finishIdleTestIfNeeded();

View File

@ -285,7 +285,7 @@ private:
if (widebandUpdatePending) { if (widebandUpdatePending) {
#if EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT #if EFI_WIDEBAND_FIRMWARE_UPDATE && EFI_CAN_SUPPORT
updateWidebandFirmware(logger); updateWidebandFirmware();
#endif #endif
widebandUpdatePending = false; widebandUpdatePending = false;
} }
@ -437,7 +437,7 @@ void executeTSCommand(uint16_t subsystem, uint16_t index) {
break; break;
#ifdef EFI_WIDEBAND_FIRMWARE_UPDATE #ifdef EFI_WIDEBAND_FIRMWARE_UPDATE
case 0x15: case 0x15:
setWidebandOffset(logger, index); setWidebandOffset(index);
break; break;
#endif // EFI_WIDEBAND_FIRMWARE_UPDATE #endif // EFI_WIDEBAND_FIRMWARE_UPDATE
case CMD_TS_BENCH_CATEGORY: case CMD_TS_BENCH_CATEGORY:
@ -506,7 +506,7 @@ void initBenchTest(Logging *sharedLogger) {
#if EFI_WIDEBAND_FIRMWARE_UPDATE #if EFI_WIDEBAND_FIRMWARE_UPDATE
addConsoleAction("update_wideband", []() { widebandUpdatePending = true; }); addConsoleAction("update_wideband", []() { widebandUpdatePending = true; });
addConsoleActionI("set_wideband_index", [](int index) { setWidebandOffset(logger, index); }); addConsoleActionI("set_wideband_index", [](int index) { setWidebandOffset(index); });
#endif // EFI_WIDEBAND_FIRMWARE_UPDATE #endif // EFI_WIDEBAND_FIRMWARE_UPDATE
addConsoleAction(CMD_STARTER_BENCH, starterRelayBench); addConsoleAction(CMD_STARTER_BENCH, starterRelayBench);

View File

@ -30,9 +30,9 @@ void registerCanSensor(CanSensorBase& sensor);
// Indicate that an ack response was received from the wideband bootloader // Indicate that an ack response was received from the wideband bootloader
void handleWidebandBootloaderAck(); void handleWidebandBootloaderAck();
// Update the firmware on any connected wideband controller // Update the firmware on any connected wideband controller
void updateWidebandFirmware(Logging*); void updateWidebandFirmware();
// Set the CAN index offset of any attached wideband controller // Set the CAN index offset of any attached wideband controller
void setWidebandOffset(Logging* logging, uint8_t index); void setWidebandOffset(uint8_t index);
class CanWrite final : public PeriodicController<512> { class CanWrite final : public PeriodicController<512> {
public: public:

View File

@ -24,17 +24,17 @@ bool waitAck() {
return chEvtWaitAnyTimeout(EVT_BOOTLOADER_ACK, TIME_MS2I(1000)) != 0; return chEvtWaitAnyTimeout(EVT_BOOTLOADER_ACK, TIME_MS2I(1000)) != 0;
} }
void updateWidebandFirmware(Logging* logging) { void updateWidebandFirmware() {
// Clear any pending acks for this thread // Clear any pending acks for this thread
chEvtGetAndClearEvents(EVT_BOOTLOADER_ACK); chEvtGetAndClearEvents(EVT_BOOTLOADER_ACK);
// Send messages to the current thread when acks come in // Send messages to the current thread when acks come in
waitingBootloaderThread = chThdGetSelfX(); waitingBootloaderThread = chThdGetSelfX();
scheduleMsg(logging, "***************************************"); efiPrintf("***************************************");
scheduleMsg(logging, " WIDEBAND FIRMWARE UPDATE"); efiPrintf(" WIDEBAND FIRMWARE UPDATE");
scheduleMsg(logging, "***************************************"); efiPrintf("***************************************");
scheduleMsg(logging, "Wideband Update: Rebooting to bootloader..."); efiPrintf("Wideband Update: Rebooting to bootloader...");
// The first request will reboot the chip (if necessary), and the second one will enable bootloader mode // The first request will reboot the chip (if necessary), and the second one will enable bootloader mode
// If the chip was already in bootloader (aka manual mode), then that's ok - the second request will // If the chip was already in bootloader (aka manual mode), then that's ok - the second request will
@ -46,7 +46,7 @@ void updateWidebandFirmware(Logging* logging) {
} }
if (!waitAck()) { if (!waitAck()) {
scheduleMsg(logging, "Wideband Update ERROR: Expected ACK from entry to bootloader, didn't get one."); efiPrintf("Wideband Update ERROR: Expected ACK from entry to bootloader, didn't get one.");
return; return;
} }
@ -54,7 +54,7 @@ void updateWidebandFirmware(Logging* logging) {
chThdSleepMilliseconds(200); chThdSleepMilliseconds(200);
} }
scheduleMsg(logging, "Wideband Update: in update mode, erasing flash..."); efiPrintf("Wideband Update: in update mode, erasing flash...");
{ {
// Erase flash - opcode 1, magic value 0x5A5A // Erase flash - opcode 1, magic value 0x5A5A
@ -62,13 +62,13 @@ void updateWidebandFirmware(Logging* logging) {
} }
if (!waitAck()) { if (!waitAck()) {
scheduleMsg(logging, "Wideband Update ERROR: Expected ACK from flash erase command, didn't get one."); efiPrintf("Wideband Update ERROR: Expected ACK from flash erase command, didn't get one.");
return; return;
} }
size_t totalSize = sizeof(build_wideband_image_bin); size_t totalSize = sizeof(build_wideband_image_bin);
scheduleMsg(logging, "Wideband Update: Flash erased! Sending %d bytes...", totalSize); efiPrintf("Wideband Update: Flash erased! Sending %d bytes...", totalSize);
// Send flash data 8 bytes at a time // Send flash data 8 bytes at a time
for (size_t i = 0; i < totalSize; i += 8) { for (size_t i = 0; i < totalSize; i += 8) {
@ -78,12 +78,12 @@ void updateWidebandFirmware(Logging* logging) {
} }
if (!waitAck()) { if (!waitAck()) {
scheduleMsg(logging, "Wideband Update ERROR: Expected ACK from data write, didn't get one."); efiPrintf("Wideband Update ERROR: Expected ACK from data write, didn't get one.");
return; return;
} }
} }
scheduleMsg(logging, "Wideband Update: Update complete! Rebooting controller."); efiPrintf("Wideband Update: Update complete! Rebooting controller.");
{ {
// Reboot to firmware! // Reboot to firmware!
@ -95,17 +95,17 @@ void updateWidebandFirmware(Logging* logging) {
waitingBootloaderThread = nullptr; waitingBootloaderThread = nullptr;
} }
void setWidebandOffset(Logging* logging, uint8_t index) { void setWidebandOffset(uint8_t index) {
// Clear any pending acks for this thread // Clear any pending acks for this thread
chEvtGetAndClearEvents(EVT_BOOTLOADER_ACK); chEvtGetAndClearEvents(EVT_BOOTLOADER_ACK);
// Send messages to the current thread when acks come in // Send messages to the current thread when acks come in
waitingBootloaderThread = chThdGetSelfX(); waitingBootloaderThread = chThdGetSelfX();
scheduleMsg(logging, "***************************************"); efiPrintf("***************************************");
scheduleMsg(logging, " WIDEBAND INDEX SET"); efiPrintf(" WIDEBAND INDEX SET");
scheduleMsg(logging, "***************************************"); efiPrintf("***************************************");
scheduleMsg(logging, "Setting all connected widebands to index %d...", index); efiPrintf("Setting all connected widebands to index %d...", index);
{ {
CanTxMessage m(0xEF4'0000, 1, true); CanTxMessage m(0xEF4'0000, 1, true);

View File

@ -565,7 +565,7 @@ void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S
#if !EFI_UNIT_TEST #if !EFI_UNIT_TEST
// This is tested independently - don't configure sensors for tests. // This is tested independently - don't configure sensors for tests.
// This lets us selectively mock them for each test. // This lets us selectively mock them for each test.
initNewSensors(sharedLogger); initNewSensors();
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
initSensors(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX); initSensors(sharedLogger PASS_ENGINE_PARAMETER_SUFFIX);

View File

@ -122,7 +122,7 @@ public:
protected: protected:
// Print sensor info - current RPM state // Print sensor info - current RPM state
void showInfo(Logging* logger, const char* sensorName) const override; void showInfo(const char* sensorName) const override;
private: private:
/** /**

View File

@ -8,7 +8,7 @@ public:
explicit Lps25Sensor(Lps25& sensor); explicit Lps25Sensor(Lps25& sensor);
void update(); void update();
void showInfo(Logging* logger, const char* sensorName) const override; void showInfo(const char* sensorName) const override;
private: private:
Lps25* m_sensor; Lps25* m_sensor;

View File

@ -26,7 +26,7 @@ public:
{ {
} }
void showInfo(Logging* logger, const char* sensorName) const override; void showInfo(const char* sensorName) const override;
}; };
template <typename TStorage, int TScale> template <typename TStorage, int TScale>

View File

@ -25,9 +25,8 @@ protected:
return input; return input;
} }
void showInfo(Logging* logger, float testInputValue) const { void showInfo(float testInputValue) const {
// base case does nothing // base case does nothing
(void)logger;
(void)testInputValue; (void)testInputValue;
} }
}; };
@ -64,14 +63,14 @@ public:
return TBase::template get<TGet>(); return TBase::template get<TGet>();
} }
void showInfo(Logging* logger, float testInputValue) const { void showInfo(float testInputValue) const {
// Print info about this level // Print info about this level
m_f.showInfo(logger, testInputValue); m_f.showInfo(testInputValue);
// If valid, recurse down // If valid, recurse down
auto res = m_f.convert(testInputValue); auto res = m_f.convert(testInputValue);
if (res.Valid) { if (res.Valid) {
TBase::showInfo(logger, res.Value); TBase::showInfo(res.Value);
} }
} }
@ -94,8 +93,8 @@ public:
return m_fs.template get<TGet>(); return m_fs.template get<TGet>();
} }
void showInfo(Logging* logger, float testInputValue) const override { void showInfo(float testInputValue) const override {
m_fs.showInfo(logger, testInputValue); m_fs.showInfo(testInputValue);
} }
private: private:

View File

@ -10,7 +10,7 @@ public:
SensorResult convert(float inputValue) const override; SensorResult convert(float inputValue) const override;
void showInfo(Logging* logger, float testRawValue) const override; void showInfo(float testRawValue) const override;
float getDivideInput() const { float getDivideInput() const {
return m_divideInput; return m_divideInput;

View File

@ -16,7 +16,7 @@ public:
SensorResult convert(float inputValue) const override; SensorResult convert(float inputValue) const override;
void showInfo(Logging* logger, float testInputValue) const override; void showInfo(float testInputValue) const override;
private: private:
float m_supplyVoltage = 5.0f; float m_supplyVoltage = 5.0f;

View File

@ -2,8 +2,6 @@
#include "sensor.h" #include "sensor.h"
class Logging;
struct SensorConverter { struct SensorConverter {
// Trying to copy a converter func by value is almost guaranteed to be a bug - disallow it // Trying to copy a converter func by value is almost guaranteed to be a bug - disallow it
SensorConverter(const SensorConverter&) = delete; SensorConverter(const SensorConverter&) = delete;
@ -11,9 +9,8 @@ struct SensorConverter {
SensorConverter() = default; SensorConverter() = default;
virtual SensorResult convert(float raw) const = 0; virtual SensorResult convert(float raw) const = 0;
virtual void showInfo(Logging* logger, float testRawValue) const { virtual void showInfo(float testRawValue) const {
// Unused base - nothing to print // Unused base - nothing to print
(void)logger;
(void)testRawValue; (void)testRawValue;
} }
}; };

View File

@ -26,7 +26,7 @@ public:
return interpolate2d(inputValue, m_bins, m_values) * TOutputScale::asFloat(); return interpolate2d(inputValue, m_bins, m_values) * TOutputScale::asFloat();
} }
void showInfo(Logging* /*logger*/, float /*testInputValue*/) const override { } void showInfo(float /*testInputValue*/) const override { }
private: private:
TBin (&m_bins)[TSize]; TBin (&m_bins)[TSize];

View File

@ -16,7 +16,7 @@ public:
void configure(thermistor_conf_s &cfg); void configure(thermistor_conf_s &cfg);
void showInfo(Logging* logger, float testRawValue) const override; void showInfo(float testRawValue) const override;
// Steinhart-Hart coefficients // Steinhart-Hart coefficients
float m_a = 0; float m_a = 0;

View File

@ -11,7 +11,7 @@ public:
void onEdge(efitick_t nowNt); void onEdge(efitick_t nowNt);
void showInfo(Logging* /*logger*/, const char* /*sensorName*/) const override { } void showInfo(const char* /*sensorName*/) const override { }
private: private:
Timer m_edgeTimer; Timer m_edgeTimer;

View File

@ -33,7 +33,7 @@ public:
return result; return result;
} }
void showInfo(Logging* /*logger*/, const char* /*sensorName*/) const override {} void showInfo(const char* /*sensorName*/) const override {}
private: private:
float (*m_func)(); float (*m_func)();

View File

@ -38,7 +38,7 @@ public:
return m_rawValue; return m_rawValue;
} }
void showInfo(Logging* logger, const char* sensorName) const override; void showInfo(const char* sensorName) const override;
private: private:
// Conversion function for this sensor // Conversion function for this sensor

View File

@ -21,7 +21,7 @@ public:
m_proxiedSensor = proxiedSensor; m_proxiedSensor = proxiedSensor;
} }
void showInfo(Logging* logger, const char* sensorName) const override; void showInfo(const char* sensorName) const override;
private: private:
SensorResult get() const override { SensorResult get() const override {

View File

@ -19,7 +19,7 @@ public:
return true; return true;
} }
void showInfo(Logging* logger, const char* sensorName) const override; void showInfo(const char* sensorName) const override;
private: private:
// The two sensors we interpret to form one redundant sensor // The two sensors we interpret to form one redundant sensor

View File

@ -20,7 +20,7 @@ public:
return !m_ignoreSecond; return !m_ignoreSecond;
} }
void showInfo(Logging* logger, const char* sensorName) const override; void showInfo(const char* sensorName) const override;
private: private:
// The two sensors we interpret to form one redundant sensor // The two sensors we interpret to form one redundant sensor

View File

@ -110,16 +110,16 @@ public:
return unexpected; return unexpected;
} }
void showInfo(Logging* logger, const char* sensorName) const { void showInfo(const char* sensorName) const {
if (m_useMock) { if (m_useMock) {
scheduleMsg(logger, "Sensor \"%s\" mocked with value %.2f", sensorName, m_mockValue); efiPrintf("Sensor \"%s\" mocked with value %.2f", sensorName, m_mockValue);
} else { } else {
const auto sensor = m_sensor; const auto sensor = m_sensor;
if (sensor) { if (sensor) {
sensor->showInfo(logger, sensorName); sensor->showInfo(sensorName);
} else { } else {
scheduleMsg(logger, "Sensor \"%s\" is not configured.", sensorName); efiPrintf("Sensor \"%s\" is not configured.", sensorName);
} }
} }
} }
@ -258,20 +258,20 @@ bool Sensor::Register() {
} }
// Print information about all sensors // Print information about all sensors
/*static*/ void Sensor::showAllSensorInfo(Logging* logger) { /*static*/ void Sensor::showAllSensorInfo() {
for (size_t i = 1; i < efi::size(s_sensorRegistry); i++) { for (size_t i = 1; i < efi::size(s_sensorRegistry); i++) {
auto& entry = s_sensorRegistry[i]; auto& entry = s_sensorRegistry[i];
const char* name = s_sensorNames[i]; const char* name = s_sensorNames[i];
entry.showInfo(logger, name); entry.showInfo(name);
} }
} }
// Print information about a particular sensor // Print information about a particular sensor
/*static*/ void Sensor::showInfo(Logging* logger, SensorType type) { /*static*/ void Sensor::showInfo(SensorType type) {
auto entry = getEntryForType(type); auto entry = getEntryForType(type);
if (entry) { if (entry) {
entry->showInfo(logger, getSensorName(type)); entry->showInfo(getSensorName(type));
} }
} }

View File

@ -56,7 +56,6 @@ using SensorResult = expected<float>;
// Fwd declare - nobody outside of Sensor.cpp needs to see inside this type // Fwd declare - nobody outside of Sensor.cpp needs to see inside this type
class SensorRegistryEntry; class SensorRegistryEntry;
class Logging;
class Sensor { class Sensor {
public: public:
@ -66,13 +65,13 @@ public:
bool Register(); bool Register();
// Print information about this sensor // Print information about this sensor
virtual void showInfo(Logging* logger, const char* sensorName) const = 0; virtual void showInfo(const char* sensorName) const = 0;
// Print information about all sensors // Print information about all sensors
static void showAllSensorInfo(Logging* logger); static void showAllSensorInfo();
// Print information about a particular sensor // Print information about a particular sensor
static void showInfo(Logging* logger, SensorType type); static void showInfo(SensorType type);
// Remove all sensors from the sensor registry - tread carefully if you use this outside of a unit test // Remove all sensors from the sensor registry - tread carefully if you use this outside of a unit test
static void resetRegistry(); static void resetRegistry();

View File

@ -11,39 +11,39 @@
#include "efilib.h" #include "efilib.h"
#include "loggingcentral.h" #include "loggingcentral.h"
void ProxySensor::showInfo(Logging* logger, const char* sensorName) const { void ProxySensor::showInfo(const char* sensorName) const {
scheduleMsg(logger, "Sensor \"%s\" proxied from sensor \"%s\"", sensorName, getSensorName(m_proxiedSensor)); efiPrintf("Sensor \"%s\" proxied from sensor \"%s\"", sensorName, getSensorName(m_proxiedSensor));
} }
void FunctionalSensor::showInfo(Logging* logger, const char* sensorName) const { void FunctionalSensor::showInfo(const char* sensorName) const {
const auto [valid, value] = get(); const auto [valid, value] = get();
scheduleMsg(logger, "Sensor \"%s\": Raw value: %.2f Valid: %s Converted value %.2f", sensorName, m_rawValue, boolToString(valid), value); efiPrintf("Sensor \"%s\": Raw value: %.2f Valid: %s Converted value %.2f", sensorName, m_rawValue, boolToString(valid), value);
// now print out the underlying function's info // now print out the underlying function's info
if (auto func = m_function) { if (auto func = m_function) {
func->showInfo(logger, m_rawValue); func->showInfo(m_rawValue);
} }
} }
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT
#include "can_sensor.h" #include "can_sensor.h"
void CanSensorBase::showInfo(Logging* logger, const char* sensorName) const { void CanSensorBase::showInfo(const char* sensorName) const {
const auto [valid, value] = get(); const auto [valid, value] = get();
scheduleMsg(logger, "CAN Sensor \"%s\": valid: %s value: %.2f", sensorName, boolToString(valid), value); efiPrintf("CAN Sensor \"%s\": valid: %s value: %.2f", sensorName, boolToString(valid), value);
} }
#endif // EFI_CAN_SUPPORT #endif // EFI_CAN_SUPPORT
void RedundantSensor::showInfo(Logging* logger, const char* sensorName) const { void RedundantSensor::showInfo(const char* sensorName) const {
scheduleMsg(logger, "Sensor \"%s\" is redundant combining \"%s\" and \"%s\"", sensorName, getSensorName(m_first), getSensorName(m_second)); efiPrintf("Sensor \"%s\" is redundant combining \"%s\" and \"%s\"", sensorName, getSensorName(m_first), getSensorName(m_second));
} }
void RedundantFordTps::showInfo(Logging* logger, const char* sensorName) const { void RedundantFordTps::showInfo(const char* sensorName) const {
scheduleMsg(logger, "Sensor \"%s\" is Ford-type redundant TPS combining \"%s\" and \"%s\"", sensorName, getSensorName(m_first), getSensorName(m_second)); efiPrintf("Sensor \"%s\" is Ford-type redundant TPS combining \"%s\" and \"%s\"", sensorName, getSensorName(m_first), getSensorName(m_second));
} }
void RpmCalculator::showInfo(Logging* logger, const char* /*sensorName*/) const { void RpmCalculator::showInfo(const char* /*sensorName*/) const {
scheduleMsg(logger, "RPM sensor: stopped: %d spinning up: %d cranking: %d running: %d rpm: %f", efiPrintf("RPM sensor: stopped: %d spinning up: %d cranking: %d running: %d rpm: %f",
isStopped(), isStopped(),
isSpinningUp(), isSpinningUp(),
isCranking(), isCranking(),
@ -52,22 +52,22 @@ void RpmCalculator::showInfo(Logging* logger, const char* /*sensorName*/) const
); );
} }
void Lps25Sensor::showInfo(Logging* logger, const char* sensorName) const { void Lps25Sensor::showInfo(const char* sensorName) const {
scheduleMsg(logger, "%s: LPS25 baro %.2f kPa", sensorName, get().Value); efiPrintf("%s: LPS25 baro %.2f kPa", sensorName, get().Value);
} }
void LinearFunc::showInfo(Logging* logger, float testRawValue) const { void LinearFunc::showInfo(float testRawValue) const {
scheduleMsg(logger, " Linear function slope: %.2f offset: %.2f min: %.1f max: %.1f", m_a, m_b, m_minOutput, m_maxOutput); efiPrintf(" Linear function slope: %.2f offset: %.2f min: %.1f max: %.1f", m_a, m_b, m_minOutput, m_maxOutput);
const auto [valid, value] = convert(testRawValue); const auto [valid, value] = convert(testRawValue);
scheduleMsg(logger, " raw value %.2f converts to %.2f valid: %s", testRawValue, value, boolToString(valid)); efiPrintf(" raw value %.2f converts to %.2f valid: %s", testRawValue, value, boolToString(valid));
} }
void ResistanceFunc::showInfo(Logging* logger, float testInputValue) const { void ResistanceFunc::showInfo(float testInputValue) const {
const auto result = convert(testInputValue); const auto result = convert(testInputValue);
scheduleMsg(logger, " %.2f volts -> %.1f ohms with supply voltage %.2f and pullup %.1f.", testInputValue, result.Value, m_supplyVoltage, m_pullupResistor); efiPrintf(" %.2f volts -> %.1f ohms with supply voltage %.2f and pullup %.1f.", testInputValue, result.Value, m_supplyVoltage, m_pullupResistor);
} }
void ThermistorFunc::showInfo(Logging* logger, float testInputValue) const { void ThermistorFunc::showInfo(float testInputValue) const {
const auto [valid, value] = convert(testInputValue); const auto [valid, value] = convert(testInputValue);
scheduleMsg(logger, " %.1f ohms -> valid: %s. %.1f deg C", testInputValue, boolToString(valid), value); efiPrintf(" %.1f ohms -> valid: %s. %.1f deg C", testInputValue, boolToString(valid), value);
} }

View File

@ -18,8 +18,6 @@
constexpr uint8_t lc2_header_mask = 162; constexpr uint8_t lc2_header_mask = 162;
constexpr uint16_t lc2_pcklen_mask = 383; constexpr uint16_t lc2_pcklen_mask = 383;
class Logging;
typedef enum {UNKNOWN, HEADER_FOUND, IDENTIFIED} innovate_serial_id_state_t; typedef enum {UNKNOWN, HEADER_FOUND, IDENTIFIED} innovate_serial_id_state_t;
extern uint8_t ser_buffer[SERBUFFLEN]; //buffer for incoming serial data extern uint8_t ser_buffer[SERBUFFLEN]; //buffer for incoming serial data

View File

@ -331,7 +331,7 @@ void printTPSInfo(void) {
static void printTemperatureInfo(void) { static void printTemperatureInfo(void) {
#if EFI_ANALOG_SENSORS #if EFI_ANALOG_SENSORS
Sensor::showAllSensorInfo(&logger); Sensor::showAllSensorInfo();
scheduleMsg(&logger, "fan=%s @ %s", boolToString(enginePins.fanRelay.getLogicValue()), scheduleMsg(&logger, "fan=%s @ %s", boolToString(enginePins.fanRelay.getLogicValue()),
hwPortname(engineConfiguration->fanPin)); hwPortname(engineConfiguration->fanPin));

View File

@ -490,7 +490,7 @@ static bool cj125periodic(CJ125 *instance DECLARE_ENGINE_PARAMETER_SUFFIX) {
float duty = globalInstance.heaterPid.getOutput(globalInstance.vUr, globalInstance.vUrCal, MS2SEC(CJ125_TICK_DELAY)); float duty = globalInstance.heaterPid.getOutput(globalInstance.vUr, globalInstance.vUrCal, MS2SEC(CJ125_TICK_DELAY));
instance->SetHeater(duty PASS_ENGINE_PARAMETER_SUFFIX); instance->SetHeater(duty PASS_ENGINE_PARAMETER_SUFFIX);
if (engineConfiguration->isCJ125Verbose) { if (engineConfiguration->isCJ125Verbose) {
globalInstance.heaterPid.showPidStatus(logger, "cj heater"); globalInstance.heaterPid.showPidStatus("cj heater");
cjPrintData(); cjPrintData();
} }
instance->prevNt = nowNt; instance->prevNt = nowNt;

View File

@ -6,10 +6,8 @@
#include "engine_ptr.h" #include "engine_ptr.h"
class Logging;
// Call this once at startup to initialize, configure, and subscribe sensors // Call this once at startup to initialize, configure, and subscribe sensors
void initNewSensors(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX); void initNewSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE);
// Call this whenever the configuration may have changed, so any sensors // Call this whenever the configuration may have changed, so any sensors
// can be reconfigured with the new settings. // can be reconfigured with the new settings.

View File

@ -6,9 +6,9 @@
#include "cli_registry.h" #include "cli_registry.h"
#include "sensor.h" #include "sensor.h"
static void initSensorCli(Logging* logger); static void initSensorCli();
void initNewSensors(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX) { void initNewSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_CAN_SUPPORT #if EFI_CAN_SUPPORT
initCanSensors(); initCanSensors();
#endif #endif
@ -27,7 +27,7 @@ void initNewSensors(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#endif #endif
// Init CLI functionality for sensors (mocking) // Init CLI functionality for sensors (mocking)
initSensorCli(logger); initSensorCli();
} }
void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
@ -37,17 +37,13 @@ void reconfigureSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
reconfigureThermistors(PASS_CONFIG_PARAMETER_SIGNATURE); reconfigureThermistors(PASS_CONFIG_PARAMETER_SIGNATURE);
} }
static Logging* s_logger;
// Mocking/testing helpers // Mocking/testing helpers
static void initSensorCli(Logging* logger) { static void initSensorCli() {
s_logger = logger;
addConsoleActionIF("set_sensor_mock", Sensor::setMockValue); addConsoleActionIF("set_sensor_mock", Sensor::setMockValue);
addConsoleAction("reset_sensor_mocks", Sensor::resetAllMocks); addConsoleAction("reset_sensor_mocks", Sensor::resetAllMocks);
addConsoleAction("show_sensors", []() { Sensor::showAllSensorInfo(s_logger); }); addConsoleAction("show_sensors", Sensor::showAllSensorInfo);
addConsoleActionI("show_sensor", addConsoleActionI("show_sensor",
[](int idx) { [](int idx) {
Sensor::showInfo(s_logger, static_cast<SensorType>(idx)); Sensor::showInfo(static_cast<SensorType>(idx));
}); });
} }

View File

@ -157,8 +157,8 @@ void Pid::sleep() {
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
} }
void Pid::showPidStatus(Logging *logging, const char*msg) const { void Pid::showPidStatus(const char*msg) const {
scheduleMsg(logging, "%s settings: offset=%f P=%.5f I=%.5f D=%.5f period=%dms", efiPrintf("%s settings: offset=%f P=%.5f I=%.5f D=%.5f period=%dms",
msg, msg,
getOffset(), getOffset(),
parameters->pFactor, parameters->pFactor,
@ -166,7 +166,7 @@ void Pid::showPidStatus(Logging *logging, const char*msg) const {
parameters->dFactor, parameters->dFactor,
parameters->periodMs); parameters->periodMs);
scheduleMsg(logging, "%s status: value=%.2f input=%.2f/target=%.2f iTerm=%.5f dTerm=%.5f", efiPrintf("%s status: value=%.2f input=%.2f/target=%.2f iTerm=%.5f dTerm=%.5f",
msg, msg,
output, output,
input, input,

View File

@ -30,7 +30,6 @@
#define MS2SEC(x) (x * 0.001) #define MS2SEC(x) (x * 0.001)
struct pid_s; struct pid_s;
class Logging;
/** /**
* default basic implementation also known as PidParallelController * default basic implementation also known as PidParallelController
@ -69,7 +68,7 @@ public:
void postState(TunerStudioOutputChannels *tsOutputChannels) const; void postState(TunerStudioOutputChannels *tsOutputChannels) const;
void postState(TunerStudioOutputChannels *tsOutputChannels, int pMult) const; void postState(TunerStudioOutputChannels *tsOutputChannels, int pMult) const;
#endif /* EFI_TUNER_STUDIO */ #endif /* EFI_TUNER_STUDIO */
void showPidStatus(Logging *logging, const char*msg) const; void showPidStatus(const char* msg) const;
void sleep(); void sleep();
int resetCounter; int resetCounter;
// todo: move this to pid_s one day // todo: move this to pid_s one day

View File

@ -25,7 +25,7 @@ struct MockSensor final : public StoredValueSensor
m_hasSensor = h; m_hasSensor = h;
} }
void showInfo(Logging* logger, const char* name) const override {} void showInfo(const char* name) const override {}
private: private:
bool m_hasSensor = true; bool m_hasSensor = true;