The TST (TrueSmartTech) Library is a comprehensive communication framework designed to facilitate seamless device connectivity through multiple protocols. The library provides a structured approach for variable management, file operations, device monitoring, and firmware updates across different communication interfaces such as Serial, BLE, I2C, and WebSockets.
The library is organized into several core components:
To use the TST Library, you need to initialize it with your device configuration:
#include "tst_library.h"
#include "tst_variables.h"
void setup() {
// Initialize the TST library with device configuration
tstInit(&TST_Device);
// Register handlers for file system operations
tstRegisterFsHandlers(handleFsList, handleFsUpload, handleFsDownload, handleFsDelete);
// Register handler for update operations
tstRegisterUpdateHandler(handleUpdate);
}
The library requires continuous execution of receive and transmit functions to maintain communication. This should be placed in your main loop:
void loop() {
// Process incoming/outgoing messages
uint8_t buffer[TSTMAXSIZE];
size_t size = 0;
// Check for incoming data from your physical interface
if (yourPhysicalInterface.available()) {
size = yourPhysicalInterface.read(buffer, TSTMAXSIZE);
// Pass received data to TST library
if (size > 0) {
tstRx(TSTNAME, "SERIAL", buffer, size);
}
}
// Check for outgoing messages
if (tstTx(TSTNAME, "SERIAL", buffer, &size) == TST_OK && size > 0) {
yourPhysicalInterface.write(buffer, size);
}
}
Variables are defined in the tst_variables.h file:
typedef struct {
uint16_t myVariable;
uint16_t myLED;
} TST_Variables;
The library provides functions to get and set variables:
// Get a variable value
tstVariablesGet(TSTNAME, "SERIAL", &TST_V.myVariable, sizeof(TST_V.myVariable));
// Set a variable value
uint16_t newValue = 100;
tstVariablesSet(TSTNAME, "SERIAL", &TST_V.myVariable, sizeof(TST_V.myVariable), &newValue);
To handle file system operations, you need to implement and register handler functions:
uint8_t handleFsList(const char *path, uint8_t **outData, uint32_t *outSize) {
// Implementation for listing files in a directory
// Populate outData with the directory listing
// Set outSize to the size of the listing
return TST_OK;
}
uint8_t handleFsUpload(const char *path, const uint8_t *data, uint32_t offset, uint32_t size) {
// Implementation for uploading/writing file data
// Write 'data' of 'size' bytes at 'offset' to 'path'
return TST_OK;
}
uint8_t handleFsDownload(const char *path, uint32_t offset, uint32_t requestedSize,
uint8_t **outData, uint32_t *outSize) {
// Implementation for downloading/reading file data
// Read 'requestedSize' bytes from 'path' starting at 'offset'
// Store the result in outData and the actual size in outSize
return TST_OK;
}
uint8_t handleFsDelete(const char *path) {
// Implementation for deleting a file
return TST_OK;
}
To perform file operations from the client side:
// List files in a directory
tstFsList(TSTNAME, "SERIAL", "/some/directory");
// Upload a file
uint8_t fileData[] = {0x01, 0x02, 0x03, 0x04};
tstFsUpload(TSTNAME, "SERIAL", "/path/to/file.bin", fileData, 0, sizeof(fileData));
// Download a file
tstFsDownload(TSTNAME, "SERIAL", "/path/to/file.bin", 0, 1024);
// Delete a file
tstFsDelete(TSTNAME, "SERIAL", "/path/to/file.bin");
To send monitoring messages:
// Send a monitoring message
tstMonitorSend(TSTNAME, "SERIAL", "System status: OK, Temperature: 25°C");
To handle firmware updates, implement and register an update handler:
uint8_t handleUpdate(const uint8_t *data, uint32_t size, uint32_t sequenceNumber,
uint32_t crc, uint8_t operation) {
switch (operation) {
case START:
// Begin update process
// Initialize update state, prepare storage
break;
case DATA:
// Process update data chunk
// Write data to storage, validate CRC
break;
case END:
// Complete update process
// Finalize, validate entire update, prepare for reboot
break;
}
return TST_OK;
}
After processing update requests, send responses to acknowledge receipt:
// Send update response
// Parameters: device, interface, operation, status, sequence, crc
tstUpdateResponseSend(TSTNAME, "SERIAL", DATA, TST_OK, sequenceNumber, crc);
The library provides a set of error codes defined in tst_errors.h:
TST_OK
: Operation completed successfullyTST_NO_STRUCT_FOUND
: Requested structure not foundTST_INVALID_POINTER
: Invalid pointer providedTST_STRUCT_ALREADY_PRESENT
: Structure already registeredTST_FAIL_ALLOCATE_MEMORY
: Memory allocation failedTST_FAIL
: General failureTST_FAIL_UPDATE
: Update operation failedAlways check return values from TST library functions to handle errors appropriately.
The library supports multiple communication interfaces. To use more than one interface:
// Define interfaces in tst_variables.h
static const TST_InterfaceConfig TST_Interfaces[] = {
{.interface = "SERIAL", .maxSize = 1024},
{.interface = "BLE", .maxSize = 512},
{.interface = "I2C", .maxSize = 256}
};
// Update device config
static const TST_DeviceConfig TST_Device = {
.name = "MyDevice",
.pInterfaces = TST_Interfaces,
.nInterfaces = sizeof(TST_Interfaces),
.pStructs = &TST_Struct,
.nStructs = sizeof(TST_Struct)
};
You can manage multiple variable structures:
typedef struct {
uint16_t sensorValue;
} TST_SensorData;
typedef struct {
uint8_t ledState;
} TST_OutputState;
// Define and initialize the structs
TST_SensorData TST_Sensors = {0};
TST_OutputState TST_Outputs = {0};
// Create struct configs
static const TST_StructConfig TST_Structs[] = {
{.name = "Sensors", .structName = "TST_SensorData", .pStruct = &TST_Sensors, .sStruct = sizeof(TST_Sensors)},
{.name = "Outputs", .structName = "TST_OutputState", .pStruct = &TST_Outputs, .sStruct = sizeof(TST_Outputs)}
};
// Update device config
static const TST_DeviceConfig TST_Device = {
.name = "MyDevice",
.pInterfaces = &TST_Interface,
.nInterfaces = sizeof(TST_Interface),
.pStructs = TST_Structs,
.nStructs = sizeof(TST_Structs)
};
If you encounter communication issues:
/*TSTVARIABLESSTART*/
/*TSTVARIABLESEND*/
#define TSTNAME "your_device_name"
Function | Description | Example |
---|---|---|
tstInit | Initializes the TST library with device configuration | tstInit(&TST_Device); |
tstRx | Processes received data from an interface | tstRx(TSTNAME, ”INTERFACE”, data, size); |
tstTx | Transmits data through the specified interface | tstTx(TSTNAME, ”INTERFACE”, buffer, &size); |
tstVariablesGet | Retrieves variable values from another device | tstVariablesGet(TSTNAME, ”INTERFACE”, &variable, sizeof(variable)); |
tstVariablesSet | Sets a variable value on another device | tstVariablesSet(TSTNAME, ”INTERFACE”, &variable, sizeof(variable), &value); |
tstMonitorSend | Sends a text message to the monitor | tstMonitorSend(TSTNAME, ”INTERFACE”, message); |
tstRegisterFsHandlers | Registers handlers for file system operations | tstRegisterFsHandlers(handleList, handleUpload, handleDownload, handleDelete); |
tstRegisterUpdateHandler | Registers handler for firmware updates | tstRegisterUpdateHandler(handleUpdate); |
Type | Size (bytes) | Description |
---|---|---|
bool | 1 | Boolean value (true/false) |
int8_t | 1 | 8-bit signed integer |
uint8_t | 1 | 8-bit unsigned integer |
int16_t | 2 | 16-bit signed integer |
uint16_t | 2 | 16-bit unsigned integer |
int32_t | 4 | 32-bit signed integer |
uint32_t | 4 | 32-bit unsigned integer |
int64_t | 8 | 64-bit signed integer |
uint64_t | 8 | 64-bit unsigned integer |
float | 4 | Single-precision floating-point |
double | 8 | Double-precision floating-point |
char[] | Variable | Character array (string) |
struct | Variable | Custom data structure (packed) |
array | Variable | Array of any supported type |
This guide explains how to operate the application across its different communication interfaces. Follow these steps for a smooth experience.
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.
ws://<device_ip>/ws
.Version | Changes |
---|---|
v4.0.4 |
|
v4.0.3 |
|
v4.0.2 |
|
v4.0.1 |
|
v4.0.0 |
|
v3.0.0 |
|
v2.0.0 |
|
v1.0.1 |
|
v1.0.0 |
|
Have questions or need assistance? We'd love to hear from you.