Block Recovery Protocol (pdf) - Güralp Systems Ltd
Block Recovery Protocol (pdf) - Güralp Systems Ltd
Block Recovery Protocol (pdf) - Güralp Systems Ltd
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Block</strong> <strong>Recovery</strong> <strong>Protocol</strong><br />
Transmission of GCF over Serial<br />
Specification<br />
Part No. SWA-RFC-BRPR<br />
Designed and manufactured by<br />
<strong>Güralp</strong> <strong>Systems</strong> Limited<br />
3 Midas House, Calleva Park<br />
Aldermaston RG7 8EA<br />
England<br />
Proprietary Notice: The information in this manual<br />
is propriety to <strong>Güralp</strong> <strong>Systems</strong> Limited and may not be<br />
copied or distributed outside the approved recipient’s<br />
organisation without the approval of <strong>Güralp</strong> <strong>Systems</strong><br />
Limited. <strong>Güralp</strong> System Limited shall not be liable for<br />
technical or editorial errors or omissions made herein,<br />
nor for incidental or consequential damages resulting<br />
from the furnishing, performance or usage of this<br />
material.<br />
Issue B September 27, 2008
<strong>Block</strong> <strong>Recovery</strong> <strong>Protocol</strong> — Transmission of GCF over Serial<br />
Contents<br />
Contents 2<br />
1 Introduction 3<br />
2 Transmission of data 5<br />
2.1 GCF blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5<br />
2.2 ACK and NAK . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5<br />
2.3 ACK packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6<br />
2.4 ACK commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 7<br />
2.5 NAK packets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7<br />
3 Other considerations 9<br />
3.1 Terminal passthrough . . . . . . . . . . . . . . . . . . . . . . . . 9<br />
3.2 Real-time status . . . . . . . . . . . . . . . . . . . . . . . . . . . 9<br />
2 SWA-RFC-BRPR — Issue B
Specification<br />
1 Introduction<br />
<strong>Güralp</strong> instruments that communicate via a serial stream (e.g. the DM24 and<br />
the CD24), either over RS232 or via a TCP/IP to serial converter, will use block<br />
recovery protocol. This is a transport layer that allows for efficient use of the<br />
available bandwidth (GCF packets which are not ‘full’ are truncated) and for a<br />
degree of error detection and missing block recovery.<br />
The BRP transmitter prepends a small 4-byte header to each data block that is<br />
transmitted, and appends a 16 bit checksum (see section 2). It may also transmit<br />
real-time status blocks, which provide information about the current time, i.e.<br />
UTC (see section 3.2).<br />
The BRP receiver can send a 6-byte ACK/NAK block for flow control. An ACK<br />
will allow the next block to be transmitted as soon as it is available; a NAK allows<br />
for the transmission to be ‘rewound’ to a previous block. There is also a small set<br />
of commands available to the receiver to initiate terminal passthrough (section<br />
3.1), etc.<br />
September 27, 2008 3
Specification<br />
2 Transmission of data<br />
2.1 GCF blocks<br />
Each transmitted GCF block is pepended with a 4-byte header, shown in table<br />
2.1. The header contains an identifier for synchronising the start of the block, a<br />
sequence number (these are assigned by the transmitter and will increase sequentially,<br />
wrapping from 255 to 0), and the size of the packet. The packet size is in<br />
bytes and may be less than 1024 if there were any unused bytes after the RIC.<br />
Most receivers will want to discard a header (or assume it is terminal data) if the<br />
size is greater than 1024 bytes.<br />
Immediately following the header is the data block itself, truncated to the block<br />
size listed in the header. After the block a 16-bit checksum is sent. The checksum<br />
is computed by finding the sum of all the bytes in the header and data packet and<br />
discarding all but the lowest 16 bits. The remainder is transmitted in network<br />
byte order. The whole transmission is summarised in table 2.2.<br />
2.2 ACK and NAK<br />
After each transmitted block, the transmitter will wait up to n milliseconds (n is<br />
sometimes referred to as the “MS_GAP” setting) for a valid ACK or NAK signal<br />
before transmitting the next block. On receiving a valid ACK block, the transmitter<br />
assumes that the block has been successfully received and will not retransmit<br />
it later. On receiving a valid NAK block, the transmitter can be rewound to an-<br />
15<br />
8 7<br />
Identifier: 0x47: ‘G’<br />
Sequence number<br />
<strong>Block</strong> size (network byte order)<br />
0<br />
Table 2.1: GCF block BRP header.<br />
September 27, 2008 5
<strong>Block</strong> <strong>Recovery</strong> <strong>Protocol</strong> — Transmission of GCF over Serial<br />
Start block: ‘G’<br />
Length<br />
GCF block<br />
Sequence number<br />
❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤<br />
❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤<br />
Checksum<br />
Table 2.2: GCF block transmission.<br />
other point in the sequence 1 . If neither signal is received, the transmitter will<br />
generally store the unacknowledged blocks in some sort of memory until they<br />
can be transmitted later.<br />
2.3 ACK packets<br />
The format of a valid ACK packet is shown in table 2.3. The ACK packet is<br />
tied to the last block received by the stream ID, which is transmitted in little<br />
endian format 2 . Note that this should be the stream ID of the last block received,<br />
regardless of whether that block was out of sequence, or corrupted (in which<br />
case the stream ID might be wrong; but this simply means that the ACK will be<br />
ignored by the transmitter).<br />
The ‘Ctrl’ bit is set to 0 if a control code is used (see table 2.4 below), or 1 if a<br />
control code is not used, in which case the ACK packet is further tied to the block<br />
1 Unfortunately, some BRP transmitters have modes where, due to the implementation,<br />
rewinding does not work (e.g. CMG-DM24mk3 in adaptive mode). There is no way for the<br />
receiver to detect this. In such a mode, the receiver should NAK blocks that have corrupt checksums,<br />
but it should not pay attention to the sequence numbers. Otherwise, there will be suboptimal<br />
behaviour as the receiver continues to try to rewind but the transmitter does not perform<br />
this — although no data should be lost, transmission bandwidth will be wasted. This could be<br />
implemented as an option that the user must explicity activate in the receiver.<br />
2 An earlier version of serial link protocol used only the first two bytes of the ACK/NAK<br />
packet. It was only deemed necessary to use the least siginificant byte of the stream ID, since that<br />
would capture the tap and component information. Once BRP was introduced, this packet was<br />
extended in a backward-compatible manner, leading to the strange layout of bytes.<br />
6 SWA-RFC-BRPR — Issue B
Specification<br />
15<br />
14<br />
13 12 11 10<br />
ACK byte: 0x01<br />
9<br />
8<br />
7<br />
6<br />
5 4 3 2<br />
Stream ID LSB<br />
1<br />
0<br />
Ctrl<br />
Sequence ID<br />
Stream ID MSB, little-endian<br />
Table 2.3: ACK packet layout.<br />
Control code Description Digitisers<br />
0x00 Acknowledge, ignore sequence number All<br />
0x13 (^S) Break in to command mode All<br />
0x54 (‘T’) Initiate software trigger CD24<br />
Table 2.4: Control codes that may be used in BRP ACK packets.<br />
by least significant 7 bits of the sequence number. For example, if the transmitter’s<br />
last block was sequence number 0x67, the receiver would ACK it with 0xE7 in<br />
byte 2 of its ACK packet. If the ACK of the previous packet (0xE6) was delayed,<br />
the transmitter would not match the sequence number and would discard the<br />
delayed ACK packet.<br />
2.4 ACK commands<br />
In addition to simply acknowledging correctly received blocks, the ACK packet<br />
can be used to send some special commands. These are detailed in table 2.4. A<br />
special code of 0 will cause the digitiser to accept the ACK packet as long as<br />
the stream ID matches (i.e. the block sequence number is ignored 3 ). To request<br />
terminal passthrough mode on the digitiser, a control code of 0x13 (byte 2 as<br />
0x13) is sent. The CD24 digitiser firmware also recognises a control code of 0x54<br />
to initiate a software trigger.<br />
2.5 NAK packets<br />
Finally, the format of a NAK packet is shown below. The NAK packet contains<br />
a field which tells the transmitter which block sequence number to rewind to.<br />
3 This method of acknowledgement was widely used until later versions of the CD24 and<br />
DM24 firmware. However, the new method of sending the sequence byte with the top bit set is<br />
backwards compatible with the old firmware so it should be used by any new receiver software.<br />
September 27, 2008 7
<strong>Block</strong> <strong>Recovery</strong> <strong>Protocol</strong> — Transmission of GCF over Serial<br />
On receipt of a valid NAK packet, the transmitter should rewind to the given<br />
sequence number and begin transmitting from there (but see earlier note about<br />
certain digitisers and certain modes).<br />
15<br />
14<br />
13<br />
12<br />
11<br />
10<br />
NAK byte: 0x02<br />
Rewind sequence ID<br />
9<br />
8<br />
Stream ID MSB, little-endian<br />
7<br />
6<br />
5<br />
4<br />
Stream ID LSB<br />
3<br />
2<br />
1<br />
0<br />
8 SWA-RFC-BRPR — Issue B
Specification<br />
3 Other considerations<br />
3.1 Terminal passthrough<br />
BRP receivers may request terminal passthrough by transmitting a lone ^S character<br />
(ASCII code 19), or by sending a specially-formulated ACK packet (preferred<br />
method; see section 2.4). If the transmitter is not currently transmitting, a single<br />
^S should be sent; otherwise, the receiver should wait for its next ACK packet<br />
before requesting BRP mode. This avoids incompatible behaviour between the<br />
CD24 and the DM24 1 , and avoids a long wait if no packets are currently being<br />
transmitted.<br />
There is no clear indicator of when passthrough mode has been activated. The<br />
CMG-DCM receiver code currently assumes passthrough mode is activated when<br />
it has requested passthrough and it receives bytes that do not belong to a block<br />
transmission (table 2.2).<br />
The terminal passthrough should time out after some seconds if there is no activity<br />
on the link. This should be enforced by the BRP transmitter. The receiver may<br />
end the link at any time by sending a ‘GO’ command (this is actually transmitterspecific,<br />
but all current known transmitters implement GO, although there may be<br />
other commands for other situations). The transmitter should send the sequence<br />
0x1B 0x11 to signify it has exited passthrough mode.<br />
3.2 Real-time status<br />
Due to a design flaw, the CMG-DCM mk2x hardware does not contain a realtime<br />
clock module. The CMG-EAM hardware does, but the clock must be synchronised<br />
somehow. The DCM must attempt to retrieve its time from the connected<br />
digitisers. This process is not easy — only status packets can be used, because<br />
1 The CMG-CD24 always honours ^S characters, whereas the CMG-DM24 may ignore them<br />
if it is busy transmitting a packet.<br />
September 27, 2008 9
<strong>Block</strong> <strong>Recovery</strong> <strong>Protocol</strong> — Transmission of GCF over Serial<br />
15<br />
Packet identifier: 0x67: ‘g’<br />
14 13 12 11 10 9 8 7 6 5<br />
4<br />
3<br />
2<br />
1<br />
0<br />
FracLock<br />
GCF day<br />
GCF seconds<br />
(Optional) Fraction of second<br />
Table 3.1: Real-time status packet.<br />
there is no (unmeasurable) filtering delay, but even so there is a variable transmission<br />
delay and status packets may not be frequent; moreover, in any mode<br />
other than direct, packets can be delayed by arbitrary amounts so their timestamps<br />
do not correspond to the real time.<br />
To counter this problem, the real-time status packet has been introduced. This is<br />
a very small packet that is transmitted on the second, every second (where possible).<br />
If the digitiser is busy transmitting when the second boundary is crossed, the<br />
real-time status packet is inhibited to avoid inaccuracy. The layout of the packet<br />
is shown in table 3.1.<br />
The current lock status is transmitted by setting bit ‘Lock’ to 1 if the clock is<br />
locked to a time source, or to 0 if not. The time itself is transmitted in GCF<br />
format: number of days elapsed since 1989-11-17 and number of seconds elapsed<br />
since midnight of that day. Note this accurately represents leap seconds.<br />
In some implementations (e.g. the CMG-CD24), the packet may not be transmitted<br />
exactly on the second boundary but at some fraction of a second later. As long<br />
as the time at which it is transmitted is known, the fractional time bit (‘Frac’) may<br />
be set to indicate the packet contains an extra two bytes with the fractional second<br />
offset. This offset is unsigned, in network byte order, and has units of 1/40000<br />
seconds.<br />
10 SWA-RFC-BRPR — Issue B