/* * bsp_decode_command.c * * Created on: Sep 24, 2024 * Author: akeguo */ #include "bsp_decode_command.h" #include "bsp_Error.pb.h" #define success 1 #define fail 0 Cmd decoded_Cmd = Cmd_init_default; ReCmd send_Cmd = ReCmd_init_default; pb_istream_t i_stream = { 0 }; char StartDownLoadFlag = 0; static uint32_t downloadCount = 0; static uint8_t readData[1024]; static uint8_t ReceivedData[1024]; static uint16_t calbriation; static uint16_t length_count; void decode_command_and_feedback(uint8_t *buffer, uint16_t length, char isMqtt, struct UARTHandler *send_Handler) { // char array[1000]; // memset(array, 0, sizeof(array)); // memcpy(array, buffer, length); // length_count = length; // if (length_count != 42) // { // char a = 100; // } //if (length >= 0) if (length >= 1 ) { i_stream = pb_istream_from_buffer(buffer, length); pb_decode(&i_stream, Cmd_fields, &decoded_Cmd); // int i=0; // for(i=0;iTx_Buf[4], sizeof(send_Handler->Tx_Buf) - 4); pb_encode(&ReCmd_out_stream, ReCmd_fields, &send_Cmd); //encode to buffer send_Handler->Tx_Buf[0] = '3'; send_Handler->Tx_Buf[1] = ','; send_Handler->Tx_Buf[2] = 0xfe; send_Handler->Tx_Buf[3] = 0xfe; send_Handler->TxCount = ReCmd_out_stream.bytes_written + 4; send_Handler->UART_Tx(send_Handler); } else { ReCmd_out_stream = pb_ostream_from_buffer(&send_Handler->Tx_Buf[2], sizeof(send_Handler->Tx_Buf)-2); pb_encode(&ReCmd_out_stream, ReCmd_fields, &send_Cmd); //encode to buffer send_Handler->Tx_Buf[0] = 0xfe; send_Handler->Tx_Buf[1] = 0xfe; //send_Handler->AddSendList(send_Handler,send_Handler->Tx_Buf,send_Handler->TxCount,NULL); send_Handler->TxCount = ReCmd_out_stream.bytes_written+2; //send_Handler->TxCount = 200; send_Handler->UART_Tx(send_Handler); } } //send_Cmd.CommadNum=0xff;//代表返回信息 //send_Cmd.Parameter0 代表执行的指令,发过来的命令号; //send_Cmd.Parameter1 1 代表成功,0 代表失败; //send_Cmd.databuf 存的是相关信息,可以通过ACII转成string; void WrapInCmdAndSendMessage(ReCmd send_Cmd, int8_t functionNum, char isSuccess, uint8_t *buf, char isMqtt, struct UARTHandler *send_Handler) { send_Cmd.CommadNum = 0xff; //代表返回信息 send_Cmd.Parameter0 = functionNum; //代表返回信息 send_Cmd.Parameter1 = isSuccess; //1 代表成功,0 代表失败; send_Cmd.Buff_Data_Length = strlen(buf); WrapInCmdAndSend(send_Cmd, buf, isMqtt, send_Handler); } void send_received_data_to_upper_computer(uint8_t *buffer, uint16_t length) { send_Cmd.CommadNum = 12; //定义12为设定Mqtt透传向上返回的数据 send_Cmd.Buff_Data_Length = length; WrapInCmdAndSend(send_Cmd, buffer, 0, desulfurizer_message_UART_Handler); }