Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/ents_proto/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Makefile for user application

# Specify this directory relative to the current application.
TOCK_USERLAND_BASE_DIR = ../..

# Which files to compile.
C_SRCS := $(wildcard *.c)

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
7 changes: 7 additions & 0 deletions examples/ents_proto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ENTS Protobuf Example
=========

App includes the necessary source files and demonstrates how to encode a repeated sensor measurement command with TEROS12 data.

Files are copied from [ents-firmware repo](https://github.com/jlab-sensing/ENTS-node-firmware/tree/c5c7d364068dc00ec7cdce562b29ab6a69ed8ca6/proto/c). This repo has additional documentation on implementation and usage. In the future we will setup a library that automatically gets upstream updates.

50 changes: 50 additions & 0 deletions examples/ents_proto/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <libtock-sync/services/alarm.h>

#include "sensor.h"

int main(void) {
uint8_t buffer[256] = {};
size_t buffer_len = 0;

// float vwc_adj = (3.879e-4 * sens_data.vwc) - 0.6956;

// metadata
// 200 for logger_id and cell_id are known to exist
// should change to newly created cells on dirtviz
Metadata meta = Metadata_init_zero;
meta.ts = 1769113673;
meta.logger_id = 200;
meta.cell_id = 200;

SensorMeasurement meas[4] = {};

// vwc measurements
SensorMeasurement* vwc_raw = &meas[0];
vwc_raw->type = SensorType_TEROS12_VWC;
vwc_raw->which_value = SensorMeasurement_decimal_tag;
vwc_raw->value.decimal = 2000.;

SensorMeasurement* vwc_adj = &meas[1];
vwc_adj->type = SensorType_TEROS12_VWC_ADJ;
vwc_adj->which_value = SensorMeasurement_decimal_tag;
vwc_adj->value.decimal = 20.;

SensorMeasurement* temp = &meas[2];
temp->type = SensorType_TEROS12_TEMP;
temp->which_value = SensorMeasurement_decimal_tag;
temp->value.decimal = 22.;

SensorMeasurement* ec = &meas[3];
ec->type = SensorType_TEROS12_EC;
ec->which_value = SensorMeasurement_unsigned_int_tag;
ec->value.unsigned_int = 20.;

SensorStatus status = SENSOR_OK;
status = EncodeRepeatedSensorMeasurements(meta, meas, sizeof(meas), buffer, sizeof(buffer), &buffer_len);
if (status != SENSOR_OK) {
// ERROR in formatting or buffer
return -1;
}

return 0;
}
Loading
Loading