Skip to content

Instantly share code, notes, and snippets.

@bewest
Last active August 2, 2020 10:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bewest/6330546 to your computer and use it in GitHub Desktop.
Save bewest/6330546 to your computer and use it in GitHub Desktop.
diagrams
[blockdiag]
fontpath = /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf
antialias = True
[rackdiag]
fontpath = /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf
antialias = True
[packetdiag]
fontpath = /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf
antialias = True
[seqdiag]
fontpath = /usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf
antialias = True
TOOL_OPTS=-c ./block.cfg
%.rack.png: %.rack.diag
# echo $< $@
rackdiag ${TOOL_OPTS} $<
%.packet.png: %.packet.diag
# echo $< $@
packetdiag ${TOOL_OPTS} $<
%.block.png: %.block.diag
# echo $< $@
blockdiag ${TOOL_OPTS} $<
%.nw.png: %.nw.diag
# echo $< $@
nwdiag ${TOOL_OPTS} $<
%.seq.png: %.seq.diag
# echo $< $@
seqdiag ${TOOL_OPTS} $<
SOURCES=$(wildcard *.diag)
all: $(subst .diag,.png,${SOURCES})
# $<
# $(subst %.diag,%.png,${SOURCES})
# ${SOURCES} all: $(subst %.diag,%.png,${SOURCES})
{
autonumber = true;
edge_length = 138;
span_height = 18;
default_fontsize = 13;
=== Initialize modem ===
pc_app -> usb_stick [label = "signal strength"];
pc_app <-- usb_stick [label = "poll 160 - 220"];
pc_app -> usb_stick [label = "product info"];
pc_app <-- usb_stick [label = "{Version, Protocol}"];
=== Initialize pump session ===
pc_app -> usb_stick [label = "Transmit packet\n(RF Power On)"];
usb_stick ->> rf_stick [label="transmit" ] {
pc_app <-- usb_stick [label = "ACK"] ;
rf_stick ->> pump [label = "RF Power On"] {
... sleep 17 seconds ...
// auto return notation
pc_app -> usb_stick [label = "Poll buffer"];
pc_app <-- usb_stick [label = "size = 0"] {
pump -->> rf_stick [label = "begin response"] ;
}
pc_app -> usb_stick [label = "Poll size"];
usb_stick <-- rf_stick [label = "buffer status"];
pc_app <-- usb_stick [label = "size>15"];
pc_app -> usb_stick [label = "Read buffer\n(size)"] {
pc_app <-- usb_stick [label = "pump data" ];
}
pump -->> rf_stick [label = "more response"] ;
pc_app => usb_stick [label = "Poll size", return ="size=0"];
}
// { }
}
pc_app => usb_stick [label = "Poll size", return="size>15"] {
rf_stick <-- pump [label = "finish response"];
usb_stick <-- rf_stick [label="buffer status"];
}
pc_app -> usb_stick [label = "Read buffer"];
usb_stick <-- rf_stick [label = "transmit success"];
pc_app <-- usb_stick [label = "pump data" ];
=== Ready for audit ===
}
rackdiag {
// Poll buffer size
rack {
ascending;
description = "Poll opcode";
1U; //
1: 0x03;
}
rack {
5U; // 5 bytes
ascending;
description = "Poll response";
1: 0x00
2: 'U'
3: reason
4: LB_Length
5: HB_Length
}
}
rackdiag {
// ReadRadio packet - used to download N bytes from buffer
default_fontsize = 13;
5U; // 5 bytes
ascending;
description = "ReadRadio packet";
1: 0x0C;
2: 0x00;
3: HB_Length
4: LB_Length
5: CRC
}
rackdiag {
// ReadRadio response packet
// data segment is Length bytes long.
// EOD is 6th byte masked against 0x80
default_fontsize = 13;
15U;
ascending;
description = "ReadRadio response";
1: 0x02;
2: N/A [4U];
6: EOD
6: Length
7: Length
8: N/A [6U];
14: DATA
15: CRC
}

usb opcode responses

response to usb opcode

src embed svg

structure of ACK/HEAD

src embed svg

Three bytes total: ack, status, reason.

structure of ReadRadio response

ReadReadio is different from the other commands. src embed svg

Most other responses have the 3 byte HEAD/ACK followed by variant. ReadRadio response has 0x02, followed by body. Body is composed of header, pump data, CRC. Ignoring history page commands, and focusing only on simple "read serial number" type of commands, while the size, depends on the command, the average response size is 78 bytes.

This is for the 14 byte header well, 13 byte header plus 64 bytes of data plus CRC so 0x02, info, data, crc the length of the response is encoded as the distance between the 14th byte and the CRC at the end this value is stored in the 6th and 7th bytes of the response EOD flag is also encoded in the 6th byte, masked against 0x80.

{
// transmit packet
colwidth = 5;
default_fontsize = 13;
node_width = 100;
0: [ label = "1"]
1: [ label = "0"]
2: [ label = "0xA7"]
3: [ label = "1"]
4-9: PumpID
10-11: ArgLength
12: Button
13: Retries
14: Type
15: 0x00
16: Remote\nOpcode
17: CRC\nPacket
18: Remote\nParams
19: CRC\nRemoteParams
}
packetdiag {
default_fontsize = 13;
// USB Reponse
0-2: ACK
3-63: BODY
}
packetdiag {
node_width = 202;
default_fontsize = 13;
// ACK
0: 0x01 (ack)
1: 'U' (success)
2: 0x00 (reason)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment