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