### Server-Side Parameter Service Setup (C)
Source: https://context7.com/spaceinventor/libparam/llms.txt
Initializes and configures the parameter server to handle incoming parameter requests on a specific CSP port. It first initializes CSP networking, starts a VMEM server thread, and then binds the parameter service. Requires 'param/param_server.h', 'vmem/vmem_server.h', and 'csp/csp.h'.
```c
#include
#include
#include
#include
void setup_param_server() {
// Initialize CSP networking first
csp_init();
csp_bind_callback(csp_service_handler, CSP_ANY);
// Start VMEM server thread for virtual memory access
static pthread_t vmem_server_handle;
pthread_create(&vmem_server_handle, NULL,
&vmem_server_task, NULL);
// Bind parameter service to port 10
csp_bind_callback(param_serve, PARAM_PORT_SERVER);
printf("Parameter server running on port %d\n", PARAM_PORT_SERVER);
}
```
--------------------------------
### Parameter Type Operations and Conversions in C
Source: https://context7.com/spaceinventor/libparam/llms.txt
Illustrates working with parameters of various data types (float, int32_t array, string) and performing common operations like getting, setting, and copying values. It also shows how to determine parameter size. Requires the param library.
```c
#include
// Define parameters of various types
float _temperature = 25.5f;
PARAM_DEFINE_STATIC_RAM(20, temp, PARAM_TYPE_FLOAT,
1, sizeof(float), PM_TELEM, NULL,
"°C", &_temperature, "Temperature");
int32_t _position[3] = {100, -200, 300};
PARAM_DEFINE_STATIC_RAM(21, pos, PARAM_TYPE_INT32,
3, sizeof(int32_t), PM_TELEM, NULL,
"mm", &_position[0], "XYZ Position");
char _device_name[32] = "Sensor-01";
PARAM_DEFINE_STATIC_RAM(22, name, PARAM_TYPE_STRING,
32, 1, PM_CONF, NULL,
"", &_device_name[0], "Device name");
void type_operations() {
// Float operations
float t = param_get_float(&temp);
param_set_float(&temp, t + 0.5f);
// Array operations
int32_t x = param_get_int32_array(&pos, 0);
int32_t y = param_get_int32_array(&pos, 1);
int32_t z = param_get_int32_array(&pos, 2);
param_set_int32_array(&pos, 0, x + 10);
// String operations
char buffer[32];
param_get_string(&name, buffer, sizeof(buffer));
param_set_string(&name, "Sensor-02", 10);
// Generic operations
int size = param_size(&temp); // Returns 4 for float
param_copy(&temp, &temp); // Copy parameter value
}
```
--------------------------------
### Batch Parameter Operations (C)
Source: https://context7.com/spaceinventor/libparam/llms.txt
Handles retrieval and storage of multiple parameters within a single CSP transaction using parameter queues. It supports both GET and SET queue types. Requires 'param/param_queue.h' and 'param/param_client.h'. Returns -1 on failure.
```c
#include
#include
int batch_parameter_operations() {
// Initialize queue buffer
param_queue_t queue;
uint8_t queue_buf[200-2]; // PARAM_SERVER_MTU-2
int VERSION = 2;
int TIMEOUT = 1000;
// Create GET queue to retrieve multiple parameters
param_queue_init(&queue, queue_buf, sizeof(queue_buf),
0, PARAM_QUEUE_TYPE_GET, VERSION);
// Add parameters to queue
param_queue_add(&queue, &state, 0, NULL); // Get state[0]
param_queue_add(&queue, &counter, -1, NULL); // Get all counter indices
// Execute pull request
if (param_pull_queue(&queue, CSP_PRIO_NORM, 0,
remote_node, TIMEOUT) < 0) {
printf("Failed to pull queue\n");
return -1;
}
// Parameters now updated in local cache
uint8_t state_val = param_get_uint8_array(&state, 0);
uint16_t counter_val = param_get_uint16(&counter);
// Modify values
param_set_uint8_array(&state, 0, 2);
param_set_uint16(&counter, counter_val + 1);
// Create SET queue to push changes
param_queue_init(&queue, queue_buf, sizeof(queue_buf),
0, PARAM_QUEUE_TYPE_SET, VERSION);
param_queue_add(&queue, &state, 0, NULL);
param_queue_add(&queue, &counter, -1, NULL);
// Execute push request
if (param_push_queue(&queue, CSP_PRIO_NORM, 0,
remote_node, TIMEOUT, 0, false) < 0) {
printf("Failed to push queue\n");
return -1;
}
return 0;
}
```
--------------------------------
### Parameter Publishing System Configuration (C)
Source: https://context7.com/spaceinventor/libparam/llms.txt
Sets up an automatic parameter publishing system for telemetry. It defines static parameters with telemetry flags, adds them to publish queues, configures publishing queues with periods and priorities, and initializes the publishing system. A callback function controls when publishing occurs. Requires 'param/param_server.h'.
```c
#include
// Define parameters with publishing enabled
PARAM_DEFINE_STATIC_RAM(10, sensor_temp, PARAM_TYPE_FLOAT,
1, sizeof(float), PM_TELEM, NULL,
"°C", &temperature, "Temperature sensor");
PARAM_DEFINE_STATIC_RAM(11, gyro_data, PARAM_TYPE_INT16,
3, sizeof(int16_t), PM_TELEM, NULL,
"deg/s", &gyro[0], "Gyroscope XYZ");
// Add parameters to publish queues
PARAM_ADD_PUBLISH(sensor_temp, PARAM_PUBLISHQUEUE_0);
PARAM_ADD_PUBLISH(gyro_data, PARAM_PUBLISHQUEUE_0);
// Callback to control publishing
static bool shall_publish(uint8_t queue) {
// Only publish queue 0 if telemetry is valid
return queue == 0 && telemetry_enabled;
}
void init_publishing() {
// Configure high-frequency queue (200ms period)
param_publish_configure(PARAM_PUBLISHQUEUE_0,
5, // Destination node
200, // Period in ms
CSP_PRIO_HIGH); // CSP priority
// Initialize publishing system
param_publish_init(shall_publish);
}
void sampling_loop() {
while (1) {
// Update sensor values
temperature = read_temperature_sensor();
read_gyroscope(&gyro[0], &gyro[1], &gyro[2]);
// Trigger periodic publishing
param_publish_periodic();
usleep(10000); // 10ms sampling rate
}
}
```
--------------------------------
### C: Configure and Initialize libparam Publishing Queues
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Initializes the libparam publishing system and configures publishing queues. This involves setting the destination, frequency, and CSP priority for each queue. An optional callback function can be provided to `param_publish_init` to control when parameters are published.
```c
void hook_init(void) {
/* High freq data for AOCS */
param_publish_configure(PARAM_PUBLISHQUEUE_0, param_get_uint16_array(¶m_publish_destination, PARAM_PUBLISHQUEUE_0), 200, CSP_PRIO_HIGH);
/* Low freq data for HK */
param_publish_configure(PARAM_PUBLISHQUEUE_1, param_get_uint16_array(¶m_publish_destination, PARAM_PUBLISHQUEUE_1), 5000, CSP_PRIO_LOW);
param_publish_init(shall_publish);
}
```
--------------------------------
### Object Store Allocation and Scanning in C
Source: https://context7.com/spaceinventor/libparam/llms.txt
Provides functionalities for managing typed objects within virtual memory, including allocation, writing, reading, and removal. It also demonstrates scanning for existing objects using a callback function. Requires the objstore library and a configured VMEM.
```c
#include
// Callback for scanning objects
int scan_callback(vmem_t * vmem, int offset, int verbose, void * ctx) {
int type = objstore_read_obj_type(vmem, offset);
int length = objstore_read_obj_length(vmem, offset);
printf("Found object: type=%d, length=%d at offset=%d\n",
type, length, offset);
return 0; // Continue scanning
}
void objstore_usage() {
vmem_t * vmem = &vmem_config;
// Scan existing objects in VMEM
objstore_scan(vmem, scan_callback, 1, NULL);
// Allocate space for new object
int offset = objstore_alloc(vmem, 64, 1);
if (offset < 0) {
printf("Allocation failed\n");
return;
}
// Write object with data
uint8_t object_data[64] = {0};
objstore_write_obj(vmem, offset, OBJ_TYPE_SCHEDULE,
sizeof(object_data), object_data);
// Read object back
uint8_t read_buffer[64];
if (objstore_read_obj(vmem, offset, read_buffer, 1) == 0) {
printf("Object read successfully\n");
}
// Remove object when done
objstore_rm_obj(vmem, offset, 1);
}
```
--------------------------------
### Initialize VMEM Server and Bind Parameter Service (C)
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Initializes the virtual memory server task and binds the parameter service to a specific CSP port. This is typically done after CSP initialization in the application's main function to make the parameter service available over CSP.
```c
static pthread_t vmem_server_handle;
pthread_create(&vmem_server_handle, NULL, &vmem_server_task, NULL);
csp_bind_callback(param_serve, PARAM_PORT_SERVER);
```
--------------------------------
### Configure Build Options (Meson)
Source: https://github.com/spaceinventor/libparam/blob/master/meson_options.txt
These options are used to configure the build process for libparam, controlling which features and functionalities are included. They are typically set in a build system configuration file like Meson's meson.build. Dependencies are noted in the descriptions where applicable.
```meson
option('collector', type: 'boolean', value: false, description: 'Build collector')
option('vmem_fram', type: 'boolean', value: false, description: 'Build vmem fram')
option('have_fopen', type: 'boolean', value: false, description: 'POSIX fopen available')
option('list_dynamic', type: 'boolean', value: false, description: 'Compile support for dynamic param list (requres sys/queue.h) and dynamic memory allocation')
option('list_pool', type: 'integer', value: 0, description: 'Compile support for pre-allocated param list (requres sys/queue.h)')
option('have_float', type: 'boolean', value: true, description: 'Support float/double')
option('num_publishqueues', type: 'integer', value: 0, description: 'Number of param publish queues required')
option('test', type: 'boolean', value: false, description: 'Build GoogleTest based tests (requires gtest)')
```
--------------------------------
### Virtual Memory Read/Write Operations in C
Source: https://context7.com/spaceinventor/libparam/llms.txt
Demonstrates direct read and write operations on virtual memory addresses using the vmem library. It initializes a RAM-based VMEM, writes data to it, reads data back, and identifies the VMEM by its virtual address. Ensure vmem and vmem_ram libraries are included.
```c
#include
#include
// Define RAM-based VMEM
VMEM_DEFINE_STATIC_RAM(
config, // Name
"config", // String name
256 // Size in bytes
);
void vmem_operations() {
uint64_t vaddr = vmem_config.vaddr;
// Write data to VMEM
uint32_t data_out = 0x12345678;
vmem_write(vaddr + 0x10, &data_out, sizeof(data_out));
// Read data from VMEM
uint32_t data_in;
vmem_read(&data_in, vaddr + 0x10, sizeof(data_in));
printf("Read back: 0x%08X\n", data_in);
// Find VMEM by virtual address
vmem_t * vmem = vmem_vaddr_to_vmem(vaddr + 0x10);
if (vmem) {
printf("VMEM name: %s, size: %lu\n", vmem->name, vmem->size);
}
}
```
--------------------------------
### Manage Multiple Remote Parameters with Queues
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Illustrates efficient retrieval and storage of multiple remote parameters using a queue mechanism. This reduces network overhead by consolidating multiple operations into single CSP packets. It includes initialization, adding parameters to the queue, triggering the CSP transfer, and modifying values.
```c
param_queue_t queue;
uint8_t queue_buf[PARAM_SERVER_MTU-2];
param_queue_init(&queue, queue_buf, PARAM_SERVER_MTU-2, 0, PARAM_QUEUE_TYPE_GET, VERSION);
param_queue_add(&queue, &state, idx, NULL);
param_queue_add(&queue, &counter, INDEX_ALL, NULL);
/* Trigger CSP to request value from parameter server */
if (param_pull_queue(&queue, CSP_PRIO_NORM, VERBOSE, &state.node, TIMEOUT) < 0)
printf("Retrieving multiple parameter values failed\n");
/* Modify parameters */
if (param_get_uint8_array(&state, idx) == 0)
param_set_uint8_array(&state, idx, 1);
param_set_uint16(&counter, param_get_uint16(&counter) + 1);
/* Allocate new CSP packet and rebuild queue */
param_queue_init(&queue, queue_buf, PARAM_SERVER_MTU-2, 0, PARAM_QUEUE_TYPE_SET, VERSION);
param_queue_add(&queue, &state, idx, NULL);
param_queue_add(&queue, &counter, INDEX_ALL, NULL);
/* Trigger CSP to push queue values */
if (param_push_queue(&queue, CSP_PRIO_NORM, VERBOSE, &state.node, TIMEOUT, 0) < 0)
printf("Storing multiple parameter values failed\n");
```
--------------------------------
### Define Static RAM Parameter with Callback (C)
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Defines a parameter that maps to a static RAM array. It includes a callback function to be executed when the parameter's value is modified. This is useful for triggering actions upon data changes.
```c
uint8_t _state[2];
void state_cb(param_t * param, int index);
PARAM_DEFINE_STATIC_RAM(PARAMID_STATE, state, PARAM_TYPE_UINT8, \
sizeof(_state)/sizeof(_state[0]), sizeof(_state[0]), PM_TELEM, state_cb, NULL, \
&_state[0], "0 = idle, 1 = waiting, 2 = running");
```
--------------------------------
### Define VMEM-Based Parameter (C)
Source: https://context7.com/spaceinventor/libparam/llms.txt
Creates a parameter stored in virtual memory, such as FRAM or Flash, allowing for persistent storage. It requires defining a VMEM area first and specifies the parameter's offset within that area. Suitable for configuration settings that must survive reboots.
```c
#include
#include
// Define FRAM virtual memory area
VMEM_DEFINE_FRAM(
fram_cfg, // VMEM name
"fram_cfg", // String name
0x50000000, // Physical address
0x100, // Size (256 bytes)
0x1000 // Virtual address
);
// Define parameter stored in FRAM at offset 0x06
PARAM_DEFINE_STATIC_VMEM(
1, // Parameter ID (PARAMID_counter)
counter, // Parameter name
PARAM_TYPE_UINT16, // Data type
0, // Array size (0 = scalar)
0, // Element size
PM_SYSINFO, // Flags: system info
NULL, // No callback
"", // No unit
fram_cfg, // VMEM area
0x06, // Offset in VMEM
"Event counter" // Documentation
);
// Access VMEM parameter
int main() {
// Read counter from persistent storage
uint16_t count = param_get_uint16(&counter);
// Increment and write back (persisted to FRAM)
param_set_uint16(&counter, count + 1);
return 0;
}
```
--------------------------------
### Remote VMEM Upload/Download and CRC Calculation in C
Source: https://context7.com/spaceinventor/libparam/llms.txt
Enables transferring data to and from a remote node's virtual memory over the CSP network. It includes functions for uploading data, downloading data, and calculating the CRC32 checksum of a remote memory region. Requires the vmem_client library and a configured CSP network.
```c
#include
int remote_vmem_transfer() {
int node = 5;
int timeout = 5000; // 5 seconds
int version = 2;
uint64_t remote_addr = 0x1000;
// Upload data to remote VMEM
char upload_data[128] = "Configuration data";
int result = vmem_upload(node, timeout, remote_addr,
upload_data, sizeof(upload_data), version);
if (result < 0) {
printf("Upload failed: %d\n", result);
return -1;
}
// Download data from remote VMEM
char download_data[128];
result = vmem_download(node, timeout, remote_addr,
sizeof(download_data), download_data,
version, 0);
if (result < 0) {
printf("Download failed: %d\n", result);
return -1;
}
printf("Downloaded: %s\n", download_data);
// Calculate CRC32 of remote memory region
uint32_t crc;
vmem_client_calc_crc32(node, timeout, remote_addr, 128, &crc, version);
printf("Remote CRC32: 0x%08X\n", crc);
return 0;
}
```
--------------------------------
### Push Single Remote Parameter (C)
Source: https://context7.com/spaceinventor/libparam/llms.txt
Sends a single parameter value to a remote node using the CSP network. It modifies the local cache before pushing the updated value. Requires inclusion of 'param/param_client.h' and 'csp/csp.h'. Returns -1 on failure and 0 on success.
```c
#include
#include
int write_remote_parameter() {
int TIMEOUT = 1000;
int VERSION = 2;
// Modify local cache
param_set_uint8_array(&state, 0, 1);
// Push single index to remote node
if (param_push_single(&state, 0, CSP_PRIO_NORM, NULL,
0, remote_node, TIMEOUT, VERSION, false) < 0) {
printf("Failed to push parameter\n");
return -1;
}
printf("Successfully updated remote parameter\n");
return 0;
}
```
--------------------------------
### Access and Modify Local Parameter (C)
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Demonstrates programmatic access to a local parameter. It shows how to read the current value of an array parameter element and then set a new value. This is useful for interacting with parameters from within the same application.
```c
int idx = 0;
if (param_get_uint8_array(&state, idx) == 0)
param_set_uint8_array(&state, idx, 1);
```
--------------------------------
### C: Add Parameter for Publishing in libparam
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Uses the PARAM_ADD_PUBLISH macro to specify which parameters should be published and to which queue. This macro takes the parameter name and the target publish queue as arguments.
```c
PARAM_ADD_PUBLISH(state, PARAM_PUBLISHQUEUE_0);
```
--------------------------------
### Define Static RAM Parameter (C)
Source: https://context7.com/spaceinventor/libparam/llms.txt
Defines a parameter directly mapped to a RAM variable. Supports optional callbacks on modification and provides metadata like ID, type, size, and documentation. It's suitable for volatile parameters that can be directly accessed and modified in memory.
```c
#include
#include
// Define the backing storage
uint8_t _state[2] = {0, 1};
// Callback function triggered on parameter write
void state_cb(param_t * param, int index) {
printf("State[%d] changed to: %d\n", index, param_get_uint8_array(param, index));
}
// Define parameter with ID, type, size, flags, and callback
PARAM_DEFINE_STATIC_RAM(
0, // Parameter ID (PARAMID_STATE)
state, // Parameter name
PARAM_TYPE_UINT8, // Data type
2, // Array size
sizeof(uint8_t), // Element size
PM_TELEM, // Flags: telemetry parameter
state_cb, // Callback function
NULL, // Unit string
&_state[0], // Physical address
"0=idle, 1=waiting, 2=running" // Documentation
);
// Access the parameter locally
int main() {
// Read value at index 0
uint8_t value = param_get_uint8_array(&state, 0);
// Modify value at index 1 (triggers callback)
param_set_uint8_array(&state, 1, 2);
return 0;
}
```
--------------------------------
### Access and Modify Single Remote Parameter
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Demonstrates how to retrieve, modify, and store a single remote parameter. It involves pulling the parameter value, optionally modifying it, and then pushing the updated value back to the server. Error handling for network operations is included.
```c
if (param_pull_single(&state, INDEX_ALL, CSP_PRIO_NORM, VERBOSE, *state.node, TIMEOUT, 2) < 0)
printf("Retrieving parameter value failed\n");
if (param_get_uint8_array(&state, idx) == 0)
param_set_uint8_array(&state, idx, 1);
if (param_push_single(&state, idx, CSP_PRIO_NORM, NULL, VERBOSE, *state.node, TIMEOUT, VERSION) < 0)
printf("Storing parameter value failed\n");
```
--------------------------------
### Define Static VMEM Parameter from FRAM (C)
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Defines a parameter that resides in a virtual memory (VMEM) area, specifically an FRAM configuration memory. This allows persistent storage of parameter values. The parameter is mapped to a specific offset within the defined VMEM.
```c
VMEM_DEFINE_FRAM(fram_cfg, "fram_cfg", PHYS_ADDR, PHYS_SIZE, VIRT_ADDR);
PARAM_DEFINE_STATIC_VMEM(PARAMID_counter, counter, PARAM_TYPE_UINT16, 0, 0, PM_SYSINFO, NULL, \
"", fram_cfg, 0x06, "Event counter");
```
--------------------------------
### Define VMEM-Based Parameter
Source: https://context7.com/spaceinventor/libparam/llms.txt
Creates a parameter that is stored in virtual memory, such as FRAM or Flash. This allows for persistent storage of parameter values across power cycles.
```APIDOC
## Define VMEM-Based Parameter
### Description
Creates a parameter stored in virtual memory (FRAM, Flash, or other persistent storage).
### Method
N/A (Compile-time definition)
### Endpoint
N/A (Compile-time definition)
### Parameters
N/A (Compile-time definition)
### Request Example
```c
#include
#include
// Define FRAM virtual memory area
VMEM_DEFINE_FRAM(
fram_cfg, // VMEM name
"fram_cfg", // String name
0x50000000, // Physical address
0x100, // Size (256 bytes)
0x1000 // Virtual address
);
// Define parameter stored in FRAM at offset 0x06
PARAM_DEFINE_STATIC_VMEM(
1, // Parameter ID (PARAMID_counter)
counter, // Parameter name
PARAM_TYPE_UINT16, // Data type
0, // Array size (0 = scalar)
0, // Element size
PM_SYSINFO, // Flags: system info
NULL, // No callback
"", // No unit
fram_cfg, // VMEM area
0x06, // Offset in VMEM
"Event counter" // Documentation
);
// Access VMEM parameter
int main() {
// Read counter from persistent storage
uint16_t count = param_get_uint16(&counter);
// Increment and write back (persisted to FRAM)
param_set_uint16(&counter, count + 1);
return 0;
}
```
### Response
N/A (Compile-time definition)
```
--------------------------------
### Define Static RAM Parameter
Source: https://context7.com/spaceinventor/libparam/llms.txt
Defines a parameter that is directly mapped to a RAM variable. It supports an optional callback function that is triggered when the parameter's value is modified.
```APIDOC
## Define Static RAM Parameter
### Description
Creates a parameter definition mapped directly to a RAM variable with optional callback on modification.
### Method
N/A (Compile-time definition)
### Endpoint
N/A (Compile-time definition)
### Parameters
N/A (Compile-time definition)
### Request Example
```c
#include
#include
// Define the backing storage
uint8_t _state[2] = {0, 1};
// Callback function triggered on parameter write
void state_cb(param_t * param, int index) {
printf("State[%d] changed to: %d\n", index, param_get_uint8_array(param, index));
}
// Define parameter with ID, type, size, flags, and callback
PARAM_DEFINE_STATIC_RAM(
0, // Parameter ID (PARAMID_STATE)
state, // Parameter name
PARAM_TYPE_UINT8, // Data type
2, // Array size
sizeof(uint8_t), // Element size
PM_TELEM, // Flags: telemetry parameter
state_cb, // Callback function
NULL, // Unit string
&_state[0], // Physical address
"0=idle, 1=waiting, 2=running" // Documentation
);
// Access the parameter locally
int main() {
// Read value at index 0
uint8_t value = param_get_uint8_array(&state, 0);
// Modify value at index 1 (triggers callback)
param_set_uint8_array(&state, 1, 2);
return 0;
}
```
### Response
N/A (Compile-time definition)
```
--------------------------------
### C: Conditional Parameter Publishing Logic
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Defines a callback function for the libparam publish system. This function determines whether a parameter should be published based on the queue identifier or a telemetry validity check. It is used during the initialization of the publish system.
```c
static bool shall_publish(uint8_t q) {
return q == 1 || telemetry_is_valid();
}
```
--------------------------------
### Pull Single Remote Parameter (C)
Source: https://context7.com/spaceinventor/libparam/llms.txt
Retrieves a parameter value from a remote node over the CSP network. It defines a local cache for the remote parameter and uses a client function to pull data, specifying the remote node, timeout, and protocol version. This is essential for monitoring and controlling distributed systems.
```c
#include
#include
// Define remote parameter with local cache
uint8_t _remote_state[2];
uint16_t remote_node = 5; // CSP node address
PARAM_DEFINE_REMOTE(
0, // Remote parameter ID
state, // Parameter name
&remote_node, // Pointer to node address
PARAM_TYPE_UINT8, // Data type
2, // Array size
sizeof(uint8_t), // Element size
PM_TELEM, // Flags
&_remote_state[0], // Local cache storage
NULL // Documentation
);
int read_remote_parameter() {
int INDEX_ALL = -1; // Pull all array indices
int TIMEOUT = 1000; // 1 second timeout
int VERSION = 2; // Protocol version
// Pull parameter from remote node
if (param_pull_single(&state, INDEX_ALL, CSP_PRIO_NORM,
0, remote_node, TIMEOUT, VERSION) < 0) {
printf("Failed to retrieve parameter\n");
return -1;
}
// Access cached value
uint8_t value = param_get_uint8_array(&state, 0);
printf("Remote state[0] = %d\n", value);
return 0;
}
```
--------------------------------
### Define Remote Parameter
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Defines a remote parameter that can be accessed and modified by a client executable. It requires specifying parameter ID, name, node, type, size, and mask. The parameter value is cached locally in RAM.
```c
int INDEX_ALL = -1; /* Pull/push all indices */
int VERBOSE = 0; /* Do not print additional debug output */
int TIMEOUT = 1000; /* Timeout for remote access [ms] */
int VERSION = 2; /* Current param interface version */
uint8_t _state[2];
uint16_t node;
PARAM_DEFINE_REMOTE(PARAMID_STATE, state, &node, PARAM_TYPE_UINT8, \
sizeof(_state)/sizeof(_state[0]), sizeof(_state[0]), PM_TELEM, &_state[0], NULL);
```
--------------------------------
### C: Periodic Publishing Call in libparam
Source: https://github.com/spaceinventor/libparam/blob/master/doc/introduction.rst
Calls the `param_publish_periodic` function to handle the publishing of registered parameters to their configured queues. The frequency of calling this function dictates the accuracy of respecting the configured publishing queue periodicity. It's typically called within a sampling or update loop.
```c
void my_sample(void)
{
/* Sampling and parameter update code goes here */
/* and finally */
param_publish_periodic();
}
```
--------------------------------
### Pull Single Remote Parameter
Source: https://context7.com/spaceinventor/libparam/llms.txt
Retrieves the value of a parameter from a remote node over the CSP network. The retrieved value is stored in a local cache.
```APIDOC
## Pull Single Remote Parameter
### Description
Retrieves a parameter value from a remote node over CSP network.
### Method
N/A (Client-side function call)
### Endpoint
N/A (Function call with remote node address)
### Parameters
N/A (Function parameters and compile-time definition)
### Request Example
```c
#include
#include
// Define remote parameter with local cache
uint8_t _remote_state[2];
uint16_t remote_node = 5; // CSP node address
PARAM_DEFINE_REMOTE(
0, // Remote parameter ID
state, // Parameter name
&remote_node, // Pointer to node address
PARAM_TYPE_UINT8, // Data type
2, // Array size
sizeof(uint8_t), // Element size
PM_TELEM, // Flags
&_remote_state[0], // Local cache storage
NULL // Documentation
);
int read_remote_parameter() {
int INDEX_ALL = -1; // Pull all array indices
int TIMEOUT = 1000; // 1 second timeout
int VERSION = 2; // Protocol version
// Pull parameter from remote node
if (param_pull_single(&state, INDEX_ALL, CSP_PRIO_NORM,
0, remote_node, TIMEOUT, VERSION) < 0) {
printf("Failed to retrieve parameter\n");
return -1;
}
// Access cached value
uint8_t value = param_get_uint8_array(&state, 0);
printf("Remote state[0] = %d\n", value);
return 0;
}
```
### Response
#### Success Response (200)
N/A (Value is stored in local cache)
#### Response Example
N/A (Value is stored in local cache)
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.