/* Parse incoming frame and find the handler to process the request.  */
static void usart_frame_parse(uint8_t *buffer, uint8_t size)
/* Parse incoming frame and find the handler to process the request.  */
static void usart_frame_parse(uint8_t *buffer, uint8_t size)
{
	if (size == 0) {
		return;
	}
	for (uint32_t i = 0; i < HANDLER_SIZE; i++) {
		if (size >= usart_handler[i].min_size &&
				!memcmp(usart_handler[i].header, buffer, usart_handler[i].header_size)) {
			if (usart_handler[i].handler) {
				if ((usart_handler[i].handler(buffer, size)) == 0) {
					return;
				} else {
					break;
				}
			}
		}
	}
	if (buffer[0] == 0xFF) {
		usart_stream_reset();
	} else if (buffer[0] != 0x12 && buffer[0] != 0xA5) {
		usart_stream_write(0xEA);
		usart_stream_reset();
	}
}