My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hexdump.h 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * Contact information
  19. * -------------------
  20. *
  21. * Circuits At Home, LTD
  22. * Web : http://www.circuitsathome.com
  23. * e-mail : support@circuitsathome.com
  24. */
  25. #pragma once
  26. #ifndef _usb_h_
  27. #error "Never include hexdump.h directly; include Usb.h instead"
  28. #endif
  29. extern int UsbDEBUGlvl;
  30. template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
  31. class HexDumper : public BASE_CLASS {
  32. uint8_t byteCount;
  33. OFFSET_TYPE byteTotal;
  34. public:
  35. HexDumper() : byteCount(0), byteTotal(0) {
  36. };
  37. void Initialize() {
  38. byteCount = 0;
  39. byteTotal = 0;
  40. };
  41. void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset);
  42. };
  43. template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
  44. void HexDumper<BASE_CLASS, LEN_TYPE, OFFSET_TYPE>::Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset __attribute__((unused))) {
  45. if (UsbDEBUGlvl >= 0x80) { // Fully bypass this block of code if we do not debug.
  46. for (LEN_TYPE j = 0; j < len; j++, byteCount++, byteTotal++) {
  47. if (!byteCount) {
  48. PrintHex<OFFSET_TYPE > (byteTotal, 0x80);
  49. E_Notify(PSTR(": "), 0x80);
  50. }
  51. PrintHex<uint8_t > (pbuf[j], 0x80);
  52. E_Notify(PSTR(" "), 0x80);
  53. if (byteCount == 15) {
  54. E_Notify(PSTR("\r\n"), 0x80);
  55. byteCount = 0xFF;
  56. }
  57. }
  58. }
  59. }