ua_debug_dump_pkgs.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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.h"
  7. #include <ctype.h>
  8. #include <stdio.h>
  9. void UA_dump_hex_pkg(UA_Byte* buffer, size_t bufferLen) {
  10. printf("--------------- HEX Package Start ---------------\n");
  11. char ascii[17];
  12. memset(ascii,0,17);
  13. for (size_t i = 0; i < bufferLen; i++)
  14. {
  15. if (i == 0)
  16. printf("%08zx ", i);
  17. else if (i%16 == 0)
  18. printf(" |%s|\n%08zx ", ascii, i);
  19. if (isprint((int)(buffer[i])))
  20. ascii[i%16] = (char)buffer[i];
  21. else
  22. ascii[i%16] = '.';
  23. if (i%8==0)
  24. printf(" ");
  25. printf("%02X ", (unsigned char)buffer[i]);
  26. }
  27. size_t fillPos = bufferLen %16;
  28. ascii[fillPos] = 0;
  29. for (size_t i=fillPos; i<16; i++) {
  30. if (i%8==0)
  31. printf(" ");
  32. printf(" ");
  33. }
  34. printf(" |%s|\n%08zx\n", ascii, bufferLen);
  35. printf("--------------- HEX Package END ---------------\n");
  36. }