Ejemplo n.º 1
0
void FreeSSM::dumpCUdata()
{
	const size_t VINlength = 17;

	QFile dumpfile;
	SSMCUdata ssmCUdata;
	std::string hexstr = "";

	unsigned int dataaddr[VINlength] = {0};
	char data[VINlength] = {0};
	int ssm1_cu_index = SSM1_CU_Engine;
	bool cu_resp = false;

	if (_dumping) return;
	// Initialize and configure serial port:
	AbstractDiagInterface *diagInterface = initInterface();
	if (!diagInterface)
		return;
	_dumping = true;
	// Set filename:
	QString filename(QDir::homePath() + "/dump");
	if (QFile::exists(filename + ".dat"))
	{
		for (unsigned int f=2; f<65535; f++)
		{
			if (!QFile::exists(filename + QString::number(f) + ".dat"))
			{
				filename.append(QString::number(f));
				break;
			}
		}
	}
	filename.append(".dat");
	dumpfile.setFileName(filename);
	if (!dumpfile.open(QIODevice::WriteOnly | QIODevice::Text))
	{
		delete diagInterface;	// will be closed in destructor
		_dumping = false;
		return;
	}
	// Create SSMP1-Communication-object:
	SSMP1communication SSMP1com(diagInterface, SSM1_CU_Engine, 0);
	// Create SSMP2-Communication-object:
	SSMP2communication SSMP2com(diagInterface, 0x10, 0);
	// ######## SSM2-Control-Units ########
	// **************** ECU ***************
	// Read ECU data:
	if (diagInterface->connect(AbstractDiagInterface::protocol_SSM2_ISO14230))
	{
		cu_resp = true;
		if (!SSMP2com.getCUdata(ssmCUdata))
		{
			SSMP2com.setCUaddress(0x01);
			if (!SSMP2com.getCUdata(ssmCUdata))
			{
				SSMP2com.setCUaddress(0x02);
				cu_resp = SSMP2com.getCUdata(ssmCUdata);
			}
		}
	}
	if (!cu_resp)
	{
		diagInterface->disconnect();
		if (diagInterface->connect(AbstractDiagInterface::protocol_SSM2_ISO15765))
		{
			SSMP2com.setCUaddress(0x7E0);
			cu_resp = SSMP2com.getCUdata(ssmCUdata);
		}
	}
	if (cu_resp)
	{
		dumpfile.write(libFSSM::StrToMultiLineHexstr(ssmCUdata.SYS_ID).c_str());
		dumpfile.write(libFSSM::StrToMultiLineHexstr(ssmCUdata.ROM_ID).c_str());
		dumpfile.write(libFSSM::StrToMultiLineHexstr(ssmCUdata.flagbytes).c_str());
		dumpfile.write("\n");
		// VIN:
		if (ssmCUdata.flagbytebit(36, 0))
		{
			dataaddr[0] = 0xDA;
			dataaddr[1] = 0xDB;
			dataaddr[2] = 0xDC;
			if (SSMP2com.readMultipleDatabytes(0x0, dataaddr, 3, data))
			{
				hexstr = libFSSM::StrToHexstr(data, 3);
				hexstr.push_back('\n');
				dumpfile.write(hexstr.data(), hexstr.length());

				dataaddr[0] = libFSSM::parseUInt24BigEndian(data);
				for (unsigned char k=1; k<VINlength; k++)
					dataaddr[k] = dataaddr[0]+k;
				if (SSMP2com.readMultipleDatabytes(0x0, dataaddr, VINlength, data))
				{
					hexstr = libFSSM::StrToMultiLineHexstr(data, VINlength, VINlength);
					hexstr.append(data, VINlength);
					hexstr += "\n\n";
					dumpfile.write(hexstr.data(), hexstr.size());
				}
			}
		}
	}
	else
		dumpfile.write("\n---\n", 5);
	// **************** TCU ***************
	// Read TCU data:
	cu_resp = false;
	diagInterface->disconnect();
	if (diagInterface->connect(AbstractDiagInterface::protocol_SSM2_ISO14230))
	{
		SSMP2com.setCUaddress(0x18);
		cu_resp = true;
		if (!SSMP2com.getCUdata(ssmCUdata))
		{
			SSMP2com.setCUaddress(0x01);
			cu_resp = SSMP2com.getCUdata(ssmCUdata);
		}
	}
	if (!cu_resp)
	{
		diagInterface->disconnect();
		if (diagInterface->connect(AbstractDiagInterface::protocol_SSM2_ISO15765))
		{
			SSMP2com.setCUaddress(0x7E1);
			// Read TCU data:
			cu_resp = SSMP2com.getCUdata(ssmCUdata);
		}
	}
	if (cu_resp)
	{
		dumpfile.write(libFSSM::StrToMultiLineHexstr(ssmCUdata.SYS_ID).c_str());
		dumpfile.write(libFSSM::StrToMultiLineHexstr(ssmCUdata.ROM_ID).c_str());
		dumpfile.write(libFSSM::StrToMultiLineHexstr(ssmCUdata.flagbytes).c_str());
	}
	else
		dumpfile.write("\n---\n", 5);
	diagInterface->disconnect();

	// ######## SSM1-Control-Units ########
	// Configure interface:
	if (!diagInterface->connect(AbstractDiagInterface::protocol_SSM1))
		goto end;
	// Dump all SSM1-CUs:
	for (ssm1_cu_index=SSM1_CU_Engine; ssm1_cu_index<=SSM1_CU_PwrSteer; ssm1_cu_index++)
	{
		// Select CU:
		SSMP1com.selectCU( SSM1_CUtype_dt(ssm1_cu_index) );
		// Read CU-ID(s):
		if (SSMP1com.getCUdata(0, ssmCUdata))
		{
			dumpfile.write("\n");
			// *** Convert and write data to file:
			// ID:
			dumpfile.write(libFSSM::StrToMultiLineHexstr(ssmCUdata.SYS_ID).c_str());

			if ((ssmCUdata.SYS_ID.at(0) & '\xF0') == '\xA0')
			{
				// ROM-ID:
				if (ssmCUdata.SYS_ID.at(1) == '\x10')
				{
					std::vector<unsigned int> addresses;
					for (unsigned int addr=0x01; addr<=0x05; addr++)
						addresses.push_back(addr);
					if (!SSMP1com.readAddresses(addresses, &ssmCUdata.ROM_ID))
						dumpfile.write("error\n", 4);
					else
					{
						dumpfile.write(libFSSM::StrToMultiLineHexstr(ssmCUdata.ROM_ID).c_str());
					}
				}
				// Flagbytes:
				if (SSMP1com.getCUdata(32, ssmCUdata))
				{
					dumpfile.write(libFSSM::StrToMultiLineHexstr(ssmCUdata.flagbytes).c_str());
				}
				else
					dumpfile.write("error\n", 4);
			}
		}
		else
			dumpfile.write("\n-----\n", 7);
	}
	diagInterface->disconnect();

end:
	dumpfile.close();
	delete diagInterface;	// will be closed in destructor
	_dumping = false;
}
Ejemplo n.º 2
0
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;
}