Common Lisp Package: COM.INFORMATIMAGO.COMMON-LISP.DATA-ENCODING.ECP

Minitel-1b Error Correction Procedure. Reference: page 55 and on in <http://543210.free.fr/TV/stum1b.pdf> License: AGPL3 Copyright Pascal J. Bourguignon 2012 - 2012 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>

README:

FUNCTION

Public

ECP-ACTIVE (INSTANCE)

Whether the ECP is active.

ECP-STATE (INSTANCE)

State of the ECP, one of :ecp-start, :ecp-block or :ecp-syn.

PROCESS-INPUT-BUFFER (ECP BUFFER &KEY (START 0) (END NIL) ((STATISTICS STATS) NIL) (SEND-NAK NIL) (CANCEL-NAK NIL))

DO: Process the bytes in the BUFFER from START to END. ECP: An ECP-DATA structure maintaining the persistent data between calls to PROCESS-INPUT-BUFFER. BUFFER: Input octet vector. START: Index of the first octet in BUFFER to process. END: Index of the first octet in BUFFER after the last to process. STATS: A STATISTICS structure. SEND-NAK: A thunk to call when an uncorrectable error is detected. CANCEL-NAK: A thunk to call when a SYN SYN 4x sequence is received (so it can cancel the NAK timer). RETURN: NIL; next; NIL; STATS -- in case of incomplete or erroneous block. data-vector; next; block-number; STATS -- when a valid block is received. next is the index of the next start in buffer.

PROCESS-OUTPUT-BUFFER (ECP BUFFER &KEY (START 0) (END NIL) (LAST NIL))

ECP: An ECP-DATA structure maintaining the persistent data between calls to PROCESS-OUTPUT-BUFFER. BUFFER: Source data octet vector (only 7-bit values). START: Index of the first octet in BUFFER to process. END: Index of the first octet in BUFFER after the last to process. LAST: When true, if there's not enough bytes in the BUFFER to fill a packet, the packet is padded with NULs. DO: Encode an ECP packet from bytes obtained from BUFFER, between START and END. RETURN: index of first byte not processed from BUFFER; (ecp-block ecp) -- when a packet is complete, index of first byte not processed from BUFFER; nil -- when the package is not complete.

START-ECP (ECP)

Initialize the ECP data.

STATISTICS-BYTES-RECEIVED (INSTANCE)

ECP statistics: number of bytes processed.

STATISTICS-CORRECT-COUNT (INSTANCE)

ECP statistics: number of correct blocks.

STATISTICS-INVALID-COUNT (INSTANCE)

ECP statistics: number of invalid blocks.

STATISTICS-INVALID-SYN-COUNT (INSTANCE)

ECP statistics: number of invalid syn.

STATISTICS-PARITY-ERRORS (INSTANCE)

ECP statistics: number of parity errors.

STATISTICS-UNCORRECTABLE-COUNT (INSTANCE)

ECP statistics: number of uncorrectable errors.

STATISTICS-VALID-SYN-COUNT (INSTANCE)

ECP statistics: number of valid syn.

STOP-ECP (ECP)

Resets the ECP data.

Undocumented

SETFECP-ACTIVE (NEW-VALUE INSTANCE)

SETFECP-STATE (NEW-VALUE INSTANCE)

SETFSTATISTICS-BYTES-RECEIVED (NEW-VALUE INSTANCE)

SETFSTATISTICS-CORRECT-COUNT (NEW-VALUE INSTANCE)

SETFSTATISTICS-INVALID-COUNT (NEW-VALUE INSTANCE)

SETFSTATISTICS-INVALID-SYN-COUNT (NEW-VALUE INSTANCE)

SETFSTATISTICS-PARITY-ERRORS (NEW-VALUE INSTANCE)

SETFSTATISTICS-UNCORRECTABLE-COUNT (NEW-VALUE INSTANCE)

SETFSTATISTICS-VALID-SYN-COUNT (NEW-VALUE INSTANCE)

Private

CLEAR-PARITY (BUFFER &KEY (START 0) (END NIL))

DO: Resets the parity bit in each octets of the BUFFER between START and END, RETURN: BUFFER

ECP-BLOCK (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

ECP-BLOCK-NUMBER (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

ECP-COUNT (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

ECP-PARITY-ERRORS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

ECP-PARITY-INDEX (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

REMOVE-ESCAPES (BUFFER &KEY (START 0) (END NIL))

PRE: bytes in buffer are with no parity. POST: DLE escapes and the trailling NULs are removed from the buffer. DO: Modifies the buffer. RETURN: the new byte count.

SET-PARITY (BUFFER &KEY (START 0) (END NIL))

DO: Modifies the octets in the BUFFER between START and END, setting the parity bit to even parity. RETURN: BUFFER

STATISTICS-UNCORRECTED-COUNT (INSTANCE)

ECP statistics: number of uncorrected errors.

Undocumented

COPY-ECP-DATA (INSTANCE)

COPY-STATISTICS (INSTANCE)

SETFECP-BLOCK (NEW-VALUE INSTANCE)

SETFECP-BLOCK-NUMBER (NEW-VALUE INSTANCE)

SETFECP-COUNT (NEW-VALUE INSTANCE)

ECP-DATA-P (OBJECT)

SETFECP-PARITY-ERRORS (NEW-VALUE INSTANCE)

SETFECP-PARITY-INDEX (NEW-VALUE INSTANCE)

MAKE-ECP-DATA (&KEY ((ACTIVE DUM58) NIL) ((STATE DUM59) ECP-START) ((COUNT DUM60) 0) ((PARITY-INDEX DUM61) 0) ((PARITY-ERRORS DUM62) 0) ((BLOCK-NUMBER DUM63) 0) ((BLOCK DUM64) (MAKE-ARRAY +ECP-BLOCK-SIZE+ ELEMENT-TYPE '(UNSIGNED-BYTE 8) INITIAL-ELEMENT 0)))

MAKE-STATISTICS (&KEY ((BYTES-RECEIVED DUM0) 0) ((PARITY-ERRORS DUM1) 0) ((UNCORRECTABLE-COUNT DUM2) 0) ((UNCORRECTED-COUNT DUM3) 0) ((INVALID-COUNT DUM4) 0) ((CORRECT-COUNT DUM5) 0) ((VALID-SYN-COUNT DUM6) 0) ((INVALID-SYN-COUNT DUM7) 0))

STATISTICS-P (OBJECT)

SETFSTATISTICS-UNCORRECTED-COUNT (NEW-VALUE INSTANCE)

TEST

VARIABLE

Private

Undocumented

*ECP-RANK*

CLASS

Public

ECP-DATA

State for the ECP algorithm.

STATISTICS

Statistics for the ECP algorithm.

CONSTANT

Public

+ECP-BLOCK-SIZE+

Size of an ECP block.

Private

Undocumented

+G+