asciiwave: WaveDrom to ASCII art
This utility reads WaveDrom JSON files like this:
{ signal: [
{ name: "clk", wave: "P......" },
{ name: "bus", wave: "x.==.=x", data: ["head", "body", "tail", "data"] },
{ name: "wire", wave: "0.1..0." }
]}
And produces ASCII art like this:
$ ./asciiwave example/step3.json
ββββ ββββ ββββ ββββ ββββ ββββ ββββ
clk : β ββββ ββββ ββββ ββββ ββββ ββββ βββ
xxxxxxxxxxxxβ± β²β± β²β± β²xxxxxx
bus : xxxxxxxxxxxxβ²headβ±β² body β±β²tailβ±xxxxxx
β βββββββββββββββββββ
wire: βββββββββββββ ββββββββββββ
WaveDrom would usually render a PNG or SVG like the below:
However, PNGs can not be pasted into comments in your HDL project!
asciiwave requires the json5
library from PyPI, as a lot of WaveJSON samples floating around on the internet rely on non-vanilla-JSON features like unquoted keys, single-quoted strings and trailing commas. The jsonschema
library is also required, for input validation. These can be obtained via:
$ pip3 install json5 jsonschema
asciiwave features a watch mode (-w
), which will continously poll a file on disk, and redraw whenever the
file changes. This can be used interactively alongside a text editor.
$ ./asciiwave --watch example/step4.json
ββββ ββββ ββββ ββββ ββββ ββββ βββββ ββββ ββββ
clk : β ββββ ββββ ββββ ββββ ββββ βββββ ββββ ββββ βββ
xxxxxxxxxxxxβ± β²β± β²β± β²xxxxxxββ± β²xxxxxx
Data : xxxxxxxxxxxxβ²headβ±β²bodyβ±β²tailβ±xxxxxxββ² data β±xxxxxx
β βββββββββββββββββββ ββββββββββββββ
Request : βββββββββββββ ββββββββ ββββββ
ββββββββββββββββββββββββββββββββββββββ ββββββββββββ
Acknowledge: β ββββββββ
Watching file example/step4.json
Ctrl-C to exit
There are simple command-line options for formatting:
$ ./asciiwave --hscale=4 --graphics=tall example/step4.json
ββββββ ββββββ ββββββ ββββββ ββββββ ββββββ βββββββ ββββββ ββββββ
β β β β β β β β β β β β ββ β β β β β
clk : β ββββββ ββββββ ββββββ ββββββ ββββββ βββββββ ββββββ ββββββ βββββ
xxxxxxxxxxxxxxxxxxxxβ± β²β± β²β± β²xxxxxxxxxxββ± β²xxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx head body tail xxxxxxxxxxβ data xxxxxxxxxx
Data : xxxxxxxxxxxxxxxxxxxxβ² β±β² β±β² β±xxxxxxxxxxββ² β±xxxxxxxxxx
β βββββββββββββββββββββββββββββββ ββββββββββββββββββββββ
β β β ββ β
Request : βββββββββββββββββββββ ββββββββββββ ββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββ
β ββ β
Acknowledge: β ββββββββββββ
$ ./asciiwave --hscale=1 --graphics=tiny example/step4.json
clk : βββ_βββ_βββ_βββ_βββ_βββ_ββββ_βββ_βββ_
Data : xxxxxxxx<he><bo><ta>xxxxβ< data >xxxx
Request : β_______βββββββββββββ___ββββββββββ___
Acknowledge: ββββββββββββββββββββββββββ___ββββββββ
WaveJSON Subset
asciiwave does not implement the full gamut of WaveJSON features. It supports:
wave
commands:1hHu 0lLd pPnN =2345 zx |
- The
hscale
config property: the width of each time unit ishscale * 2 + 2
characters. This is overridden by the--hscale
command line parameter. - The
period
signal property: this can be a floating point number. The width of each wave time unit is multiplied byperiod
and rounded down. - The
phase
signal property: this can be a floating point number. The signal is advanced (positive) or retarded (negative) by this number of periods. - The
data
signal property: either an array of strings, or a single string containing whitespace-separated values.
Graphics
asciiwave defines its graphics like this:
graphics_default = [
"0+1-rfxz< >|UuDd",
" βββββx_β± β²βββ ",
"ββ βββx β² β±β β°β"
]
The first line is a key which maps asciiwave's internal representation of wire state to columns of the graphics; the following lines contain the actual graphics. These can be modified if you can't use the Unicode box drawing characters, or have found better-looking characters.
The height is not fixed at 2 lines; any positive number of lines will do. However, the width of each wire state is limited to one column, to simplify rendering (this will be fixed)