mirror of https://github.com/rusefi/rusefi-1.git
CJ125 unit-tests coverage #617
This commit is contained in:
parent
3b5a07c9d6
commit
2b852ea48e
|
@ -301,6 +301,7 @@ void startSimplePwm(SimplePwm *state, const char *msg, ExecutorInterface *execut
|
|||
OutputPin *output, float frequency, float dutyCycle, pwm_gen_callback *stateChangeCallback) {
|
||||
efiAssertVoid(CUSTOM_ERR_6692, state != NULL, "state");
|
||||
efiAssertVoid(CUSTOM_ERR_6665, dutyCycle >= 0 && dutyCycle <= 1, "dutyCycle");
|
||||
efiAssertVoid(CUSTOM_ERR_6693, stateChangeCallback != NULL, "listener");
|
||||
if (frequency < 1) {
|
||||
warning(CUSTOM_OBD_LOW_FREQUENCY, "low frequency %.2f", frequency);
|
||||
return;
|
||||
|
|
|
@ -29,8 +29,6 @@ EXTERN_ENGINE;
|
|||
#include "pin_repository.h"
|
||||
extern TunerStudioOutputChannels tsOutputChannels;
|
||||
|
||||
static OutputPin wboHeaterPin;
|
||||
static OutputPin cj125Cs;
|
||||
static Logging *logger;
|
||||
static unsigned char tx_buff[2];
|
||||
static unsigned char rx_buff[1];
|
||||
|
@ -351,15 +349,6 @@ static void cjStart(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static void cjStartHeaterControl(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
scheduleMsg(logger, "cj125: Starting heater control");
|
||||
// todo: use custom pin state method, turn pin off while not running
|
||||
startSimplePwmExt(&globalInstance.wboHeaterControl, "wboHeaterPin",
|
||||
&engine->executor,
|
||||
CONFIGB(wboHeaterPin),
|
||||
&wboHeaterPin, CJ125_HEATER_PWM_FREQ, 0.0f, applyPinState);
|
||||
}
|
||||
|
||||
void CJ125::setError(cj125_error_e errCode DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
errorCode = errCode;
|
||||
state = CJ125_ERROR;
|
||||
|
@ -411,18 +400,16 @@ void cj125defaultPinout(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
|
||||
static void cjStartSpi(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
cj125Cs.initPin("cj125 CS", CONFIGB(cj125CsPin),
|
||||
globalInstance.cj125Cs.initPin("cj125 CS", CONFIGB(cj125CsPin),
|
||||
&engineConfiguration->cj125CsPinMode);
|
||||
// Idle CS pin - SPI CS is high when idle
|
||||
cj125Cs.setValue(true);
|
||||
globalInstance.cj125Cs.setValue(true);
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
cj125spicfg.ssport = getHwPort("cj125", CONFIGB(cj125CsPin));
|
||||
cj125spicfg.sspad = getHwPin("cj125", CONFIGB(cj125CsPin));
|
||||
driver = getSpiDevice(engineConfiguration->cj125SpiDevice);
|
||||
scheduleMsg(logger, "cj125: Starting SPI driver");
|
||||
spiStart(driver, &cj125spicfg);
|
||||
#endif /* EFI_PROD_CODE */
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -595,11 +582,9 @@ float cjGetAfr(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
bool cjHasAfrSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
if (!CONFIGB(isCJ125Enabled))
|
||||
return false;
|
||||
#if ! EFI_UNIT_TEST
|
||||
// check if controller is functioning
|
||||
if (!globalInstance.isWorkingState())
|
||||
return false;
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
// check if amplification is turned on
|
||||
if (amplCoeff == 0.0f)
|
||||
return false;
|
||||
|
@ -642,8 +627,8 @@ void initCJ125(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
|
||||
cjInitPid(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
cjStartSpi(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
cjStartHeaterControl(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
globalInstance.SetIdleHeater(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
scheduleMsg(logger, "cj125: Starting heater control");
|
||||
globalInstance.StartHeaterControl(applyPinState PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
cjStart(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
|
||||
#ifdef CJ125_DEBUG
|
||||
|
|
|
@ -36,3 +36,12 @@ void CJ125::SetIdleHeater(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
bool CJ125::isWorkingState(void) {
|
||||
return state != CJ125_ERROR && state != CJ125_INIT && state != CJ125_IDLE;
|
||||
}
|
||||
|
||||
void CJ125::StartHeaterControl(pwm_gen_callback *stateChangeCallback DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
// todo: use custom pin state method, turn pin off while not running
|
||||
startSimplePwmExt(&wboHeaterControl, "wboHeaterPin",
|
||||
&engine->executor,
|
||||
CONFIGB(wboHeaterPin),
|
||||
&wboHeaterPin, CJ125_HEATER_PWM_FREQ, 0.0f, stateChangeCallback);
|
||||
SetIdleHeater(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ public:
|
|||
efitick_t prevNt;
|
||||
float heaterDuty = 0.0f;
|
||||
|
||||
OutputPin wboHeaterPin;
|
||||
OutputPin cj125Cs;
|
||||
|
||||
// Used by CJ125 driver state machine
|
||||
volatile cj125_state_e state = CJ125_INIT;
|
||||
|
@ -64,6 +66,7 @@ public:
|
|||
bool isWorkingState(void);
|
||||
void SetHeater(float value DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void SetIdleHeater(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void StartHeaterControl(pwm_gen_callback *stateChangeCallback DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
};
|
||||
|
||||
// Heater params for Idle(cold), Preheating and Control stages
|
||||
|
|
|
@ -50,7 +50,7 @@ GTEST_API_ int main(int argc, char **argv) {
|
|||
// printTriggerDebug = true;
|
||||
|
||||
// resizeMap();
|
||||
printf("Success 20190117\r\n");
|
||||
printf("Success 20190201\r\n");
|
||||
printAllTriggers();
|
||||
// printConvertedTable();
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
|
|
@ -9,15 +9,23 @@
|
|||
#include "CJ125_logic.h"
|
||||
#include "engine_test_helper.h"
|
||||
|
||||
static void applyHeaterPinState(PwmConfig *state, int stateIndex) {
|
||||
|
||||
}
|
||||
|
||||
TEST(testCJ125, testInitialState) {
|
||||
CJ125 cj;
|
||||
|
||||
ASSERT_EQ(cj.state, CJ125_INIT);
|
||||
ASSERT_FALSE(cj.isWorkingState());
|
||||
ASSERT_EQ(cj.heaterDuty, 0);
|
||||
|
||||
WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996);
|
||||
ASSERT_EQ(engine->sensors.vBatt, 0);
|
||||
|
||||
cj.StartHeaterControl(&applyHeaterPinState PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
ASSERT_EQ(cj.heaterDuty, CJ125_HEATER_IDLE_RATE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue