QuakeGod
2024-09-02 7eb19e6024af7f05cf94c66fb843439a3509147e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
  ******************************************************************************
  * @file           : ModbusRTU.h
  * @brief          : Header for ModbusRTU.c file.
  *                   This file contains the common defines of the ModbusRTU protocol.
  ******************************************************************************
    */
#ifndef __MODBUSRTU_H__
#define __MODBUSRTU_H__
 
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef int int32_t;
 
/*
enum enResult
{
    S_OK = 0,
    S_ERR = 1,
};
*/
enum enModbusRTUCmd
{
    None =0,
    ReadCoils =1, //读线圈
    ReadInputs =2,  //读离散量输入
    ReadKeepRegs =3,    //读保持寄存器
    ReadInputRegs =4,    //读输入寄存器
    WriteCoil = 5,        //写单个线圈
    WriteReg =6,        //写单个寄存器
    ReadExptStat = 7,  //读取异常状态
    FetchCommEventCtr =11,   //Fetch Comm Event Ctr
                                                     // 12 Fetch Comm Event Log
                                                    
    WriteCoils =15,                //写多个线圈
    WriteRegs = 16,        //写多个寄存器
                                        //17 Report Slave ID
                                        //20 Read General Reference
                                        //21 Write General Reference
                                        //22 Mask Write 4X Register
                                        // 23 Read/Write 4X Registers
                                        //24 Read FIFO Queue
    
};
#pragma anon_unions
typedef struct tagModBusRTUReqPkg
{
    uchar Dst;
    uchar Cmd;
    union    {
        ushort Addr;
        struct        {
            uchar AddrH;
            uchar AddrL;
        };
    };
    union
    {
        ushort nCount;
        struct 
        {
            uchar CountH;
            uchar CountL;
        };
    };
}stModBusRTUReqPkg, *pModBusRTUReqPkg;
 
typedef struct tagModBusRTUReplyPkg
{
    uchar Dst;
    uchar Cmd;
    uchar nByteCount;
    uchar Datas[1];
}stModBusRTUReplyPkg, *pModBusRTUReplyPkg;
 
//int ModBusCRC16(void * pBuf, int len1);
uint16_t crc16tablefast(const uint8_t *ptr, uint16_t len);
 
int ModBusSlaveCheckPkg(int nChn, void * pPkg, uint16_t len1);
 
int ModBusSlaveParsePkg(int nChn, void * pPkg, uint16_t len1);
 
 
 
#endif    /* __MODBUSRTU_H__ */