void TransmissionDialog::runClearMemory(SSMprotocol::CMlevel_dt level) { bool ok = false; ClearMemoryDlg::CMresult_dt result; // Create "Clear Memory"-dialog: ClearMemoryDlg cmdlg(this, _SSMPdev, level); // Temporary disconnect from "communication error"-signal: disconnect(_SSMPdev, SIGNAL( commError() ), this, SLOT( communicationError() )); // Run "Clear Memory"-procedure: result = cmdlg.run(); // Reconnect to "communication error"-signal: connect(_SSMPdev, SIGNAL( commError() ), this, SLOT( communicationError() )); // Check result: if ((result == ClearMemoryDlg::CMresult_success) && (_mode == Adaptions_mode)) { FSSM_WaitMsgBox waitmsgbox(this, tr("Reading Adjustment Values... Please wait !")); waitmsgbox.show(); ok = _content_Adjustments->setup(_SSMPdev); // refresh adjustment values waitmsgbox.close(); if (!ok) communicationError(); } else if (result == ClearMemoryDlg::CMresult_communicationError) { communicationError(); } else if ((result == ClearMemoryDlg::CMresult_reconnectAborted) || (result == ClearMemoryDlg::CMresult_reconnectFailed)) { close(); // exit engine control unit dialog } }
//-------------------------------------------------------------- // HIGH LEVEL MESSAGE FUNCTIONS //-------------------------------------------------------------- // This function will receive a full request message from a // RasPi and return proper confirmation bytes int * receiveMessage(void){ // Hold inital byte received uint8_t i=0; uint8_t j=0; uint8_t n=0; // Array to hold received data static int msgArray[10]; int dataByteIn[2]; // Receive initial byte for(j=0; j<2; j++){ dataByteIn[j] = receiveByte(); } // If message is not properly terminated write error code // to entire array and call commError() if(dataByteIn[1] != END_MSG){ for (i=0; i<4; i++){ msgArray[i] = UART_COMM_ERROR; } commError(); } // RasPi normal request message to AVR else if (dataByteIn[0] == RASPI_REQ_AVR){ // Transmit AVR ready to receive message transmitReady(); // Loop through until EOM reached and store in array do{ msgArray[n] = receiveByte(); n++; }while(msgArray[n-1] != END_MSG); transmitConfirm(); } // RasPi initialize request to AVR else if(dataByteIn[0] == RASPI_INIT_TO_AVR){ // Transmit AVR initialized ready byte transmitInitialize(); // Write initialized byte to array for(i=0; i<4; i++){ msgArray[i] = AVR_INIT_TO_RASPI; } } // Improper initial communication byte, call commError() else{ commError(); } return msgArray; }
void SSMprotocol2::resetCUdata() { // RESET COMMUNICATION: if (_SSMP2com != NULL) { // Disconnect communication error and data signals: disconnect( _SSMP2com, SIGNAL( commError() ), this, SIGNAL( commError() ) ); disconnect( _SSMP2com, SIGNAL( commError() ), this, SLOT( resetCUdata() ) ); disconnect( _SSMP2com, SIGNAL( receivedData(const std::vector<char>&, int) ), this, SLOT( processDCsRawdata(const std::vector<char>&, int) ) ); disconnect( _SSMP2com, SIGNAL( receivedData(const std::vector<char>&, int) ), this, SLOT( processMBSWrawData(const std::vector<char>&, int) ) ); // Try to stop active communication processes: // NOTE: DO NOT CALL any communicating member functions here because of possible recursions ! if (_SSMP2com->stopCommunication() && (_state == state_ActTesting)) { unsigned int dataadr = 0x61; char currentdatabyte = '\x0'; if (_SSMP2com->readMultipleDatabytes(0x0, &dataadr, 1, ¤tdatabyte)) { // Check if test mode is active: if (currentdatabyte & 0x20) { bool ok = false; // Stop all actuator tests: for (unsigned int k=0; k<_allActByteAddr.size(); k++) { ok =_SSMP2com->writeDatabyte(_allActByteAddr.at(k), 0x00); if (!ok) break; } _state = state_needSetup; // MUST BE DONE AFTER ALL CALLS OF MEMBER-FUNCTIONS AND BEFORE EMITTING SIGNALS if (ok) emit stoppedActuatorTest(); } } } _state = state_needSetup; // MUST BE DONE AFTER ALL CALLS OF MEMBER-FUNCTIONS AND BEFORE EMITTING SIGNALS delete _SSMP2com; _SSMP2com = NULL; // Emit stoppedXXX()-signals (_SSMP2com has been deleted, so we are sure they have finished): if (_state == state_MBSWreading) { emit stoppedMBSWreading(); } else if (_state == state_DCreading) { emit stoppedDCreading(); } }
// This function will transmit a full message to RasPi uint8_t transmitMessage(volatile int sendData[4]){ // Initialize loop counter uint8_t i; uint8_t badSendFlag = 0; // Clear global interrupt to stop receive interrupt cli(); // Send AVR request RasPi byte transmitRequest(); // Wait for response from RasPi // **** This has possibility of hanging program -- needs improvement! if (receiveByte() == RASPI_READY){ // Remove EOM from buffer receiveByte(); // Loop to send all of data array for(i=0; i<4; i++){ transmitByte(sendData[i]); } // Transmit end of message byte transmitByte(END_MSG); // Check for good confirm byte if (receiveByte() == RASPI_REC_MSG_CONFIRM){ // Remove EOM from buffer receiveByte(); } else{ // Set bad send flag badSendFlag = 2; } } // If improper response is received, call commError() else{ // Set bad send flag badSendFlag = 1; } // If badSendFlag is set - call commError() if(badSendFlag != 0){ commError(); } // reenable global interrupts sei(); // Return value of badSendFlag return badSendFlag; }
void ABSdialog::clearMemory() { ClearMemoryDlg::CMresult_dt result; // Create "Clear Memory"-dialog: ClearMemoryDlg cmdlg(this, _SSMPdev, SSMprotocol::CMlevel_1); // Temporary disconnect from "communication error"-signal: disconnect(_SSMPdev, SIGNAL( commError() ), this, SLOT( communicationError() )); // Run "Clear Memory"-procedure: result = cmdlg.run(); // Reconnect to "communication error"-signal: connect(_SSMPdev, SIGNAL( commError() ), this, SLOT( communicationError() )); // Check result: if (result == ClearMemoryDlg::CMresult_communicationError) { communicationError(); } else if ((result == ClearMemoryDlg::CMresult_reconnectAborted) || (result == ClearMemoryDlg::CMresult_reconnectFailed)) { close(); // exit engine control unit dialog } }
ControlUnitDialog::~ControlUnitDialog() { disconnect( exit_pushButton, SIGNAL( released() ), this, SLOT( close() ) ); if (_infoWidget) delete _infoWidget; if (_contentWidget) delete _contentWidget; delete _ifstatusbar; if (_SSMPdev) { disconnect( _SSMPdev, SIGNAL( commError() ), this, SLOT( communicationError() ) ); delete _SSMPdev; } for (int k=0; k<_selButtons.size(); k++) { _selButtons.at(k)->disconnect(); delete _selButtons.at(k); } }
SSMprotocol::CUsetupResult_dt ControlUnitDialog::probeProtocol(SSMprotocol::CUtype_dt CUtype) { /* NOTE: probe SSM2-protocol first ! If a serial pass through (K)KL-interface is used, the interface echo could be detected as a SSM1-ROM-ID, if receive buffer flushing doesn't work reliable with the used serial port driver ! */ SSMprotocol::CUsetupResult_dt result = SSMprotocol::result_commError; if ((CUtype == SSMprotocol::CUtype_Engine) || (CUtype == SSMprotocol::CUtype_Transmission)) { // Probe SSM2-protocol: _SSMPdev = new SSMprotocol2(_diagInterface, _language); if (_diagInterface->connect(AbstractDiagInterface::protocol_SSM2_ISO15765)) { result = _SSMPdev->setupCUdata( CUtype ); if ((result != SSMprotocol::result_success) && (result != SSMprotocol::result_noOrInvalidDefsFile) && (result != SSMprotocol::result_noDefs)) _diagInterface->disconnect(); } if (!_diagInterface->isConnected()) { if (_diagInterface->connect(AbstractDiagInterface::protocol_SSM2_ISO14230)) { result = _SSMPdev->setupCUdata( CUtype ); if ((result != SSMprotocol::result_success) && (result != SSMprotocol::result_noOrInvalidDefsFile) && (result != SSMprotocol::result_noDefs)) _diagInterface->disconnect(); } } if (_diagInterface->isConnected()) connect( _SSMPdev, SIGNAL( commError() ), this, SLOT( communicationError() ) ); else { delete _SSMPdev; _SSMPdev = NULL; } } if (_SSMPdev == NULL) { // Probe SSM1-protocol: if (_diagInterface->connect(AbstractDiagInterface::protocol_SSM1)) { _SSMPdev = new SSMprotocol1(_diagInterface, _language); result = _SSMPdev->setupCUdata( CUtype ); if ((result == SSMprotocol::result_success) || (result == SSMprotocol::result_noOrInvalidDefsFile) || (result == SSMprotocol::result_noDefs)) connect( _SSMPdev, SIGNAL( commError() ), this, SLOT( communicationError() ) ); else { delete _SSMPdev; _SSMPdev = NULL; _diagInterface->disconnect(); } } } // Update diagnostic interface status bar: if (_SSMPdev != NULL) { // Display protocol name: _ifstatusbar->setProtocolName( QString::fromStdString( _diagInterface->protocolDescription() ), Qt::darkGreen ); // Display protocol baud rate: unsigned int br = _diagInterface->protocolBaudRate(); QString bstr; if (br <100000) { bstr = QString::number(br) + " baud"; } else if (br < 100000000) { bstr = QString::number(br/1000.0, 'g', 5) + " Kbaud"; } else { bstr = QString::number(br/1000000.0, 'g', 5) + " Mbaud"; } _ifstatusbar->setBaudRate(bstr, Qt::darkGreen); } return result; }