478 lines
18 KiB
C++
478 lines
18 KiB
C++
#include "CableTestEngine.h"
|
|
#include "CableTestBench.h"
|
|
|
|
CCableTestEngine::CCableTestEngine()
|
|
{
|
|
|
|
mCableTestSMState = CABLE_TEST_INIT_STATE;
|
|
}
|
|
|
|
CCableTestEngine::~CCableTestEngine()
|
|
{
|
|
delete mCableTestSMTimer;
|
|
}
|
|
|
|
int CCableTestEngine::InitCableTestEngine(CCableTestBench *ProgramHandle, CTestBenchSettings *SettingsHandle)
|
|
{
|
|
mProgramHandle = ProgramHandle;
|
|
mTestCable = ProgramHandle->GetActualCable();
|
|
mTestInputConnectorHandle = mTestCable->GetInputConnector();
|
|
mTestOutputConnectorHandle = mTestCable->GetOutputConnector();
|
|
mTestReportHandle = ProgramHandle->GetTestReportHandle();
|
|
mAutoTestReportHandle = mTestReportHandle->GetAutomatedTestReport();
|
|
|
|
|
|
|
|
mCableTestSMTimer = new QTimer();
|
|
mCableTestSMTimer->setSingleShot(false);
|
|
mCableTestSMTimer->setInterval(TEST_ENGINE_SM_TIMEOUT);
|
|
mCableTestSMTimer->stop();
|
|
connect(mCableTestSMTimer,SIGNAL(timeout()),this,SLOT(SMTimerExpired()));
|
|
|
|
|
|
mTestSettingsHandle = SettingsHandle;
|
|
mIsSecondPass = false;
|
|
|
|
|
|
CableTestEngineStateMachine(CABLE_TEST_TICK_SM_EVENT);
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
|
|
void CCableTestEngine::CableTestEngineStateMachine(int Event)
|
|
{
|
|
|
|
switch(mCableTestSMState)
|
|
{
|
|
case CABLE_TEST_INIT_STATE:
|
|
{
|
|
mCableTestSMState = CABLE_TEST_STBY_STATE;
|
|
mIsSecondPass = false;
|
|
mCableTestSMTimer->start();
|
|
break;
|
|
}//case CABLE_TEST_INIT_STATE
|
|
|
|
case CABLE_TEST_STBY_STATE:
|
|
{
|
|
switch(Event)
|
|
{
|
|
case CABLE_TEST_START_AUTO_TEST_SM_EVENT:
|
|
{
|
|
mCableTestSMState = CABLE_TEST_START_AUTOMATED_TEST_STATE;
|
|
mProgramHandle->CableEngineModeChanged(GetTestEngineCurrentMode());
|
|
break;
|
|
}
|
|
case CABLE_TEST_START_MANUAL_TEST_SM_EVENT:
|
|
{
|
|
mCableTestSMState = CABLE_TEST_START_MANUAL_TEST_STATE;
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
break;
|
|
}// case CABLE_TEST_STBY_STATE
|
|
|
|
case CABLE_TEST_START_AUTOMATED_TEST_STATE:
|
|
{
|
|
mTestOutputConnectorHandle->ClearAllPins();
|
|
mCableTestSMState = CABLE_AUTO_TEST_SELF_TEST_STATE;
|
|
|
|
mCableTestGPTimer.start();
|
|
|
|
//qDebug("Test automatique démarré...");
|
|
mTestReportHandle->AddLogEntry(QString("Démarrage du test automatique."));
|
|
break;
|
|
}//case CABLE_TEST_START_AUTOMATED_TEST_STATE
|
|
|
|
case CABLE_AUTO_TEST_SELF_TEST_STATE:
|
|
{
|
|
if(mCableTestGPTimer.elapsed() < mTestSettingsHandle->mPinHoldTime)
|
|
{
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
QBitArray Out = mTestOutputConnectorHandle->GetOutputPinsStates();
|
|
if(Out.count(true) != 0)
|
|
{
|
|
//TODO: Manage this failure mode
|
|
mAutoTestReportHandle->SetPreTestResult(false);
|
|
// qDebug("Échec de l'auto test des modules d'I/O");
|
|
QString LogString = QString("Échec de l'auto test des modules de sortie. %1 contacts sont activés : ");
|
|
|
|
for(int pin = 0; pin < Out.count(); pin++)
|
|
{
|
|
if(Out.at(pin))
|
|
{
|
|
mAutoTestReportHandle->AddShortedPinToPinTest(mCurPinUnderTest,pin+1);
|
|
LogString.append(QString("[%1], "));
|
|
}
|
|
}
|
|
|
|
mTestReportHandle->AddLogEntry(LogString);
|
|
mCableTestSMState = CABLE_AUTO_TEST_END_TEST_STATE;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
mCurPinUnderTest = 1;
|
|
mTestOutputConnectorHandle->SetSinglePin(mCurPinUnderTest);
|
|
mAutoTestReportHandle->SetPreTestResult(true);
|
|
mTestReportHandle->AddLogEntry(QString("Succès de l'auto test des modules d'I/O"));
|
|
//OK
|
|
}
|
|
|
|
mCableTestGPTimer.start();
|
|
mCableTestSMState = CABLE_AUTO_TEST_PINS_STATE;
|
|
}
|
|
break;
|
|
}//case CABLE_AUTO_TEST_SELF_TEST_STATE
|
|
|
|
case CABLE_AUTO_TEST_PINS_STATE:
|
|
{
|
|
switch(Event)
|
|
{
|
|
case CABLE_TEST_TICK_SM_EVENT:
|
|
{
|
|
if(mCableTestGPTimer.elapsed() < mTestSettingsHandle->mPinHoldTime)
|
|
{
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
QBitArray Out = mTestOutputConnectorHandle->GetOutputPinsStates();
|
|
QBitArray In = mTestInputConnectorHandle->GetInputPinsStates();
|
|
|
|
//Analyse the inputs buffer...
|
|
|
|
if(In.count(true) != 1) //check if only 1 input pin is active
|
|
{
|
|
if(In.count(true) == 0) //Check if no input pin is active
|
|
{
|
|
if(mIsSecondPass == false)
|
|
{
|
|
mAutoTestReportHandle->SetPinContinuityResult(mCurPinUnderTest,false);
|
|
mTestReportHandle->AddLogEntry(QString("Échec du test du contact %1 : aucun contact activé en entrée").arg(mCurPinUnderTest));
|
|
}
|
|
else
|
|
{
|
|
mAutoTestReportHandle->SetPinSecondTestResult(mCurPinUnderTest,false);
|
|
mTestReportHandle->AddLogEntry(QString("2è passe: échec du test du contact %1 : aucun contact activé en entrée").arg(mCurPinUnderTest));
|
|
}
|
|
}
|
|
else //If here, many input pins are active...
|
|
{
|
|
if(mIsSecondPass == false)
|
|
{
|
|
QString LogString = QString("Échec du test d'isolation du contact %1 : (%2) contacts activés en entrée : ").arg(mCurPinUnderTest).arg(In.count(true));
|
|
mAutoTestReportHandle->SetPinIsolationResult(mCurPinUnderTest,false);
|
|
for(int pin = 0; pin < In.count(); pin++)
|
|
{
|
|
if(In.at(pin))
|
|
{
|
|
mAutoTestReportHandle->AddShortedPinToPinTest(mCurPinUnderTest,pin+1);
|
|
LogString.append(QString("[%1]").arg(pin+1));
|
|
}
|
|
}
|
|
// qDebug("Échec du test d'isolation du contact %d : (%d) contacts activés en entrée",mCurPinUnderTest,In.count(true));
|
|
mTestReportHandle->AddLogEntry(LogString);
|
|
|
|
}
|
|
else
|
|
{
|
|
mAutoTestReportHandle->SetPinSecondTestResult(mCurPinUnderTest,false);
|
|
QString LogString = QString("2è passe: chec du test d'isolation du contact %1 : (%2) contacts activés en entrée : ").arg(mCurPinUnderTest).arg(In.count(true));
|
|
mTestReportHandle->AddLogEntry(LogString);
|
|
}
|
|
}
|
|
}
|
|
else if(In.at(mCurPinUnderTest-1) == false)
|
|
{
|
|
//TODO: Manage this failure mode
|
|
//the wrong pin is set on the input... find which
|
|
|
|
int WrongPin = 0;
|
|
for(int pin = 0; pin < In.count(); pin++)
|
|
{
|
|
if(In.at(pin))
|
|
{
|
|
WrongPin = pin+1;
|
|
break;
|
|
}
|
|
}
|
|
if(mIsSecondPass == false)
|
|
{
|
|
mAutoTestReportHandle->SetPinConcordanceTestResult(mCurPinUnderTest,false,WrongPin);
|
|
mTestReportHandle->AddLogEntry(QString("Échec du test d'assignation du contact %1: le contact %2 est activé.").arg(mCurPinUnderTest).arg(WrongPin));
|
|
}
|
|
else
|
|
{
|
|
mAutoTestReportHandle->SetPinSecondTestResult(mCurPinUnderTest,false);
|
|
mTestReportHandle->AddLogEntry(QString("2è passe: échec du test d'assignation du contact %1: le contact %2 est activé.").arg(mCurPinUnderTest).arg(WrongPin));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Pin test passed. Test the next one
|
|
if(mIsSecondPass == false)
|
|
{
|
|
mAutoTestReportHandle->SetPinTestAllPassed(mCurPinUnderTest);
|
|
mTestReportHandle->AddLogEntry(QString("Succès du test du contact %1").arg(mCurPinUnderTest));
|
|
}
|
|
else
|
|
{
|
|
mAutoTestReportHandle->SetPinSecondTestResult(mCurPinUnderTest,true);
|
|
mTestReportHandle->AddLogEntry(QString("2è passe: succès du test du contact %1").arg(mCurPinUnderTest));
|
|
}
|
|
}
|
|
|
|
mCurPinUnderTest++;
|
|
int TestPinCount = mTestOutputConnectorHandle->GetPinCount();
|
|
if(mTestInputConnectorHandle->GetPinCount() < TestPinCount)
|
|
{
|
|
TestPinCount = mTestInputConnectorHandle->GetPinCount();
|
|
}
|
|
if(mCurPinUnderTest > TestPinCount)
|
|
{
|
|
//Test finished.
|
|
|
|
if(mTestSettingsHandle->mExecSecondPass == true) //Check if we need to execute the test twice
|
|
{
|
|
if(mIsSecondPass == true) //Check if this was the second pass.
|
|
{
|
|
mCableTestSMState = CABLE_AUTO_TEST_END_TEST_STATE; //test finished
|
|
}
|
|
else
|
|
{
|
|
mCableTestSMState = CABLE_AUTO_TEST_START_SECOND_PASS_STATE; //start the 2nd test
|
|
}
|
|
}
|
|
else
|
|
{
|
|
mCableTestSMState = CABLE_AUTO_TEST_END_TEST_STATE; //test finished
|
|
}
|
|
}
|
|
else
|
|
{
|
|
mTestOutputConnectorHandle->SetSinglePin(mCurPinUnderTest);
|
|
mCableTestGPTimer.start();
|
|
}
|
|
|
|
}
|
|
break;
|
|
}
|
|
case CABLE_TEST_PAUSE_AUTO_TEST_SM_EVENT:
|
|
{
|
|
mCableTestSMState = CABLE_AUTO_TEST_PAUSE_STATE;
|
|
mProgramHandle->CableEngineModeChanged(GetTestEngineCurrentMode());
|
|
// qDebug("Test mis en pause...");
|
|
mTestReportHandle->AddLogEntry(QString("Test mis en pause"));
|
|
break;
|
|
}
|
|
case CABLE_TEST_CANCEL_AUTO_TEST_SM_EVENT:
|
|
{
|
|
mCableTestSMState = CABLE_AUTO_TEST_END_TEST_STATE;
|
|
// qDebug("Test annulé...");
|
|
mTestReportHandle->AddLogEntry(QString("Test annulé par l'utilisateur"));
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
}//case CABLE_AUTO_TEST_PINS_STATE:
|
|
|
|
case CABLE_AUTO_TEST_PAUSE_STATE:
|
|
{
|
|
switch(Event)
|
|
{
|
|
case CABLE_TEST_RESUME_AUTO_TEST_SM_EVENT:
|
|
{
|
|
mCableTestSMState = CABLE_AUTO_TEST_PINS_STATE;
|
|
mProgramHandle->CableEngineModeChanged(GetTestEngineCurrentMode());
|
|
// qDebug("Test redémarré...");
|
|
mTestReportHandle->AddLogEntry(QString("Test redémarré..."));
|
|
break;
|
|
}
|
|
case CABLE_TEST_CANCEL_AUTO_TEST_SM_EVENT:
|
|
{
|
|
mCableTestSMState = CABLE_AUTO_TEST_END_TEST_STATE;
|
|
// qDebug("Test annulé...");
|
|
mTestReportHandle->AddLogEntry(QString("Test annulé par l'utilisateur"));
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
break;
|
|
}//case CABLE_AUTO_TEST_PAUSE_STATE
|
|
case CABLE_AUTO_TEST_START_SECOND_PASS_STATE:
|
|
{
|
|
//restart test but skip module self-test...
|
|
mIsSecondPass = true;
|
|
mCurPinUnderTest = 1;
|
|
mTestOutputConnectorHandle->SetSinglePin(mCurPinUnderTest);
|
|
mCableTestGPTimer.start();
|
|
mCableTestSMState = CABLE_AUTO_TEST_PINS_STATE;
|
|
mTestReportHandle->AddLogEntry(QString("Démarrage du deuxième test"));
|
|
break;
|
|
}//case CABLE_AUTO_TEST_START_SECOND_PASS_STATE
|
|
|
|
case CABLE_AUTO_TEST_END_TEST_STATE:
|
|
{
|
|
// qDebug("Test automatique terminé...");
|
|
mIsSecondPass = false;
|
|
mTestReportHandle->AddLogEntry(QString("Test automatique terminé"));
|
|
mTestOutputConnectorHandle->ClearAllPins();
|
|
mCableTestSMState = CABLE_TEST_STBY_STATE;
|
|
mProgramHandle->CableEngineModeChanged(GetTestEngineCurrentMode());
|
|
break;
|
|
}//case CABLE_TEST_END_TEST_STATE
|
|
|
|
case CABLE_TEST_START_MANUAL_TEST_STATE:
|
|
{
|
|
mTestOutputConnectorHandle->ClearAllPins();
|
|
// qDebug("Entrée en mode test manuel");
|
|
mTestReportHandle->AddLogEntry(QString("Entrée en mode test manuel"));
|
|
mCableTestSMState = CABLE_MANUAL_TEST_PINS_STATE;
|
|
mProgramHandle->CableEngineModeChanged(GetTestEngineCurrentMode());
|
|
break;
|
|
}//CABLE_TEST_START_MANUAL_TEST_STATE
|
|
|
|
case CABLE_MANUAL_TEST_PINS_STATE:
|
|
{
|
|
switch(Event)
|
|
{
|
|
case CABLE_TEST_EXIT_MANUAL_TEST_SM_EVENT:
|
|
{
|
|
mCableTestSMState = CABLE_MANUAL_TEST_END_TEST_STATE;
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
break;
|
|
}//CABLE_MANUAL_TEST_PINS_STATE
|
|
|
|
case CABLE_MANUAL_TEST_END_TEST_STATE:
|
|
{
|
|
mTestOutputConnectorHandle->ClearAllPins();
|
|
mCableTestSMState = CABLE_TEST_STBY_STATE;
|
|
mProgramHandle->CableEngineModeChanged(GetTestEngineCurrentMode());
|
|
mTestReportHandle->AddLogEntry(QString("Fin du test manuel"));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CCableTestEngine::SMTimerExpired()
|
|
{
|
|
//TODO: manage the end of the test
|
|
CableTestEngineStateMachine(CABLE_TEST_TICK_SM_EVENT);
|
|
|
|
}
|
|
|
|
int CCableTestEngine::StartAutomatedTest()
|
|
{
|
|
if(mCableTestSMState != CABLE_TEST_STBY_STATE)
|
|
{
|
|
return RET_ERROR;
|
|
}
|
|
|
|
CableTestEngineStateMachine(CABLE_TEST_START_AUTO_TEST_SM_EVENT);
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
int CCableTestEngine::PauseAutomatedTest()
|
|
{
|
|
CableTestEngineStateMachine(CABLE_TEST_PAUSE_AUTO_TEST_SM_EVENT);
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
int CCableTestEngine::ResumeAutomatedTest()
|
|
{
|
|
CableTestEngineStateMachine(CABLE_TEST_RESUME_AUTO_TEST_SM_EVENT);
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
int CCableTestEngine::StopAutomatedTest()
|
|
{
|
|
CableTestEngineStateMachine(CABLE_TEST_CANCEL_AUTO_TEST_SM_EVENT);
|
|
return RET_OK;
|
|
}
|
|
|
|
int CCableTestEngine::StartManualTest()
|
|
{
|
|
CableTestEngineStateMachine(CABLE_TEST_START_MANUAL_TEST_SM_EVENT);
|
|
return RET_OK;
|
|
}
|
|
|
|
int CCableTestEngine::StopManualTest()
|
|
{
|
|
CableTestEngineStateMachine(CABLE_TEST_EXIT_MANUAL_TEST_SM_EVENT);
|
|
return RET_OK;
|
|
}
|
|
|
|
CCableTestEngine::eCableTestEngineMode CCableTestEngine::GetTestEngineCurrentMode()
|
|
{
|
|
switch(mCableTestSMState)
|
|
{
|
|
case CABLE_TEST_INIT_STATE:
|
|
case CABLE_TEST_STBY_STATE:
|
|
case CABLE_AUTO_TEST_END_TEST_STATE:
|
|
case CABLE_MANUAL_TEST_END_TEST_STATE:
|
|
{
|
|
return CABLE_TEST_STBY_MODE;
|
|
break;
|
|
}
|
|
case CABLE_TEST_START_AUTOMATED_TEST_STATE:
|
|
case CABLE_AUTO_TEST_SELF_TEST_STATE:
|
|
case CABLE_AUTO_TEST_PINS_STATE:
|
|
{
|
|
return CABLE_AUTO_TEST_RUNNING_MODE;
|
|
break;
|
|
}
|
|
case CABLE_AUTO_TEST_PAUSE_STATE:
|
|
{
|
|
return CABLE_AUTO_TEST_PAUSED_MODE;
|
|
break;
|
|
}
|
|
case CABLE_TEST_START_MANUAL_TEST_STATE:
|
|
case CABLE_MANUAL_TEST_PINS_STATE:
|
|
default:
|
|
{
|
|
return CABLE_TEST_MANUAL_MODE;
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
int CCableTestEngine::ManualPinToggle(int ConnectorPinNbr)
|
|
{
|
|
if(GetTestEngineCurrentMode() == CABLE_TEST_MANUAL_MODE)
|
|
{
|
|
return mTestOutputConnectorHandle->TogglePin(ConnectorPinNbr);
|
|
}
|
|
|
|
return RET_ERROR;
|
|
}
|