[][src]Crate mylib

Sensor app that reads sensor data from a temperature sensor and sends the sensor data to a CoAP server or Collector Node. Note that we are using a patched version of apps/my_sensor_app/src/vsscanf.c that fixes ESP8266 response parsing bugs. The patched file must be present in that location. This is the Rust version of https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/rust/apps/my_sensor_app/OLDsrc/main.c

Modules

base

Common declarations for the application. Includes custom sensor declarations.

listen_sensor

Poll the temperature sensor every 10 seconds. We support 2 types of temperature sensors: (1) BME280 Temperature Sensor, connected to Blue Pill on port SPI1. This sensor is selected if BME280_OFB is defined in syscfg.yml. (2) Blue Pill internal temperature sensor, connected to port ADC1 on channel 16 This sensor is selected if TEMP_STM32 is defined in syscfg.yml. If this is the Collector Node, send the sensor data to the CoAP Server after polling. This is the Rust version of https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/rust/apps/my_sensor_app/OLDsrc/listen_sensor.c

mynewt

Mynewt API for Rust. Contains Rust bindings for Mynewt API for C, generated by bindgen. Also includes safe versions of Mynewt APIs created specially for Rust.

send_coap

Send sensor data to a CoAP Server or a Collector Node. The CoAP payload will be encoded as JSON for CoAP Server and CBOR for Collector Node. The sensor data will be transmitted to CoAP Server over WiFi via the ESP8266 transceiver, and to Collector Node via nRF24L01 transceiver. This enables transmission of Sensor Data to a local Sensor Network (via nRF24L01) and to the internet (via ESP8266). For sending to Collector Node we use raw temperature (integer) instead of computed temperature (floating-point) to make the encoding simpler and faster. Note that we are using a patched version of apps/my_sensor_app/src/vsscanf.c that fixes ESP8266 response parsing bugs. The patched file must be present in that location. This is the Rust version of https://github.com/lupyuen/stm32bluepill-mynewt-sensor/blob/rust/apps/my_sensor_app/OLDsrc/send_coap.c

Macros

coap

Macro to compose a CoAP payloads with JSON or CBOR encoding. Adapted from the json!() macro: https://docs.serde.rs/src/serde_json/macros.rs.html

coap_array

Compose an array under "object", named as "key". Add "children" as array elements.

coap_item

Append an array item under the array named array0. Add children0 as the items (key and value). { <array0>: [ ..., { <children0> } ] }

coap_item_int
coap_item_int_val

Create a new Item object in the parent array and set the Sensor Value's key/value (integer).

coap_item_str

Append a (key + val string value) item to the array named parent: { <parent>: [ ..., {"key": <key>, "value": <val>} ] }

coap_root

Compose the payload root.

coap_set_int_val

Given an object parent and an integer Sensor Value val, set the val's key/value in the object.

d

Macro to dump all tokens received as a literal string, e.g. d!(a b c) returns "a b c"

fill_zero

Return a const struct that has all fields set to 0. Used for initialising static mutable structs like os_task. fill_zero!(os_task) expands to

json_rep_close_array
json_rep_object_array_end_item
json_rep_object_array_start_item
json_rep_set_array
json_rep_set_int
json_rep_set_text_string
json_value_int
json_value_string

$value must be an str

nx

Macro to display the token being parsed and the remaining tokens

oc_rep_close_array
oc_rep_end_array
oc_rep_end_object
oc_rep_end_root_object
oc_rep_object_array_end_item
oc_rep_object_array_start_item
oc_rep_set_array
oc_rep_set_int
oc_rep_set_text_string
oc_rep_start_array
oc_rep_start_object
oc_rep_start_root_object
parse
parse_vector
stringify_null

Macro that takes an identifier and returns a [u8] containing the identifier, terminated by 0. Used to convert an identifier to a C null-terminated string.

test_ident
test_internal_rules
test_internal_rules2
test_literal
unexpected_token

Functions

main

main() will be called at Mynewt startup. It replaces the C version of the main() function.

panic

This function is called on panic, like an assertion failure. We display the filename and line number and pause in the debugger. From https://os.phil-opp.com/freestanding-rust-binary/