Beispiel #1
0
void Transfer::Dispatch(Message* m)
{
	switch(m->type())
	{
	case TRANSFER_INNER_COMMAND:
		{
			MsgCommand msg;
			memcpy(&msg, m->data(), sizeof(msg));
			
			ExecCommand(msg.tranId, msg.step, msg.message);

			if(msg.message)
			{
				delete msg.message;
			}
		}
		break;
	case TRANSFER_INNER_RESULT:
		{
			// 提取事务信息
			MsgResult msg;
			memcpy(&msg, m->data(), sizeof(msg));

			// 执行事务步骤
			ExecResult(msg.tranId, msg.step, msg.compId, msg.message);

			// 释放内部消息
			if(msg.message)
			{
				delete msg.message;
			}
		}
		break;
	case TRANSFER_INNER_REQUEST:
		{
			MsgRequest msg;
			memcpy(&msg, m->data(), sizeof(msg));

			ExecRequest(msg.tranId, msg.step, msg.compId, msg.message);

			if(msg.message)
			{
				delete msg.message;
			}
		}
		break;
	default:
		{
			LOG(LEVEL_WARNING, "Don't Support This Command, Type = %d", m->type());
		}
		break;
	}

	// 释放消息
	delete m;

}
/* Method is called for every feedback that is received by feedback_Struct Pin;
 *   Implements the general structure and calls necessary functions for processing */
tResult StateControlManagementSlim::ProcessData(TFeedbackStruct::Data feedback)
{
	/* HANDLING OF SPONTANEOUS INTERRUPTIONS BY JURY -> action_STOP signal sent! has to be treated in every mode */
	if(feedback.ui32_status == FB_JURY_COMMAND_RECEIVED_STOP){
		LOG_WARNING(cString::Format("SCM: Interrupted via action_STOP signal from jury! System will be set to startup mode."));
		#ifdef WRITE_DEBUG_OUTPUT_TO_FILE
		scm_logfile << std::endl << "### --- " << std::endl << "SCM: Interrupted via action_STOP signal from jury! System will be set to startup mode." << std::endl;
		#endif
		/* set SCM to startup maneuver, as it can be started again from this position via action_START from jury */
		JumpToManeuver(0);
		ChangeCurrentActivityLvlMode(ACTIVE);
		if(m_bDebugModeEnabled) LOG_WARNING(cString::Format("SCM: Set to current ScmManeuverID %d, step %d, actLvl %d",i16CurrentScmManeuverID,i16CurrentScmStepID,CheckCurrentActivityLvlMode()));
		#ifdef WRITE_DEBUG_OUTPUT_TO_FILE
		scm_logfile << "SCM: Set to current ScmManeuverID: " << i16CurrentScmManeuverID << ", step: "<< i16CurrentScmStepID << ", actLvl: ACTIVE"<< std::endl <<"### --- " << std::endl;
		#endif
		ExecAction();
		/* all filters will be disabled in this way, except of JCom, which sends alive-signal;
		 *  afterwards, system is reset to beginning of current sector, is in CarState startup mode and
		 *  waiting for new Start-Signal from jury */
		RETURN_NOERROR;
	}

	/* regular, normal behaviour without interruptions by action_STOP */

	// check if current activity level is passive, so feedback is requested
	if(CheckCurrentActivityLvlMode() == ACTIVE){
		LOG_WARNING(cString::Format("SCM: System is in ACTIVE mode, but input registered: ID %d, status %d. Input will not be processed.",feedback.ui32_filterID,feedback.ui32_status));
	}else if(CheckCurrentActivityLvlMode() == PASSIVE){
		if(m_bDebugModeEnabled) LOG_WARNING(cString::Format("SCM: In PASSIVE mode, Input registered: ID %d, status %d. Input will be checked for relevance.",feedback.ui32_filterID,feedback.ui32_status));

		// check if input status is relevant to current SCM-State, return command that should be executed
		tUInt32 scmStep_command = CheckRequestRelevance(feedback);
		// check if command was relevant and successfully decoded
		if (scmStep_command == 0){
			if(m_bDebugModeEnabled) LOG_WARNING(cString::Format("SCM: Feedback status was not in list, thus will be ignored!"));
			#ifdef WRITE_DEBUG_OUTPUT_TO_FILE
			scm_logfile << "SCM: Feedback status was not in list, thus will be ignored!" << std::endl;
			#endif
		}else{
			// corresponding command will be executed
			if(m_bDebugModeEnabled) LOG_WARNING(cString::Format("SCM: Feedback relevant, status will be processed."));
			#ifdef WRITE_DEBUG_OUTPUT_TO_FILE
			scm_logfile << "SCM: Feedback relevant, status will be processed." << std::endl << "---" << std::endl;
			#endif
			tResult tmpReturn = ExecRequest(scmStep_command);
			// check if ExecRequest was successful
			if(tmpReturn < 0){
				#ifdef WRITE_DEBUG_OUTPUT_TO_FILE
				scm_logfile << std::endl << "### --- " << std::endl << "SCM ERROR: ERROR occurred in ExecRequest!" << std::endl;
				#endif
				RETURN_AND_LOG_ERROR_STR(ERR_INVALID_ADDRESS,cString::Format("SCM: ERROR occurred in ExecRequest!"));
			}else{
				/* Change current activity level mode to ACTIVE, as passive command has been successfully executed*/
				ChangeCurrentActivityLvlMode(ACTIVE);
				ExecAction();
			}
		}

	}else{ // NOT_INITIALIZED or error occurred

		RETURN_AND_LOG_ERROR_STR(ERR_INVALID_STATE, cString::Format("SCM: ERROR occurred!"));
	}

	RETURN_NOERROR;
}