| | |
| | | sum = ~sum; |
| | | return sum; |
| | | } |
| | | |
| | | void SendComMap0(uint8_t data_length, uint8_t index)//表示成功读取的回应包 |
| | | { |
| | | static uint8_t send_frame[EUART0_RX_BUF_SIZE]; |
| | | uint16_t checksum = 0; |
| | | send_frame[0] = 0x55; |
| | | send_frame[1] = 0xAA; |
| | | send_frame[2] = 0x03; |
| | | send_frame[3] = data_length+5; |
| | | send_frame[4] = CMD_REPLY; |
| | | send_frame[5] = index; |
| | | send_frame[6] = data_length; |
| | | memcpy(&send_frame[7], &g_com_map[index], data_length); |
| | | for(int i = 0; i<(data_length+5); i++) |
| | | { |
| | | checksum += send_frame[2+i]; |
| | | } |
| | | checksum = Checksum_u16(&send_frame[2],5+data_length); |
| | | memcpy(&send_frame[7+data_length],&checksum,2); |
| | | |
| | | uart_send(UART_ID0, send_frame,data_length+9, NULL); |
| | | } |
| | | void SendComMap(uint8_t data_length, uint8_t index)//表示成功读取的回应包 |
| | | { |
| | | static uint8_t send_frame[EUART0_RX_BUF_SIZE]; |
| | |
| | | uint8_t required_size_temp; |
| | | uint8_t delete_count_temp; |
| | | int low_temp,high_temp,mid_temp,elements_to_move_temp,temp_index; |
| | | void add_new_tag_id_to_list(uint8_t* add_list,uint32_t*tag_authorization_idlist,uint32_t*authorization_list_num) |
| | | { |
| | | uint32_t count = add_list[0]; |
| | | uint32_t current_size = *authorization_list_num; |
| | | uint32_t new_size = current_size + count; |
| | | |
| | | // 处理每个新ID |
| | | for (uint32_t i = 0; i < count; i++) { |
| | | uint32_t add_offset = 1 + i * 4; // 跳过计数byte |
| | | uint32_t new_id=0; |
| | | memcpy(&new_id,&add_list[add_offset],4); |
| | | |
| | | // 二分查找确定插入位置 |
| | | uint32_t left = 0; |
| | | uint32_t right = current_size; |
| | | uint32_t insert_pos = current_size; |
| | | bool exists = false; |
| | | while (left < right) { |
| | | uint32_t mid = left + (right - left) / 2; |
| | | uint32_t mid_val = tag_authorization_idlist[mid]; |
| | | |
| | | if (mid_val == new_id) { |
| | | exists = true; |
| | | break; |
| | | } else if(tag_authorization_idlist[mid] < new_id) { |
| | | left = mid + 1; |
| | | } else { |
| | | right = mid; |
| | | } |
| | | } |
| | | |
| | | // 如果ID不存在,则插入 |
| | | if (!exists) { |
| | | insert_pos = left; |
| | | // 使用memmove移动元素为新ID腾出空间 |
| | | memmove( |
| | | &tag_authorization_idlist[left + 1], |
| | | &tag_authorization_idlist[left], |
| | | (current_size - left) * sizeof(uint32_t) |
| | | ); |
| | | |
| | | // 插入新ID |
| | | tag_authorization_idlist[left] = new_id; |
| | | current_size++; // 更新当前大小 |
| | | } |
| | | } |
| | | *authorization_list_num = current_size; // 更新总数 |
| | | |
| | | } |
| | | void delete_authorization_list(uint8_t* delete_list,uint32_t*tag_authorization_idlist,uint32_t*authorization_list_num) |
| | | { |
| | | if (*authorization_list_num == 0) { |
| | |
| | | static uint8_t send_frame[256]; // 用于计算校验和的帧 |
| | | static uint8_t frame_index = 0; // 帧缓冲区索引 |
| | | static uint8_t pack_datalen = 0; |
| | | |
| | | LOG_INFO(TRACE_MODULE_APP,"收到 %#x\r\n",data); |
| | | LOG_INFO(TRACE_MODULE_APP,"收到数据%c\r\n",data); |
| | | //LOG_INFO(TRACE_MODULE_APP,"收到 %#x\r\n",data); |
| | | switch(usart0_receive_state) { |
| | | case Usart0ReceiveWaitHead0: |
| | | if(data == 0x55) { |
| | |
| | | break; |
| | | |
| | | case Usart0ReceiveWaitMsgType: |
| | | if(data == 0x2||data==0x1||data == 0x3||data==0x4||data==0x5) { // 读写回复消息类型 |
| | | if(data == 0x2||data==0x1||data == 0x3||data==0x4||data==0x5||data==0x6) { // 读写回复消息类型 |
| | | pack_msg_type = data; |
| | | usart0_receive_state = Usart0ReceiveWaitDataLen; |
| | | send_frame[frame_index++] = data; |
| | |
| | | memcpy(&g_com_map[NERA_FREQUENCY],&tag_near_frequency,1); |
| | | save_com_map_to_flash(); |
| | | break; |
| | | case ADD_NEW_TAG_IN_LIST: |
| | | add_new_tag_id_to_list(&mUsart2ReceivePack,&tag_id_authorization_list,&tag_id_authorization_list_num); |
| | | save_taglist_map_to_flash();//存入flash |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | case CMD_READ: |
| | | //read包中data字节,即mUsartReceivePack[0]表示数据长度; |
| | | //从g_com_data结构体中的第index位置读取长度为mUsartReceivePack[0]的字节,发送出来 |
| | | SendComMap(pack_datalen,pack_index>>1); |
| | | SendComMap0(pack_datalen,pack_index>>1); |
| | | break; |
| | | default: |
| | | break; |