Introduce tests for the setEndTooth function in missing tooth

This commit is contained in:
Josh Stewart 2020-02-13 11:51:58 +11:00
parent dac19a9ed1
commit 349d03249d
5 changed files with 368 additions and 35 deletions

View File

@ -191,11 +191,10 @@ extern unsigned long lastCrankAngleCalc;
extern int16_t lastToothCalcAdvance; //Invalid value here forces calculation of this on first main loop
extern unsigned long lastVVTtime; //The time between the vvt reference pulse and the last crank pulse
//These must be signed as they can go to negative during calculation
extern int16_t ignition1EndTooth;
extern int16_t ignition2EndTooth;
extern int16_t ignition3EndTooth;
extern int16_t ignition4EndTooth;
extern uint16_t ignition1EndTooth;
extern uint16_t ignition2EndTooth;
extern uint16_t ignition3EndTooth;
extern uint16_t ignition4EndTooth;
extern int16_t toothAngles[24]; //An array for storing fixed tooth angles. Currently sized at 24 for the GM 24X decoder, but may grow later if there are other decoders that use this style

View File

@ -78,10 +78,10 @@ unsigned long lastCrankAngleCalc;
int16_t lastToothCalcAdvance = 99; //Invalid value here forces calculation of this on first main loop
unsigned long lastVVTtime; //The time between the vvt reference pulse and the last crank pulse
int16_t ignition1EndTooth = 0;
int16_t ignition2EndTooth = 0;
int16_t ignition3EndTooth = 0;
int16_t ignition4EndTooth = 0;
uint16_t ignition1EndTooth = 0;
uint16_t ignition2EndTooth = 0;
uint16_t ignition3EndTooth = 0;
uint16_t ignition4EndTooth = 0;
int16_t toothAngles[24]; //An array for storing fixed tooth angles. Currently sized at 24 for the GM 24X decoder, but may grow later if there are other decoders that use this style
@ -535,25 +535,35 @@ void triggerSetEndTeeth_missingTooth()
byte toothAdder = 0;
if( (configPage4.sparkMode == IGN_MODE_SEQUENTIAL) && (configPage4.TrigSpeed == CRANK_SPEED) ) { toothAdder = configPage4.triggerTeeth; }
ignition1EndTooth = ( (ignition1EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1;
if(ignition1EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition1EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(ignition1EndTooth <= 0) { ignition1EndTooth += (configPage4.triggerTeeth + toothAdder); }
if(ignition1EndTooth > (triggerActualTeeth + toothAdder)) { ignition1EndTooth = (triggerActualTeeth + toothAdder); }
//Temp variables are used here to avoid potential issues if a trigger interrupt occurs part way through this function
ignition2EndTooth = ( (ignition2EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1;
if(ignition2EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition2EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(ignition2EndTooth <= 0) { ignition2EndTooth += (configPage4.triggerTeeth + toothAdder); }
if(ignition2EndTooth > (triggerActualTeeth + toothAdder)) { ignition2EndTooth = (triggerActualTeeth + toothAdder); }
int16_t tempIgnition1EndTooth;
tempIgnition1EndTooth = ( (ignition1EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1;
if(tempIgnition1EndTooth > (configPage4.triggerTeeth + toothAdder)) { tempIgnition1EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(tempIgnition1EndTooth <= 0) { tempIgnition1EndTooth += (configPage4.triggerTeeth + toothAdder); }
if((uint16_t)tempIgnition1EndTooth > (triggerActualTeeth + toothAdder)) { tempIgnition1EndTooth = (triggerActualTeeth + toothAdder); }
ignition1EndTooth = tempIgnition1EndTooth;
ignition3EndTooth = ( (ignition3EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1;
if(ignition3EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition3EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(ignition3EndTooth <= 0) { ignition3EndTooth += (configPage4.triggerTeeth + toothAdder); }
if(ignition3EndTooth > (triggerActualTeeth + toothAdder)) { ignition3EndTooth = (triggerActualTeeth + toothAdder); }
int16_t tempIgnition2EndTooth;
tempIgnition2EndTooth = ( (ignition2EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1;
if(tempIgnition2EndTooth > (configPage4.triggerTeeth + toothAdder)) { tempIgnition2EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(tempIgnition2EndTooth <= 0) { tempIgnition2EndTooth += (configPage4.triggerTeeth + toothAdder); }
if((uint16_t)tempIgnition2EndTooth > (triggerActualTeeth + toothAdder)) { tempIgnition2EndTooth = (triggerActualTeeth + toothAdder); }
ignition2EndTooth = tempIgnition2EndTooth;
ignition4EndTooth = ( (ignition4EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1;
if(ignition4EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition4EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(ignition4EndTooth <= 0) { ignition4EndTooth += (configPage4.triggerTeeth + toothAdder); }
if(ignition4EndTooth > (triggerActualTeeth + toothAdder)) { ignition4EndTooth = (triggerActualTeeth + toothAdder); }
int16_t tempIgnition3EndTooth;
tempIgnition3EndTooth = ( (ignition3EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1;
if(tempIgnition3EndTooth > (configPage4.triggerTeeth + toothAdder)) { tempIgnition3EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(tempIgnition3EndTooth <= 0) { tempIgnition3EndTooth += (configPage4.triggerTeeth + toothAdder); }
if((uint16_t)tempIgnition3EndTooth > (triggerActualTeeth + toothAdder)) { tempIgnition3EndTooth = (triggerActualTeeth + toothAdder); }
ignition3EndTooth = tempIgnition3EndTooth;
int16_t tempIgnition4EndTooth;
tempIgnition4EndTooth = ( (ignition4EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1;
if(tempIgnition4EndTooth > (configPage4.triggerTeeth + toothAdder)) { tempIgnition4EndTooth -= (configPage4.triggerTeeth + toothAdder); }
if(tempIgnition4EndTooth <= 0) { tempIgnition4EndTooth += (configPage4.triggerTeeth + toothAdder); }
if((uint16_t)tempIgnition4EndTooth > (triggerActualTeeth + toothAdder)) { tempIgnition4EndTooth = (triggerActualTeeth + toothAdder); }
ignition4EndTooth = tempIgnition4EndTooth;
lastToothCalcAdvance = currentStatus.advance;
}

View File

@ -15,18 +15,320 @@ void test_setup_36_1()
triggerSetup_missingTooth();
}
void test_missingtooth_newIgn_1()
void test_setup_60_2()
{
//Setup a 60-2 wheel
configPage4.triggerTeeth = 60;
configPage4.triggerMissingTeeth = 2;
configPage4.TrigSpeed = CRANK_SPEED;
configPage4.trigPatternSec = SEC_TRIGGER_SINGLE;
triggerSetup_missingTooth();
}
//************************************** Begin the new ignition setEndTooth tests **************************************
void test_missingtooth_newIgn_36_1_trig0_1()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=0
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition1EndAngle = 350; //Set 10 degrees advance
ignition1EndAngle = 360 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 0; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(ignition1EndTooth, 34);
TEST_ASSERT_EQUAL(34, ignition1EndTooth);
}
void test_missingtooth_newIgn_36_1_trig90_1()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=90
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition1EndAngle = 360 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 90; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(25, ignition1EndTooth);
}
void test_missingtooth_newIgn_36_1_trig180_1()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=180
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition1EndAngle = 360 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 180; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(16, ignition1EndTooth);
}
void test_missingtooth_newIgn_36_1_trig270_1()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=270
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition1EndAngle = 360 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 270; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(7, ignition1EndTooth);
}
void test_missingtooth_newIgn_36_1_trig360_1()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=360
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition1EndAngle = 360 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 360; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(34, ignition1EndTooth);
}
void test_missingtooth_newIgn_36_1_trigNeg90_1()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=-90
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition1EndAngle = 360 - 10; //Set 10 degrees advance
configPage4.triggerAngle = -90; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(7, ignition1EndTooth);
}
void test_missingtooth_newIgn_36_1_trigNeg180_1()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=-180
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition1EndAngle = 360 - 10; //Set 10 degrees advance
configPage4.triggerAngle = -180; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(16, ignition1EndTooth);
}
void test_missingtooth_newIgn_36_1_trigNeg270_1()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=-270
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition1EndAngle = 360 - 10; //Set 10 degrees advance
configPage4.triggerAngle = -270; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(25, ignition1EndTooth);
}
void test_missingtooth_newIgn_36_1_trigNeg360_1()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=-360
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition1EndAngle = 360 - 10; //Set 10 degrees advance
configPage4.triggerAngle = -360; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(34, ignition1EndTooth);
}
// ******* CHannel 2 *******
void test_missingtooth_newIgn_36_1_trig0_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=0
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 0; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(16, ignition2EndTooth);
}
void test_missingtooth_newIgn_36_1_trig90_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=90
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 90; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(7, ignition2EndTooth);
}
void test_missingtooth_newIgn_36_1_trig180_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=180
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 180; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(34, ignition2EndTooth);
}
void test_missingtooth_newIgn_36_1_trig270_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=270
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 270; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(25, ignition2EndTooth);
}
void test_missingtooth_newIgn_36_1_trig360_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=360
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 360; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(16, ignition2EndTooth);
}
void test_missingtooth_newIgn_36_1_trigNeg90_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=-90
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = -90; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(25, ignition2EndTooth);
}
void test_missingtooth_newIgn_36_1_trigNeg180_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=-180
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = -180; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(34, ignition2EndTooth);
}
void test_missingtooth_newIgn_36_1_trigNeg270_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=-270
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = -270; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(7, ignition2EndTooth);
}
void test_missingtooth_newIgn_36_1_trigNeg360_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 36-1
//Advance: 10
//triggerAngle=-360
test_setup_36_1();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = -360; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(16, ignition2EndTooth);
}
void test_missingtooth_newIgn_60_2_trig0_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 60-2
//Advance: 10
//triggerAngle=300
test_setup_60_2();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 0; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(57, ignition2EndTooth);
}
void test_missingtooth_newIgn_60_2_trig181_2()
{
//Test the set end tooth function. Conditions:
//Trigger: 60-2
//Advance: 10
//triggerAngle=300
test_setup_60_2();
configPage4.sparkMode = IGN_MODE_WASTED;
ignition2EndAngle = 180 - 10; //Set 10 degrees advance
configPage4.triggerAngle = 181; //No trigger offset
triggerSetEndTeeth_missingTooth();
TEST_ASSERT_EQUAL(58, ignition2EndTooth);
}
void test_missingtooth_newIgn_2()
{
@ -38,4 +340,30 @@ void test_missingtooth_newIgn_3()
void test_missingtooth_newIgn_4()
{
}
void testMissingTooth()
{
RUN_TEST(test_missingtooth_newIgn_36_1_trig0_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trig90_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trig180_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trig270_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trig360_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trigNeg90_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trigNeg180_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trigNeg270_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trigNeg360_1);
RUN_TEST(test_missingtooth_newIgn_36_1_trig0_2);
RUN_TEST(test_missingtooth_newIgn_36_1_trig90_2);
RUN_TEST(test_missingtooth_newIgn_36_1_trig180_2);
RUN_TEST(test_missingtooth_newIgn_36_1_trig270_2);
RUN_TEST(test_missingtooth_newIgn_36_1_trig360_2);
RUN_TEST(test_missingtooth_newIgn_36_1_trigNeg90_2);
RUN_TEST(test_missingtooth_newIgn_36_1_trigNeg180_2);
RUN_TEST(test_missingtooth_newIgn_36_1_trigNeg270_2);
RUN_TEST(test_missingtooth_newIgn_36_1_trigNeg360_2);
//RUN_TEST(test_missingtooth_newIgn_60_2_trig181_2);
//RUN_TEST(test_missingtooth_newIgn_60_2_trig182_2);
}

View File

@ -1,5 +1 @@
void test_missingtooth_newIgn_1();
void test_missingtooth_newIgn_3();
void test_missingtooth_newIgn_3();
void test_missingtooth_newIgn_4();
void testMissingTooth();

View File

@ -7,5 +7,5 @@
void testDecoders()
{
RUN_TEST(test_missingtooth_newIgn_1);
testMissingTooth();
}