Enc C Reference

Defines

HDC2021_TEMPRH

Last character of the URL version string if the URL contains both temperature and relative humidity measurands.

HDC2021_TEMPONLY

Last character of the URL version string if the URL contains only temperature measurands.

ENDSTOP_BYTE

Last character of the endstop. Must be URL safe according to RFC 1738.

BATV_RESETCAUSE(BATV, RSTC)

Macro for creating a 16-bit batv_resetcause value from 8-bit CODEC_FEAT_30 and CODEC_SPEC_16 values.

Enums

enum pairbufstate_t

Values:

enumerator pairbuf_initial
enumerator pair0_both

Write pair0

enumerator pair0_reading1

Overwrite reading1 of pair0

enumerator pair1_both

Write pair1

enumerator pair1_reading1

Overwrite reading1 of pair1

Functions

void fram_write_enable(void)

Enable writes to FRAM. Should be defined in the processor-specific cuplTag project.

void fram_write_disable(void)

Disable writes to FRAM. Should be defined in the processor-specific cuplTag project.

static bool one_reading_per_sample(void)
static void incr_loopcounter(void)

Update loop counter and battery voltage in the preamble status field.

Calls a function to measure battery voltage, increases loopcount and clears the battery reset field. These data are base64 encoded and written to EEPROM. ndef_writepreamble overwrites the bufferred circular buffer blocks so these must be read again after with demi_restore.

static void set_elapsed(unsigned int minutes)

Update the endmarker of the endstop with elapsed time in minutes.

Parameters

minutes – Minutes elapsed since the previous sample.

static void set_pair(pair_t *pair, int rd0, int rd1)

Write one pair.

Parameters
  • pair – Pointer to the pair that will be modified.

  • rd0 – Reading 0 (12 bits).

  • rd1 – Reading 1 (12 bits).

static void set_rd1(pair_t *pair, int rd1)

Overwrite reading1 in a pair This is used when the format stipulates one reading per pair (see CODEC_FEAT_42).

Parameters
  • pair – Pointer to the pair that will be modified.

  • rd1 – Reading 1 (12 bits).

unsigned int enc_getbatv(void)

Get battery voltage from the status field. This is a value from 0-255. Step size increases exponentially. 255 corresponds to 1V5. 0 is infinity.

void enc_init(unsigned int resetcause, bool err, unsigned int batv)

Initialise the encoder state machine. Writes the.

Parameters
  • resetcause – 16-bit status value.

  • err – Sets an error condition where data will not be logged to the URL circular buffer.

  • batv – Battery voltage from ADC (not in mv).

void enc_setelapsed(unsigned int minutes)

Update the base64 encoded endstop and write it to the tag.

Parameters

minutes – Minutes elapsed since the previous sample.

int enc_pushsample(int rd0, int rd1)

Push a sample containing up to two readings onto the circular buffer.

Parameters
  • rd0 – First reading in the sample e.g. temperature.

  • rd1 – Second reading in the sample (optional) e.g. relative humidity.

Returns

1 if the cursor has moved from the end to the start and data are being overwritten. Otherwise 0.

Variables

nv_t nv

Externally defined parameters stored in non-volatile memory.

int overwriting = 0
pair_t pairbuf[2] = {0}

Stores two unencoded 3-byte pairs.

unsigned int npairs = 0

Number of base64 encoded pairs in the circular buffer, starting from the endstop and counting backwards.

pairbufstate_t state = pairbuf_initial

Pair buffer write state.

endstop_t endstop = {0}

The 16 byte end stop.

stat_t status = {0}

Structure to hold unencoded status data.

struct stat_t

Public Members

uint16_t loopcount

Number of times the last demi in the circular buffer endstop has wrapped from the end to the beginning.

uint16_t resetsalltime

2-byte status. Bits are set according to stat_bits.h

uint16_t batv_resetcause

Battery voltage in mV

struct endstop_t

Public Members

char hashnb64[12]

MD5 length field containing a base64 encoded hashn_t.

char markerb64[4]

End-stop marker comprised of base64 encoded minutes since the previous sample and ENDSTOP_BYTE

struct endmarker_t

Public Members

char elapsedLSB

Minutes elapsed since previous sample (Least Significant Byte).

char elapsedMSB

Minutes elapsed since previous sample (Most Signficant Byte).