@@ -1166,6 +1166,17 @@ static uint8_t deterministic_rand_flipper(void)
11661166 return onOff ? deterministic_rand_low () : deterministic_rand_high ();
11671167}
11681168
1169+ static void assert_applyRollingCutPercentage (engineProtection_test_context_t context, uint8_t expectedFuel, uint8_t expectedIgnition, SchedulerCutStatus expectedStatus)
1170+ {
1171+ context.current .schedulerCutState .fuelChannels = 0xFF ;
1172+ context.current .schedulerCutState .ignitionChannels = 0xFF ;
1173+ context.current .schedulerCutState .status = SchedulerCutStatus::None;
1174+ auto onOff = applyRollingCutPercentage (context.current , context.page6 , 50U , false );
1175+ TEST_ASSERT_EQUAL_HEX8 (expectedFuel, onOff.fuelChannels );
1176+ TEST_ASSERT_EQUAL_HEX8 (expectedIgnition, onOff.ignitionChannels );
1177+ TEST_ASSERT_EQUAL (expectedStatus, onOff.status );
1178+ }
1179+
11691180static void test_applyRollingCutPercentage_all_cut (void )
11701181{
11711182 engineProtection_test_context_t context;
@@ -1175,14 +1186,15 @@ static void test_applyRollingCutPercentage_all_cut(void)
11751186
11761187 context.current .maxInjOutputs = 5 ;
11771188 context.current .maxIgnOutputs = 4 ;
1178- context.current .schedulerCutState .fuelChannels = 0xFF ;
1179- context.current .schedulerCutState .ignitionChannels = 0xFF ;
1180- context.current .schedulerCutState .status = SchedulerCutStatus::None;
1181- auto onOff = applyRollingCutPercentage (context.current , context.page6 , 50U , false );
11821189
1183- TEST_ASSERT_EQUAL_HEX8 (0x00 , onOff.fuelChannels );
1184- TEST_ASSERT_EQUAL_HEX8 (0x00 , onOff.ignitionChannels );
1185- TEST_ASSERT_EQUAL (onOff.status , SchedulerCutStatus::Rolling);
1190+ context.page6 .engineProtectType = PROTECT_CUT_BOTH;
1191+ assert_applyRollingCutPercentage (context, 0b00000000 , 0b00000000 , SchedulerCutStatus::Rolling);
1192+
1193+ context.page6 .engineProtectType = PROTECT_CUT_IGN;
1194+ assert_applyRollingCutPercentage (context, 0b00011111 , 0b00000000 , SchedulerCutStatus::Rolling);
1195+
1196+ context.page6 .engineProtectType = PROTECT_CUT_FUEL;
1197+ assert_applyRollingCutPercentage (context, 0b00000000 , 0b00001111 , SchedulerCutStatus::Rolling);
11861198}
11871199
11881200static void test_applyRollingCutPercentage_all_on (void )
@@ -1192,29 +1204,33 @@ static void test_applyRollingCutPercentage_all_on(void)
11921204 // Inject deterministic RNG that never triggers cuts
11931205 rollingCutRandFunc_override_t rngOverride (deterministic_rand_high);
11941206
1195- context.current .schedulerCutState .fuelChannels = 0xFF ;
1196- context.current .schedulerCutState .ignitionChannels = 0xFF ;
1197- context.current .schedulerCutState .status = SchedulerCutStatus::None;
11981207 context.current .maxInjOutputs = 3 ;
11991208 context.current .maxIgnOutputs = 2 ;
1200- auto onOff = applyRollingCutPercentage (context.current , context.page6 , 50U , false );
1201- TEST_ASSERT_EQUAL_HEX8 (0x07 , onOff.fuelChannels );
1202- TEST_ASSERT_EQUAL_HEX8 (0x03 , onOff.ignitionChannels );
1203- TEST_ASSERT_EQUAL (onOff.status , SchedulerCutStatus::Rolling);
1209+
1210+ context.page6 .engineProtectType = PROTECT_CUT_BOTH;
1211+ assert_applyRollingCutPercentage (context, 0b00000111 , 0b00000011 , SchedulerCutStatus::Rolling);
1212+ context.page6 .engineProtectType = PROTECT_CUT_FUEL;
1213+ assert_applyRollingCutPercentage (context, 0b00000111 , 0b00000011 , SchedulerCutStatus::Rolling);
1214+ context.page6 .engineProtectType = PROTECT_CUT_IGN;
1215+ assert_applyRollingCutPercentage (context, 0b00000111 , 0b00000011 , SchedulerCutStatus::Rolling);
12041216
12051217 context.current .maxInjOutputs = 4 ;
12061218 context.current .maxIgnOutputs = 5 ;
1207- onOff = applyRollingCutPercentage (context.current , context.page6 , 50U , false );
1208- TEST_ASSERT_EQUAL_HEX8 (0x0F , onOff.fuelChannels );
1209- TEST_ASSERT_EQUAL_HEX8 (0x1F , onOff.ignitionChannels );
1210- TEST_ASSERT_EQUAL (onOff.status , SchedulerCutStatus::Rolling);
1219+ context.page6 .engineProtectType = PROTECT_CUT_BOTH;
1220+ assert_applyRollingCutPercentage (context, 0b00001111 , 0b00011111 , SchedulerCutStatus::Rolling);
1221+ context.page6 .engineProtectType = PROTECT_CUT_FUEL;
1222+ assert_applyRollingCutPercentage (context, 0b00001111 , 0b00011111 , SchedulerCutStatus::Rolling);
1223+ context.page6 .engineProtectType = PROTECT_CUT_IGN;
1224+ assert_applyRollingCutPercentage (context, 0b00001111 , 0b00011111 , SchedulerCutStatus::Rolling);
12111225
12121226 context.current .maxInjOutputs = 2 ;
12131227 context.current .maxIgnOutputs = 1 ;
1214- onOff = applyRollingCutPercentage (context.current , context.page6 , 50U , false );
1215- TEST_ASSERT_EQUAL_HEX8 (0x03 , onOff.fuelChannels );
1216- TEST_ASSERT_EQUAL_HEX8 (0x01 , onOff.ignitionChannels );
1217- TEST_ASSERT_EQUAL (onOff.status , SchedulerCutStatus::Rolling);
1228+ context.page6 .engineProtectType = PROTECT_CUT_BOTH;
1229+ assert_applyRollingCutPercentage (context, 0b00000011 , 0b00000001 , SchedulerCutStatus::Rolling);
1230+ context.page6 .engineProtectType = PROTECT_CUT_FUEL;
1231+ assert_applyRollingCutPercentage (context, 0b00000011 , 0b00000001 , SchedulerCutStatus::Rolling);
1232+ context.page6 .engineProtectType = PROTECT_CUT_IGN;
1233+ assert_applyRollingCutPercentage (context, 0b00000011 , 0b00000001 , SchedulerCutStatus::Rolling);
12181234}
12191235
12201236static void test_applyRollingCutPercentage_half_on (void )
@@ -1224,15 +1240,17 @@ static void test_applyRollingCutPercentage_half_on(void)
12241240 // Inject deterministic RNG that never triggers cuts
12251241 rollingCutRandFunc_override_t rngOverride (deterministic_rand_flipper);
12261242
1227- context.current .schedulerCutState .fuelChannels = 0xFF ;
1228- context.current .schedulerCutState .ignitionChannels = 0xFF ;
1229- context.current .schedulerCutState .status = SchedulerCutStatus::None;
12301243 context.current .maxInjOutputs = 5 ;
12311244 context.current .maxIgnOutputs = 3 ;
1232- auto onOff = applyRollingCutPercentage (context.current , context.page6 , 50U , false );
1233- TEST_ASSERT_EQUAL_HEX8 (0x0A , onOff.fuelChannels );
1234- TEST_ASSERT_EQUAL_HEX8 (0x02 , onOff.ignitionChannels );
1235- TEST_ASSERT_EQUAL (onOff.status , SchedulerCutStatus::Rolling);
1245+
1246+ context.page6 .engineProtectType = PROTECT_CUT_BOTH;
1247+ assert_applyRollingCutPercentage (context, 0b00001010 , 0b00000010 , SchedulerCutStatus::Rolling);
1248+
1249+ context.page6 .engineProtectType = PROTECT_CUT_FUEL;
1250+ assert_applyRollingCutPercentage (context, 0b00010101 , 0b00000111 , SchedulerCutStatus::Rolling);
1251+
1252+ context.page6 .engineProtectType = PROTECT_CUT_IGN;
1253+ assert_applyRollingCutPercentage (context, 0b00011111 , 0b00000010 , SchedulerCutStatus::Rolling);
12361254}
12371255
12381256static void test_applyPendingIgnitionCuts (void )
0 commit comments