找出来下面代码的问题，进行改正，然后给出改正后的位置代码出来，代码如下：#include "main.h"
#include "crc.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

#include "string.h"
#include "stdio.h"
#include "ctype.h"

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */



#define BUFFER_SIZE     1024
#define MAX_DATA_LEN    512



// ??????
#define HEADER_H        0xAA
#define HEADER_L        0x55
#define FOOTER_H        0x55
#define FOOTER_L        0xAA


#define CMD_LENGTH      1
#define FLAG_LENGTH     1
#define ADDR_LENGTH     2
#define DATALEN_LENGTH  2           
#define CHECKSUM_LENGTH 2      
#define HEADER_LENGTH   2
#define FOOTER_LENGTH   2
#define PACKET_LENGTH_FIELD_LEN 2 

#define MIN_PAYLOAD_LEN (CMD_LENGTH + FLAG_LENGTH + ADDR_LENGTH + DATALEN_LENGTH)



//Receive and  Send
#define CMD_SEND_DATA     0x02
#define CMD_RECEIVE_DATA  0x03



typedef struct {
    uint8_t   cmd;           // ??
    uint8_t   flag;          // ??
    uint16_t  addr;          // ??
    uint16_t  data_len;      // ???????
    uint8_t   data[MAX_DATA_LEN]; // ????
} ProtocolData;




typedef enum {
    STATE_WAIT_HEADER_1,        // ?????1
    STATE_WAIT_HEADER_2,        // ?????2
    STATE_READ_PACKET_LEN_1,    // ???????1
    STATE_READ_PACKET_LEN_2,    // ???????2
    STATE_READ_PAYLOAD,         // ??????(CMD, FLAG, ADDR, DATALEN, DATA)
    STATE_READ_CHECKSUM_1,      // ??CRC????1
    STATE_READ_CHECKSUM_2,      // ??CRC????2
    STATE_WAIT_FOOTER_1,        // ?????1
    STATE_WAIT_FOOTER_2         // ?????2
} ParserState;




typedef struct {
	  ParserState state;                               //?????
    uint16_t    payload_index;                       //??????payload???
    uint16_t    expected_payload_length;             //???payload???
    uint8_t     raw_payload_data[BUFFER_SIZE];       //??payload?? (CMD, FLAG, ADDR, DATALEN, DATA)
    uint16_t    checksum_received;                   //??????
    ProtocolData pkg_data;                           //????????
} ProtocolParser;




typedef enum {
    MODE_UPPER_TO_LOWER,
    MODE_LOWER_TO_UPPER,     
		MODE_BOTH_CONVERT,
} CaseConvertMode;


CaseConvertMode current_mode = MODE_UPPER_TO_LOWER; 



/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */


uint8_t rx_buffer1[BUFFER_SIZE];
uint8_t tx_buffer1[BUFFER_SIZE];
uint8_t rx_buffer2[BUFFER_SIZE];
uint8_t tx_buffer2[BUFFER_SIZE];
ProtocolParser parser;


//Data send  and keep Receive
uint8_t simulated_memory[512];  
uint16_t simulated_data_len = 0;


/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */


void  ProcessReceivedPacket1(ProtocolData *pkg); 
void  ProcessReceivedPacket2(ProtocolData *pkg);
void  SendResponse1(uint8_t cmd, uint16_t addr, uint8_t *data, uint16_t data_len);
void  SendResponse2(uint8_t cmd, uint16_t addr, uint8_t *data, uint16_t data_len);
uint16_t CalculateChecksum(const uint8_t *data, size_t length);                             
void  ProtocolParser_Init(ProtocolParser *parser);                                        
void  HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t size);
void  HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
void  Key_Toggle_Mode(void);




int __io_putchar(int ch)
{
	HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 10);
	return ch;
}
 




void ProtocolParser_Init(ProtocolParser *parser)
{
    parser->state = STATE_WAIT_HEADER_1;                          
    parser->payload_index = 0;                                    
	  parser->expected_payload_length = 0;                          
    parser->checksum_received = 0; 
    memset(&parser->pkg_data, 0, sizeof(ProtocolData));           
    memset(parser->raw_payload_data, 0, sizeof(parser->raw_payload_data));  
}




//CRC???????
uint16_t CalculateChecksum(const uint8_t *data, size_t length)
{
    uint16_t checksum = 0;
    for(size_t i = 0; i < length; i++) 
    {
        checksum += data[i];
    }
    return checksum;
}




void Key_Toggle_Mode(void)
{
    static uint8_t mode_counter = 0;
    mode_counter++;
    if (mode_counter > 3)
    {
        mode_counter = 1;
    }

    switch (mode_counter)
    {
        case 1:
            current_mode = MODE_UPPER_TO_LOWER;
            HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);   
            HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); 
            break;
        case 2:
            current_mode = MODE_LOWER_TO_UPPER;
            HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);  
            HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET); 
            break;
        case 3:
            current_mode = MODE_BOTH_CONVERT;
            HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);   
            HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);  
            break;				
    }
}










void ProcessReceivedPacket1(ProtocolData *pkg)
{
    
	 if((pkg == NULL) || (pkg->data_len > MAX_DATA_LEN))
	 {
		   return;
	 }
				
	switch(pkg->cmd)       
  {		
        case 0x01: 
					
							for(uint16_t i=0; i < pkg->data_len; i++)                    
							{
										switch(current_mode)
										{
											case MODE_UPPER_TO_LOWER:
														if (pkg->data[i] >= 'A' && pkg->data[i] <= 'Z')
														{
															pkg->data[i] = pkg->data[i] + 32;
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
														}
														else
														{
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
														}
														break;

											case MODE_LOWER_TO_UPPER:
														if (pkg->data[i] >= 'a' && pkg->data[i] <= 'z')
														{
															pkg->data[i] = pkg->data[i] - 32;
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);
														}
														else
														{
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
														}
														break;

											case MODE_BOTH_CONVERT:
														if (pkg->data[i] >= 'A' && pkg->data[i] <= 'Z')
														{
															pkg->data[i] = pkg->data[i] + 32;
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
														}
														else if (pkg->data[i] >= 'a' && pkg->data[i] <= 'z')
														{
															pkg->data[i] = pkg->data[i] - 32;
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
														}
														break;					  
											
									}					  
							}
							SendResponse1(0x83, pkg->addr, pkg->data, pkg->data_len);
							break;

								
        case CMD_SEND_DATA://0x02
											
							for(uint16_t i=0; i < pkg->data_len; i++)                   
							{
											switch(current_mode)
											{
												case MODE_UPPER_TO_LOWER:
															if (pkg->data[i] >= 'A' && pkg->data[i] <= 'Z')
															{
																pkg->data[i] = pkg->data[i] + 32;
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															}
															else
															{
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
															}
															break;

												case MODE_LOWER_TO_UPPER:
															if (pkg->data[i] >= 'a' && pkg->data[i] <= 'z')
															{
																pkg->data[i] = pkg->data[i] - 32;
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);
															}
															else
															{
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
															}
															break;

												case MODE_BOTH_CONVERT:
															if (pkg->data[i] >= 'A' && pkg->data[i] <= 'Z')
															{
																pkg->data[i] = pkg->data[i] + 32;
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															}
															else if (pkg->data[i] >= 'a' && pkg->data[i] <= 'z')
															{
																pkg->data[i] = pkg->data[i] - 32;
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
														}
														break;					  
										
									 }					  
							}		
				
								
							if (pkg->data_len <= sizeof(simulated_memory)) 
							{
									memcpy(simulated_memory, pkg->data, pkg->data_len);
									simulated_data_len = pkg->data_len;
									SendResponse1(0x82, pkg->addr, (uint8_t*)"SEND_OK", 7);  
								
							} else {
									
									SendResponse1(0xFE, pkg->addr, (uint8_t*)"SEND_TOO_LONG", 13);  
							}
							break;

						
        case CMD_RECEIVE_DATA://0x03
            // send before keep data
            if (simulated_data_len > 0) {
                SendResponse1(0x83, pkg->addr, simulated_memory, simulated_data_len);
            } else {
                SendResponse1(0xFD, pkg->addr, (uint8_t*)"NO_DATA", 7);
            }
            break;


			
        default:
            //printf("CMD Unknown: 0x%02X\r\n", pkg->cmd);
            SendResponse1(0xFF, pkg->addr, (uint8_t*)"UNKNOWN_CMD", 11);
            break;
    }
}




void ProcessReceivedPacket2(ProtocolData *pkg)
{
    
	 if((pkg == NULL) || (pkg->data_len > MAX_DATA_LEN))
	 {
		   return;
	 }
				
	switch(pkg->cmd)       //??????????????????????
  {		
        case 0x01: 
					
							for(uint16_t i=0; i < pkg->data_len; i++)                    //?????????????
							{
										switch(current_mode)
										{
											case MODE_UPPER_TO_LOWER:
														if (pkg->data[i] >= 'A' && pkg->data[i] <= 'Z')
														{
															pkg->data[i] = pkg->data[i] + 32;
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
														}
														else
														{
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
														}
														break;

											case MODE_LOWER_TO_UPPER:
														if (pkg->data[i] >= 'a' && pkg->data[i] <= 'z')
														{
															pkg->data[i] = pkg->data[i] - 32;
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);
														}
														else
														{
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
														}
														break;

											case MODE_BOTH_CONVERT:
														if (pkg->data[i] >= 'A' && pkg->data[i] <= 'Z')
														{
															pkg->data[i] = pkg->data[i] + 32;
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
														}
														else if (pkg->data[i] >= 'a' && pkg->data[i] <= 'z')
														{
															pkg->data[i] = pkg->data[i] - 32;
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
														}
														break;					  
											
									}					  
							}
							SendResponse2(0x83, pkg->addr, pkg->data, pkg->data_len);
							break;

								
        case CMD_SEND_DATA://0x02
											
							for(uint16_t i=0; i < pkg->data_len; i++)                    //?????????????
							{
											switch(current_mode)
											{
												case MODE_UPPER_TO_LOWER:
															if (pkg->data[i] >= 'A' && pkg->data[i] <= 'Z')
															{
																pkg->data[i] = pkg->data[i] + 32;
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															}
															else
															{
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
															}
															break;

												case MODE_LOWER_TO_UPPER:
															if (pkg->data[i] >= 'a' && pkg->data[i] <= 'z')
															{
																pkg->data[i] = pkg->data[i] - 32;
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);
															}
															else
															{
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
															}
															break;

												case MODE_BOTH_CONVERT:
															if (pkg->data[i] >= 'A' && pkg->data[i] <= 'Z')
															{
																pkg->data[i] = pkg->data[i] + 32;
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
															}
															else if (pkg->data[i] >= 'a' && pkg->data[i] <= 'z')
															{
																pkg->data[i] = pkg->data[i] - 32;
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
																HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
														}
														break;					  
										
									 }					  
							}		
				
								
							if (pkg->data_len <= sizeof(simulated_memory)) 
							{
									memcpy(simulated_memory, pkg->data, pkg->data_len);
									simulated_data_len = pkg->data_len;
									SendResponse2(0x82, pkg->addr, (uint8_t*)"SEND_OK", 7);  
								
							} else {
									
									SendResponse2(0xFE, pkg->addr, (uint8_t*)"SEND_TOO_LONG", 13);  
							}
							break;

						
        case CMD_RECEIVE_DATA://0x03
            // send before keep data
            if (simulated_data_len > 0) {
                SendResponse2(0x83, pkg->addr, simulated_memory, simulated_data_len);
            } else {
                SendResponse2(0xFD, pkg->addr, (uint8_t*)"NO_DATA", 7);
            }
            break;


			
        default:
            //printf("CMD Unknown: 0x%02X\r\n", pkg->cmd);
            SendResponse2(0xFF, pkg->addr, (uint8_t*)"UNKNOWN_CMD", 11);
            break;
    }
}




void SendResponse1(uint8_t cmd, uint16_t addr, uint8_t *data, uint16_t data_len)
{
	
					 // ???????????????
					 if (data_len > MAX_DATA_LEN) {
						 return;
					 }


					// ??payload??(?? + ?? + ?? + ?????? + ????)
					uint16_t payload_len = CMD_LENGTH + FLAG_LENGTH + ADDR_LENGTH + DATALEN_LENGTH + data_len;   
					// ?????????????		 
					if ((HEADER_LENGTH + PACKET_LENGTH_FIELD_LEN + payload_len + CHECKSUM_LENGTH + FOOTER_LENGTH) > BUFFER_SIZE)
						{
						 Error_Handler(); // Critical error, packet too big for tx_buffer
						 return;
					 }


					 uint16_t index = 0;    //???????index,???????????????????

						 
					// 1.??,??????????
					tx_buffer1[index++] = HEADER_H;
					tx_buffer1[index++] = HEADER_L;




					//2. ??????(2 ??)
					tx_buffer1[index++] = (payload_len >> 8) & 0xFF;
					tx_buffer1[index++] = payload_len & 0xFF;


					// 3.?? payload ????,???? CRC ??
					uint16_t payload_start_index = index;


					//4.??payload??
					//CMD
					tx_buffer1[index++] = cmd;
					// FLAG
					tx_buffer1[index++] = 0x01; // Assuming a default flag for responses
					// ADDR
					tx_buffer1[index++] = (addr >> 8) & 0xFF;
					tx_buffer1[index++] = addr & 0xFF;
					// DATALEN (????(????????????))
					tx_buffer1[index++] = (data_len >> 8) & 0xFF;
					tx_buffer1[index++] = data_len & 0xFF;
					// DATA
					if (data_len > 0 && data != NULL)     //???????????
					{
						memcpy(&tx_buffer1[index], data, data_len);
						index += data_len;      /// ??????????????????
					}


					// 5.??????????????????
					if ((index - payload_start_index) != payload_len) {
						//printf("SendResponse Error: Payload construction mismatch. Expected %u, Got %u\r\n", payload_len, (index - payload_start_index));
						Error_Handler();
						return;
					}



					// 6.?????
					uint16_t checksum = CalculateChecksum(&tx_buffer1[payload_start_index], payload_len);
					tx_buffer1[index++] = (checksum >> 8) & 0xFF; // ????
					tx_buffer1[index++] = checksum & 0xFF;     // ????

					//7. ??  ??????????????
					tx_buffer1[index++] = FOOTER_H;
					tx_buffer1[index++] = FOOTER_L;


					// ????????????“index?
					if (index > BUFFER_SIZE) 
						{
						//printf("SendResponse Error: Constructed packet size %d > BUFFER_SIZE %d\r\n", index, BUFFER_SIZE);
						Error_Handler(); // Critical error
						return;
					}

						

					// 8.??????
					if (HAL_UART_Transmit(&huart1, tx_buffer1, index, 10) != HAL_OK)
					{
						Error_Handler();
					}

}







void SendResponse2(uint8_t cmd, uint16_t addr, uint8_t *data, uint16_t data_len)
{
	
					 // ???????????????
					 if (data_len > MAX_DATA_LEN) {
						 return;
					 }


					// ??payload??(?? + ?? + ?? + ?????? + ????)
					uint16_t payload_len = CMD_LENGTH + FLAG_LENGTH + ADDR_LENGTH + DATALEN_LENGTH + data_len;   
					// ?????????????		 
					if ((HEADER_LENGTH + PACKET_LENGTH_FIELD_LEN + payload_len + CHECKSUM_LENGTH + FOOTER_LENGTH) > BUFFER_SIZE)
						{
						 Error_Handler(); // Critical error, packet too big for tx_buffer
						 return;
					 }


					 uint16_t index = 0;    //???????index,???????????????????

						 
					// 1.??,??????????
					tx_buffer2[index++] = HEADER_H;
					tx_buffer2[index++] = HEADER_L;




					//2. ??????(2 ??)
					tx_buffer2[index++] = (payload_len >> 8) & 0xFF;
					tx_buffer2[index++] = payload_len & 0xFF;


					// 3.?? payload ????,???? CRC ??
					uint16_t payload_start_index = index;


					//4.??payload??
					//CMD
					tx_buffer2[index++] = cmd;
					// FLAG
					tx_buffer2[index++] = 0x01; // Assuming a default flag for responses
					// ADDR
					tx_buffer2[index++] = (addr >> 8) & 0xFF;
					tx_buffer2[index++] = addr & 0xFF;
					// DATALEN (????(????????????))
					tx_buffer2[index++] = (data_len >> 8) & 0xFF;
					tx_buffer2[index++] = data_len & 0xFF;
					// DATA
					if (data_len > 0 && data != NULL)     //???????????
					{
						memcpy(&tx_buffer2[index], data, data_len);
						index += data_len;      /// ??????????????????
					}


					// 5.??????????????????
					if ((index - payload_start_index) != payload_len) {
						//printf("SendResponse Error: Payload construction mismatch. Expected %u, Got %u\r\n", payload_len, (index - payload_start_index));
						Error_Handler();
						return;
					}



					// 6.?????
					uint16_t checksum = CalculateChecksum(&tx_buffer2[payload_start_index], payload_len);
					tx_buffer2[index++] = (checksum >> 8) & 0xFF; // ????
					tx_buffer2[index++] = checksum & 0xFF;     // ????

					//7. ??  ??????????????
					tx_buffer2[index++] = FOOTER_H;
					tx_buffer2[index++] = FOOTER_L;


					// ????????????“index?
					if (index > BUFFER_SIZE) 
						{
						//printf("SendResponse Error: Constructed packet size %d > BUFFER_SIZE %d\r\n", index, BUFFER_SIZE);
						Error_Handler(); // Critical error
						return;
					}

						

					// 8.??????
					if (HAL_UART_Transmit(&huart2, tx_buffer2, index, 10) != HAL_OK)
					{
						Error_Handler();
					}

}







void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{	
		 if (GPIO_Pin == GPIO_PIN_15) // KEY2 -> PB15
		 {
							static uint32_t last_debounce_time = 0;
							uint32_t current_time = HAL_GetTick();
							if (current_time - last_debounce_time > 200) 
							{
									last_debounce_time = current_time;
									Key_Toggle_Mode();
							}																
			}

}




// UART ??????????
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t size)
{
    if (huart == &huart1)
    {    			
			 //HAL_UART_Transmit(&huart1, rx_buffer, size, 100);

        for (uint16_t i = 0; i < size; i++)
        {
            uint8_t byte=rx_buffer1[i];     //????????????
            switch(parser.state)          //??????????,??????????
            {
						// 1. ???????????(0xAA)
						case STATE_WAIT_HEADER_1:    
								if (byte == HEADER_H)
								{
										parser.state = STATE_WAIT_HEADER_2;    //??????????????
								}
								break;
						
						// ???????????(0x55)        
						case STATE_WAIT_HEADER_2:
								if (byte == HEADER_L)
								{
										parser.state = STATE_READ_PACKET_LEN_1;    //?????????????
								}else{
										ProtocolParser_Init(&parser);     //???????
								}
								break;
						
						// 2. ?? payload ???? 1    
						case STATE_READ_PACKET_LEN_1:
								parser.expected_payload_length = (uint16_t)byte << 8;    //???????????,???expected_payload_length????
								parser.state = STATE_READ_PACKET_LEN_2;
								break;
						
						// ?? payload ???? 2                                    
						case STATE_READ_PACKET_LEN_2:
								parser.expected_payload_length |= byte;    //???????????,?????????????
								parser.payload_index = 0;     //??????payload???

								if (parser.expected_payload_length < MIN_PAYLOAD_LEN || parser.expected_payload_length > sizeof(parser.raw_payload_data))
								{
										ProtocolParser_Init(&parser);
								}
								else
								{
										parser.state = STATE_READ_PAYLOAD;
								}
								break;
						
						// 3. ?? payload ??(CMD + FLAG + ADDR + DATALEN + DATA)    
						case STATE_READ_PAYLOAD:
								if (parser.payload_index < sizeof(parser.raw_payload_data))
								{
										parser.raw_payload_data[parser.payload_index++] = byte;   //????????????(????????????????????)
								}
								else
								{
										ProtocolParser_Init(&parser);													
										break;
								}

								if (parser.payload_index >= parser.expected_payload_length)
								{
										parser.state = STATE_READ_CHECKSUM_1;
								}
								break;

						// 4. ???????1
						case STATE_READ_CHECKSUM_1:
								parser.checksum_received = (uint16_t)byte << 8;   // ?????????,???checksum_received????
								parser.state = STATE_READ_CHECKSUM_2;
								break;
						

						// ???????2                                    
						case STATE_READ_CHECKSUM_2:
								parser.checksum_received |=  byte;  // ?????????,??????????
							
							 //?????????????????????????
								if ((CalculateChecksum(parser.raw_payload_data, parser.expected_payload_length)) == parser.checksum_received)  
								{
													parser.state = STATE_WAIT_FOOTER_1;
								} else{
											  ProtocolParser_Init(&parser);
								}                    
								break;

						// 5. ?????????(0x55)        
						case STATE_WAIT_FOOTER_1:
								if (byte == FOOTER_H)
								{
										parser.state = STATE_WAIT_FOOTER_2;
								}
								else
								{
										 ProtocolParser_Init(&parser);
								}
								break;

						// ?????????(0xAA)        
						case STATE_WAIT_FOOTER_2:
								if (byte == FOOTER_L)
								{                                                
										// ?????????,??????
										uint8_t *p = parser.raw_payload_data;                                
										// ????
										parser.pkg_data.cmd = *p++;
										
										// ????
										parser.pkg_data.flag = *p++;
										
										// ???? (???)
										parser.pkg_data.addr = (uint16_t)(*p++) << 8;
										parser.pkg_data.addr |= *p++;
										
										// ?????? (???)
										parser.pkg_data.data_len = (uint16_t)(*p++) << 8;
										parser.pkg_data.data_len |= *p++;

										// ??????data_len????
										if (parser.expected_payload_length != (MIN_PAYLOAD_LEN + parser.pkg_data.data_len))
										{
											  ProtocolParser_Init(&parser); // ???????
												break;
										}

										if (parser.pkg_data.data_len > MAX_DATA_LEN)
										{
											  ProtocolParser_Init(&parser); // ????????
												break;
										}

										if (parser.pkg_data.data_len > 0)
										{
												memcpy(parser.pkg_data.data, p, parser.pkg_data.data_len);
										}

										// ????????????
										ProcessReceivedPacket1(&parser.pkg_data);
								}
								// ??????????????
								ProtocolParser_Init(&parser);
								break;

						default:
								ProtocolParser_Init(&parser);
								break;
				}
		}

        // ????????							
		if(HAL_UARTEx_ReceiveToIdle_IT(&huart1, rx_buffer1, BUFFER_SIZE) != HAL_OK)
		{
				Error_Handler();
		}
    }
		
		
		
		
		if (huart == &huart2)
    {    			
			 //HAL_UART_Transmit(&huart1, rx_buffer, size, 100);

        for (uint16_t i = 0; i < size; i++)
        {
            uint8_t byte=rx_buffer2[i];     //????????????
            switch(parser.state)          //??????????,??????????
            {
						// 1. ???????????(0xAA)
						case STATE_WAIT_HEADER_1:    
								if (byte == HEADER_H)
								{
										parser.state = STATE_WAIT_HEADER_2;    //??????????????
								}
								break;
						
						// ???????????(0x55)        
						case STATE_WAIT_HEADER_2:
								if (byte == HEADER_L)
								{
										parser.state = STATE_READ_PACKET_LEN_1;    //?????????????
								}else{
										ProtocolParser_Init(&parser);     //???????
								}
								break;
						
						// 2. ?? payload ???? 1    
						case STATE_READ_PACKET_LEN_1:
								parser.expected_payload_length = (uint16_t)byte << 8;    //???????????,???expected_payload_length????
								parser.state = STATE_READ_PACKET_LEN_2;
								break;
						
						// ?? payload ???? 2                                    
						case STATE_READ_PACKET_LEN_2:
								parser.expected_payload_length |= byte;    //???????????,?????????????
								parser.payload_index = 0;     //??????payload???

								if (parser.expected_payload_length < MIN_PAYLOAD_LEN || parser.expected_payload_length > sizeof(parser.raw_payload_data))
								{
										ProtocolParser_Init(&parser);
								}
								else
								{
										parser.state = STATE_READ_PAYLOAD;
								}
								break;
						
						// 3. ?? payload ??(CMD + FLAG + ADDR + DATALEN + DATA)    
						case STATE_READ_PAYLOAD:
								if (parser.payload_index < sizeof(parser.raw_payload_data))
								{
										parser.raw_payload_data[parser.payload_index++] = byte;   //????????????(????????????????????)
								}
								else
								{
										ProtocolParser_Init(&parser);													
										break;
								}

								if (parser.payload_index >= parser.expected_payload_length)
								{
										parser.state = STATE_READ_CHECKSUM_1;
								}
								break;

						// 4. ???????1
						case STATE_READ_CHECKSUM_1:
								parser.checksum_received = (uint16_t)byte << 8;   // ?????????,???checksum_received????
								parser.state = STATE_READ_CHECKSUM_2;
								break;
						

						// ???????2                                    
						case STATE_READ_CHECKSUM_2:
								parser.checksum_received |=  byte;  // ?????????,??????????
							
							 //?????????????????????????
								if ((CalculateChecksum(parser.raw_payload_data, parser.expected_payload_length)) == parser.checksum_received)  
								{
													parser.state = STATE_WAIT_FOOTER_1;
								} else{
											  ProtocolParser_Init(&parser);
								}                    
								break;

						// 5. ?????????(0x55)        
						case STATE_WAIT_FOOTER_1:
								if (byte == FOOTER_H)
								{
										parser.state = STATE_WAIT_FOOTER_2;
								}
								else
								{
										 ProtocolParser_Init(&parser);
								}
								break;

						// ?????????(0xAA)        
						case STATE_WAIT_FOOTER_2:
								if (byte == FOOTER_L)
								{                                                
										// ?????????,??????
										uint8_t *p = parser.raw_payload_data;                                
										// ????
										parser.pkg_data.cmd = *p++;
										
										// ????
										parser.pkg_data.flag = *p++;
										
										// ???? (???)
										parser.pkg_data.addr = (uint16_t)(*p++) << 8;
										parser.pkg_data.addr |= *p++;
										
										// ?????? (???)
										parser.pkg_data.data_len = (uint16_t)(*p++) << 8;
										parser.pkg_data.data_len |= *p++;

										// ??????data_len????
										if (parser.expected_payload_length != (MIN_PAYLOAD_LEN + parser.pkg_data.data_len))
										{
											  ProtocolParser_Init(&parser); // ???????
												break;
										}

										if (parser.pkg_data.data_len > MAX_DATA_LEN)
										{
											  ProtocolParser_Init(&parser); // ????????
												break;
										}

										if (parser.pkg_data.data_len > 0)
										{
												memcpy(parser.pkg_data.data, p, parser.pkg_data.data_len);
										}

										// ????????????
										ProcessReceivedPacket2(&parser.pkg_data);
								}
								// ??????????????
								ProtocolParser_Init(&parser);
								break;

						default:
								ProtocolParser_Init(&parser);
								break;
				}
		}

        // ????????							
		if(HAL_UARTEx_ReceiveToIdle_IT(&huart2, rx_buffer2, BUFFER_SIZE) != HAL_OK)
		{
				Error_Handler();
		}
    }

		
}





/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_CRC_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_USART3_UART_Init();
  /* USER CODE BEGIN 2 */


  ProtocolParser_Init(&parser);                                   //????????
	if(HAL_UARTEx_ReceiveToIdle_IT(&huart1, rx_buffer1, BUFFER_SIZE) != HAL_OK)
	{
				Error_Handler();
	}

  ProtocolParser_Init(&parser);	
	if(HAL_UARTEx_ReceiveToIdle_IT(&huart2, rx_buffer2, BUFFER_SIZE) != HAL_OK)
	{
				Error_Handler();
	}

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */