Пример #1
0
_TC_INLINE_STATIC void grayEventHandlerDeferred(uint32 mode)
{
	HRESULT		hResult = NO_ERROR;
	uint32		i;
	uint32		ptr;
	uint32		enc;
	BOOL		bFound = FALSE;
	GRAY_EVENT	*event;

	ptr = grayDeferredEvent.ptr;

	for (i = 0; i < GRAY_DEFERRED_ITEMS; i++)
	{
		if (grayDeferredEvent.allocated[ptr] == FALSE)
		{
			grayDeferredEvent.allocated[ptr] = TRUE;
			event = &grayDeferredEvent.events[ptr];
			bFound = TRUE;
		}

		ptr++;
		if (ptr > GRAY_DEFERRED_ITEMS - 1)
		{
			ptr = 0;
		}
		if (bFound == TRUE)
		{
			grayDeferredEvent.ptr = ptr;
			break;
		}
	}

	if (bFound == FALSE)
	{
		grayEventGetCounters(); // clear interrupt
		hResult = E_GRAY_EVENT_FULL;
		sysLogErrorISR(hResult, __LINE__, moduleName);
		return;
	}

	event->mode = mode;
	for (enc = 0; enc < GRAY_ENC_ITEMS; enc++)
	{
		event->change[enc] = 0;
	}
	event->timeDiff = 0;
	grayEventGetChange(event);

	// gray deferred event handler thread message queue
	hResult = TCMsgQueueSend(grayDeferredQueueID, (void *) &event, TC_NO_WAIT);
	if (hResult != NO_ERROR)
	{
		sysLogErrorISR(hResult, __LINE__, moduleName);
		return;
	}
}
Пример #2
0
HRESULT cliCBCallArea(PB * incomingPacket, PB_PACKETTYPE packetType, RCODE_1394 *errorResponse)
// Called when a CLI remote call arrives at the CLI_CALL_AREA for the new CLI interface
// Only block writes are allowed to this register
{
	HRESULT			hResult = NO_ERROR;
	uint32			payloadSize = 0;
	uint32*			pPayload = NULL;
	char			cliCommandStr[kTempBufferSize] = {0};

	*errorResponse = RSP_TYPE_ERROR;

	hResult = pbGetPayloadSize(incomingPacket,&payloadSize);
	if (hResult != NO_ERROR) return hResult;
	hResult = pbGetPayload(incomingPacket, (void **) &pPayload);
	if (hResult != NO_ERROR) return hResult;

	SYS_DEBUG(SYSDEBUG_TRACE_CLICB, "CLI command call: ");
	SYS_DEBUG(SYSDEBUG_TRACE_CLICB, "packetType: %i, ", packetType);
	SYS_DEBUG(SYSDEBUG_TRACE_CLICB, "payloadSize: %i", payloadSize);
	SYS_DEBUG(SYSDEBUG_TRACE_CLICB, "\n\r");

	if ((packetType == PB_TYPE_WRITE_REQUEST) && payloadSize > 4)
	{
		// Get the command and execute it
		if (payloadSize <= kTempBufferSize)
		{
			memcpy(cliCommandStr, pPayload, payloadSize);
			formatSwapStrBytes(cliCommandStr, payloadSize);

			SYS_DEBUG(SYSDEBUG_TRACE_CLICB, "CLI command call: ");
			SYS_DEBUG(SYSDEBUG_TRACE_CLICB, cliCommandStr);
			SYS_DEBUG(SYSDEBUG_TRACE_CLICB, "\n\r");

#ifdef _CLICB_DEFERRED_TASK	
			if (cliCBDeferred == TRUE)
			{
				CLICB_CMD*	cmd = NULL;

				hResult = lalReplyWriteResponse(incomingPacket, RSP_COMPLETE, TRUE);
				*errorResponse = RSP_COMPLETE;

				SYS_DEBUG(SYSDEBUG_TRACE_CLICB, "CLI command call: deferring to cli CB task \n\r");
				
				hResult = cliCBAllocateDeferredCmd(&cmd, cliCommandStr);
				if (hResult != NO_ERROR) return hResult;

				// thread cli CB deferred task message queue
				hResult = TCMsgQueueSend(cliCBDeferredQueueID, (void *) &cmd, TC_NO_WAIT);
				if (hResult != NO_ERROR)
				{
					sysLogError(hResult, __LINE__, moduleName);
				}
			}
			else
#endif //_CLICB_DEFERRED_TASK
			{
				cliCBResult = cliCBHandleCommand(cliCommandStr);
				if (cliCBResult == NO_ERROR)
				{
					hResult = lalReplyWriteResponse(incomingPacket, RSP_COMPLETE, TRUE);
					*errorResponse = RSP_COMPLETE;
				}
				else
				{
					*errorResponse = RSP_DATA_ERROR;
				}
			}
		}
		else
		{
			*errorResponse = RSP_DATA_ERROR;
		}
	}
	else 
	{
		if (payloadSize < 4) {
			// <4 = DATA ERROR, =4 = TYPE ERROR, >4 <max = ok, >max = DATA ERROR
			*errorResponse = RSP_DATA_ERROR;
		}
	}

	return hResult;
}