wheel/components/modbus_tcp/modbus.h
2024-01-25 14:12:50 +08:00

64 lines
1.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _MODBUS_H
#define _MODBUS_H
#include <stdint.h>
#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32 unsigned int
#define setBit(Add) gBitVar[(Add) >> 3] |= (1 << ((Add)&0x07))
#define clrBit(Add) gBitVar[(Add) >> 3] &= ~(1 << ((Add)&0x07))
#define gBIT_SIZE 128
#define gWORD_SIZE 12288
#define MODBUS_ANGLE_ADDR 0
#define MODBUS_SPEED_ADDR 1
#define MODBUS_PID_FLAG_ADDR 2
#define MODBUS_P_ADDR 3
#define MODBUS_I_ADDR 4
#define MODBUS_D_ADDR 5
/* 角度 */
#define BDC_SERVO_INPUT_RANGE 1000
#define BDC_SERVO_REAL_RANGE (45)
extern uint8_t gBitVar[(gBIT_SIZE + 7) / 8];
extern uint16_t gWordVar[gWORD_SIZE];
/* modbus的寄存器数据含义建议都定义在这个文件内这样的话定义的时候就可以观察是否定义有冲突 */
typedef struct
{
/* 从Mudbus服务器端得到设置参数 */
uint16_t angle;
uint16_t speed;
uint16_t pid_flag;
uint16_t p;
uint16_t i;
uint16_t d;
// uint16_t res;
/* 发送到Modbus服务器显示的数据 */
uint32_t encoder_accumul; /* 编码器的累计值 修正:可能装不下,考虑用多少位的来扩展 */
uint32_t encoder_accumur;
uint16_t expect_speedl;
uint16_t real_speedl; /* 真实速度 */
uint16_t real_motor_outputl; /* 真实电机输出 */
uint16_t expect_speedr;
uint16_t real_speedr; /* 真实速度 */
uint16_t real_motor_outputr; /* 真实电机输出 */
} modbus_data_type_t;
extern modbus_data_type_t *modbus_data;
extern uint16_t crc16(uint8_t *puchMsg, uint16_t usDataLen);
int isBitHI(uint16_t Add);
extern int ModbusSlaveProcess(uint8_t *txbuf, uint8_t *rxbuf, uint16_t rxLen, int is_crc);
void ModBusWordWriteHook(uint16_t addr, uint16_t length);
#endif