добавил работу с modbus tcp
This commit is contained in:
@@ -807,6 +807,17 @@ RS_StatusTypeDef RS_Parse_Message(RS_HandleTypeDef *hmodbus, RS_MsgTypeDef *modb
|
||||
uint32_t check_empty_buff;
|
||||
int ind = 0; // ind for modbus-uart buffer
|
||||
//-----INFO ABOUT DATA/MESSAGE-------
|
||||
#ifdef TCP_ModBus
|
||||
modbus_msg->ID_Transaction=modbus_uart_buff[ind++]<<8;
|
||||
modbus_msg->ID_Transaction|=modbus_uart_buff[ind++];
|
||||
|
||||
modbus_msg->ID_Prot=modbus_uart_buff[ind++]<<8;
|
||||
modbus_msg->ID_Prot|=modbus_uart_buff[ind++];
|
||||
modbus_msg->PDU_Length=modbus_uart_buff[ind++]<<8;
|
||||
modbus_msg->PDU_Length|=modbus_uart_buff[ind++];
|
||||
#else
|
||||
|
||||
#endif
|
||||
//-----------[first bits]------------
|
||||
// get ID of message/user
|
||||
modbus_msg->MbAddr = modbus_uart_buff[ind++];
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*************************************************************************/
|
||||
#ifndef __MODBUS_H_
|
||||
#define __MODBUS_H_
|
||||
|
||||
#define TCP_ModBus
|
||||
#include "modbus_config.h"
|
||||
#include "modbus_data.h"
|
||||
//#include "settings.h" // for modbus settings
|
||||
@@ -32,6 +32,10 @@
|
||||
/////////////////////---USER MESSAGE DEFINES---//////////////////////
|
||||
//-------------DEFINES FOR STRUCTURE----------------
|
||||
/* defines for structure of modbus message */
|
||||
|
||||
#define ID_Transaction_size 2
|
||||
#define ID_Prot_size 2
|
||||
#define DataLength_size 2
|
||||
#define MbAddr_SIZE 1 ///< size of (MbAddr)
|
||||
#define Func_Code_SIZE 1 ///< size of (Func_Code)
|
||||
#define Addr_SIZE 2 ///< size of (Addr)
|
||||
@@ -41,8 +45,11 @@
|
||||
#define CRC_SIZE 2 ///< size of (MB_CRC) in bytes
|
||||
|
||||
/** @brief Size of whole message */
|
||||
#ifdef TCP_ModBus
|
||||
#define INFO_SIZE_MAX (ID_Transaction_size+ID_Prot_size+DataLength_size+MbAddr_SIZE+Func_Code_SIZE+Addr_SIZE+Qnt_SIZE)
|
||||
#else
|
||||
#define INFO_SIZE_MAX (MbAddr_SIZE+Func_Code_SIZE+Addr_SIZE+Qnt_SIZE+ByteCnt_SIZE)
|
||||
|
||||
#endif
|
||||
/** @brief Size of first part of message that will be received
|
||||
first receive info part of message, than defines size of rest message*/
|
||||
#define RX_FIRST_PART_SIZE INFO_SIZE_MAX
|
||||
@@ -134,6 +141,10 @@ typedef struct
|
||||
/** @brief Structure for modbus messsage */
|
||||
typedef struct // RS_MsgTypeDef
|
||||
{
|
||||
uint16_t ID_Transaction;
|
||||
uint16_t ID_Prot;
|
||||
uint16_t PDU_Length;
|
||||
|
||||
uint8_t MbAddr; ///< Modbus Slave Address
|
||||
MB_FunctonTypeDef Func_Code; ///< Modbus Function Code
|
||||
MB_DevIdMsgTypeDef DevId; ///< Read Device Identification Header struct
|
||||
|
||||
@@ -168,6 +168,8 @@ typedef struct
|
||||
typedef struct // RS_HandleTypeDef
|
||||
{
|
||||
/* MESSAGE */
|
||||
|
||||
|
||||
uint8_t ID; ///< ID of RS "channel"
|
||||
RS_MsgTypeDef *pMessagePtr; ///< pointer to message struct
|
||||
uint8_t *pBufferPtr; ///< pointer to message buffer
|
||||
|
||||
Reference in New Issue
Block a user