Exemplo n.º 1
0
/*
 *  DoSCSICommand()
 *  Encapsulate super::SendCommand() to handle unexpected service and
 *  task errors as well as hand off to SCSI SENSE interpreter.
 */
SCSITaskStatus
IOSCSITape::DoSCSICommand(
	SCSITaskIdentifier	request,
	UInt32				timeoutDuration)
{
	SCSITaskStatus		taskStatus		= kSCSITaskStatus_DeliveryFailure;
	SCSIServiceResponse	serviceResponse	= kSCSIServiceResponse_SERVICE_DELIVERY_OR_TARGET_FAILURE;
	
	require((request != 0), ErrorExit);
	
	serviceResponse = SendCommand(request, timeoutDuration);
	sense_flags = 0;
	
	if (serviceResponse != kSCSIServiceResponse_TASK_COMPLETE)
	{
		STATUS_LOG("unknown service response: 0x%x", serviceResponse);
		goto ErrorExit;
	}
	else
	{
		taskStatus = GetTaskStatus(request);
		
		if (taskStatus == kSCSITaskStatus_CHECK_CONDITION)
		{
			/* Get and interpret SCSI SENSE information */
			GetSense(request);
		}
		else if (taskStatus != kSCSITaskStatus_GOOD)
		{
			STATUS_LOG("unknown task status: 0x%x", taskStatus);
		}
		else if (taskStatus == kSCSITaskStatus_GOOD)
		{
			/* setup flags for device file closing */
			if (flags & ST_WRITTEN_TOGGLE)
				flags |= ST_WRITTEN;
			else
				flags &= ~ST_WRITTEN;
		}
	}
	
	/* clear the write toggle bit in case the next command is not a
	 * write */
	flags &= ~ST_WRITTEN_TOGGLE;
	
ErrorExit:
	
	return taskStatus;
}
Exemplo n.º 2
0
void CAISenseRecorderAbstract::HandleSenses(uint32 nCycle)
{
	AISENSE_RECORD_MAP::iterator it;
	for(it = m_mapSenseRecords.begin(); it != m_mapSenseRecords.end(); ++it)
	{
		AISenseRecord* pSenseRecord = it->second;
		AIBM_Stimulus* pAIBM_Stimulus = pSenseRecord->pAIBM_Last_Stimulus;

		// If pAIBM_Stimulus is NULL, this sense has never been stimulated.
		if(pAIBM_Stimulus == LTNULL)
		{
			continue;
		}

		// Check for senses that were not updated this cycle.
		// Ignore senses that were not updated this cycle because
		// of a delayed stimulus.
		if((pSenseRecord->nCycle != nCycle) && (pSenseRecord->fReactionDelayTimer == 0.f))
		{
			// Decrease the simulation, if there is any.
			if(pSenseRecord->fCurStimulation > 0.f)
			{
				LTBOOL bFalseStimulation = DecreaseStimulation(pSenseRecord, 1.0f);

				// If not a false stimulation, do not let the state handle the sense.
				if(!bFalseStimulation)
				{
					continue;
				}

				// If we have hit the false stimulation limit, treat it as a real stimulation.

				if( pSenseRecord->cFalseStimulation >= pAIBM_Stimulus->nFalseStimulationLimit )
				{
					pSenseRecord->cFalseStimulation = 0;
					pSenseRecord->fCurStimulation	= pAIBM_Stimulus->rngStimulationThreshhold.GetMax();
					pSenseRecord->fMaxStimulation	= pAIBM_Stimulus->rngStimulationThreshhold.GetMax();
		
					AITRACE(AIShowSenses, (m_pSensing->GetSensingObject(), "Hit FalseStimulution Limit %d of %s\n", pAIBM_Stimulus->nFalseStimulationLimit, SenseToString(pSenseRecord->eSenseType)) );
				}

				// Treat other false stimulations as other senses,
				// if an optional FalseStimulusSense was specified.

				else if( pAIBM_Stimulus->eFalseStimulusSense != kSense_InvalidType )
				{
					AISenseRecord* pFalseStimulationSense = GetSense( pAIBM_Stimulus->eFalseStimulusSense );
					if( pFalseStimulationSense )
					{
						pFalseStimulationSense->pAIBM_Last_Stimulus = pAIBM_Stimulus;
						pFalseStimulationSense->hLastStimulusSource = pSenseRecord->hLastStimulusSource;
						pFalseStimulationSense->vLastStimulusPos = pSenseRecord->vLastStimulusPos;
						pFalseStimulationSense->eLastStimulusID = pSenseRecord->eLastStimulusID;
						pFalseStimulationSense->fCurStimulation = pAIBM_Stimulus->rngStimulationThreshhold.GetMax();
						pFalseStimulationSense->fMaxStimulation = pAIBM_Stimulus->rngStimulationThreshhold.GetMax();
						pFalseStimulationSense->fLastStimulationTime = pSenseRecord->fLastStimulationTime;
						pFalseStimulationSense->nLastStimulusAlarmLevel = 1;
						pFalseStimulationSense->nCycle = nCycle;
					}
				}
			}
		}

		// Invalidate hiding spots if AI can already see player.

		if( ( pSenseRecord->eSenseType == kSense_SeeEnemy ) && 
			IsPlayer( pSenseRecord->hLastStimulusSource ) &&
			IsAI( m_pSensing->GetSensingObject() ) &&
			( pSenseRecord->fCurStimulation >= 0.5f ) )
		{
			CPlayerObj* pPlayer = (CPlayerObj*)g_pLTServer->HandleToObject( pSenseRecord->hLastStimulusSource );
			CAI* pAI = (CAI*)g_pLTServer->HandleToObject( m_pSensing->GetSensingObject() );
			if( pPlayer && pAI )
			{
				pPlayer->SetVisibleToEnemyAI( pAI, true ); 
			}
		}

		// Check if we're fully stimulated.
		if(pSenseRecord->fCurStimulation >= pAIBM_Stimulus->rngStimulationThreshhold.GetMax())
		{
			// Wait for, or increment, ReactionDelay.
			if(pSenseRecord->fReactionDelayTimer >= pSenseRecord->fReactionDelayTime)
			{
				m_pSensing->HandleSenseTrigger( pSenseRecord );
				pSenseRecord->fReactionDelayTimer = 0.f;
				pSenseRecord->fReactionDelayTime = 0.f;
			}
			else pSenseRecord->fReactionDelayTimer += m_pSensing->GetSenseUpdateRate();
		}
	}
}