Рефакторинг modbus_core енумов и структур

This commit is contained in:
2025-11-06 17:53:22 +03:00
parent f7ab05d097
commit 920ceb1a3d
20 changed files with 329 additions and 294 deletions

View File

@@ -47,7 +47,7 @@ void MB_WriteObjectsToMessage(RS_MsgTypeDef *modbus_msg, unsigned maxidofobj)
{
MB_DeviceObjectTypeDef *obj = (MB_DeviceObjectTypeDef *)&MB_DEVID;
unsigned objidtmp = modbus_msg->DevId.NextObjId;
modbus_msg->Except_Code = NO_ERRORS;
modbus_msg->Except_Code = ET_NO_ERRORS;
/* Define number of object in one message */
unsigned lastobjid = 0;
@@ -73,7 +73,7 @@ void MB_WriteObjectsToMessage(RS_MsgTypeDef *modbus_msg, unsigned maxidofobj)
/* Fill message with objects data */
char *mbdata = (char *)&modbus_msg->DATA;
char *mbdata = (char *)&modbus_msg->MbData;
unsigned ind = 0;
unsigned objid = modbus_msg->DevId.NextObjId;
for(; objid <= lastobjid; objid++)
@@ -98,7 +98,7 @@ void MB_WriteObjectsToMessage(RS_MsgTypeDef *modbus_msg, unsigned maxidofobj)
}
else
{
modbus_msg->Except_Code = ILLEGAL_DATA_VALUE;
modbus_msg->Except_Code = ET_ILLEGAL_DATA_VALUE;
}
}
@@ -111,9 +111,11 @@ void MB_WriteObjectsToMessage(RS_MsgTypeDef *modbus_msg, unsigned maxidofobj)
*/
uint8_t MB_Process_Read_Device_Identifications(RS_MsgTypeDef *modbus_msg)
{
modbus_msg->DevId.Conformity = MODBUS_DEVICE_CONFORMITY;
switch(modbus_msg->DevId.ReadDevId)
{
case MB_BASIC_IDENTIFICATIONS:
case RID_BASIC_IDENTIFICATIONS:
if (modbus_msg->DevId.NextObjId == 0)
{
modbus_msg->DevId.NextObjId = 0;
@@ -123,7 +125,7 @@ uint8_t MB_Process_Read_Device_Identifications(RS_MsgTypeDef *modbus_msg)
modbus_msg->DevId.NumbOfObj = 3;
break;
case MB_REGULAR_IDENTIFICATIONS:
case RID_REGULAR_IDENTIFICATIONS:
if (modbus_msg->DevId.NextObjId == 0)
{
modbus_msg->DevId.NextObjId = 3;
@@ -133,10 +135,10 @@ uint8_t MB_Process_Read_Device_Identifications(RS_MsgTypeDef *modbus_msg)
modbus_msg->DevId.NumbOfObj = 4;
break;
case MB_EXTENDED_IDENTIFICATIONS:
case RID_EXTENDED_IDENTIFICATIONS:
if(MODBUS_NUMB_OF_USEROBJECTS <= 0 || MODBUS_NUMB_OF_USEROBJECTS > 128)
{
modbus_msg->Except_Code = ILLEGAL_DATA_VALUE;
modbus_msg->Except_Code = ET_ILLEGAL_DATA_VALUE;
break;
}
@@ -149,7 +151,7 @@ uint8_t MB_Process_Read_Device_Identifications(RS_MsgTypeDef *modbus_msg)
modbus_msg->DevId.NumbOfObj = MODBUS_NUMB_OF_USEROBJECTS;
break;
case MB_SPEDIFIC_IDENTIFICATIONS:
case RID_SPEDIFIC_IDENTIFICATIONS:
MB_WriteObjectsToMessage(modbus_msg, modbus_msg->DevId.NextObjId);
modbus_msg->DevId.NumbOfObj = 1;
break;
@@ -157,7 +159,7 @@ uint8_t MB_Process_Read_Device_Identifications(RS_MsgTypeDef *modbus_msg)
return 0;
}
if(modbus_msg->Except_Code != NO_ERRORS)
if(modbus_msg->Except_Code != ET_NO_ERRORS)
{
return 0;
}
@@ -568,4 +570,4 @@ void MB_DeviceInentificationInit(void)
}
#endif //MODBUS_ENABLE_DEVICE_IDENTIFICATIONS
#endif //MODBUS_ENABLE_DEVICE_IDENTIFICATIONS