Exemplo n.º 1
0
bool try_parse_message(void)
{
	while (Serial_IsCharReceived()) {
		(*inprog_message)[curmsg_firstempty] = Serial_ReceiveByte();
		//Serial_SendByte((*inprog_message)[curmsg_firstempty]);
		
		/* dumb idea for resync - we only care about one kind of message */
		//*
		curmsg_firstempty++;
		
		if (curmsg_firstempty == 1) {
			if ((*inprog_message)[0] != 0x44 && (*inprog_message)[0] != 0x19
				&& (*inprog_message)[0] != 0x1b) {
				curmsg_firstempty = 0;
			}
		} else if (curmsg_firstempty > 1) {
			char len = (*inprog_message)[1];
			if (curmsg_firstempty >= len || curmsg_firstempty >= 64) {
				char (*t)[64] = usable_message;
				usable_message = inprog_message;
				inprog_message = t;
				//for (int i = 0; i<64; i++) {
				//	(*inprog_message)[i]=0;
				//}
				curmsg_firstempty = 0;
				rfid_usable_to_send = 1;
				//we have a fully parsed message, and we have reset current
				return 1;
			}
		}
		//*/
	}
	return 0;
}
Exemplo n.º 2
0
int Serial_getchar_Blocking(FILE *Stream)
{
	(void)Stream;

	while (!(Serial_IsCharReceived()));
	return Serial_ReceiveByte();
}
Exemplo n.º 3
0
int Serial_getchar_Blocking(FILE *Stream)
{
	USART_t* USART = fdev_get_udata(Stream);

	while (!(Serial_IsCharReceived(USART)));
	return Serial_ReceiveByte(USART);
}
Exemplo n.º 4
0
int Serial_getchar(FILE *Stream)
{
	(void)Stream;

	if (!(Serial_IsCharReceived()))
	  return _FDEV_EOF;

	return Serial_ReceiveByte();
}
Exemplo n.º 5
0
int Serial_getchar(FILE *Stream)
{
	USART_t* USART = fdev_get_udata(Stream);

	if (!(Serial_IsCharReceived(USART)))
	  return _FDEV_EOF;

	return Serial_ReceiveByte(USART);
}
Exemplo n.º 6
0
uint8_t BT::read(void)
{
	if(!present)
		return 1;


	uint16_t bytes = 0;

	dataId = 0;
	dataSize = 0;

	BT_SET_CTS;

	uint16_t timeout;

	for(;;)
	{
		timeout = 0;

		while(!Serial_IsCharReceived())
		{
			wdt_reset();
			_delay_us(10);
			if(++timeout > (bytes > 0 ? 50000 : 5000))
				break;
		}

		if(timeout > 50000)
		{
			debug(STR("TIMED OUT!"));
			debug(STR("\r\n   BYTES: "));
			debug(bytes);
			debug(STR("\r\n      ID: "));
			debug((uint8_t)buf[1]);
			debug(STR("\r\n    SIZE: "));
			debug(dataSize);
			debug(STR("\r\n  DATA[0]: "));
			debug(buf[0]);
			debug(STR("\r\n  DATA[1]: "));
			debug((uint8_t)buf[1]);
			debug(STR("\r\n  DATA[2]: "));
			debug((uint8_t)buf[2]);
			debug(STR("\r\n  DATA[3]: "));
			debug((uint8_t)buf[3]);
			debug(STR("\r\n  DATA[4]: "));
			debug(buf[4]);
			debug(STR("\r\n  DATA[5]: "));
			debug(buf[5]);
		    debug(STR("\r\n"));
			break;
		}
		else if(timeout > 5000 && bytes == 0)
		{
			break;
		}

		buf[bytes] = (char)Serial_ReceiveByte();

		if(!(bytes == 0 && (buf[0] == '\n' || buf[0] == '\r'))) bytes++; // skip leading CR/LF
		if(mode == BT_MODE_CMD)
		{
			if(bytes > 0 && buf[bytes - 1] == '\n') // just get one line at a time
				break;
		}
		else
		{
			if(buf[0] != '$' && bytes > 1 && buf[bytes - 1] == '$')
			{
				buf[0] = '$';
				bytes = 1;
			}
			if(dataSize > 0)
			{
				if(bytes > dataSize + 5) break;
			}
			else
			{
				if(bytes > 5 && buf[0] == '$' && buf[5] == ':')
				{
					dataId = buf[1];
					dataType = buf[2];

					*(&dataSize) = buf[3];
					*(&dataSize + 1) = buf[4];

					data = (buf + 6);

					if(dataSize == 0) break;
				}
				else if(buf[0] != '$' && buf[bytes - 1] == '\n') // just get one line at a time
				{
					break;
				}
			}
		}

		if(bytes >= BT_BUF_SIZE)
			break;
	}

	BT_CLR_CTS;

	buf[bytes] = 0;

	return bytes;
}