ua_debug_dump_pkgs.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  5. */
  6. #include "ua_util_internal.h"
  7. #include <ctype.h>
  8. #include <stdio.h>
  9. #ifdef UA_DEBUG_DUMP_PKGS
  10. void UA_dump_hex_pkg(UA_Byte* buffer, size_t bufferLen) {
  11. printf("--------------- HEX Package Start ---------------\n");
  12. char ascii[17];
  13. memset(ascii,0,17);
  14. for (size_t i = 0; i < bufferLen; i++)
  15. {
  16. if (i == 0)
  17. printf("%08zx ", i);
  18. else if (i%16 == 0)
  19. printf(" |%s|\n%08zx ", ascii, i);
  20. if (isprint((int)(buffer[i])))
  21. ascii[i%16] = (char)buffer[i];
  22. else
  23. ascii[i%16] = '.';
  24. if (i%8==0)
  25. printf(" ");
  26. printf("%02X ", (unsigned char)buffer[i]);
  27. }
  28. size_t fillPos = bufferLen %16;
  29. ascii[fillPos] = 0;
  30. for (size_t i=fillPos; i<16; i++) {
  31. if (i%8==0)
  32. printf(" ");
  33. printf(" ");
  34. }
  35. printf(" |%s|\n%08zx\n", ascii, bufferLen);
  36. printf("--------------- HEX Package END ---------------\n");
  37. }
  38. #endif