USB_Host_Shield_2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hexdump.h
Go to the documentation of this file.
1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2 
3 This software may be distributed and modified under the terms of the GNU
4 General Public License version 2 (GPL2) as published by the Free Software
5 Foundation and appearing in the file GPL2.TXT included in the packaging of
6 this file. Please note that GPL2 Section 2[b] requires that all works based
7 on this software must also be made publicly available under the terms of
8 the GPL2 ("Copyleft").
9 
10 Contact information
11 -------------------
12 
13 Circuits At Home, LTD
14 Web : http://www.circuitsathome.com
15 e-mail : support@circuitsathome.com
16 */
17 #if !defined(__HEXDUMP_H__)
18 #define __HEXDUMP_H__
19 
20 #include <inttypes.h>
21 #include <avr/pgmspace.h>
22 #include "printhex.h"
23 
24 template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
25 class HexDumper : public BASE_CLASS
26 {
27  uint8_t byteCount;
28  OFFSET_TYPE byteTotal;
29 
30 public:
31  HexDumper() : byteCount(0), byteTotal(0) {};
32  void Initialize() { byteCount = 0; byteTotal = 0; };
33 
34  virtual void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset);
35 };
36 
37 template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
38 void HexDumper<BASE_CLASS, LEN_TYPE, OFFSET_TYPE>::Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset)
39 {
40  for (LEN_TYPE j=0; j<len; j++, byteCount++, byteTotal++)
41  {
42  if (!byteCount)
43  {
44  PrintHex<OFFSET_TYPE>(byteTotal);
45  Serial.print(": ");
46  }
47  PrintHex<uint8_t>(pbuf[j]);
48  Serial.print(" ");
49 
50  if (byteCount == 15)
51  {
52  Serial.println("");
53  byteCount = 0xFF;
54  }
55  }
56 }
57 
58 #endif // __HEXDUMP_H__