Implementation

Implementation: Sample interval CODEC_IMPL_1 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_FEAT_10, CODEC_FEAT_6

The time interval between samples (in minutes) is defined in the global variable smplintervalmins.

ndef_writepreamble() converts smplintervalmins into a base64 string and writes it to URL parameter ‘t’.

Decoder method decode_timeinterval converts this back to an integer.

Implementation: Elapsed time CODEC_IMPL_2 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_FEAT_26

The function enc_setelapsed() alters the elapsed time field, independent of the rest of the URL. It is intended that this is called once for each minute after a sample is taken. Elapsed time (as an integer) is converted to base64 and written to the end stop.

Base64 elapsed time is extracted in BufferDecoder and converted back to an integer.

Implementation: Length in blocks CODEC_IMPL_3 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_FEAT_23

Buffer length is set at compile time with BUFSIZE_BLKS.

Implementation: Length in samples CODEC_IMPL_4 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_FEAT_25

The function enc_pushsample() uses integer npairs to record how many valid samples are in the circular buffer. When an demi is overwritten, it is reduced by PAIRS_PER_DEMI. Otherwise it is incremented by one. When the buffer is full npairs will equal buflenpairs.

Implementation: MD5 CODEC_IMPL_5 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_FEAT_24, CODEC_FEAT_40

The encoder maintains pairhistory, a RAM-based shadow of the EEPROM circular buffer. It consumes a lot of RAM, but this is unavoidable.

On each call to enc_pushsample(), the sample is appended to pairhistory by pairhist_push(). The hash (MD5 or HMAC) is calculated with pairhist_hash(). This outputs a 9 byte structure (hashn_t). It is converted to base64 (hashnb64) before it is written to the endstop demis (Endstop (CODEC_SPEC_13)).

Implementation: Append sample CODEC_IMPL_6 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_FEAT_15

Samples are added to the circular buffer with enc_pushsample(). This takes one or two measurands, depending on the circular buffer format.

Implementation: Initialisation CODEC_IMPL_7 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_FEAT_12

The NDEF message and its circular buffer are initialised with enc_init(). Given there are no samples in the circular buffer, the endstop and cursor are omitted. All demis are set to MDaW (all zeroes).

State machines in the sample and demi files are reset.

Implementation: Serial CODEC_IMPL_8 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_FEAT_38

The serial string is defined in the global variable serial. This must be SERIAL_LENBYTES long. It must contain only URL-safe characters.

ndef_writepreamble() copies this into URL parameter ‘s’.