modbus_debug.c
Go to the documentation of this file.
1 /**
2  * @file modbus_debug.c
3  * @brief Data logging functions for debugging purpose (Modbus/TCP)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL MODBUS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "modbus/modbus_client.h"
37 #include "modbus/modbus_server.h"
38 #include "modbus/modbus_debug.h"
39 #include "debug.h"
40 
41 //Check TCP/IP stack configuration
42 #if (MODBUS_CLIENT_SUPPORT == ENABLED || MODBUS_SERVER_SUPPORT == ENABLED)
43 
44 //Modbus functions codes
46 {
47  "", //0
48  "Read Coils", //1
49  "Read Discrete Inputs", //2
50  "Read Holding Registers", //3
51  "Read Input Registers", //4
52  "Write Single Coil", //5
53  "Write Single Register", //6
54  "Read Exception Status", //7
55  "Diagnostics", //8
56  "", //9
57  "", //10
58  "Get Comm Event Counter", //11
59  "Get Comm Event Log", //12
60  "", //13
61  "", //14
62  "Write Multiple Coils", //15
63  "Write Multiple Registers", //16
64  "Report Slave ID", //17
65  "", //18
66  "", //19
67  "Read File Record", //20
68  "Write File Record", //21
69  "Mask Write Register", //22
70  "Read/Write Multiple Registers", //23
71  "Read FIFO Queue" //24
72 };
73 
74 //Modbus exception codes
76 {
77  "", //0
78  "Illegal Function", //1
79  "Illegal Data Address", //2
80  "Illegal Data Value", //3
81  "Slave Device Failure", //4
82  "Acknowledge", //5
83  "Slave Device Busy", //6
84  "", //7
85  "Memory Parity Error", //8
86  "", //9
87  "Gateway Path Unavailable", //10
88  "Gateway Target Device Failed To Respond" //11
89 };
90 
91 
92 /**
93  * @brief Dump Modbus request PDU for debugging purpose
94  * @param[in] pdu Pointer to the Modbus request PDU
95  * @param[in] length Length of the PDU, in bytes
96  * @return Error code
97  **/
98 
99 error_t modbusDumpRequestPdu(const void *pdu, size_t length)
100 {
101 #if (MODBUS_TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
102  error_t error;
103  uint8_t functionCode;
104  const char_t *label;
105 
106  //Sanity check
107  if(length == 0)
108  return ERROR_INVALID_LENGTH;
109 
110  //Retrieve function code
111  functionCode = *((uint8_t *) pdu);
112 
113  //Retrieve the name associated with the function code
116  else
117  label = "";
118 
119  //Dump function code
120  TRACE_DEBUG(" Function Code = %" PRIu8 " (%s)\r\n", functionCode, label);
121 
122  //Check function code
123  switch(functionCode)
124  {
125  //Read Coils request?
127  //Dump Modbus PDU
129  break;
130  //Format Read Discrete Inputs request?
132  //Dump Modbus PDU
134  break;
135  //Read Holding Registers request?
137  //Dump Modbus PDU
139  break;
140  //Read Input Registers request?
142  //Dump Modbus PDU
144  break;
145  //Write Single Coil request?
147  //Dump Modbus PDU
149  break;
150  //Write Single Register request?
152  //Dump Modbus PDU
154  break;
155  //Write Multiple Coils request?
157  //Dump Modbus PDU
159  break;
160  //Write Multiple Registers request?
162  //Dump Modbus PDU
164  break;
165  //Mask Write Register request?
167  //Dump Modbus PDU
169  break;
170  //Read/Write Multiple Registers request?
172  //Dump Modbus PDU
174  break;
175  //Illegal function code?
176  default:
177  //Report an error
179  break;
180  }
181 
182  //Return error code
183  return error;
184 #else
185  //Not implemented
186  return NO_ERROR;
187 #endif
188 }
189 
190 
191 /**
192  * @brief Dump Modbus response PDU for debugging purpose
193  * @param[in] pdu Pointer to the Modbus response PDU
194  * @param[in] length Length of the PDU, in bytes
195  * @return Error code
196  **/
197 
199 {
200 #if (MODBUS_TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
201  error_t error;
202  uint8_t functionCode;
203  const char_t *label;
204 
205  //Sanity check
206  if(length == 0)
207  return ERROR_INVALID_LENGTH;
208 
209  //Retrieve function code
210  functionCode = *((uint8_t *) pdu);
211 
212  //Exception response?
214  {
215  //Dump Modbus PDU
217  }
218  else
219  {
220  //Retrieve the name associated with the function code
223  else
224  label = "";
225 
226  //Dump function code
227  TRACE_DEBUG(" Function Code = %" PRIu8 " (%s)\r\n", functionCode, label);
228 
229  //Check function code
230  switch(functionCode)
231  {
232  //Read Coils response?
234  //Dump Modbus PDU
236  break;
237  //Format Read Discrete Inputs response?
239  //Dump Modbus PDU
241  break;
242  //Read Holding Registers response?
244  //Dump Modbus PDU
246  break;
247  //Read Input Registers response?
249  //Dump Modbus PDU
251  break;
252  //Write Single Coil response?
254  //Dump Modbus PDU
256  break;
257  //Write Single Register response?
259  //Dump Modbus PDU
261  break;
262  //Write Multiple Coils response?
264  //Dump Modbus PDU
266  break;
267  //Write Multiple Registers response?
269  //Dump Modbus PDU
271  break;
272  //Mask Write Register response?
274  //Dump Modbus PDU
276  break;
277  //Read/Write Multiple Registers response?
279  //Dump Modbus PDU
281  break;
282  //Illegal function code?
283  default:
284  //Report an error
286  break;
287  }
288  }
289 
290  //Return error code
291  return error;
292 #else
293  //Not implemented
294  return NO_ERROR;
295 #endif
296 }
297 
298 
299 /**
300  * @brief Dump Read Coils request
301  * @param[in] request Pointer to the request PDU
302  * @param[in] length Length of the request PDU, in bytes
303  * @return Error code
304  **/
305 
307  size_t length)
308 {
309  //Malformed request PDU?
310  if(length < sizeof(ModbusReadCoilsReq))
311  return ERROR_INVALID_LENGTH;
312 
313  //Dump request PDU
314  TRACE_DEBUG(" Starting Address = %" PRIu16 "\r\n", ntohs(request->startingAddr));
315  TRACE_DEBUG(" Quantity of Coils = %" PRIu16 "\r\n", ntohs(request->quantityOfCoils));
316 
317  //Successful processing
318  return NO_ERROR;
319 }
320 
321 
322 /**
323  * @brief Dump Read Coils response
324  * @param[in] response Pointer to the response PDU
325  * @param[in] length Length of the response PDU, in bytes
326  * @return Error code
327  **/
328 
330  size_t length)
331 {
332  //Malformed response PDU?
333  if(length < sizeof(ModbusReadCoilsResp))
334  return ERROR_INVALID_LENGTH;
335 
336  //Calculate the length of the data field
337  length -= sizeof(ModbusReadCoilsResp);
338 
339  //Dump response PDU
340  TRACE_DEBUG(" Byte Count = %" PRIu16 "\r\n", response->byteCount);
341  TRACE_DEBUG_ARRAY(" Coil Status = ", response->coilStatus, length);
342 
343  //Successful processing
344  return NO_ERROR;
345 }
346 
347 
348 /**
349  * @brief Dump Read Discrete Inputs request
350  * @param[in] request Pointer to the request PDU
351  * @param[in] length Length of the request PDU, in bytes
352  * @return Error code
353  **/
354 
356  size_t length)
357 {
358  //Malformed request PDU?
359  if(length < sizeof(ModbusReadDiscreteInputsReq))
360  return ERROR_INVALID_LENGTH;
361 
362  //Dump request PDU
363  TRACE_DEBUG(" Starting Address = %" PRIu16 "\r\n", ntohs(request->startingAddr));
364  TRACE_DEBUG(" Quantity of Inputs = %" PRIu16 "\r\n", ntohs(request->quantityOfInputs));
365 
366  //Successful processing
367  return NO_ERROR;
368 }
369 
370 
371 /**
372  * @brief Dump Read Discrete Inputs response
373  * @param[in] response Pointer to the response PDU
374  * @param[in] length Length of the response PDU, in bytes
375  * @return Error code
376  **/
377 
379  size_t length)
380 {
381  //Malformed response PDU?
383  return ERROR_INVALID_LENGTH;
384 
385  //Calculate the length of the data field
387 
388  //Dump response PDU
389  TRACE_DEBUG(" Byte Count = %" PRIu16 "\r\n", response->byteCount);
390  TRACE_DEBUG_ARRAY(" Input Status = ", response->inputStatus, length);
391 
392  //Successful processing
393  return NO_ERROR;
394 }
395 
396 
397 /**
398  * @brief Dump Read Holding Registers request
399  * @param[in] request Pointer to the request PDU
400  * @param[in] length Length of the request PDU, in bytes
401  * @return Error code
402  **/
403 
405  size_t length)
406 {
407  //Malformed request PDU?
408  if(length < sizeof(ModbusReadHoldingRegsReq))
409  return ERROR_INVALID_LENGTH;
410 
411  //Dump request PDU
412  TRACE_DEBUG(" Starting Address = %" PRIu16 "\r\n", ntohs(request->startingAddr));
413  TRACE_DEBUG(" Quantity of Registers = %" PRIu16 "\r\n", ntohs(request->quantityOfRegs));
414 
415  //Successful processing
416  return NO_ERROR;
417 }
418 
419 
420 /**
421  * @brief Dump Read Holding Registers response
422  * @param[in] response Pointer to the response PDU
423  * @param[in] length Length of the response PDU, in bytes
424  * @return Error code
425  **/
426 
428  size_t length)
429 {
430  //Malformed response PDU?
431  if(length < sizeof(ModbusReadHoldingRegsResp))
432  return ERROR_INVALID_LENGTH;
433 
434  //Calculate the length of the data field
436 
437  //Dump response PDU
438  TRACE_DEBUG(" Byte Count = %" PRIu16 "\r\n", response->byteCount);
439  TRACE_DEBUG_ARRAY(" Register Value = ", (void *) response->regValue, length);
440 
441  //Successful processing
442  return NO_ERROR;
443 }
444 
445 
446 /**
447  * @brief Dump Read Input Registers request
448  * @param[in] request Pointer to the request PDU
449  * @param[in] length Length of the request PDU, in bytes
450  * @return Error code
451  **/
452 
454  size_t length)
455 {
456  //Malformed request PDU?
457  if(length < sizeof(ModbusReadInputRegsReq))
458  return ERROR_INVALID_LENGTH;
459 
460  //Dump request PDU
461  TRACE_DEBUG(" Starting Address = %" PRIu16 "\r\n", ntohs(request->startingAddr));
462  TRACE_DEBUG(" Quantity of Registers = %" PRIu16 "\r\n", ntohs(request->quantityOfRegs));
463 
464  //Successful processing
465  return NO_ERROR;
466 }
467 
468 
469 /**
470  * @brief Dump Read Input Registers response
471  * @param[in] response Pointer to the response PDU
472  * @param[in] length Length of the response PDU, in bytes
473  * @return Error code
474  **/
475 
477  size_t length)
478 {
479  //Malformed response PDU?
480  if(length < sizeof(ModbusReadInputRegsResp))
481  return ERROR_INVALID_LENGTH;
482 
483  //Calculate the length of the data field
484  length -= sizeof(ModbusReadInputRegsResp);
485 
486  //Dump response PDU
487  TRACE_DEBUG(" Byte Count = %" PRIu16 "\r\n", response->byteCount);
488  TRACE_DEBUG_ARRAY(" Register Value = ", (void *) response->regValue, length);
489 
490  //Successful processing
491  return NO_ERROR;
492 }
493 
494 
495 /**
496  * @brief Dump Write Single Coil request
497  * @param[in] request Pointer to the request PDU
498  * @param[in] length Length of the request PDU, in bytes
499  * @return Error code
500  **/
501 
503  size_t length)
504 {
505  //Malformed request PDU?
506  if(length < sizeof(ModbusWriteSingleCoilReq))
507  return ERROR_INVALID_LENGTH;
508 
509  //Dump request PDU
510  TRACE_DEBUG(" Output Address = %" PRIu16 "\r\n", ntohs(request->outputAddr));
511  TRACE_DEBUG(" Output Value = %" PRIu16 "\r\n", ntohs(request->outputValue));
512 
513  //Successful processing
514  return NO_ERROR;
515 }
516 
517 
518 /**
519  * @brief Dump Write Single Coil response
520  * @param[in] response Pointer to the response PDU
521  * @param[in] length Length of the response PDU, in bytes
522  * @return Error code
523  **/
524 
526  size_t length)
527 {
528  //Malformed response PDU?
529  if(length < sizeof(ModbusWriteSingleCoilResp))
530  return ERROR_INVALID_LENGTH;
531 
532  //Dump response PDU
533  TRACE_DEBUG(" Output Address = %" PRIu16 "\r\n", ntohs(response->outputAddr));
534  TRACE_DEBUG(" Output Value = %" PRIu16 "\r\n", ntohs(response->outputValue));
535 
536  //Successful processing
537  return NO_ERROR;
538 }
539 
540 
541 /**
542  * @brief Dump Write Single Register request
543  * @param[in] request Pointer to the request PDU
544  * @param[in] length Length of the request PDU, in bytes
545  * @return Error code
546  **/
547 
549  size_t length)
550 {
551  //Malformed request PDU?
552  if(length < sizeof(ModbusWriteSingleRegReq))
553  return ERROR_INVALID_LENGTH;
554 
555  //Dump request PDU
556  TRACE_DEBUG(" Register Address = %" PRIu16 "\r\n", ntohs(request->regAddr));
557  TRACE_DEBUG(" Register Value = %" PRIu16 "\r\n", ntohs(request->regValue));
558 
559  //Successful processing
560  return NO_ERROR;
561 }
562 
563 
564 /**
565  * @brief Dump Write Single Register response
566  * @param[in] response Pointer to the response PDU
567  * @param[in] length Length of the response PDU, in bytes
568  * @return Error code
569  **/
570 
572  size_t length)
573 {
574  //Malformed response PDU?
575  if(length < sizeof(ModbusWriteSingleRegResp))
576  return ERROR_INVALID_LENGTH;
577 
578  //Dump response PDU
579  TRACE_DEBUG(" Register Address = %" PRIu16 "\r\n", ntohs(response->regAddr));
580  TRACE_DEBUG(" Register Value = %" PRIu16 "\r\n", ntohs(response->regValue));
581 
582  //Successful processing
583  return NO_ERROR;
584 }
585 
586 
587 /**
588  * @brief Dump Write Multiple Coils request
589  * @param[in] request Pointer to the request PDU
590  * @param[in] length Length of the request PDU, in bytes
591  * @return Error code
592  **/
593 
595  size_t length)
596 {
597  //Malformed request PDU?
598  if(length < sizeof(ModbusWriteMultipleCoilsReq))
599  return ERROR_INVALID_LENGTH;
600 
601  //Calculate the length of the data field
603 
604  //Dump request PDU
605  TRACE_DEBUG(" Starting Address = %" PRIu16 "\r\n", ntohs(request->startingAddr));
606  TRACE_DEBUG(" Quantity of Outputs = %" PRIu16 "\r\n", ntohs(request->quantityOfOutputs));
607  TRACE_DEBUG(" Byte Count = %" PRIu16 "\r\n", request->byteCount);
608  TRACE_DEBUG_ARRAY(" Output Value = ", request->outputValue, length);
609 
610  //Successful processing
611  return NO_ERROR;
612 }
613 
614 
615 /**
616  * @brief Dump Write Multiple Coils response
617  * @param[in] response Pointer to the response PDU
618  * @param[in] length Length of the response PDU, in bytes
619  * @return Error code
620  **/
621 
623  size_t length)
624 {
625  //Malformed response PDU?
627  return ERROR_INVALID_LENGTH;
628 
629  //Dump response PDU
630  TRACE_DEBUG(" Starting Address = %" PRIu16 "\r\n", ntohs(response->startingAddr));
631  TRACE_DEBUG(" Quantity of Outputs = %" PRIu16 "\r\n", ntohs(response->quantityOfOutputs));
632 
633  //Successful processing
634  return NO_ERROR;
635 }
636 
637 
638 /**
639  * @brief Dump Write Multiple Registers request
640  * @param[in] request Pointer to the request PDU
641  * @param[in] length Length of the request PDU, in bytes
642  * @return Error code
643  **/
644 
646  size_t length)
647 {
648  //Malformed request PDU?
649  if(length < sizeof(ModbusWriteMultipleRegsReq))
650  return ERROR_INVALID_LENGTH;
651 
652  //Calculate the length of the data field
654 
655  //Dump request PDU
656  TRACE_DEBUG(" Starting Address = %" PRIu16 "\r\n", ntohs(request->startingAddr));
657  TRACE_DEBUG(" Quantity of Registers = %" PRIu16 "\r\n", ntohs(request->quantityOfRegs));
658  TRACE_DEBUG(" Byte Count = %" PRIu16 "\r\n", request->byteCount);
659  TRACE_DEBUG_ARRAY(" Register Value = ", (void *) request->regValue, length);
660 
661  //Successful processing
662  return NO_ERROR;
663 }
664 
665 
666 /**
667  * @brief Dump Write Multiple Registers response
668  * @param[in] response Pointer to the response PDU
669  * @param[in] length Length of the response PDU, in bytes
670  * @return Error code
671  **/
672 
674  size_t length)
675 {
676  //Malformed response PDU?
677  if(length < sizeof(ModbusWriteMultipleRegsResp))
678  return ERROR_INVALID_LENGTH;
679 
680  //Dump response PDU
681  TRACE_DEBUG(" Starting Address = %" PRIu16 "\r\n", ntohs(response->startingAddr));
682  TRACE_DEBUG(" Quantity of Registers = %" PRIu16 "\r\n", ntohs(response->quantityOfRegs));
683 
684  //Successful processing
685  return NO_ERROR;
686 }
687 
688 
689 /**
690  * @brief Dump Mask Write Register request
691  * @param[in] request Pointer to the request PDU
692  * @param[in] length Length of the request PDU, in bytes
693  * @return Error code
694  **/
695 
697  size_t length)
698 {
699  //Malformed request PDU?
700  if(length < sizeof(ModbusMaskWriteRegReq))
701  return ERROR_INVALID_LENGTH;
702 
703  //Dump request PDU
704  TRACE_DEBUG(" Reference Address = %" PRIu16 "\r\n", ntohs(request->referenceAddr));
705  TRACE_DEBUG(" And Value = %" PRIu16 "\r\n", ntohs(request->andMask));
706  TRACE_DEBUG(" Or Value = %" PRIu16 "\r\n", ntohs(request->orMask));
707 
708  //Successful processing
709  return NO_ERROR;
710 }
711 
712 
713 /**
714  * @brief Dump Mask Write Register response
715  * @param[in] response Pointer to the response PDU
716  * @param[in] length Length of the response PDU, in bytes
717  * @return Error code
718  **/
719 
721  size_t length)
722 {
723  //Malformed response PDU?
724  if(length < sizeof(ModbusMaskWriteRegResp))
725  return ERROR_INVALID_LENGTH;
726 
727  //Dump response PDU
728  TRACE_DEBUG(" Reference Address = %" PRIu16 "\r\n", ntohs(response->referenceAddr));
729  TRACE_DEBUG(" And Value = %" PRIu16 "\r\n", ntohs(response->andMask));
730  TRACE_DEBUG(" Or Value = %" PRIu16 "\r\n", ntohs(response->orMask));
731 
732  //Successful processing
733  return NO_ERROR;
734 }
735 
736 
737 /**
738  * @brief Dump Read Write Multiple Registers request
739  * @param[in] request Pointer to the request PDU
740  * @param[in] length Length of the request PDU, in bytes
741  * @return Error code
742  **/
743 
745  size_t length)
746 {
747  //Malformed request PDU?
749  return ERROR_INVALID_LENGTH;
750 
751  //Calculate the length of the data field
753 
754  //Dump request PDU
755  TRACE_DEBUG(" Read Starting Address = %" PRIu16 "\r\n", ntohs(request->readStartingAddr));
756  TRACE_DEBUG(" Quantity to Read = %" PRIu16 "\r\n", ntohs(request->quantityToRead));
757  TRACE_DEBUG(" Write Starting Address = %" PRIu16 "\r\n", ntohs(request->writeStartingAddr));
758  TRACE_DEBUG(" Quantity to Write = %" PRIu16 "\r\n", ntohs(request->quantityToWrite));
759  TRACE_DEBUG(" Write Byte Count = %" PRIu16 "\r\n", request->writeByteCount);
760  TRACE_DEBUG_ARRAY(" Write Register Value = ", (void *) request->writeRegValue, length);
761 
762  //Successful processing
763  return NO_ERROR;
764 }
765 
766 
767 /**
768  * @brief Dump Read Write Multiple Registers response
769  * @param[in] response Pointer to the response PDU
770  * @param[in] length Length of the response PDU, in bytes
771  * @return Error code
772  **/
773 
775  size_t length)
776 {
777  //Malformed response PDU?
779  return ERROR_INVALID_LENGTH;
780 
781  //Calculate the length of the data field
783 
784  //Dump response PDU
785  TRACE_DEBUG(" Read Byte Count = %" PRIu16 "\r\n", response->readByteCount);
786  TRACE_DEBUG_ARRAY(" Read Register Value = ", (void *) response->readRegValue, length);
787 
788  //Successful processing
789  return NO_ERROR;
790 }
791 
792 
793 /**
794  * @brief Dump Exception response
795  * @param[in] response Pointer to the response PDU
796  * @param[in] length Length of the response PDU, in bytes
797  * @return Error code
798  **/
799 
801  size_t length)
802 {
803 #if (MODBUS_TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
804  const char_t *label;
805 
806  //Malformed response PDU?
807  if(length < sizeof(ModbusExceptionResp))
808  return ERROR_INVALID_LENGTH;
809 
810  //Get the description of the exception code
811  if(response->exceptionCode < arraysize(modbusExceptionCodeLabel))
812  label = modbusExceptionCodeLabel[response->exceptionCode];
813  else
814  label = "";
815 
816  //Dump response PDU
817  TRACE_DEBUG(" Function Code = %" PRIu8 " (Exception)\r\n", response->functionCode);
818  TRACE_DEBUG(" Exception Code = %" PRIu16 " (%s)\r\n", response->exceptionCode, label);
819 #endif
820 
821  //Successful processing
822  return NO_ERROR;
823 }
824 
825 #endif
error_t modbusDumpRequestPdu(const void *pdu, size_t length)
Dump Modbus request PDU for debugging purpose.
Definition: modbus_debug.c:99
Modbus/TCP client.
uint8_t length
Definition: dtls_misc.h:149
__start_packed struct @228 ModbusReadWriteMultipleRegsResp
Read/Write Multiple Registers response PDU.
error_t modbusDumpWriteSingleCoilResp(const ModbusWriteSingleCoilResp *response, size_t length)
Dump Write Single Coil response.
Definition: modbus_debug.c:525
error_t modbusDumpReadDiscreteInputsReq(const ModbusReadDiscreteInputsReq *request, size_t length)
Dump Read Discrete Inputs request.
Definition: modbus_debug.c:355
error_t modbusDumpReadWriteMultipleRegsResp(const ModbusReadWriteMultipleRegsResp *response, size_t length)
Dump Read Write Multiple Registers response.
Definition: modbus_debug.c:774
error_t modbusDumpWriteSingleCoilReq(const ModbusWriteSingleCoilReq *request, size_t length)
Dump Write Single Coil request.
Definition: modbus_debug.c:502
__start_packed struct @222 ModbusWriteMultipleCoilsResp
Write Multiple Coils response PDU.
const char_t * modbusExceptionCodeLabel[]
Definition: modbus_debug.c:75
__start_packed struct @223 ModbusWriteMultipleRegsReq
Write Multiple Registers request PDU.
error_t modbusDumpResponsePdu(const void *pdu, size_t length)
Dump Modbus response PDU for debugging purpose.
Definition: modbus_debug.c:198
__start_packed struct @229 ModbusExceptionResp
Exception response PDU.
__start_packed struct @217 ModbusWriteSingleCoilReq
Write Single Coil request PDU.
__start_packed struct @210 ModbusReadCoilsResp
Read Coils response PDU.
__start_packed struct @224 ModbusWriteMultipleRegsResp
Write Multiple Registers response PDU.
error_t modbusDumpReadCoilsReq(const ModbusReadCoilsReq *request, size_t length)
Dump Read Coils request.
Definition: modbus_debug.c:306
error_t modbusDumpReadInputRegsResp(const ModbusReadInputRegsResp *response, size_t length)
Dump Read Input Registers response.
Definition: modbus_debug.c:476
@ MODBUS_FUNCTION_READ_DISCRETE_INPUTS
Definition: modbus_common.h:77
error_t modbusDumpReadCoilsResp(const ModbusReadCoilsResp *response, size_t length)
Dump Read Coils response.
Definition: modbus_debug.c:329
__start_packed struct @225 ModbusMaskWriteRegReq
Mask Write Register request PDU.
error_t modbusDumpReadWriteMultipleRegsReq(const ModbusReadWriteMultipleRegsReq *request, size_t length)
Dump Read Write Multiple Registers request.
Definition: modbus_debug.c:744
@ MODBUS_FUNCTION_READ_WRITE_MULTIPLE_REGS
Definition: modbus_common.h:92
error_t
Error codes.
Definition: error.h:42
__start_packed struct @214 ModbusReadHoldingRegsResp
Read Holding Registers response PDU.
error_t modbusDumpWriteMultipleCoilsResp(const ModbusWriteMultipleCoilsResp *response, size_t length)
Dump Write Multiple Coils response.
Definition: modbus_debug.c:622
Modbus/TCP server.
__start_packed struct @213 ModbusReadHoldingRegsReq
Read Holding Registers request PDU.
__start_packed struct @209 ModbusReadCoilsReq
Read Coils request PDU.
uint8_t pdu[]
error_t modbusDumpWriteMultipleRegsResp(const ModbusWriteMultipleRegsResp *response, size_t length)
Dump Write Multiple Registers response.
Definition: modbus_debug.c:673
@ MODBUS_FUNCTION_WRITE_MULTIPLE_REGS
Definition: modbus_common.h:87
#define MODBUS_EXCEPTION_MASK
Definition: modbus_common.h:55
__start_packed struct @219 ModbusWriteSingleRegReq
Write Single Register request PDU.
error_t modbusDumpMaskWriteRegReq(const ModbusMaskWriteRegReq *request, size_t length)
Dump Mask Write Register request.
Definition: modbus_debug.c:696
@ ERROR_INVALID_LENGTH
Definition: error.h:109
__start_packed struct @221 ModbusWriteMultipleCoilsReq
Write Multiple Coils request PDU.
error_t modbusDumpWriteSingleRegResp(const ModbusWriteSingleRegResp *response, size_t length)
Dump Write Single Register response.
Definition: modbus_debug.c:571
@ MODBUS_FUNCTION_MASK_WRITE_REG
Definition: modbus_common.h:91
error_t modbusDumpReadHoldingRegsReq(const ModbusReadHoldingRegsReq *request, size_t length)
Dump Read Holding Registers request.
Definition: modbus_debug.c:404
__start_packed struct @227 ModbusReadWriteMultipleRegsReq
Read/Write Multiple Registers request PDU.
error_t modbusDumpWriteMultipleRegsReq(const ModbusWriteMultipleRegsReq *request, size_t length)
Dump Write Multiple Registers request.
Definition: modbus_debug.c:645
@ MODBUS_FUNCTION_WRITE_SINGLE_REG
Definition: modbus_common.h:81
@ MODBUS_FUNCTION_READ_INPUT_REGS
Definition: modbus_common.h:79
__start_packed struct @226 ModbusMaskWriteRegResp
Mask Write Register response PDU.
error_t modbusDumpReadHoldingRegsResp(const ModbusReadHoldingRegsResp *response, size_t length)
Dump Read Holding Registers response.
Definition: modbus_debug.c:427
error_t modbusDumpMaskWriteRegResp(const ModbusMaskWriteRegResp *response, size_t length)
Dump Mask Write Register response.
Definition: modbus_debug.c:720
__start_packed struct @218 ModbusWriteSingleCoilResp
Write Single Coil response PDU.
#define ntohs(value)
Definition: cpu_endian.h:398
__start_packed struct @211 ModbusReadDiscreteInputsReq
Read Discrete Inputs request PDU.
#define TRACE_DEBUG(...)
Definition: debug.h:106
char char_t
Definition: compiler_port.h:43
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:107
__start_packed struct @215 ModbusReadInputRegsReq
Read Holding Input request PDU.
Data logging functions for debugging purpose (Modbus/TCP)
error_t modbusDumpExceptionResp(const ModbusExceptionResp *response, size_t length)
Dump Exception response.
Definition: modbus_debug.c:800
__start_packed struct @220 ModbusWriteSingleRegResp
Write Single Register response PDU.
__start_packed struct @212 ModbusReadDiscreteInputsResp
Read Discrete Inputs response PDU.
const char_t * modbusFunctionCodeLabel[]
Definition: modbus_debug.c:45
@ MODBUS_FUNCTION_READ_HOLDING_REGS
Definition: modbus_common.h:78
error_t modbusDumpReadInputRegsReq(const ModbusReadInputRegsReq *request, size_t length)
Dump Read Input Registers request.
Definition: modbus_debug.c:453
error_t modbusDumpReadDiscreteInputsResp(const ModbusReadDiscreteInputsResp *response, size_t length)
Dump Read Discrete Inputs response.
Definition: modbus_debug.c:378
error_t modbusDumpWriteSingleRegReq(const ModbusWriteSingleRegReq *request, size_t length)
Dump Write Single Register request.
Definition: modbus_debug.c:548
@ MODBUS_FUNCTION_WRITE_SINGLE_COIL
Definition: modbus_common.h:80
uint8_t functionCode
TCP/IP stack core.
@ MODBUS_FUNCTION_WRITE_MULTIPLE_COILS
Definition: modbus_common.h:86
__start_packed struct @216 ModbusReadInputRegsResp
Read Holding Input response PDU.
@ MODBUS_FUNCTION_READ_COILS
Definition: modbus_common.h:76
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
#define arraysize(a)
Definition: os_port.h:70
@ ERROR_INVALID_FUNCTION_CODE
Definition: error.h:263
error_t modbusDumpWriteMultipleCoilsReq(const ModbusWriteMultipleCoilsReq *request, size_t length)
Dump Write Multiple Coils request.
Definition: modbus_debug.c:594