-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a455b5
commit b49c2c6
Showing
8 changed files
with
275 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,51 @@ | ||
# SHEX | ||
Arduino library for transforming Serial in a HEX dump | ||
|
||
Arduino library to generate hex dump over Serial | ||
|
||
# Description | ||
|
||
SHEX is a simple library that wraps the Serial output side (by default) and | ||
generates an hexdump of all data that is printed. 16 bytes per row. | ||
|
||
The default output format is | ||
``` | ||
0xABCDABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx | ||
0xABCDABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx | ||
0xABCDABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx | ||
0xABCDABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx | ||
``` | ||
with a separator line after each 8th line. | ||
|
||
The constructor has a length parameter which can be used to have another | ||
number of bytes per row. After construction this cannot be changed, at | ||
least not in this initial release. | ||
|
||
The only thing one can toggle is HEX output or pass through by means | ||
of **setHEX(bool)**. | ||
This makes it possible to switch between the modes e.g. between | ||
'debugging' and 'release' mode. | ||
|
||
### ideas for the future | ||
|
||
Although no follow up release is really planned, some ideas are kept here | ||
so they won't get lost. | ||
|
||
- Optional ASCII colomn in the output format ( . if not printable) e.g. | ||
``` | ||
0xABCDABCD xx xx xx xx xx xx xx xx xx c.cc c..c | ||
``` | ||
|
||
- bytes per line: runtime configurable | ||
|
||
- seperarator: runtime configurable; | ||
|
||
- headerline: runtime configurable; optional combined with separator | ||
|
||
- HEX reader: converts dump format to a normal stream again. | ||
|
||
- better name for the class? | ||
|
||
# Operational | ||
|
||
See examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// FILE: SHEX.cpp | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.1.0 | ||
// PURPOSE: Arduino library to generate hex dump over Serial | ||
// DATE: 2020-05-24 | ||
// URL: https://github.com/RobTillaart/SHEX | ||
// | ||
// HISTORY: | ||
// 0.1.0 2020-05-24 initial version | ||
// | ||
|
||
#include "SHEX.h" | ||
|
||
SHEX::SHEX(Print* stream, uint8_t len) | ||
{ | ||
_stream = stream; | ||
_hexOutput = true; | ||
_length = min(32, ((len + 3) / 4) * 4); // force multiple of 4; max 32 | ||
_charCount = 0; | ||
}; | ||
|
||
|
||
/////////////////////////////////////////// | ||
// | ||
// WRITE - the core | ||
// | ||
size_t SHEX::write(uint8_t c) | ||
{ | ||
// PASS THROUGH MODE | ||
if (_hexOutput == false) return _stream->write(c); | ||
|
||
// HEX MODE | ||
// handle end of line and position number | ||
if ((_charCount % _length) == 0) | ||
{ | ||
_stream->println(); | ||
// separator line every 8 lines | ||
if ((_charCount % (_length * 8)) == 0) | ||
{ | ||
_stream->println(); | ||
} | ||
// next line | ||
uint32_t mask = 0xF0000000; | ||
while((mask > 0xF) && (mask & _charCount) == 0) | ||
{ | ||
_stream->print('0'); | ||
mask >>= 4; | ||
} | ||
_stream->print(_charCount, HEX); | ||
_stream->print('\t'); | ||
} | ||
|
||
// Print char as HEX | ||
if (c < 0x10) _stream->print('0'); | ||
_stream->print(c, HEX); | ||
_stream->print(' '); | ||
_charCount++; | ||
if ((_charCount % 4) == 0) _stream->print(' '); | ||
return 1; | ||
} | ||
|
||
void SHEX::setHEX(bool hexOutput) | ||
{ | ||
_hexOutput = hexOutput; | ||
_charCount = 0; | ||
_stream->println(); | ||
}; | ||
|
||
// -- END OF FILE -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
// | ||
// FILE: SHEX.h | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.1.0 | ||
// PURPOSE: Arduino library to generate hex dump over Serial | ||
// DATE: 2020-05-24 | ||
// URL: https://github.com/RobTillaart/SHEX | ||
// | ||
|
||
|
||
#include "Arduino.h" | ||
#include "Print.h" | ||
|
||
class SHEX: public Print | ||
{ | ||
public: | ||
SHEX(Print* stream = &Serial, uint8_t len = 16); | ||
|
||
size_t write(uint8_t c); | ||
|
||
void setHEX(bool hexOutput = true); | ||
|
||
private: | ||
Print * _stream; | ||
bool _hexOutput; | ||
uint8_t _length; | ||
uint32_t _charCount; | ||
}; | ||
|
||
// -- END OF FILE -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// FILE: SHEX_demo.ino | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.1.0 | ||
// PURPOSE: demo SHEX hexdump class | ||
// DATE: 2020-05-24 | ||
// (c) : MIT | ||
// | ||
|
||
#include "SHEX.h" | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(__FILE__); | ||
|
||
for (int i = 0; i < 64; i++) | ||
{ | ||
Serial.print(random(127)); | ||
Serial.print(' '); | ||
if ((i % 16) == 0) Serial.println(); | ||
} | ||
Serial.println("\n\nSHEX\n"); | ||
|
||
SHEX shex(&Serial, 16); | ||
|
||
for (int i = 0; i < 300; i++) | ||
{ | ||
char c = random(150); | ||
shex.print(c); | ||
} | ||
|
||
Serial.println("\n Done...\n"); | ||
} | ||
|
||
void loop() | ||
{ | ||
} | ||
|
||
// -- END OF FILE -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// FILE: SHEX_echo.ino | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.1.0 | ||
// PURPOSE: demo SHEX hexdump class | ||
// DATE: 2020-05-24 | ||
// (c) : MIT | ||
// | ||
|
||
// this sketch echos all incoming bytes back in hex dump format. | ||
// | ||
|
||
#include "SHEX.h" | ||
|
||
// default Serial and length 16 | ||
SHEX shex; | ||
|
||
// SHEX shex(&Serial, 8); | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(__FILE__); | ||
} | ||
|
||
void loop() | ||
{ | ||
if (Serial.available()) | ||
{ | ||
char c = Serial.read(); | ||
shex.print(c); | ||
} | ||
} | ||
|
||
// -- END OF FILE -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Syntax Coloring Map For SHEX | ||
|
||
# Datatypes (KEYWORD1) | ||
SHEX KEYWORD1 | ||
|
||
|
||
# Methods and Functions (KEYWORD2) | ||
write KEYWORD2 | ||
setHEX KEYWORD2 | ||
|
||
|
||
|
||
# Constants (LITERAL1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "SHEX", | ||
"keywords": "Stream, Serial, HEX dump", | ||
"description": "Arduino library to generate hex dump over Serial.", | ||
"authors": | ||
[ | ||
{ | ||
"name": "Rob Tillaart", | ||
"email": "Rob.Tillaart@gmail.com", | ||
"maintainer": true | ||
} | ||
], | ||
"repository": | ||
{ | ||
"type": "git", | ||
"url": "https://github.com/RobTillaart/SHEX.git" | ||
}, | ||
"version":"0.1.0", | ||
"frameworks": "arduino", | ||
"platforms": "*", | ||
"export": { | ||
"include": "SHEX" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name=SHEX | ||
version=0.1.0 | ||
author=Rob Tillaart <rob.tillaart@gmail.com> | ||
maintainer=Rob Tillaart <rob.tillaart@gmail.com> | ||
sentence=Arduino library to generate hex dump over Serial | ||
paragraph= | ||
category=Data Processing | ||
url=https://github.com/RobTillaart/SHEX | ||
architectures=* | ||
includes=SHEX.h | ||
depends= |