Esempio n. 1
0
void TimingHackUnitTests()
{
	PopulateRamVariables();
	
	*pEngineSpeed = 3000;
	*pEngineLoad = 1.0;
	*pVehicleSpeed = 1.0;
	
	pRamVariables->TimingHackInitFlag = 0x00;
	pRamVariables->MapBlendRatio = 0.5;				//default is 0
	pRamVariables->LCTimingLock = 10;		//default is 20
	
	TimingHack();
	
	float DefaultBlend = 0.0f;
	float DefaultLCTimingLock = 20.0f;

	Assert(pRamVariables->LCTimingLock == DefaultLCTimingLock, "check timing lock default value");
	Assert(pRamVariables->MapBlendRatio == DefaultBlend, "Check default blending value");
	Assert(pRamVariables->TimingHackInitFlag == 0x01, "Check Timing init flag is set");
	Assert(pRamVariables->TimingHackOutput == -12.96875, "check timing map 1 is used");
	
	pRamVariables->MapBlendRatio = 1;
	TimingHack();
	Assert(pRamVariables->TimingHackOutput == -20, "check timing map 1 is used");
	
	
	pRamVariables->MapBlendRatio = 0.5;
	TimingHack();
	Assert(pRamVariables->TimingHackOutput == ((-12.96875 - 20)/2), "check timing map 1 is used");
	
	pRamVariables->LCTimingMode = LCTimingModeLocked;		//Set locked timing, default is +20
	
	
	
}
Esempio n. 2
0
void RevLimUnitTests()
{
	ClearRam();
	//Run initializer
	PopulateRamVariables();
	
#if VIN_HACKS
	//Bypass VIN Cut
	pRamVariables->VinAuth = 0x01;
#endif

	SetBrake(0);
	SetClutch(0);

	////
	//Redline Test
	///////////////
	//Clear flag
	*pFlagsRevLim = 0x00;
	//Set just below REDLINE, should not cut
	*pEngineSpeed = pRamVariables->RedLineCut - 1;
	*pVehicleSpeed = 19.0f;
	SetClutch(0);
	RevLimCode();
	Assert(!GetFuelCutFlag(), "RedLine: Allow fuel at RedLineCut - 1 RPM, moving, clutch not pressed !FuelCut");
	Assert(!pRamVariables->LCEngaged, "RedLine: Allow fuel at RedLineCut - 1 RPM, moving, clutch not pressed, !LCEngaged");
	
	//Set above REDLINE, should cut
	*pEngineSpeed = pRamVariables->RedLineCut + 1;
	*pVehicleSpeed = 19.0f;
	SetClutch(0);
	RevLimCode();
	Assert(GetFuelCutFlag() && !pRamVariables->LCEngaged, "RedLine: Cut fuel at RedLineCut + 1 RPM, moving, clutch not pressed");	

	//Set back below hysteresis, should RESUME
	*pEngineSpeed = pRamVariables->RedLineCut - pRamVariables->RedLineHyst - 1;
	*pVehicleSpeed = 19.0f;
	SetClutch(0);
	RevLimCode();
	Assert(!GetFuelCutFlag() && !pRamVariables->LCEngaged, "RedLine: Resume fuel at RedLineResume - 1 RPM, moving, clutch not pressed");
	
	////
	//LC Tests
	///////////
	
	//TEST 1: Stationary car
	//Clutch is out
	//RPM is between LC limit and Redline Limit
	//Should NOT CUT
	*pThrottlePlate = 100;
	*pEngineSpeed = pRamVariables->LaunchControlCut + 1000;
	*pVehicleSpeed = 0.0f;
	RevLimCode();
	//-----V this ! means it SHOULD NOT cut
	Assert(!GetFuelCutFlag() && !pRamVariables->LCEngaged, "Normal stopped: Allow fuel at LaunchControlCut + 1000 RPM, stopped, no clutch");
	

	//TEST 2: Repeat test 1 with vehicle speed
	//Should NOT CUT
	*pEngineSpeed = pRamVariables->LaunchControlCut + 1000;
	*pVehicleSpeed = 19.0f;
	SetClutch(0);
	RevLimCode();
	Assert(!GetFuelCutFlag() && !pRamVariables->LCEngaged, "Normal moving: Allow fuel at LaunchControlCut + 1000 RPM, moving, no clutch");
	
	//TEST 3: Stationary car
	//Clutch in
	//RPM Below limits
	//Shoudl NOT CUT
	*pEngineSpeed = pRamVariables->LaunchControlCut - 1;
	*pVehicleSpeed = 0.0f;
	*pThrottlePlate = 10.0f;
	SetClutch(1);
	RevLimCode();
	Assert(!GetFuelCutFlag() && !pRamVariables->LCEngaged, "Launch Control: Allow fuel at LaunchControlCut - 1 RPM, standstill, clutch pressed");
	
	//TEST 4: Repeat test 3
	//Set above LC limit
	//SHOULD CUT FUEL HERE!!
	*pThrottlePlate = 100.0f;
	*pEngineSpeed = pRamVariables->LaunchControlCut + 1;
	*pVehicleSpeed = 0.0f;
	SetClutch(1);
	RevLimCode();
	Assert(GetFuelCutFlag() && pRamVariables->LCEngaged, "Launch Control: Cut fuel at LaunchControlCut + 1 RPM, standstill, clutch pressed");
	
	//Test 5: Repeat test 4
	//Set RPM below limit, but above resume value
	//SHOULD NOT RESUME YET!
	*pEngineSpeed = pRamVariables->LaunchControlCut - 1;
	*pVehicleSpeed = 0.0f;
	SetClutch(1);
	RevLimCode();
	Assert(GetFuelCutFlag() && pRamVariables->LCEngaged, "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed");
	
	//TEST 6: Repeat test 5
	//Set below LC hysteresis
	//SHOULD RESUME HERE, but LC still engaged (on LC limit)
	*pEngineSpeed = pRamVariables->LaunchControlCut - pRamVariables->LaunchControlHyst - 1;
	*pVehicleSpeed = 0.0f;
	SetClutch(1);
	RevLimCode();
	int shit = !GetFuelCutFlag();
	shit &= pRamVariables->LCEngaged;
	Assert(shit , "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed");
	
	//TEST7: low throttle
	//Set throttle 
	*pEngineSpeed = pRamVariables->RedLineCut - 200;
	*pVehicleSpeed = 0.0f;
	*pThrottlePlate = LCMinimumThrottle + 1;
	SetClutch(1);
	RevLimCode();
	//should cut here
	Assert(GetFuelCutFlag() && pRamVariables->LCEngaged, "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed");
	*pThrottlePlate -= 10;
	RevLimCode();
	Assert(!GetFuelCutFlag() && !pRamVariables->LCEngaged, "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed");
	//should resume here
	
		
#if LC_ADJUST
	//Test LC adjust
	//Setup:
	*pEngineSpeed = pRamVariables->RedLineCut - 200;
	*pVehicleSpeed = 0.0f;
	*pThrottlePlate = LCMinimumThrottle + 1;
	SetClutch(1);
	RevLimCode();
	//should cut here
	Assert(GetFuelCutFlag() && pRamVariables->LCEngaged, "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed");
	//Adjust
	*pEngineSpeed = pRamVariables->LaunchControlCut - pRamVariables->LaunchControlHyst + 5; //Still should cut
	Assert(GetFuelCutFlag() && pRamVariables->LCEngaged, "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed");
	*pResumeFlags |= ResumeBitMask;
	//increases limit
	WGDCHack();
	RevLimCode();
	//should resume as limit has increased
	Assert(pRamVariables->LCEngaged, "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed, !LCEngaged");
	Assert(!GetFuelCutFlag(), "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed !FuelCut");
	*pResumeFlags = 0x00;
	*pCoastFlags |= CoastBitMask;
	WGDCHack();
	RevLimCode();
	//should cut again
	Assert(pRamVariables->LCEngaged, "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed, !LCEngaged");
	Assert(!GetFuelCutFlag(), "Launch Control: Resume fuel at LaunchControlResume - 1 RPM, standstill, clutch pressed !FuelCut");
#endif
	
	//////
	//FFS TESTS
	////////////////
	
	//TEST 1: Check that low throttle disables the cut
	//Set pre-shift conditions
	*pCurrentGear = 4;
	*pThrottlePlate = 20;
	*pVehicleSpeed = 50.0f;
	*pEngineSpeed = pRamVariables->LaunchControlCut - 100;
	SetClutch(0);
	RevLimCode(); //This sets the current gear
	SetClutch(1);
	RevLimCode();
	//Should NOT cut due to throttle.
	Assert(!GetFuelCutFlag() && !pRamVariables->LCEngaged, "Flat Foot Shifting: Resume fuel at FlatFootShiftResume - 1 RPM, moving, clutch pressed");

	//TEST 2: Set throttle high
	//Should engage FFS and cut
	*pEngineSpeed = pRamVariables->FlatFootShiftRpmThreshold + 500;
	*pThrottlePlate = FFSMinimumThrottle + 1;
	RevLimCode(); //This sets the FFS engaged, and sets the FFSRPM
	Assert(GetFuelCutFlag() && (pRamVariables->FFSEngaged == 2), "Flat Foot Shifting: Cut fuel at FlatFootShiftCut + 1 RPM, moving, clutch pressed");	

	//TEST 3: Set rpm low
	//Should disable FFS and resume fuel
	*pEngineSpeed = pRamVariables->RevLimResume - 1;
	RevLimCode();
	Assert(!GetFuelCutFlag() && !pRamVariables->FFSEngaged, "FFS resume when rpm drops");
	
	//TEST 4: Engage ffs and cut again
	*pEngineSpeed = pRamVariables->FlatFootShiftRpmThreshold + 500;
	RevLimCode(); //This sets the FFS engaged, and sets the FFSRPM
	RevLimCode(); //This runs the FFS limiter, and SHOULD CUT
	Assert(GetFuelCutFlag() && pRamVariables->FFSEngaged, "Flat Foot Shifting: Cut fuel at FlatFootShiftCut + 1 RPM, moving, clutch pressed");	
	//Set throttle below  FFS threshold, should resume
	*pThrottlePlate = FFSMinimumThrottle - 1;
	*pVehicleSpeed = 19.0f;
	SetClutch(1);
	RevLimCode();
	RevLimCode();
	Assert(!GetFuelCutFlag(), "Flat Foot Shifting: Resume fuel at FlatFootShiftResume - 1 RPM, moving, clutch pressed");
	*pThrottlePlate = 100;
	

	
	// Verify the other bits in the rev limiter flag are not modified.
	// ONLY NECESSARY FOR BITMASKING
	
	*pEngineSpeed = 6000.0f;
	*pVehicleSpeed = 0.0f;
	SetClutch(1);
	SetBrake(0);
	*pFlagsRevLim = 0x00;					
	RevLimCode();
	unsigned char flags = *pFlagsRevLim;
	Assert(flags == (unsigned char) RevLimBitMask, "When rev limit flag is set, no other bits are set.");

	// Verify the other bits in the rev limiter flag are not modified.
	*pEngineSpeed = 1000.0f;
	*pVehicleSpeed = 0.0f;
	SetClutch(0);
	*pFlagsRevLim = 0xFF;
	RevLimCode();
	flags = ~*pFlagsRevLim;
	Assert( flags == (unsigned char) RevLimBitMask, "When rev limit flag is cleared, no other bits are cleared.");
		
	// Sanity check the defaults
	Assert(pRamVariables->RedLineCut > pRamVariables->RedLineCut - pRamVariables->RedLineHyst, "RedLine cut/resume sanity.");
	Assert(pRamVariables->LaunchControlCut > pRamVariables->LaunchControlCut - pRamVariables->LaunchControlHyst, "LaunchControl cut/resume sanity.");
}
Esempio n. 3
0
void PolfHackUnitTests()
{
	PopulateRamVariables();
	
	*pEngineSpeed = 3000;
	*pEngineLoad = 1.0;
	*pThrottlePlate = 0;

	POLFHack();
	Assert(pRamVariables->MapBlendRatio == DefaultBlend, "Check for init Blend");
	Assert(pRamVariables->LCFuelLock == DefaultLCFuelLock, "Check for init LCFuelLock");
	Assert(pRamVariables->LCFuelMode == DefaultLCFuelMode, "Check for init FuelMode");
	
	*pIAM = 0;
	POLFHack();
	float ftff = 0;
	Assert(AreCloseEnough(pRamVariables->PolfOutput, ftff), "Check IAM Failsafe Map is used");
	
	*pEngineSpeed = 7000;
	POLFHack();
	ftff = 0.3203125;
	Assert(AreCloseEnough(pRamVariables->PolfOutput, ftff), "Check IAM Failsafe Map is used");
	
	*pIAM = 1;//TODO 1byte/4byte
	POLFHack();
	float ft1 = 0.3203125;	
	Assert(AreCloseEnough(pRamVariables->PolfOutput, ft1), "Check map 1 is used");
	
	*pEngineSpeed = 3000;
	*pIAM = 1;
	POLFHack();
	ft1 = 0;	
	Assert(AreCloseEnough(pRamVariables->PolfOutput, ft1), "Check map 1 is used");
	
	pRamVariables->MapBlendRatio = 1;
	POLFHack();
	float ft2 = 0;
	Assert(AreCloseEnough(pRamVariables->PolfOutput, ft2), "Check map 2 is used");
	
	*pEngineSpeed = 7000;
	pRamVariables->MapBlendRatio = 1;
	POLFHack();
	ft2 = 0.3203125;
	Assert(AreCloseEnough(pRamVariables->PolfOutput, ft2), "Check map 2 is used");
	
	pRamVariables->MapBlendRatio = 0.5;
	POLFHack();
	float ftb = 0.3203125;
	Assert(AreCloseEnough(pRamVariables->PolfOutput, ftb), "Check Blending Value");
	
	pRamVariables->LCFuelMode = LCFuelModeLocked; //Lock the fueling target
	*pEngineSpeed  = (pRamVariables->LaunchControlCut - pRamVariables->LaunchControlHyst - 25);
	SetClutch(1);
	*pVehicleSpeed = 0.0f;
	*pThrottlePlate = LCMinimumThrottle + 1;
	RevLimCode();	//init the rev limiter stuff
	POLFHack();
	float locked = 0.35;
	Assert(AreCloseEnough(pRamVariables->PolfOutput, locked), "Check Locked Value");
	
	*pEngineSpeed = 7000;
	SetClutch(0);
	RevLimCode();	
	pRamVariables->LCFuelMode = LCFuelModeCompensated; //Set to compensation
	pRamVariables->MapBlendRatio = 0;
	POLFHack();
	float comp = 0.5625;
	Assert(AreCloseEnough(pRamVariables->PolfOutput, comp), "Check Comp Value");
	
	
	pRamVariables->LCFuelMode = LCFuelModeDisabled;
	POLFHack();
	float mine = 0.3203125;
	Assert(AreCloseEnough(pRamVariables->PolfOutput, mine), "Check Comp Value");
	
}