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