TST-Library Documentation

Overview

The TST-Protocol Variables is designed for communication between devices in embedded systems and PC applications. It supports any interface.

Key Features

  • Device Registration: Allows registering a device along with its properties.
  • Interface Registration: Enables registration of an interface for a device with a designated maximum payload size.
  • Struct Registration: Supports mapping of memory structures.
  • Fragmentation Support: Splits messages into fragments if they exceed the allowed payload size and reassembles them on receipt.
  • Dynamic memory: Utilizes complex internal functions for managing data exchange.

Compilation and Integration

  • Include the following files in your build environment:
    • tst_library.c
    • tst_library.h
    • tst_variables.c
    • tst_variables.h
  • Set appropriate include paths.
  • Insert your variables in the struct inside the two markers /*TSTVARIABLESSTART*/ /*TSTVARIABLESEND*/
  • Set your device name #define TSTNAME "your_device_name"

Core Functions

FunctionDescriptionExample
tstProtocolRegisterRegisters a device in the TST protocol systemtstProtocolRegister(&TST_Device);
tstProtocolRxProcesses received data from an interfacetstProtocolRx("DEVICE", "INTERFACE", data, size);
tstProtocolTxTransmits data through the specified interfacetstProtocolTx("DEVICE", "INTERFACE", data, size);
tstProtocolVariablesGetRetrieves variable values from another devicetstProtocolVariablesGet("DEVICE", "INTERFACE", VARIABLE, sizeof(VARIABLE));
tstProtocolVariablesSetSets a variable value on another devicetstProtocolVariablesSet("DEVICE", "INTERFACE", &VARIABLE, sizeof(VARIABLE), VALUE);
tstMonitorSends a text message to the monitortstMonitor("DEVICE", "INTERFACE", TEXT);

Supported Variable Types

TypeSize (bytes)Description
bool1Boolean value (true/false)
int8_t18-bit signed integer
uint8_t18-bit unsigned integer
int16_t216-bit signed integer
uint16_t216-bit unsigned integer
int32_t432-bit signed integer
uint32_t432-bit unsigned integer
int64_t864-bit signed integer
uint64_t864-bit unsigned integer
float4Single-precision floating-point
double8Double-precision floating-point
char[]VariableCharacter array (string)
structVariableCustom data structure (packed)
arrayVariableArray of any supported type

User Manual for the Application

This guide explains how to operate the application across its different communication interfaces. Follow these steps for a smooth experience.

General Overview

The application implements a protocol that lets users read and update internal variables of the device. The device supports several communication methods (I2C, BLE, Serial, and WebSocket). This manual explains how to interact with the device using these methods.

Example I2C (Master/Slave)

For the Master Device

  1. Connect the Device: Connect the master device to your computer or power supply.
  2. Power Up the Device: When the device starts, it registers itself and initializes communication with the slave device.
  3. Variable Update: The master periodically toggles an LED variable on the slave device and sends protocol messages via I2C.
  4. Monitoring Activity: Use a serial monitor (if available) to observe any debug output provided by the master.

For the Slave Device

  1. Setup and Listen: The slave device listens for incoming I2C messages. It receives messages that update an internal LED variable.
  2. Visual Feedback: The device’s LED will turn on or off based on the received variable value.
  3. Status Reporting: Consult the serial console for debugging information about message reception if required.
Tested with Arduino Nano esp32

Example BLE

  1. Turn on BLE: Power on the BLE device. It will automatically advertise its presence with the name provided by the application.
  2. Connect from a Client: Use a smartphone or BLE-compatible device to search for the advertised BLE device (e.g., "tst-device").
  3. Data Write and Notification:
    • Once connected, send binary messages to the device.
    • The device processes incoming messages and can update its internal variables.
    • When a variable changes, the device notifies the client via BLE characteristics.
  4. Visual Feedback: The onboard LED will reflect the state of a variable (on or off).
Tested with Arduino Nano esp32

Example Serial Communication (USB)

  1. Connect via USB/Serial Cable: Attach the device to your computer using a USB/serial cable.
  2. Start a Serial Monitor: Open your preferred serial monitor (set to 115200 baud) to view command and status messages.
  3. Sending Data: You can send text or binary data from the serial monitor. The device listens and processes incoming data according to the protocol.
  4. Variable Update: The device increments a primary variable continuously and toggles an LED based on an internal state. Messages are sent back automatically on the serial line.
Tested with Arduino Nano esp32

Example WebSocket (Wi‑Fi Based)

  1. Network Connection: Power on the Wi‑Fi device and ensure it connects to the preconfigured network. The device will print its local IP address on startup.
  2. Access the WebSocket: Use a WebSocket-enabled client (such as a web browser with a JavaScript client) to open a connection to ws://<device_ip>/ws.
  3. Sending Messages: Send binary messages from the client to control or query the device's status. The device processes these messages and updates its internal variables.
  4. Receiving Data: The device sends updated protocol messages via the WebSocket. Use your client to display these binary updates.
  5. LED Status: The device's LED reflects the current value of the relevant variable.
Tested with Arduino Nano esp32

Troubleshooting and Tips

  • Verify Wiring and Power: Ensure that all physical connections (for I2C and Serial) are secure and that the device is properly powered.
  • Communication Settings: Double-check the baud rate in Serial mode (115200) and the device address (e.g., 0x08 for I2C).
  • Network Credentials: For WebSocket mode, make sure the correct SSID and password are configured. If the device fails to connect, verify your network settings.
  • BLE Pairing: If your BLE client does not find the device, ensure that the device is broadcasting and that your client's BLE is enabled.
  • Client Software: Have a serial monitor, a BLE scanner, or a WebSocket client (for example, a browser-based tool) readily available during testing.

Changelog

VersionChanges
v3.0.0
  • Monitor function
  • New examples
v2.0.0
  • New Registration function for easier implementation (It combine the previous 3 functions)
  • Changed definition and declaration of structs in the .h file
v1.0.1
  • Added BLE example (between device and desktop)
  • Added I2C example (between two devices)
v1.0.0
  • Initial release