Перенос заглушек в modbus_compat и заготовки для TCP

This commit is contained in:
2025-11-06 12:48:37 +03:00
parent 510e8aec50
commit 8a2e7398e1
12 changed files with 175 additions and 114 deletions

View File

@@ -173,6 +173,16 @@ RS_StatusTypeDef MB_Slave_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeD
else
{
//------INFO ABOUT DATA/MESSAGE------
#ifdef MODBUS_PROTOCOL_TCP
modbus_uart_buff[ind++] = modbus_msg->ID_Transaction >> 8;
modbus_uart_buff[ind++] = modbus_msg->ID_Transaction& 0xFF;
modbus_uart_buff[ind++] = modbus_msg->ID_Protocol >> 8;
modbus_uart_buff[ind++] = modbus_msg->ID_Protocol& 0xFF;
modbus_uart_buff[ind++] = modbus_msg->PDU_Length >> 8;
modbus_uart_buff[ind++] = modbus_msg->PDU_Length& 0xFF;
#endif
//-----------[first bytes]-----------
// set ID of message/user
modbus_uart_buff[ind++] = modbus_msg->MbAddr;
@@ -255,12 +265,14 @@ RS_StatusTypeDef MB_Slave_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeD
//---------------CRC----------------
//---------[last 16 bytes]----------
#ifndef MODBUS_PROTOCOL_TCP
// calc crc of received data
uint16_t CRC_VALUE = crc16(modbus_uart_buff, ind);
// write crc to message structure and modbus-uart buffer
modbus_msg->MB_CRC = CRC_VALUE;
modbus_uart_buff[ind++] = CRC_VALUE;
modbus_uart_buff[ind++] = CRC_VALUE >> 8;
#endif
hmodbus->RS_Message_Size = ind;
@@ -317,6 +329,16 @@ RS_StatusTypeDef MB_Slave_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef
hmodbus->f.RX_Continue = 0;
int expected_size = 0;
//-----INFO ABOUT DATA/MESSAGE-------
#ifdef MODBUS_PROTOCOL_TCP
modbus_msg->ID_Transaction =modbus_uart_buff[ind++]<<8;
modbus_msg->ID_Transaction |=modbus_uart_buff[ind++];
modbus_msg->ID_Protocol =modbus_uart_buff[ind++]<<8;
modbus_msg->ID_Protocol |=modbus_uart_buff[ind++];
modbus_msg->PDU_Length =modbus_uart_buff[ind++]<<8;
modbus_msg->PDU_Length |=modbus_uart_buff[ind++];
#endif
//-----------[first bits]------------
// get ID of message/user
if(modbus_uart_buff[ind] != hmodbus->ID)
@@ -414,6 +436,7 @@ RS_StatusTypeDef MB_Slave_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef
//---------------CRC----------------
//----------[last 16 bits]----------
#ifndef MODBUS_PROTOCOL_TCP
// calc crc of received data
uint16_t CRC_VALUE = crc16(modbus_uart_buff, ind);
// get crc of received data
@@ -426,12 +449,9 @@ RS_StatusTypeDef MB_Slave_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef
TrackerCnt_Err(hmodbus->rs_err);
modbus_msg->Func_Code |= ERR_VALUES_START;
}
#endif
return RS_OK;
}
#else // MODBUS_ENABLE_SLAVE
RS_StatusTypeDef MB_Slave_Response(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modbus_msg) {return RS_ERR;}
RS_StatusTypeDef MB_Slave_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modbus_msg, uint8_t *modbus_uart_buff) {return RS_ERR;}
RS_StatusTypeDef MB_Slave_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modbus_msg, uint8_t *modbus_uart_buff) {return RS_ERR;}
#endif
#endif //MODBUS_ENABLE_SLAVE