14 #include "unicodestringhandler.h"
18 #include "classnums.h"
20 #include "modbus_common.h"
24 #define DEBUG_MB_VERBOSE 0
29 #define MB_COMAPNY_ID 500
30 #define MB_NANO_PRODUCT_ID 0x3600
32 #define MAX_SERIAL_PORTS 1
33 #define MB_SLAVE_PORT_NUMBER (502)
35 #define OVER_RANGE 32767
36 #define UNDER_RANGE -32767
38 #define MAX_ALARMS_PER_POINT 2
43 #define SCALED_FORMAT 1
44 #define MB_BYTES_IN_WORD 2
45 #define UNCONFIGURED_REG 0x8000
46 #define REGISTER_65535 0xFFFF
47 #define LOW_WORD 0x0000FFFF
48 #define UPPER_WORD 0xFFFF0000
50 #define NETWORK_MAC_ADDRESS_START 0x5FE0
51 #define NETWORK_MAC_ADDRESS_END 0x5FEF
56 #define EXCEPTION_MSG_LENGTH 3
57 #define WRITE_REPLY_SIZE 6
58 #define WRITE_REPLY_SIZE_106 8
59 #define MIN_RAW_DATA_SIZE 2
60 #define EXCEPTION_ERROR 128
61 #define ILLEGAL_FUNCTION 1
62 #define ILLEGAL_ADDRESS 2
63 #define ILLEGAL_DATA_VALUE 3
64 #define SLAVE_DEVICE_FAIL 4
65 #define ILLEGAL_REGION 5
66 #define REGION_LOCKED 6
67 #define ILLEGAL_LOGIN_STATUS 10
68 #define SINGLE_REGISTER 1
73 #define MB_PID_SIZE 0x0000
74 #define MB_PID_START 0x0000
79 #define MB_INST_SIZE 0x007A
80 #define MB_INST_START 0x0001
81 #define MB_INST_GLOBAL_ALM_ACK 0x0020
83 #define MB_START_AT_CONFIG_COUNTER 21
84 #define INST_DESC_SIZE 20
85 #define MB_INST_TIME_DATE_SIZE 8
86 #define MB_INST_SPARE_1 75
90 #define MB_INST_SPARE_2 11
95 #define MB_FIT_SIZE 0x007A
96 #define MB_FIT_START 0xCC26
97 #define MB_NO_OF_FEATURES 0x0003
98 #define MB_INDIRECT_REF 0x0001
99 #define MB_FC_ID_REF 0x0004
100 #define MB_LOGIN_REF 0x0009
101 #define MB_SUPPORTED_FC 0x80AC //32940
102 #define MB_USERNAME_START 0xCC30
103 #define MB_PASSWORD_START 0xCC58
104 #define MB_USERNAME_SIZE 41
109 #define MB_RO_INDIRECT_SIZE 0x0201
110 #define MB_RO_INDIRECT_START 0xCCE5
111 #define MB_RO_INDIRECT_END 0xCEE5
112 #define MB_RO_DATA_ACCESS_START 0xCEE6
113 #define MB_RO_DATA_ACCESS_END 0xD0E5
114 #define MB_NUM_OF_RO_ENTRIES 512
119 #define MB_RW_INDIRECT_SIZE 0x0201
120 #define MB_RW_INDIRECT_START 0xD0E6
121 #define MB_RW_INDIRECT_END 0xD2E6
122 #define MB_RW_DATA_ACCESS_START 0xD2E7
123 #define MB_RW_DATA_ACCESS_END 0xD4E6
124 #define MB_NUM_OF_RW_ENTRIES 512
130 #define MB_GRP_SIZE 0x0275
131 #define MB_GRP_START 0xA4D6
132 #define MB_BATCH_TEXT_1_START 0xA57F
133 #define MB_BATCH_TEXT_2_START 0xA5BB
134 #define MB_BATCH_TEXT_3_START 0xA5F7
135 #define MB_BATCH_TEXT_4_START 0xA633
136 #define MB_BATCH_TEXT_5_START 0xA66F
137 #define MB_BATCH_TEXT_6_START 0xA6AB
138 #define MB_BATCH_START_1 0xA57C
139 #define MB_BATCH_STOP_1 0xA57D
140 #define MB_WRITE_TEXT_START_1 0xA540
141 #define MB_TEXT_LENGTH_GRP1 0xA4FF
142 #define MB_READ_TXT_GRP1_START 0xA4FF
143 #define MB_READ_TXT_GRP1_END 0xA53F
145 #define MB_TEXT_LEN_OFFSET 41
146 #define MB_TEXT_DATA_SIZE 65
148 #define MB_MAX_RAW_MSG_SIZE 500
151 #define GRP_DESC_SIZE 20
152 #define ASCII_GROUP_TEXT_SIZE 60
153 #define GROUP_NULL_TERMINATOR 59
154 #define ASCII_BATCH_TEXT_SIZE 60
155 #define UC_GROUP_TEXT_SIZE 120
156 #define GROUP_CONTENTS_SIZE 16
158 #define MB_QUEUE_SIZE 12000
160 #define MB_GRP_SPARE_1 10
161 #define MB_START_AT_TEXT_LEN 41
162 #define MB_GRP_MATHS_CHAN_START 4
163 #define MB_GRP_TOT_CHAN_START 10
164 #define MB_GRP_COUNT_CHAN_START 14
170 #define MB_FLOAT_SCALE 2
175 #define MB_PNT_CNFG_SIZE 162
176 #define MB_MAX_NUM_MODBUS_IP_CHANS 75
177 #define MB_MAX_NUM_EIP_CHANS 100
178 #define MB_MAX_NUM_MATHS 100
179 #define MB_MAX_NUM_TOTALISER 50
180 #define MB_MAX_NUM_COUNTERS 30
184 #define MB_MAX_CHANNELS 100
187 #define UNITS_TEXT_SIZE 5
188 #define OPEN_TEXT_SIZE 8
189 #define CLOSE_TEXT_SIZE 8
190 #define CHAN_DESC_SIZE 20
191 #define MB_PNT_ALRM_SIZE 13
192 #define MB_PNT_CNFG_SPARE_1 60
193 #define MB_PNT_CNFG_SPARE_2 10
196 #define MB_PNT_IEEE_CNFG_SIZE 36
197 #define MB_PNT_IEEE_SPARE_1 20
198 #define MB_PNT_IEEE_ALM_SIZE 2
203 #define MB_CHAN1_CNFG_START 0x007B
204 #define MB_CHAN1_ALARM_SP_1 0x00EB
205 #define MB_CHAN1_ALARM_SP_2 0x00F8
206 #define MB_CHAN1_ALARM_SP_3 0x0105
207 #define MB_CHAN1_ALARM_SP_4 0x0112
208 #define MB_CHAN1_MDP (MB_CHAN1_CNFG_START + 5)
214 #define MB_CHAN2_CNFG_START 0xFDA0
215 #define MB_CHAN2_ALARM_SP_1 0xFE10
216 #define MB_CHAN2_ALARM_SP_2 0xFE1D
217 #define MB_CHAN2_ALARM_SP_3 0xFE2A
218 #define MB_CHAN2_ALARM_SP_4 0xFE37
219 #define MB_CHAN2_MDP (MB_CHAN2_CNFG_START + 5)
224 #define MB_MATH1_CNFG_START (MB_CHAN1_CNFG_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
225 #define MB_MATH1_ALARM_SP_1 (MB_CHAN1_ALARM_SP_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
226 #define MB_MATH1_ALARM_SP_2 (MB_CHAN1_ALARM_SP_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
227 #define MB_MATH1_ALARM_SP_3 (MB_CHAN1_ALARM_SP_3 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
228 #define MB_MATH1_ALARM_SP_4 (MB_CHAN1_ALARM_SP_4 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
229 #define MB_MATH1_MDP (MB_MATH1_CNFG_START + 5)
234 #define MB_TOT1_CNFG_START (MB_MATH1_CNFG_START + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
235 #define MB_TOT1_ALARM_SP_1 (MB_MATH1_ALARM_SP_1 + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
236 #define MB_TOT1_ALARM_SP_2 (MB_MATH1_ALARM_SP_2 + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
237 #define MB_TOT1_ALARM_SP_3 (MB_MATH1_ALARM_SP_3 + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
238 #define MB_TOT1_ALARM_SP_4 (MB_MATH1_ALARM_SP_4 + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
239 #define MB_TOT1_MDP (MB_TOT1_CNFG_START + 5)
244 #define MB_COUNT1_CNFG_START (MB_TOT1_CNFG_START + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
245 #define MB_COUNT1_ALARM_SP_1 (MB_TOT1_ALARM_SP_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
246 #define MB_COUNT1_ALARM_SP_2 (MB_TOT1_ALARM_SP_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
247 #define MB_COUNT1_ALARM_SP_3 (MB_TOT1_ALARM_SP_3 + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
248 #define MB_COUNT1_ALARM_SP_4 (MB_TOT1_ALARM_SP_4 + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
249 #define MB_COUNT1_MDP (MB_COUNT1_CNFG_START + 5)
255 #define MB_CHAN1_IEEE_CNFG_START 0xD4E7
256 #define MB_CHAN1_IEEE_SP1_REG_1 0xD4EF
257 #define MB_CHAN1_IEEE_SP1_REG_2 0xD4F0
258 #define MB_CHAN1_IEEE_SP2_REG_1 0xD4F1
259 #define MB_CHAN1_IEEE_SP2_REG_2 0xD4F2
260 #define MB_CHAN1_IEEE_SP3_REG_1 0xD4F3
261 #define MB_CHAN1_IEEE_SP3_REG_2 0xD4F4
262 #define MB_CHAN1_IEEE_SP4_REG_1 0xD4F5
263 #define MB_CHAN1_IEEE_SP4_REG_2 0xD4F6
268 #define MB_MATH1_IEEE_CNFG_START (MB_CHAN1_IEEE_CNFG_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
269 #define MB_MATH1_IEEE_SP1_REG_1 (MB_CHAN1_IEEE_SP1_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
270 #define MB_MATH1_IEEE_SP1_REG_2 (MB_CHAN1_IEEE_SP1_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
271 #define MB_MATH1_IEEE_SP2_REG_1 (MB_CHAN1_IEEE_SP2_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
272 #define MB_MATH1_IEEE_SP2_REG_2 (MB_CHAN1_IEEE_SP2_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
273 #define MB_MATH1_IEEE_SP3_REG_1 (MB_CHAN1_IEEE_SP3_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
274 #define MB_MATH1_IEEE_SP3_REG_2 (MB_CHAN1_IEEE_SP3_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
275 #define MB_MATH1_IEEE_SP4_REG_1 (MB_CHAN1_IEEE_SP4_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
276 #define MB_MATH1_IEEE_SP4_REG_2 (MB_CHAN1_IEEE_SP4_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
281 #define MB_TOT1_IEEE_CNFG_START (MB_MATH1_IEEE_CNFG_START + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
282 #define MB_TOT1_IEEE_SP1_REG_1 (MB_MATH1_IEEE_SP1_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
283 #define MB_TOT1_IEEE_SP1_REG_2 (MB_MATH1_IEEE_SP1_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
284 #define MB_TOT1_IEEE_SP2_REG_1 (MB_MATH1_IEEE_SP2_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
285 #define MB_TOT1_IEEE_SP2_REG_2 (MB_MATH1_IEEE_SP2_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
286 #define MB_TOT1_IEEE_SP3_REG_1 (MB_MATH1_IEEE_SP3_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
287 #define MB_TOT1_IEEE_SP3_REG_2 (MB_MATH1_IEEE_SP3_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
288 #define MB_TOT1_IEEE_SP4_REG_1 (MB_MATH1_IEEE_SP4_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
289 #define MB_TOT1_IEEE_SP4_REG_2 (MB_MATH1_IEEE_SP4_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
294 #define MB_COUNT1_IEEE_CNFG_START (MB_TOT1_IEEE_CNFG_START + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
295 #define MB_COUNT1_IEEE_SP1_REG_1 (MB_TOT1_IEEE_SP1_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
296 #define MB_COUNT1_IEEE_SP1_REG_2 (MB_TOT1_IEEE_SP1_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
297 #define MB_COUNT1_IEEE_SP2_REG_1 (MB_TOT1_IEEE_SP2_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
298 #define MB_COUNT1_IEEE_SP2_REG_2 (MB_TOT1_IEEE_SP2_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
299 #define MB_COUNT1_IEEE_SP3_REG_1 (MB_TOT1_IEEE_SP3_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
300 #define MB_COUNT1_IEEE_SP3_REG_2 (MB_TOT1_IEEE_SP3_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
301 #define MB_COUNT1_IEEE_SP4_REG_1 (MB_TOT1_IEEE_SP4_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
302 #define MB_COUNT1_IEEE_SP4_REG_2 (MB_TOT1_IEEE_SP4_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
307 #define MB_PNT_RUN_SIZE 3
310 #define MB_PNT_IEEE_RUN_SIZE 4
315 #define MB_CHAN1_RUN_START 0xA1D9
316 #define MB_CHAN1_PV_1_START 0xA1D9
317 #define MB_CHAN1_ALARM_ACK 0xA1DB
323 #define MB_CHAN2_PNT_OFFSET MB_MAX_NUM_MODBUS_IP_CHANS
324 #define MB_CHAN2_RUN_START 0xFCBF
325 #define MB_CHAN2_PV_1_START 0xFCBF
326 #define MB_CHAN2_ALARM_ACK 0xFCC1
331 #define MB_MATH1_RUN_START (MB_CHAN1_RUN_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_RUN_SIZE))
332 #define MB_MATH1_PV_1_START (MB_CHAN1_PV_1_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_RUN_SIZE))
333 #define MB_MATH1_ALARM_ACK (MB_CHAN1_ALARM_ACK + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_RUN_SIZE))
338 #define MB_TOT1_RUN_START (MB_MATH1_RUN_START + (MB_MAX_NUM_MATHS * MB_PNT_RUN_SIZE))
339 #define MB_TOT1_PV_1_START (MB_MATH1_PV_1_START + (MB_MAX_NUM_MATHS * MB_PNT_RUN_SIZE))
340 #define MB_TOT1_ALARM_ACK (MB_MATH1_ALARM_ACK + (MB_MAX_NUM_MATHS * MB_PNT_RUN_SIZE))
345 #define MB_COUNT1_RUN_START (MB_TOT1_RUN_START + (MB_MAX_NUM_TOTALISER * MB_PNT_RUN_SIZE))
346 #define MB_COUNT1_PV_1_START (MB_TOT1_PV_1_START + (MB_MAX_NUM_TOTALISER * MB_PNT_RUN_SIZE))
347 #define MB_COUNT1_ALARM_ACK (MB_TOT1_ALARM_ACK + (MB_MAX_NUM_TOTALISER * MB_PNT_RUN_SIZE))
352 #define MB_CHAN1_IEEE_RUN_START 0xF8C3
353 #define MB_CHAN1_IEEE_PV_1_REG_1 0xF8C3
354 #define MB_CHAN1_IEEE_PV_1_REG_2 0xF8C4
355 #define MB_CHAN1_IEEE_ALARM_ACK 0xF8C6
360 #define MB_MATH1_IEEE_RUN_START (MB_CHAN1_IEEE_RUN_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_RUN_SIZE))
361 #define MB_MATH1_IEEE_PV_1_REG_1 (MB_CHAN1_IEEE_PV_1_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_RUN_SIZE))
362 #define MB_MATH1_IEEE_PV_1_REG_2 (MB_CHAN1_IEEE_PV_1_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_RUN_SIZE))
363 #define MB_MATH1_IEEE_ALARM_ACK (MB_CHAN1_IEEE_ALARM_ACK + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_RUN_SIZE))
368 #define MB_TOT1_IEEE_RUN_START (MB_MATH1_IEEE_RUN_START + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_RUN_SIZE))
369 #define MB_TOT1_IEEE_PV_1_REG_1 (MB_MATH1_IEEE_PV_1_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_RUN_SIZE))
370 #define MB_TOT1_IEEE_PV_1_REG_2 (MB_MATH1_IEEE_PV_1_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_RUN_SIZE))
371 #define MB_TOT1_IEEE_ALARM_ACK (MB_MATH1_IEEE_ALARM_ACK + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_RUN_SIZE))
376 #define MB_COUNT1_IEEE_RUN_START (MB_TOT1_IEEE_RUN_START + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_RUN_SIZE))
377 #define MB_COUNT1_IEEE_PV_1_REG_1 (MB_TOT1_IEEE_PV_1_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_RUN_SIZE))
378 #define MB_COUNT1_IEEE_PV_1_REG_2 (MB_TOT1_IEEE_PV_1_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_RUN_SIZE))
379 #define MB_COUNT1_IEEE_ALARM_ACK (MB_TOT1_IEEE_ALARM_ACK + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_RUN_SIZE))
384 #define MB_MEM_MAP_END 0xFFF5
389 #define DRV_NAME "DRVX"
390 #define SCOMMS1_NAME "SCX0"
391 #define CON_1_NAME "CX"
404 #define MB_MAX_TRANSACTION_SIZE 261 // to handle function codes 103/106 (used by GWE)
405 #define MB_MAX_REPLY_SIZE 260
406 #define MB_MAX_READ_REQ_SIZE 126
408 enum MB_TransactionParsing
454 SND_DATA_QTY_HI = 10,
455 SND_DATA_QTY_LO = 11,
460 WRITE_REPLY_START = 8,
462 READ_REPLY_START = 9,
463 DIAG_REPLY_START = 8,
466 enum MB_ExchangeCodes
475 enum MB_FunctionCodes
477 MB_FUNCTION_CODE_3 = 3,
478 MB_FUNCTION_CODE_4 = 4,
479 MB_FUNCTION_CODE_6 = 6,
480 MB_FUNCTION_CODE_8 = 8,
481 MB_FUNCTION_CODE_16 = 16,
484 MB_FUNCTION_CODE_103 = 103,
485 MB_FUNCTION_CODE_104 = 104,
486 MB_FUNCTION_CODE_106 = 106,
487 MB_FUNCTION_CODE_107 = 107
492 RETURN_QUERY_DATA = 0,
493 DIAG_00_REPLY_SIZE = 6
498 MAC_ADDRESS_WRITE = 1
501 enum MB_AddressRegions
512 MB_TOTALISER_RUNTIME,
522 MB_TOTALISER_IEEE_CONFIG,
523 MB_COUNTER_IEEE_CONFIG,
524 MB_CHAN_IEEE_RUNTIME,
525 MB_MATH_IEEE_RUNTIME,
526 MB_TOTALISER_IEEE_RUNTIME,
527 MB_COUNTER_IEEE_RUNTIME,
531 MB_MAX_NUMBER_OF_REGIONS = MB_PERMENANT_ID + 2
544 uint8 request[MB_MAX_TRANSACTION_SIZE];
548 uint8 reply[MB_MAX_REPLY_SIZE];
549 uint16 connectionNumber;