-
Notifications
You must be signed in to change notification settings - Fork 47
/
MQTT_Globals.SCL
93 lines (77 loc) · 2.61 KB
/
MQTT_Globals.SCL
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
88
89
90
91
92
93
DATA_BLOCK mqttData
TITLE = 'MQTT DATABLOCK'
AUTHOR : Brand
STRUCT
// TCP Incoming
tcpRecBuf : ARRAY[0..8192] OF BYTE;
pRec : INT; // Next incoming byte pos
pRead : INT; // Next byte to process
RecBufFull : BOOL; // Overflow
// TCP Outgoing
tcpSendBuf : ARRAY[0..4096] OF BYTE;
reqSend : BOOL;
sendSize : INT;
buffer : ARRAY[0..4096] OF BYTE;
nextMsgId : INT;
_state : INT := -1;
packet_state : INT;
pingOutstanding : BOOL;
lastInActivity : TIME;
lastOutActivity : TIME;
runTime : TIME;
ethTCPConnected : BOOL;
mqttErrorCode : INT := 0;
recPublishPacketID : INT := 0;
tcp_sendBufferFull : BOOL := false;
END_STRUCT
BEGIN
END_DATA_BLOCK
(**************************************************************)
DATA_BLOCK mqttGlobals
TITLE = 'MQTT CONSTANTS'
AUTHOR : Brand
STRUCT
MQTT_KEEPALIVE : TIME := T#15s;
MQTT_SOCKET_TIMEOUT : TIME := T#15s;
TCP_RECVBUFFERSIZE : INT := 8192; // size of TCP receive buffer
TCP_MAXRECVSIZE : INT := 4096; // TCP max receive packet size
TCP_SENDBUFFERSIZE : INT := 4096;
TCP_TIMEOUT : TIME := T#30s; // timeout value for TCP connection
// MQtt States
MQTT_STATE_DISCONNECT : INT := -6;
MQTT_STATE_DISCONNECTING : INT := -5;
MQTT_CONNECTION_TIMEOUT : INT := -4;
MQTT_CONNECTION_LOST : INT := -3;
MQTT_CONNECT_FAILED : INT := -2;
MQTT_DISCONNECTED : INT := -1;
MQTT_CONNECTING : INT := 0;
MQTT_CONNECTED : INT := 1;
MQTT_CONN_ACCEPTED : INT := 0;
MQTT_CONN_BAD_PROTOCOL : INT := 1;
MQTT_CONN_BAD_CLIENT_ID : INT := 2;
MQTT_CONN_SRVUNAVAIL : INT := 3;
MQTT_CONN_BAD_CREDEN : INT := 4;
MQTT_CONN_UNAUTHORIZED : INT := 5;
// Packet headers
MQTTCONNECT : INT := 16;
MQTTCONNACK : INT := 32;
MQTTPUBLISH : INT := 48;
MQTTPUBACK : INT := 64;
MQTTPUBREC : INT := 80;
MQTTPUBREL : INT := 96;
MQTTPUBCOMP : INT := 112;
MQTTSUBSCRIBE : INT := 130;
MQTTSUBACK : INT := 144;
MQTTUNSUBSCRIBE : INT := 160;
MQTTUNSUBACK : INT := 176;
MQTTPINGREQ : INT := 192;
MQTTPINGRESP : INT := 208;
MQTTDISCONNECT : INT := 224;
MQTTReserved : INT := 240;
MQTTQOS0 : INT := 0;
MQTTQOS1 : INT := 1;
MQTTQOS2 : INT := 2;
END_STRUCT
BEGIN
END_DATA_BLOCK
(**************************************************************)