AbstractDiagInterface * FreeSSM::initInterface() { // Check if an interface is selected: if (_iface_filename == "") { displayErrorMsg(tr("No interface selected !\n=> Please select a dignostic interface in the preferences.")); return NULL; } // Open interface: AbstractDiagInterface *diagInterface = NULL; if (_iface_type == AbstractDiagInterface::interface_serialPassThrough) { diagInterface = new SerialPassThroughDiagInterface; } else if (_iface_type == AbstractDiagInterface::interface_J2534) { diagInterface = new J2534DiagInterface; } else if (_iface_type == AbstractDiagInterface::interface_ATcommandControlled) { diagInterface = new ATcommandControlledDiagInterface; } else { displayErrorMsg(tr("Internal error:\nThe selected interface type cannot be initialized !\n=> Please report this as a bug.")); return NULL; } if (diagInterface->open(_iface_filename.toStdString())) return diagInterface; // Return error: displayErrorMsg(tr("Couldn't open the diagnostic interface !\nMaybe the device is already in use by another application...")); delete diagInterface; return NULL; }
void Preferences::interfacetest() { QMessageBox *msgbox; FSSM_WaitMsgBox *waitmsgbox = NULL; QFont msgboxfont; // PREPARE INTERFACE: AbstractDiagInterface *diagInterface = NULL; if (_newinterfacetype == AbstractDiagInterface::interface_serialPassThrough) { diagInterface = new SerialPassThroughDiagInterface; } else if (_newinterfacetype == AbstractDiagInterface::interface_J2534) { diagInterface = new J2534DiagInterface; } else if (_newinterfacetype == AbstractDiagInterface::interface_ATcommandControlled) { diagInterface = new ATcommandControlledDiagInterface; } else { displayErrorMsg(tr("The selected interface is not supported !")); displayErrorMsg(tr("Internal error:\nThe interface test for the selected interface is not yet implemented.\n=> Please report this as a bug.")); return; } // OPEN INTERFACE: if (!diagInterface->open(_newinterfacefilename.toStdString())) { displayErrorMsg(tr("Couldn't open the diagnostic interface !\nPlease make sure that the device is not in use by another application.")); delete diagInterface; return; } // DISPLAY INFO MESSAGE: int choice = QMessageBox::NoButton; msgbox = new QMessageBox( QMessageBox::Information, tr("Interface test"), tr("Please connect diagnostic interface to the vehicles\ndiagnostic connector and switch ignition on."), QMessageBox::NoButton, this); msgbox->addButton(tr("Start"), QMessageBox::AcceptRole); msgbox->addButton(tr("Cancel"), QMessageBox::RejectRole); msgboxfont = msgbox->font(); msgboxfont.setPixelSize(12); // 9pts msgbox->setFont( msgboxfont ); msgbox->show(); choice = msgbox->exec(); msgbox->close(); delete msgbox; if (choice == QMessageBox::AcceptRole) { // START INTERFACE-TEST: bool icresult = false; bool retry = true; choice = 0; bool SSM1configOK = false; bool SSM2configOK = false; while (retry && !icresult) { char data = 0; // OUTPUT WAIT MESSAGE: waitmsgbox = new FSSM_WaitMsgBox(this, tr("Testing interface... Please wait ! ")); waitmsgbox->show(); // SSM2: SSMP2communication *SSMP2com = new SSMP2communication(diagInterface); SSM2configOK = diagInterface->connect(AbstractDiagInterface::protocol_SSM2_ISO14230); if (SSM2configOK) { SSMP2com->setCUaddress(0x10); unsigned int addr = 0x61; icresult = SSMP2com->readMultipleDatabytes('\x0', &addr, 1, &data); if (!icresult) { SSMP2com->setCUaddress(0x01); icresult = SSMP2com->readMultipleDatabytes('\x0', &addr, 1, &data); if (!icresult) { SSMP2com->setCUaddress(0x02); icresult = SSMP2com->readMultipleDatabytes('\x0', &addr, 1, &data); } } diagInterface->disconnect(); } if (!icresult) { SSM2configOK = diagInterface->connect(AbstractDiagInterface::protocol_SSM2_ISO15765); if (SSM2configOK) { SSMP2com->setCUaddress(0x7E0); unsigned int addr = 0x61; icresult = SSMP2com->readMultipleDatabytes('\x0', &addr, 1, &data); diagInterface->disconnect(); } } delete SSMP2com; // SSM1: if (!icresult) { SSM1configOK = diagInterface->connect(AbstractDiagInterface::protocol_SSM1); if (SSM1configOK) { SSMP1communication *SSMP1com = new SSMP1communication(diagInterface, SSM1_CU_Engine); icresult = SSMP1com->readAddress(0x00, &data); if (!icresult) { SSMP1com->selectCU(SSM1_CU_Transmission); icresult = SSMP1com->readAddress(0x00, &data); delete SSMP1com; } diagInterface->disconnect(); } } // CLOSE WAIT MESSAGE: waitmsgbox->close(); delete waitmsgbox; // DISPLAY TEST RESULT: QString resultText; if (icresult) resultText = tr("Interface test successful !"); else resultText = tr("Interface test failed !"); if (!SSM1configOK && !SSM2configOK) // => test must have failed { if (_newinterfacetype == AbstractDiagInterface::interface_serialPassThrough) resultText += "\n\n" + tr("The selected serial port can not be configured for the SSM1- and SSM2-protocol."); else resultText += "\n\n" + tr("The selected interface does not support the SSM1- and SSM2-protocol."); } else if (!icresult) { resultText += "\n\n" + tr("Please make sure that the interface is connected properly and ignition is switched ON."); } if (!SSM1configOK || !SSM2configOK) { resultText += "\n\n" + tr("WARNING:"); if (!SSM1configOK) { if (_newinterfacetype == AbstractDiagInterface::interface_serialPassThrough) resultText += '\n' + tr("The selected serial port can not be configured for the SSM1-protocol."); else resultText += '\n' + tr("The selected interface does not support the SSM1-protocol."); } else if (!SSM2configOK) { if (_newinterfacetype == AbstractDiagInterface::interface_serialPassThrough) resultText += '\n' + tr("The selected serial port can not be configured for the SSM2-protocol."); else resultText += '\n' + tr("The selected interface does not support the SSM2-protocol."); } } if (icresult) msgbox = new QMessageBox(QMessageBox::Information, tr("Interface test"), resultText, QMessageBox::Ok, this); else { msgbox = new QMessageBox(QMessageBox::Critical, tr("Interface test"), resultText, QMessageBox::NoButton, this); msgbox->addButton(tr("Retry"), QMessageBox::AcceptRole); msgbox->addButton(tr("Cancel"), QMessageBox::RejectRole); } msgboxfont = msgbox->font(); msgboxfont.setPixelSize(12); // 9pts msgbox->setFont( msgboxfont ); msgbox->show(); choice = msgbox->exec(); msgbox->close(); delete msgbox; if (!icresult && (choice != QMessageBox::AcceptRole)) retry = false; } } // CLOSE INTERFACE: if (!diagInterface->close()) displayErrorMsg(tr("Couldn't close the diagnostic interface !")); delete diagInterface; }