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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

hexdump.h 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  2. This software may be distributed and modified under the terms of the GNU
  3. General Public License version 2 (GPL2) as published by the Free Software
  4. Foundation and appearing in the file GPL2.TXT included in the packaging of
  5. this file. Please note that GPL2 Section 2[b] requires that all works based
  6. on this software must also be made publicly available under the terms of
  7. the GPL2 ("Copyleft").
  8. Contact information
  9. -------------------
  10. Circuits At Home, LTD
  11. Web : http://www.circuitsathome.com
  12. e-mail : [email protected]
  13. */
  14. #if !defined(_usb_h_) || defined(__HEXDUMP_H__)
  15. #error "Never include hexdump.h directly; include Usb.h instead"
  16. #else
  17. #define __HEXDUMP_H__
  18. extern int UsbDEBUGlvl;
  19. template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
  20. class HexDumper : public BASE_CLASS {
  21. uint8_t byteCount;
  22. OFFSET_TYPE byteTotal;
  23. public:
  24. HexDumper() : byteCount(0), byteTotal(0) {
  25. };
  26. void Initialize() {
  27. byteCount = 0;
  28. byteTotal = 0;
  29. };
  30. void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset);
  31. };
  32. template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
  33. void HexDumper<BASE_CLASS, LEN_TYPE, OFFSET_TYPE>::Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset) {
  34. if(UsbDEBUGlvl >= 0x80) { // Fully bypass this block of code if we do not debug.
  35. for(LEN_TYPE j = 0; j < len; j++, byteCount++, byteTotal++) {
  36. if(!byteCount) {
  37. PrintHex<OFFSET_TYPE > (byteTotal, 0x80);
  38. E_Notify(PSTR(": "), 0x80);
  39. }
  40. PrintHex<uint8_t > (pbuf[j], 0x80);
  41. E_Notify(PSTR(" "), 0x80);
  42. if(byteCount == 15) {
  43. E_Notify(PSTR("\r\n"), 0x80);
  44. byteCount = 0xFF;
  45. }
  46. }
  47. }
  48. }
  49. #endif // __HEXDUMP_H__