Перенос заглушек в modbus_compat и заготовки для TCP
This commit is contained in:
114
Inc/__modbus_compat.h
Normal file
114
Inc/__modbus_compat.h
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/**
|
||||||
|
**************************************************************************
|
||||||
|
* @file __modbus_compat.h
|
||||||
|
* @brief Модуль для совместимости библиотеки MODBUS.
|
||||||
|
**************************************************************************
|
||||||
|
* @details Файл содержит API старых функций, а также заглушки для отключенных модулей:
|
||||||
|
******************************************************************************/
|
||||||
|
#include "modbus.h"
|
||||||
|
|
||||||
|
|
||||||
|
/** @addtogroup MODBUS_LEGACY_API Legacy API
|
||||||
|
* @ingroup MODBUS_FUNCTIONS
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** MODBUS_LEGACY_API
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @cond Заглушки отключенных модулей */
|
||||||
|
|
||||||
|
#ifndef MODBUS_ENABLE_COILS
|
||||||
|
#define MB_Coil_Write_Global(Addr, WriteVal) ILLEGAL_FUNCTION
|
||||||
|
#define MB_Coil_Read_Global(Addr, Exception) 0
|
||||||
|
#define MB_Process_Read_Coils(modbus_msg) 0
|
||||||
|
#define MB_Process_Write_Single_Coil(modbus_msg) 0
|
||||||
|
#define MB_Process_Write_Miltuple_Coils(modbus_msg) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MODBUS_ENABLE_HOLDINGS
|
||||||
|
#define MB_Holding_Write_Global(Addr, WriteVal) ILLEGAL_FUNCTION
|
||||||
|
#define MB_Holding_Read_Global(Addr, Exception) 0
|
||||||
|
#define MB_Process_Read_Hold_Regs(modbus_msg) 0
|
||||||
|
#define MB_Process_Write_Single_Reg(modbus_msg) 0
|
||||||
|
#define MB_Process_Write_Miltuple_Regs(modbus_msg) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MODBUS_ENABLE_INPUTS
|
||||||
|
#define MB_Input_Write_Global(Addr, WriteVal) ILLEGAL_FUNCTION
|
||||||
|
#define MB_Input_Read_Global(Addr, Exception) 0
|
||||||
|
#define MB_Process_Read_Input_Regs(modbus_msg) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MODBUS_ENABLE_DEVICE_IDENTIFICATIONS
|
||||||
|
#define MB_WriteSingleObjectToMessage(mbdata, ind, obj)
|
||||||
|
#define MB_WriteObjectsToMessage(modbus_msg, maxidofobj)
|
||||||
|
#define MB_Process_Read_Device_Identifications(modbus_msg) 0
|
||||||
|
#define MB_DeviceInentificationInit()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MODBUS_ENABLE_DIAGNOSTICS
|
||||||
|
#define MB_DiagnosticsInit()
|
||||||
|
#define MB_Diagnostics_WriteBit(bit_num, bit_state) 0
|
||||||
|
#define MB_Diagnostics_GetBit(bit_num) 0
|
||||||
|
#define MB_Process_Diagnostics(modbus_msg) 0
|
||||||
|
#define MB_Diagnostics_BusMessageCnt()
|
||||||
|
#define MB_Diagnostics_CommunicationErrorCnt()
|
||||||
|
#define MB_Diagnostics_ExceptionErrorCnt()
|
||||||
|
#define MB_Diagnostics_CharacterOverrunCnt()
|
||||||
|
#define MB_Diagnostics_SlaveMessageCnt()
|
||||||
|
#define MB_Diagnostics_SlaveNoResponseCnt()
|
||||||
|
#define MB_Diagnostics_SlaveNAKCnt()
|
||||||
|
#define MB_Diagnostics_SlaveBusyCnt()
|
||||||
|
#define MB_GetDeviceMode(void) MODBUS_NORMAL_MODE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MODBUS_ENABLE_MASTER
|
||||||
|
#define MB_RespGet_RegisterValue(modbus_msg, reg_addr, reg_value) 0
|
||||||
|
#define MB_RespGet_CoilState(modbus_msg, coil_addr, coil_state) 0
|
||||||
|
#define MB_RespGet_NumberOfObjects(modbus_msg) 0
|
||||||
|
#define MB_RespGet_ObjectById(modbus_msg, obj_id, obj_data, obj_length) 0
|
||||||
|
#define MB_RespGet_ObjectByIndex(modbus_msg, index, obj_id, obj_data, obj_length) 0
|
||||||
|
#define MB_RespGet_Diagnostic(modbus_msg, data) 0
|
||||||
|
#define MB_REQUEST_READ_COILS(slave_addr, start_addr, quantity) {0}
|
||||||
|
#define MB_REQUEST_READ_DISCRETE_INPUTS(slave_addr, start_addr, quantity) {0}
|
||||||
|
#define MB_REQUEST_READ_HOLDING_REGS(slave_addr, start_addr, quantity) {0}
|
||||||
|
#define MB_REQUEST_READ_INPUT_REGS(slave_addr, start_addr, quantity) {0}
|
||||||
|
#define MB_REQUEST_WRITE_SINGLE_COIL(slave_addr, coil_addr, value) {0}
|
||||||
|
#define MB_REQUEST_WRITE_SINGLE_REG(slave_addr, reg_addr, value) {0}
|
||||||
|
#define MB_REQUEST_WRITE_MULTIPLE_COILS(slave_addr, start_addr, quantity, coils_data) {0}
|
||||||
|
#define MB_REQUEST_WRITE_MULTIPLE_REGS(slave_addr, start_addr, quantity, regs_data) {0}
|
||||||
|
#define MB_REQUEST_DIAGNOSTIC_QUERY(slave_addr, sub_function, data) {0}
|
||||||
|
#define MB_REQUEST_RETURN_QUERY_DATA(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_RESTART_COMMUNICATIONS(slave_addr, data) {0}
|
||||||
|
#define MB_REQUEST_RETURN_DIAGNOSTIC_REGISTER(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_FORCE_LISTEN_ONLY_MODE(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_CLEAR_COUNTERS_AND_DIAGNOSTIC_REGISTER(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_RETURN_BUS_MESSAGE_COUNT(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_RETURN_BUS_COMMUNICATION_ERROR_COUNT(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_RETURN_SLAVE_EXCEPTION_ERROR_COUNT(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_RETURN_SLAVE_MESSAGE_COUNT(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_RETURN_SLAVE_NO_RESPONSE_COUNT(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_RETURN_SLAVE_NAK_COUNT(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_RETURN_SLAVE_BUSY_COUNT(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_RETURN_BUS_CHARACTER_OVERRUN_COUNT(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_READ_DEVICE_ID_BASIC(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_READ_DEVICE_ID_REGULAR(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_READ_DEVICE_ID_EXTENDED(slave_addr) {0}
|
||||||
|
#define MB_REQUEST_READ_DEVICE_ID_SPECIFIC(slave_addr, object_id) {0}
|
||||||
|
#define MB_Master_Collect_Message(hmodbus, modbus_msg, modbus_uart_buff) RS_ERR
|
||||||
|
#define MB_Master_Parse_Message(hmodbus, modbus_msg, modbus_uart_buff) RS_ERR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MODBUS_ENABLE_SLAVE
|
||||||
|
#define MB_Slave_Response(hmodbus, modbus_msg) RS_ERR
|
||||||
|
#define MB_Slave_Collect_Message(hmodbus, modbus_msg, modbus_uart_buff) RS_ERR
|
||||||
|
#define MB_Slave_Parse_Message(hmodbus, modbus_msg, modbus_uart_buff) RS_ERR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** @endcond */
|
||||||
16
Inc/modbus.h
16
Inc/modbus.h
@@ -28,7 +28,7 @@
|
|||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
|
||||||
MODBUS_FirstInit(&hmodbus1, &huart1, &htim3);
|
MODBUS_FirstInit(&hmodbus1, &huart1, &htim3);
|
||||||
MODBUS_Config(&hmodbus1, 1, 1000, MODBUS_MODE_SLAVE);
|
MODBUS_Config(&hmodbus1, MODBUS_DEVICE_ID, MODBUS_TIMEOUT, MODBUS_MODE_SLAVE);
|
||||||
MODBUS_SlaveStart(&hmodbus1, NULL);
|
MODBUS_SlaveStart(&hmodbus1, NULL);
|
||||||
@endverbatim
|
@endverbatim
|
||||||
@verbatim
|
@verbatim
|
||||||
@@ -84,13 +84,27 @@
|
|||||||
#define __MODBUS_H_
|
#define __MODBUS_H_
|
||||||
|
|
||||||
#include "rs_message.h"
|
#include "rs_message.h"
|
||||||
|
#ifdef MODBUS_ENABLE_MASTER
|
||||||
#include "modbus_master.h"
|
#include "modbus_master.h"
|
||||||
|
#endif
|
||||||
|
#ifdef MODBUS_ENABLE_SLAVE
|
||||||
#include "modbus_slave.h"
|
#include "modbus_slave.h"
|
||||||
|
#endif
|
||||||
|
#ifdef MODBUS_ENABLE_COILS
|
||||||
#include "modbus_coils.h"
|
#include "modbus_coils.h"
|
||||||
|
#endif
|
||||||
|
#ifdef MODBUS_ENABLE_HOLDINGS
|
||||||
#include "modbus_holdregs.h"
|
#include "modbus_holdregs.h"
|
||||||
|
#endif
|
||||||
|
#ifdef MODBUS_ENABLE_INPUTS
|
||||||
#include "modbus_inputregs.h"
|
#include "modbus_inputregs.h"
|
||||||
|
#endif
|
||||||
|
#ifdef MODBUS_ENABLE_DEVICE_IDENTIFICATIONS
|
||||||
#include "modbus_devid.h"
|
#include "modbus_devid.h"
|
||||||
|
#endif
|
||||||
|
#ifdef MODBUS_ENABLE_DIAGNOSTICS
|
||||||
#include "modbus_diag.h"
|
#include "modbus_diag.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef MODBUS_ENABLE_MASTER
|
#ifdef MODBUS_ENABLE_MASTER
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ typedef struct // RS_MsgTypeDef
|
|||||||
{
|
{
|
||||||
#ifdef MODBUS_PROTOCOL_TCP
|
#ifdef MODBUS_PROTOCOL_TCP
|
||||||
uint16_t ID_Transaction; ///< Modbus TCP: ID Transaction
|
uint16_t ID_Transaction; ///< Modbus TCP: ID Transaction
|
||||||
uint16_t ID_Prot; ///< Modbus TCP: ID Protocol
|
uint16_t ID_Protocol; ///< Modbus TCP: ID Protocol
|
||||||
uint16_t PDU_Length; ///< Modbus TCP: PDU_Length
|
uint16_t PDU_Length; ///< Modbus TCP: PDU_Length
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -299,6 +299,9 @@ MB_ExceptionTypeDef MB_DefineCoilsAddress(uint16_t **pCoils, uint16_t Addr, uint
|
|||||||
/** MODBUS_CMD_PROCESS_FUNCTIONS
|
/** MODBUS_CMD_PROCESS_FUNCTIONS
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////---FUNCTIONS---/////////////////////////////
|
/////////////////////////---FUNCTIONS---/////////////////////////////
|
||||||
#endif //__MODBUS_CORE_H_
|
#endif //__MODBUS_CORE_H_
|
||||||
/** MODBUS_INTERNAL
|
/** MODBUS_INTERNAL
|
||||||
|
|||||||
9
Src/__modbus_compat.c
Normal file
9
Src/__modbus_compat.c
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
**************************************************************************
|
||||||
|
* @file __modbus_compat.c
|
||||||
|
* @brief Модуль для совместимости библиотеки MODBUS.
|
||||||
|
**************************************************************************
|
||||||
|
* @details Файл содержит API старых функций, а также заглушки для отключенных модулей:
|
||||||
|
******************************************************************************/
|
||||||
|
#include "modbus.h"
|
||||||
|
|
||||||
@@ -236,13 +236,5 @@ uint8_t MB_Process_Write_Miltuple_Coils(RS_MsgTypeDef *modbus_msg)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#else //MODBUS_ENABLE_COILS
|
|
||||||
|
|
||||||
|
#endif //MODBUS_ENABLE_COILS
|
||||||
MB_ExceptionTypeDef MB_Coil_Write_Global(uint16_t Addr, MB_CoilsOpTypeDef WriteVal) {return ILLEGAL_FUNCTION;}
|
|
||||||
uint16_t MB_Coil_Read_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception) {return 0;}
|
|
||||||
uint8_t MB_Process_Read_Coils(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
uint8_t MB_Process_Write_Single_Coil(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
uint8_t MB_Process_Write_Miltuple_Coils(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -544,14 +544,4 @@ void MB_DeviceInentificationInit(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif //MODBUS_ENABLE_DEVICE_IDENTIFICATIONS
|
||||||
#else //MODBUS_ENABLE_DEVICE_IDENTIFICATIONS
|
|
||||||
|
|
||||||
/* Получить количество объектов в сообщении */
|
|
||||||
|
|
||||||
void MB_WriteSingleObjectToMessage(char *mbdata, unsigned *ind, MB_DeviceObjectTypeDef *obj) {}
|
|
||||||
void MB_WriteObjectsToMessage(RS_MsgTypeDef *modbus_msg, unsigned maxidofobj) {}
|
|
||||||
uint8_t MB_Process_Read_Device_Identifications(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
void MB_DeviceInentificationInit(void) {}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -293,20 +293,4 @@ MB_DeviceModeTypeDef MB_GetDeviceMode(void)
|
|||||||
return MB_DIAG.DeviceMode;
|
return MB_DIAG.DeviceMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else //MODBUS_ENABLE_DIAGNOSTICS
|
#endif //MODBUS_ENABLE_DIAGNOSTICS
|
||||||
|
|
||||||
void MB_DiagnosticsInit(void) {}
|
|
||||||
int MB_Diagnostics_WriteBit(int bit_num, int bit_state) {return 0;}
|
|
||||||
int MB_Diagnostics_GetBit(int bit_num) {return 0;}
|
|
||||||
uint8_t MB_Process_Diagnostics(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
void MB_Diagnostics_BusMessageCnt(void) {}
|
|
||||||
void MB_Diagnostics_CommunicationErrorCnt(void) {}
|
|
||||||
void MB_Diagnostics_ExceptionErrorCnt(void) {}
|
|
||||||
void MB_Diagnostics_CharacterOverrunCnt(void) {}
|
|
||||||
void MB_Diagnostics_SlaveMessageCnt(void) {}
|
|
||||||
void MB_Diagnostics_SlaveNoResponseCnt(void) {}
|
|
||||||
void MB_Diagnostics_SlaveNAKCnt(void) {}
|
|
||||||
void MB_Diagnostics_SlaveBusyCnt(void) {}
|
|
||||||
MB_DeviceModeTypeDef MB_GetDeviceMode(void) {return MODBUS_NORMAL_MODE;}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -159,13 +159,4 @@ uint8_t MB_Process_Write_Miltuple_Regs(RS_MsgTypeDef *modbus_msg)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif //MODBUS_ENABLE_HOLDINGS
|
||||||
#else //MODBUS_ENABLE_HOLDINGS
|
|
||||||
|
|
||||||
MB_ExceptionTypeDef MB_Holding_Write_Global(uint16_t Addr, uint16_t WriteVal) {return ILLEGAL_FUNCTION;}
|
|
||||||
uint16_t MB_Holding_Read_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception) {return 0;}
|
|
||||||
uint8_t MB_Process_Read_Hold_Regs(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
uint8_t MB_Process_Write_Single_Reg(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
uint8_t MB_Process_Write_Miltuple_Regs(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -104,10 +104,4 @@ uint8_t MB_Process_Read_Input_Regs(RS_MsgTypeDef *modbus_msg)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else //MODBUS_ENABLE_INPUTS
|
#endif //MODBUS_ENABLE_INPUTS
|
||||||
|
|
||||||
MB_ExceptionTypeDef MB_Input_Write_Global(uint16_t Addr, uint16_t WriteVal) {return ILLEGAL_FUNCTION;}
|
|
||||||
uint16_t MB_Input_Read_Global(uint16_t Addr, MB_ExceptionTypeDef *Exception) {return 0;}
|
|
||||||
uint8_t MB_Process_Read_Input_Regs(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -676,54 +676,4 @@ RS_MsgTypeDef MB_REQUEST_READ_DEVICE_ID_SPECIFIC(uint8_t slave_addr, uint8_t obj
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif //MODBUS_ENABLE_MASTER
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#else
|
|
||||||
RS_MsgTypeDef msg_dummy = {0};
|
|
||||||
|
|
||||||
int MB_RespGet_RegisterValue(RS_MsgTypeDef *modbus_msg, uint16_t reg_addr, uint16_t *reg_value) {return 0;}
|
|
||||||
int MB_RespGet_CoilState(RS_MsgTypeDef *modbus_msg, uint16_t coil_addr, int *coil_state) {return 0;}
|
|
||||||
int MB_RespGet_NumberOfObjects(RS_MsgTypeDef *modbus_msg) {return 0;}
|
|
||||||
int MB_RespGet_ObjectById(RS_MsgTypeDef *modbus_msg, uint8_t obj_id, char *obj_data, uint8_t *obj_length) {return 0;}
|
|
||||||
int MB_RespGet_ObjectByIndex(RS_MsgTypeDef *modbus_msg, int index, uint8_t *obj_id, char *obj_data, uint8_t *obj_length) {return 0;}
|
|
||||||
int MB_RespGet_Diagnostic(RS_MsgTypeDef *modbus_msg, uint16_t *data) {return 0;}
|
|
||||||
|
|
||||||
RS_MsgTypeDef MB_REQUEST_READ_COILS(uint8_t slave_addr, uint16_t start_addr, uint16_t quantity) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_READ_DISCRETE_INPUTS(uint8_t slave_addr, uint16_t start_addr, uint16_t quantity) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_READ_HOLDING_REGS(uint8_t slave_addr, uint16_t start_addr, uint16_t quantity) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_READ_INPUT_REGS(uint8_t slave_addr, uint16_t start_addr, uint16_t quantity) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_WRITE_SINGLE_COIL(uint8_t slave_addr, uint16_t coil_addr, uint8_t value) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_WRITE_SINGLE_REG(uint8_t slave_addr, uint16_t reg_addr, uint16_t value) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_WRITE_MULTIPLE_COILS(uint8_t slave_addr, uint16_t start_addr, uint16_t quantity, uint8_t *coils_data) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_WRITE_MULTIPLE_REGS(uint8_t slave_addr, uint16_t start_addr, uint16_t quantity, uint16_t *regs_data) {return msg_dummy;}
|
|
||||||
|
|
||||||
//---------ДИАГНОСТИЧЕСКИЕ ДАННЫЕ-----------
|
|
||||||
RS_MsgTypeDef MB_REQUEST_DIAGNOSTIC_QUERY(uint8_t slave_addr, uint16_t sub_function, uint16_t data) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_QUERY_DATA(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RESTART_COMMUNICATIONS(uint8_t slave_addr, uint16_t data) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_DIAGNOSTIC_REGISTER(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_FORCE_LISTEN_ONLY_MODE(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_CLEAR_COUNTERS_AND_DIAGNOSTIC_REGISTER(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_BUS_MESSAGE_COUNT(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_BUS_COMMUNICATION_ERROR_COUNT(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_SLAVE_EXCEPTION_ERROR_COUNT(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_SLAVE_MESSAGE_COUNT(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_SLAVE_NO_RESPONSE_COUNT(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_SLAVE_NAK_COUNT(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_SLAVE_BUSY_COUNT(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_RETURN_BUS_CHARACTER_OVERRUN_COUNT(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
|
|
||||||
//---------ИДЕНТИФИКАТОРЫ МОДБАС-----------
|
|
||||||
RS_MsgTypeDef MB_REQUEST_READ_DEVICE_ID_BASIC(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_READ_DEVICE_ID_REGULAR(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_READ_DEVICE_ID_EXTENDED(uint8_t slave_addr) {return msg_dummy;}
|
|
||||||
RS_MsgTypeDef MB_REQUEST_READ_DEVICE_ID_SPECIFIC(uint8_t slave_addr, uint8_t object_id) {return msg_dummy;}
|
|
||||||
|
|
||||||
RS_StatusTypeDef MB_Master_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modbus_msg, uint8_t *modbus_uart_buff) {return RS_ERR;}
|
|
||||||
RS_StatusTypeDef MB_Master_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modbus_msg, uint8_t *modbus_uart_buff) {return RS_ERR;}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -173,6 +173,16 @@ RS_StatusTypeDef MB_Slave_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeD
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//------INFO ABOUT DATA/MESSAGE------
|
//------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]-----------
|
//-----------[first bytes]-----------
|
||||||
// set ID of message/user
|
// set ID of message/user
|
||||||
modbus_uart_buff[ind++] = modbus_msg->MbAddr;
|
modbus_uart_buff[ind++] = modbus_msg->MbAddr;
|
||||||
@@ -255,12 +265,14 @@ RS_StatusTypeDef MB_Slave_Collect_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeD
|
|||||||
|
|
||||||
//---------------CRC----------------
|
//---------------CRC----------------
|
||||||
//---------[last 16 bytes]----------
|
//---------[last 16 bytes]----------
|
||||||
|
#ifndef MODBUS_PROTOCOL_TCP
|
||||||
// calc crc of received data
|
// calc crc of received data
|
||||||
uint16_t CRC_VALUE = crc16(modbus_uart_buff, ind);
|
uint16_t CRC_VALUE = crc16(modbus_uart_buff, ind);
|
||||||
// write crc to message structure and modbus-uart buffer
|
// write crc to message structure and modbus-uart buffer
|
||||||
modbus_msg->MB_CRC = CRC_VALUE;
|
modbus_msg->MB_CRC = CRC_VALUE;
|
||||||
modbus_uart_buff[ind++] = CRC_VALUE;
|
modbus_uart_buff[ind++] = CRC_VALUE;
|
||||||
modbus_uart_buff[ind++] = CRC_VALUE >> 8;
|
modbus_uart_buff[ind++] = CRC_VALUE >> 8;
|
||||||
|
#endif
|
||||||
|
|
||||||
hmodbus->RS_Message_Size = ind;
|
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;
|
hmodbus->f.RX_Continue = 0;
|
||||||
int expected_size = 0;
|
int expected_size = 0;
|
||||||
//-----INFO ABOUT DATA/MESSAGE-------
|
//-----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]------------
|
//-----------[first bits]------------
|
||||||
// get ID of message/user
|
// get ID of message/user
|
||||||
if(modbus_uart_buff[ind] != hmodbus->ID)
|
if(modbus_uart_buff[ind] != hmodbus->ID)
|
||||||
@@ -414,6 +436,7 @@ RS_StatusTypeDef MB_Slave_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef
|
|||||||
|
|
||||||
//---------------CRC----------------
|
//---------------CRC----------------
|
||||||
//----------[last 16 bits]----------
|
//----------[last 16 bits]----------
|
||||||
|
#ifndef MODBUS_PROTOCOL_TCP
|
||||||
// calc crc of received data
|
// calc crc of received data
|
||||||
uint16_t CRC_VALUE = crc16(modbus_uart_buff, ind);
|
uint16_t CRC_VALUE = crc16(modbus_uart_buff, ind);
|
||||||
// get crc of received data
|
// 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);
|
TrackerCnt_Err(hmodbus->rs_err);
|
||||||
modbus_msg->Func_Code |= ERR_VALUES_START;
|
modbus_msg->Func_Code |= ERR_VALUES_START;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return RS_OK;
|
return RS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // MODBUS_ENABLE_SLAVE
|
#endif //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
|
|
||||||
@@ -362,10 +362,10 @@ void RS_UART_Handler(RS_HandleTypeDef *hRS)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
RS_Set_Free(hRS); // освобожднаем RS
|
||||||
if(hRS->pCallback)
|
if(hRS->pCallback)
|
||||||
{
|
{
|
||||||
hRS->pCallback(hRS, hRS->pMessagePtr); // обрабатываем ответ
|
hRS->pCallback(hRS, hRS->pMessagePtr); // обрабатываем ответ
|
||||||
RS_Set_Free(hRS); // освобожднаем RS
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,11 +447,11 @@ void RS_TIM_Handler(RS_HandleTypeDef *hRS)
|
|||||||
|
|
||||||
if(hRS->sRS_Mode >= RS_MASTER_MODE_START)
|
if(hRS->sRS_Mode >= RS_MASTER_MODE_START)
|
||||||
{ // Мастер: коллбек и освобождение для нового запроса
|
{ // Мастер: коллбек и освобождение для нового запроса
|
||||||
|
RS_Set_Free(hRS);
|
||||||
if(hRS->pCallback)
|
if(hRS->pCallback)
|
||||||
{
|
{
|
||||||
hRS->pCallback(hRS, hRS->pMessagePtr); // обрабатываем ответ
|
hRS->pCallback(hRS, hRS->pMessagePtr); // обрабатываем ответ
|
||||||
}
|
}
|
||||||
RS_Set_Free(hRS);
|
|
||||||
} else {
|
} else {
|
||||||
// Слейв: перезапускаем прием
|
// Слейв: перезапускаем прием
|
||||||
RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
|
RS_Handle_Receive_Start(hRS, hRS->pMessagePtr);
|
||||||
|
|||||||
Reference in New Issue
Block a user