//--Private methods-------------------------------------------------------------
bool zoSms::getResponse(ZO_PROTOCOL_PACKET* p)
{
   // uint16_t
    uint16_t tOut;
 //   unsigned short int tOut; //Tag Untag if uint16_t produces issues
	zoSystemTimerTimeOutInit(&tOut);
	while( !(ha.getPacket(p)) )
	{
		if( zoSystemTimerTimeOutExpired(&tOut,ZO_PROTOCOL_COMMAND_RESPONSE_TIMEOUT_MS) )
		{
			CommSuccess = false;
			Warning = ZO_WARNING_RESPONSE_TIMEOUT;
			break;
		}
	}
	
	if( CommSuccess )
	{	
		if( p->lrc != calcLRC(p) )
		{	
			CommSuccess = false;
			Warning = ZO_WARNING_WRONG_LRC;
		}
		
		if( p->commandID == ZO_PROTOCOL_ERROR_ID)
		{
			CommSuccess = false;
			Warning = p->data[0];
		}
	}

	return CommSuccess;
}
コード例 #2
0
bool zoProtocolUartInit(ZO_PROTOCOL_HW_TYPE hw, u08 ownNodeID, u32 baudRate)
{
	bool success = TRUE;
	
	if( hw == ZO_PROTOCOL_HW_HALF_DUPLEX_RS485 )
		zoUartInitRs485(&PORTD,PD2);
	
	//no error checking for valid node ID, this is left to be done in a higher level
	OwnNodeID = ownNodeID;	//store the node ID

	if(!zoUartInit())
		success = FALSE;
	
	if(!zoUartSetBaud(baudRate))
		success = FALSE;

	zoSystemTimerTimeOutInit(&WaitOnNextCharacterTimer);

	return success;
}
コード例 #3
0
bool zoProtocolUartGetPacket(ZO_PROTOCOL_PACKET* packet)
{
	static u08 byteCount;
	bool IsWholePacket = FALSE;
	u08 c;

	if( getReceivalOfPacketStarted() && zoSystemTimerTimeOutExpired(&WaitOnNextCharacterTimer,WaitOnNextCharTimeOutMiliSec) )
	{
		DecoderState = WAIT_ON_HEADER_0;										//reset the decoder
		zoErrorPut(zoProtocolUartError,ZO_PROTOCOL_UART_ERROR_HALF_PACKET);		//indicate error

		//initialize timeout timer and flag for next pass
		zoSystemTimerTimeOutInit(&WaitOnNextCharacterTimer);
		setReceivalOfPacketStarted(FALSE);
	}

	if( !zoUartGetChar(&c) )
		return FALSE;

	zoSystemTimerTimeOutInit(&WaitOnNextCharacterTimer); //start counting timeout until reception of next character

	switch(DecoderState) 
	{
		case WAIT_ON_HEADER_0:
			if (c==ZO_PROTOCOL_HEADER_0)
			{
				DecoderState = WAIT_ON_HEADER_1;
				setReceivalOfPacketStarted(TRUE);
			}
			else
				DecoderState = WAIT_ON_HEADER_0;
			break;

		case WAIT_ON_HEADER_1:
			DecoderState = (c==ZO_PROTOCOL_HEADER_1)?WAIT_ON_ADDRESSED_NODE_ID:WAIT_ON_HEADER_0;
			break;

		case WAIT_ON_ADDRESSED_NODE_ID:
			if( ( (c & zoProtocolUartLAM) == (OwnNodeID & zoProtocolUartLAM ) ) ||
				( c == ZO_PROTOCOL_BROADCAST_ID ) )
			{
				DecoderState = WAIT_ON_OWN_NODE_ID;
				packet->AddressedNodeID = c;
			}
			else
			{
				DecoderState = WAIT_ON_HEADER_0;
				setReceivalOfPacketStarted(FALSE);
			}
			break;

		case WAIT_ON_OWN_NODE_ID:
			packet->OwnNodeID = c;
			DecoderState = WAIT_ON_COMMAND_ID;
			break;

		case WAIT_ON_COMMAND_ID:
			packet->commandID = c;
			DecoderState = WAIT_ON_BYTECOUNT;
			break;

		case WAIT_ON_BYTECOUNT:
			packet->byteCount = c;
			byteCount = packet->byteCount;	//store for internal use
			if(byteCount > 0)
				DecoderState = WAIT_ON_DATA;
			else
				DecoderState = WAIT_ON_LRC;
			break;

		case WAIT_ON_DATA:
			packet->data[packet->byteCount - byteCount--] = c;
			if(byteCount == 0)
				DecoderState =	WAIT_ON_LRC;
			break;

		case WAIT_ON_LRC:
			packet->lrc = c;
			DecoderState = WAIT_ON_HEADER_0; 
			IsWholePacket = TRUE;
			setReceivalOfPacketStarted(FALSE);
			break;
	}

	return IsWholePacket;
}