Prusa MINI Firmware overview
hexdump.h
Go to the documentation of this file.
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 
27 #ifndef _usb_h_
28  #error "Never include hexdump.h directly; include Usb.h instead"
29 #endif
30 
31 extern int UsbDEBUGlvl;
32 
33 template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
34 class HexDumper : public BASE_CLASS {
35  uint8_t byteCount;
36  OFFSET_TYPE byteTotal;
37 
38 public:
39 
40  HexDumper() : byteCount(0), byteTotal(0) {
41  };
42 
43  void Initialize() {
44  byteCount = 0;
45  byteTotal = 0;
46  };
47 
48  void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset);
49 };
50 
51 template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
52 void HexDumper<BASE_CLASS, LEN_TYPE, OFFSET_TYPE>::Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset __attribute__((unused))) {
53  if (UsbDEBUGlvl >= 0x80) { // Fully bypass this block of code if we do not debug.
54  for (LEN_TYPE j = 0; j < len; j++, byteCount++, byteTotal++) {
55  if (!byteCount) {
56  PrintHex<OFFSET_TYPE > (byteTotal, 0x80);
57  E_Notify(PSTR(": "), 0x80);
58  }
59  PrintHex<uint8_t > (pbuf[j], 0x80);
60  E_Notify(PSTR(" "), 0x80);
61 
62  if (byteCount == 15) {
63  E_Notify(PSTR("\r\n"), 0x80);
64  byteCount = 0xFF;
65  }
66  }
67  }
68 }
__attribute__
bool boolean __attribute__((deprecated))
Definition: wiring_constants.h:110
UsbDEBUGlvl
int UsbDEBUGlvl
HexDumper::Initialize
void Initialize()
Definition: hexdump.h:43
HexDumper
Definition: hexdump.h:34
PSTR
#define PSTR(str)
Definition: pgmspace.h:31
uint8_t
const uint8_t[]
Definition: 404_html.c:3
BASE_CLASS
HexDumper::HexDumper
HexDumper()
Definition: hexdump.h:40
unused
unsigned unused
Definition: masstorage.h:51
pbuf
Definition: pbuf.h:142
HexDumper::Parse
void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset)
Definition: hexdump.h:52
E_Notify
void E_Notify(char const *msg, int lvl)