sample/frame.h

Defines

DP_SAM__N_FIELD_MAX
DP_SAM__LEN_FIELD_VAL_MAX
DP_SAM__LEN_FIELD_VAL_MIN
DP_SAM__LEN_FIELD_VAL_TIME
DP_SAM__LEN_FIELD_VAL_DIAG
DP_SAM__LEN_FIELD_HEAD
DP_SAM__LEN_DATL_HEAD
DP_SAM__LEN_PAYL_HEAD
DP_SAM__LEN_PAYL_MAX
DP_SAM__PAYL_TYPE_DATA
DP_SAM__PAYL_TYPE_CONF
DP_SAM__FIELD_TYPE_TIME
DP_SAM__FIELD_TYPE_SENS
DP_SAM__FIELD_TYPE_DIAG

Functions

uint8_t reserve_field(uint8_t, uint8_t, uint8_t *, uint8_t *)

Reserve space in payload for field of desired length.

Increments internal payload pointer to end of required space for field (i.e. reserves field). Calls pack_payload_header to build and write field header to payload. Returns pointer to beginning of field value.

Return
pointer to start of field value in payload, -1 on failure
Parameters
  • type: code representing the type of data/field to be reserved
  • len: length of field value in bytes
  • payload_ptr: pointer to internal payload pointer dp_payload._payload_ptr
  • header_ptr: pointer to current position in payload

uint8_t pack_field_header(uint8_t, uint8_t, uint8_t *)

Build and write field header to payload.

Given the desired field type and length of the field value in bytes, this function constructs the appropriate field header and writes it to the payload at the position indicated by the pointer provided.

Field value length is encoded as the first (most significant) three bits of the field header such that: 0b001XXXXX > 2 0b010XXXXX > 4 0b011XXXXX > 6 0b100XXXXX > 8 0b101XXXXX > 10 0b110XXXXX > 12

Field type is encoded in the last (least significant) five bits of the field header. For instance: 0bXXX11111 > timestamp 0bXXX11110 > disgnostic In the case of sensor data, the five LSBs are encoded with the sensor type code (from system state variables).

Return
length of field header, -1 on failure
Parameters
  • type: code representing the type of field to be reserved
  • len: length of field value in bytes
  • header_ptr: pointer to current position in payload

void dp_payload_flush(void)

Clears the payload buffers.

struct dp_payload_t

Public Members

dp_payload_t::_ready_send

Used to determine if payload is ready for pushing to the Dusty module for transmission over the WSN

dp_payload_t::_payload_ptr

Pointer to the current position in the payload, i.e. the index of the payload array (next parameter) up to which the payload has been filled/ written and at which the next entry should be placed.

dp_payload_t::payload

Array for storing the current payload