You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#defineADDRESS_POS (6 * !localConfig.enableRtuOverTcp) // position of slave address in the incoming TCP/UDP message (0 for Modbus RTU over TCP/UDP and 6 for Modbus RTU over TCP/UDP)
29
+
// Stored in "header.requestType"
30
+
#definePRIORITY_REQUEST B10000000 // Request to slave which is not "nonresponding"
31
+
#defineSCAN_REQUEST B01000000 // Request triggered by slave scanner
32
+
#defineUDP_REQUEST B00100000 // UDP request
33
+
#defineTCP_REQUEST B00001111 // TCP request, also stores TCP client number
30
34
31
35
enum status : byte {
32
36
STAT_OK, // Slave Responded
@@ -40,8 +44,10 @@ enum status : byte {
40
44
// bool arrays for storing Modbus RTU status of individual slaves
41
45
uint8_t stat[STAT_NUM][(maxSlaves + 1 + 7) / 8];
42
46
43
-
// Scan request is in queue
44
-
bool scanInQueue = false;
47
+
// Scan request is in the queue
48
+
bool scanReqInQueue = false;
49
+
// Counter for priority requests in the queue
50
+
byte priorityReqInQueue;
45
51
46
52
// array for storing error counts
47
53
uint16_t errorCount[STAT_NUM];
@@ -57,7 +63,7 @@ typedef struct {
57
63
byte msgLen; // lenght of Modbus message stored in queueData
58
64
IPAddress remIP; // remote IP for UDP client (UDP response is sent back to remote IP)
59
65
unsignedint remPort; // remote port for UDP client (UDP response is sent back to remote port)
60
-
byte clientNum; // TCP client who sent the request, UDP_REQUEST (0xFF) designates UDP client
66
+
byte requestType; // TCP client who sent the request
61
67
byte atts; // attempts counter
62
68
} header;
63
69
@@ -146,16 +152,16 @@ void recvTcp() {
146
152
147
153
voidprocessRequests() {
148
154
// Insert scan request into queue, allow only one scan request in a queue
byte addressPos = 6 * !localConfig.enableRtuOverTcp; // position of slave address in the incoming TCP/UDP message (0 for Modbus RTU over TCP/UDP and 6 for Modbus RTU over TCP/UDP)
186
190
if (localConfig.enableRtuOverTcp) { // check CRC for Modbus RTU over TCP/UDP
if (queueData[0] == 0x00) { // Modbus broadcast - we do not count attempts and delete immediatelly
63
+
if (queueData[0] == 0x00) { // Modbus broadcast - we do not count attempts and delete immediatelly
64
64
serialState = IDLE;
65
65
deleteRequest();
66
66
} else {
@@ -93,41 +93,43 @@ void recvSerial() {
93
93
// Process Serial data
94
94
// Checks: 1) RTU frame is without errors; 2) CRC; 3) address of incoming packet against first request in queue; 4) only expected responses are forwarded to TCP/UDP
0 commit comments