GY-63_MS5611/libraries/SHEX/README.md

166 lines
5.4 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/SHEX/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-28 05:19:54 -05:00
[![Arduino-lint](https://github.com/RobTillaart/SHEX/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/SHEX/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/SHEX/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/SHEX/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/SHEX/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/SHEX.svg?maxAge=3600)](https://github.com/RobTillaart/SHEX/releases)
# SHEX
2021-12-28 05:19:54 -05:00
Arduino library to generate hex dump over Serial (any stream).
2021-01-29 06:31:58 -05:00
## Description
2022-05-31 11:39:54 -04:00
### SHEX
**SHEX** is a simple library that wraps the Serial output side (by default) and
2021-12-28 05:19:54 -05:00
generates an hex dump of all data that is printed. 16 bytes per row.
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
The default output format is (changed since 0.3.0)
2021-01-29 06:31:58 -05:00
```
2022-05-31 11:39:54 -04:00
ABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
ABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
ABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
ABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
2021-01-29 06:31:58 -05:00
```
with a separator line after each 8th line.
2021-12-28 05:19:54 -05:00
The constructor has a length parameter which can be used to have another number of bytes per row.
This can be changed with **setBytesPerLine()**.
2021-01-29 06:31:58 -05:00
2021-12-28 05:19:54 -05:00
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.
One can toggle the character count at the start of the line.
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
### SHEXA
**SHEXA** (Serial HEX Ascii) is a derived class from **SHEX** that also
displays a column with printable characters.
The default output format is
```
ABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx abcdefgh ijklmnop
ABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx abcdefgh ijklmnop
ABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx abcdefgh ijklmnop
ABCD xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
```
To print this ASCII column extra RAM and code is used.
Therefore this is made a derived class from **SHEX**.
Furthermore **SHEXA** has a function **flushASCII()** to flush the ASCII column to output.
This is might be needed when HEX output is restarted.
2021-01-29 06:31:58 -05:00
## Interface
2022-05-31 11:39:54 -04:00
The **SHEX** and **SHEXA** share most of their interface.
2022-05-27 04:43:49 -04:00
### Defines
To be adjusted via command line (or in SHEX.h file)
2022-05-31 11:39:54 -04:00
- **SHEX_DEFAULT_LENGTH 16**
- **SHEX_MAX_LENGTH 32**
- **SHEX_MIN_LENGTH 4**
- **SHEX_COUNTER_DIGITS 4**
- **SHEX_DEFAULT_VTAB 8**
2022-05-27 04:43:49 -04:00
2021-12-28 05:19:54 -05:00
2021-01-29 06:31:58 -05:00
### Constructor + Core
2022-05-31 11:39:54 -04:00
- **SHEX(Print \* stream = &Serial, uint8_t length = SHEX_DEFAULT_LENGTH)** Constructor,
optional set the number of bytes per line.
2022-05-27 04:43:49 -04:00
default 16 bytes per line, forced multiple of 4, max SHEX_MAX_LENGTH = 32.
2021-12-28 05:19:54 -05:00
- **size_t write(uint8_t c)** implements the Print interface.
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
### Output Modifiers
2021-01-29 06:31:58 -05:00
2021-12-28 05:19:54 -05:00
- **void setHEX(bool hexOutput = true)** switch between modi, HEX (true) or pass through (false).
- **bool getHEX()** returns mode set above.
2022-05-31 11:39:54 -04:00
- **void setBytesPerLine(uint8_t length = SHEX_DEFAULT_LENGTH)** idem, default 16 bytes per line,
forced multiple of 4, max SHEX_MAX_LENGTH = 32.
2021-01-29 06:31:58 -05:00
- **uint8_t getBytesPerLine()** returns number of bytes per line.
2022-05-31 11:39:54 -04:00
### Separator
2021-12-28 05:19:54 -05:00
- **void setSeparator(char c = ' ')** set the separator character, default a space.
Some people like a dot '.', or a tab '\t'. Feel free to experiment.
- **char getSeparator()** return the separator character set.
2022-05-31 11:39:54 -04:00
### Counter
- **void setCountDigits(uint8_t digits)** set the length of the counter, 8 or 6 or 4 (default).
Other numbers will be rounded up to 4, 6 or 8.
- **uint8_t getCountDigits()** returns idem.
- **void restartOutput()** restarts the counter from 0 and a new line.
Is automatically called if a setting is modified like **bytesPerLine**
**setVTAB** or **setCountDigits**
- **uint32_t getCounter()** return internal counter.
### VTAB
2022-05-28 05:28:52 -04:00
- **void setVTAB(uint8_t vtab = SHEX_DEFAULT_VTAB)** set the vertical separator line.
- **uint8_t getVTAB()** return the current vertical separator line.
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
### SHEXA specific
- **void flushASCII()** allows the user to flush the ASCII column to output.
This is typically used after a setting is changed, which causes a restart of
the HEX output. Best if followed by a **restartOutput()**.
_Note: it is not ideal but workable. This might change in the future._
2021-12-28 05:19:54 -05:00
## Operational
See examples.
2021-01-29 06:31:58 -05:00
## Future
Although no follow up release is planned, some ideas are kept here
so they won't get lost.
2022-11-24 06:47:19 -05:00
#### Must
2022-05-31 11:39:54 -04:00
- optimize code
- print vs write
2022-11-24 06:47:19 -05:00
#### should
2022-05-31 11:39:54 -04:00
- more testing
- performance measurement
- different platforms.
- different streams incl SW Serial
2021-01-29 06:31:58 -05:00
2022-11-24 06:47:19 -05:00
#### Could
2022-05-31 11:39:54 -04:00
- investigate **flushASCII()** for better solutions.
- HEX reader: **RHEX** converts dump format to a normal stream again.
- separate library.
2022-11-24 06:47:19 -05:00
- void setSeparatorInterval() ??
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
2022-11-24 06:47:19 -05:00
#### Wont
2022-05-31 11:39:54 -04:00
- line buffering for faster output (e.g Ethernet and SD card)
could it support **write(array, length)** call.
needs quite a rewrite..
Needs a big buffer: ~150 bytes. (counter 8 + hex 96 + printable 32 + extra sep)
2022-11-24 06:47:19 -05:00
==> go through a small buffer twice as data is same!!
2022-05-31 11:39:54 -04:00
- header line: runtime configurable;
optional combined with separator
and after how many lines the header should repeat
**header(str, lines)** ?
Can also be done by just calling Serial.print.