save failed integration state

This commit is contained in:
2020-11-26 10:24:23 +01:00
parent 77970418d8
commit 17fc4b0de1
194 changed files with 45450 additions and 2 deletions

View File

@ -0,0 +1,42 @@
#ifndef GS_PARAM_INTERNAL_PP_I2C_I2C_H
#define GS_PARAM_INTERNAL_PP_I2C_I2C_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
#if (GS_PARAM_INTERNAL_USE)
#include <gs/param/pp/i2c/i2c.h>
#include <gs/param/internal/pp/i2c/slave_dispatch.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GS_PARAM_I2C_LENGTH_TABLE(length, table) ((length << 3) | (table & 0x07))
#define GS_PARAM_I2C_LENGTH_TABLE_TO_LENGTH(lt) ((lt >> 3) & 0x1f)
#define GS_PARAM_I2C_LENGTH_TABLE_TO_TABLE(lt) (lt & 0x07)
/**
Data structure for setting parameter.
*/
typedef struct __attribute__ ((packed)) gs_param_i2c_set_request {
gs_i2c_slave_dispatch_header_t header;
uint8_t length_table;
uint8_t addr;
uint8_t data[]; // data (+ checksum)
} gs_param_i2c_set_request_t;
/**
Data structure for getting parameter.
*/
typedef struct __attribute__ ((packed)) gs_param_i2c_get_request {
gs_i2c_slave_dispatch_header_t header;
uint8_t length_table;
uint8_t addr;
uint8_t checksum; // optional
} gs_param_i2c_get_request_t;
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -0,0 +1,71 @@
#ifndef GS_PARAM_INTERNAL_PP_I2C_SLAVE_DISPATCH_H
#define GS_PARAM_INTERNAL_PP_I2C_SLAVE_DISPATCH_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
#if (GS_PARAM_INTERNAL_USE)
#include <gs/util/drivers/i2c/slave.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Header for I2C slave dispatch protocol - must be first in all protocols.
*/
typedef struct __attribute__ ((packed)) gs_i2c_slave_dispatch_header {
uint8_t domain_command;
} gs_i2c_slave_dispatch_header_t;
/**
Make header from domain and command.
*/
#define GS_I2C_SLAVE_DISPATCH_HEADER(domain, command) ((domain << 5) | (command & 0x1f))
/**
Extract domain from header.
*/
#define GS_I2C_SLAVE_DISPATCH_HEADER_TO_DOMAIN(header) ((header >> 5) & 0x7)
/**
Extract comman from header.
*/
#define GS_I2C_SLAVE_DISPATCH_HEADER_TO_COMMAND(header) (header & 0x1f)
/**
Domain handler.
Basically same features as normal I2C slave rx callback. The generic I2C dispatch interface will parse the header (first byte)
and call the associated handler, based on the domain.
@param[in] channel I2C channel (handle).
@param[in] cmd domain specific command.
@param[in] rx_buffer Pointer to start of rx buffer.
@param[in] rx number of bytes received so far.
@param[in] cswitch If called from within an ISR (embedded platform), this will none NULL.
@return total number of bytes to receive before next call back. Return 0 to ignore rest of data - no additional call backs will be done for current I2C transaction.
*/
typedef void (* gs_i2c_slave_dispatch_handler_t)(uint8_t channel, uint8_t cmd, const uint8_t * rx, size_t rx_length, gs_context_switch_t * cswitch);
/**
Dispatch domains.
Standard domains should be assigned from the lowest value.
Application/board/product should be assigned from highest value.
*/
typedef enum {
GS_I2C_SLAVE_DISPATCH_DOMAIN_RESERVED = 0, //! Avoid use - reserved for GSSB, GSSB broadcasts UID request on domain=0, cmd=13
GS_I2C_SLAVE_DISPATCH_DOMAIN_USER1, //! Avoid use - overlap with GSSB commands
GS_I2C_SLAVE_DISPATCH_DOMAIN_USER2, //! Avoid use - may overlap with GSSB commands
GS_I2C_SLAVE_DISPATCH_DOMAIN_USER3, //! Avoid use - may overlap with GSSB commands
GS_I2C_SLAVE_DISPATCH_DOMAIN_PARAM, //! Reserved for libparam.
GS_I2C_SLAVE_DISPATCH_DOMAIN_USER5,
GS_I2C_SLAVE_DISPATCH_DOMAIN_USER6,
GS_I2C_SLAVE_DISPATCH_DOMAIN_USER7,
} gs_i2c_slave_dispatch_domain_t;
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -0,0 +1,80 @@
#ifndef GS_PARAM_INTERNAL_PP_SPI_SLAVE_DISPATCH_H
#define GS_PARAM_INTERNAL_PP_SPI_SLAVE_DISPATCH_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
#if (GS_PARAM_INTERNAL_USE)
#include <gs/util/drivers/spi/slave.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Header for SPI slave dispatch protocol - must be first in all protocols.
*/
typedef struct __attribute__ ((packed)) gs_spi_slave_dispatch_header {
uint8_t domain_command;
} gs_spi_slave_dispatch_header_t;
/**
Make header from domain and command.
*/
#define GS_SPI_SLAVE_DISPATCH_HEADER(domain, command) ((domain << 5) | (command & 0x1f))
/**
Extract domain from header.
*/
#define GS_SPI_SLAVE_DISPATCH_HEADER_TO_DOMAIN(header) ((header >> 5) & 0x7)
/**
Extract comman from header.
*/
#define GS_SPI_SLAVE_DISPATCH_HEADER_TO_COMMAND(header) (header & 0x1f)
/**
Domain handler.
Basically same features as normal SPI slave rx callback. The generic SPI dispatch interface will parse the header (first byte)
and call the associated handler, based on the domain.
@param[in] channel SPI channel (handle).
@param[in] cmd domain specific command.
@param[in] rx_buffer Pointer to start of rx buffer.
@param[in] rx number of bytes received so far.
@param[in] cswitch If called from within an ISR (embedded platform), this will none NULL.
@return total number of bytes to receive before next call back. Return 0 to ignore rest of data - no additional call backs will be done for current SPI transaction.
*/
typedef uint8_t (* gs_spi_slave_dispatch_handler_t)(uint8_t channel, uint8_t cmd, const uint8_t * rx_buffer, size_t rx, gs_context_switch_t * cswitch);
/**
Dispatch domains.
Standard domains should be assigned form the lowest value.
Application/board/product should be assigned from highest value.
*/
typedef enum {
GS_SPI_SLAVE_DISPATCH_DOMAIN_RESERVED = 0, //! Avoid using 0,
GS_SPI_SLAVE_DISPATCH_DOMAIN_USER1,
GS_SPI_SLAVE_DISPATCH_DOMAIN_USER2,
GS_SPI_SLAVE_DISPATCH_DOMAIN_USER3,
GS_SPI_SLAVE_DISPATCH_DOMAIN_PARAM,
GS_SPI_SLAVE_DISPATCH_DOMAIN_USER5,
GS_SPI_SLAVE_DISPATCH_DOMAIN_USER6,
GS_SPI_SLAVE_DISPATCH_DOMAIN_USER7,
} gs_spi_slave_dispatch_domain_t;
/**
Slave dispatch SPI receiver.
Must be added on the channel as receiver function, using gs_spi_slave_set_rx().
@param[in] cswitch If called from within an ISR (embedded platform), this will be set and allow for triggering context switch.
*/
uint8_t gs_spi_slave_dispatch_rx(uint8_t channel, const uint8_t * rx_buffer, size_t rx, bool new_request, gs_context_switch_t * cswitch);
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -0,0 +1,65 @@
#ifndef GS_PARAM_INTERNAL_PP_SPI_SPI_H
#define GS_PARAM_INTERNAL_PP_SPI_SPI_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
#if (GS_PARAM_INTERNAL_USE)
#include <gs/param/pp/spi/spi.h>
#include <gs/param/internal/pp/spi/slave_dispatch.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Domain commands.
*/
typedef enum {
GS_PARAM_SPI_COMMAND_SET = 1,
GS_PARAM_SPI_COMMAND_GET = 2,
GS_PARAM_SPI_COMMAND_SET_WITH_CHECKSUM = 10,
GS_PARAM_SPI_COMMAND_GET_WITH_CHECKSUM = 11,
} gs_param_spi_command_t;
#define GS_PARAM_SPI_LENGTH_TABLE(length, table) ((length << 3) | (table & 0x07))
#define GS_PARAM_SPI_LENGTH_TABLE_TO_LENGTH(lt) ((lt >> 3) & 0x1f)
#define GS_PARAM_SPI_LENGTH_TABLE_TO_TABLE(lt) (lt & 0x07)
/**
Data structure for setting parameter.
*/
typedef struct __attribute__ ((packed)) gs_param_spi_set {
gs_spi_slave_dispatch_header_t header;
uint8_t length_table;
uint8_t addr;
uint8_t data[]; // data (+ checksum)
} gs_param_spi_set_t;
/**
Data structure for getting parameter.
*/
typedef struct __attribute__ ((packed)) gs_param_spi_get {
gs_spi_slave_dispatch_header_t header;
uint8_t length_table;
uint8_t addr;
uint8_t filler; // filler/delay - allow slave to find and prepare data/response
uint8_t data[]; // data
} gs_param_spi_get_t;
/**
Data structure for getting parameter with checksum
*/
typedef struct __attribute__ ((packed)) gs_param_spi_get_with_checksum {
gs_spi_slave_dispatch_header_t header;
uint8_t length_table;
uint8_t addr;
uint8_t checksum;
uint8_t filler; // filler/delay - allow slave to find and prepare data/response
uint8_t data[]; // data + checksum
} gs_param_spi_get_with_checksum_t;
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -0,0 +1,146 @@
#ifndef GS_PARAM_INTERNAL_RPARAM_H
#define GS_PARAM_INTERNAL_RPARAM_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
#if (GS_PARAM_INTERNAL_USE)
#include <gs/param/rparam.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Max query payload in a single message (bytes).
*/
#define GS_RPARAM_QUERY_MAX_PAYLOAD 180
/**
Macro for calculating total query message size, header + payload.
*/
#define RPARAM_QUERY_LENGTH(query, payload_size) (sizeof(*query) - sizeof(query->payload) + payload_size)
/**
R(emote) parameter request codes.
*/
typedef enum {
/**
Get one or more parameters.
*/
RPARAM_GET = 0x00,
/**
Reply to a request.
*/
RPARAM_REPLY = 0x55,
/**
Set one or more parameters.
*/
RPARAM_SET = 0xFF,
// RPARAM_SET_TO_FILE = 0xEE,
/**
Download table specification.
*/
RPARAM_TABLE = 0x44,
/**
Copy memory slot to memory slot.
@version 4.x: Not supported.
*/
RPARAM_COPY = 0x77,
/**
Load from file (slot) to memory (slot).
@version 4.x: Only load from primary store - file (slot) is ignored.
*/
RPARAM_LOAD = 0x88,
/**
Load from file (slot) to memory (slot).
@version 4.x: load by name(s).
*/
RPARAM_LOAD_FROM_STORE = 0x89,
/**
Save from memory (slot) to file (slot).
@version 4.x: Only save to primary store - file (slot) is ignored.
*/
RPARAM_SAVE = 0x99,
/**
Save from memory (slot) to file (slot).
@version 4.x: save by name(s).
*/
RPARAM_SAVE_TO_STORE = 0x9a,
// RPARAM_CLEAR = 0xAA, - completely removed
} gs_rparam_action_t;
/**
R(emote) parameter reply/completion codes.
*/
typedef enum {
RPARAM_SET_OK = 1,
RPARAM_LOAD_OK = 2,
RPARAM_SAVE_OK = 3,
RPARAM_COPY_OK = 4,
// RPARAM_CLEAR_OK = 5,
RPARAM_ERROR = 0xFF,
} gs_rparam_reply_t;
/**
Payload - save/load to/from stores
@version 4
*/
typedef struct __attribute__ ((packed)) {
char table[25 + 1];
char store[25 + 1];
char slot[25 + 1];
} gs_rparam_query_payload_store_t;
/**
Payload.
*/
typedef union __attribute__ ((packed)) {
uint16_t addr[0]; //! action = RPARAM_GET
uint8_t packed[0]; //! action = RPARAM_REPLY | RPARAM_SET
struct { //! action = RPARAM_COPY | RPARAM_LOAD | RPARM_SAVE
uint8_t from;
uint8_t to;
} copy;
} gs_rparam_query_payload_t;
/**
Protocol between client and server.
@version 4.x: layout (size) has not changed - only naming of certain fields.
*/
typedef struct __attribute__ ((packed)) {
/**
Request (gs_rparam_action_t) or Reply (gs_rparam_reply_t).
*/
uint8_t action;
/**
Table id.
Name changed in 4.0 from \a mem.
*/
uint8_t table_id;
/**
Length/size of \a payload in bytes.
*/
uint16_t length;
/**
Fletcher's checksum.
*/
uint16_t checksum;
/**
Sequence number when split over multiple frames (messages).
*/
uint16_t seq;
/**
Total number of frames.
*/
uint16_t total;
/**
Payload.
*/
gs_rparam_query_payload_t payload;
} gs_rparam_query_t;
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -0,0 +1,29 @@
#ifndef GS_PARAM_INTERNAL_SERIALIZE_H
#define GS_PARAM_INTERNAL_SERIALIZE_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
#if (GS_PARAM_INTERNAL_USE)
#include <gs/param/serialize.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Serialize data
* @param mem Pointer to indexed parameter table
* @param addr Array of addresses to serialize
* @param addr_count number of items in addr array
* @param[in|out] param_offset table parameter offset
* @param flags Set options using combination of flags
* @param buf Pointer to output
* @param buf_size Size of \a buf.
*/
gs_error_t gs_param_serialize_list(gs_param_table_instance_t * tinst, const uint16_t addr[], unsigned int addr_count, unsigned int * param_pos, uint32_t flags, uint8_t * buf, unsigned int buf_size, unsigned int * buf_pos);
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -0,0 +1,19 @@
#ifndef GS_PARAM_INTERNAL_TABLE_H
#define GS_PARAM_INTERNAL_TABLE_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
#if (GS_PARAM_INTERNAL_USE)
#include <gs/param/table.h>
#ifdef __cplusplus
extern "C" {
#endif
gs_error_t gs_param_parse_name_and_array_index(const char * inp, char * name, size_t size_name, uint8_t * array_index, bool * return_is_array);
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -0,0 +1,129 @@
#ifndef GS_PARAM_INTERNAL_TYPES_H
#define GS_PARAM_INTERNAL_TYPES_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
#if (GS_PARAM_INTERNAL_USE)
#include <gs/param/types.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Table instance.
*/
struct gs_param_table_instance {
/**
Name of table.
*/
const char * name;
/**
Table id.
*/
gs_param_table_id_t id;
/**
Table elements/rows.
*/
const gs_param_table_row_t * rows;
/**
Table element/row count.
*/
unsigned int row_count;
/**
Table memory - volatile parameter store.
The allocated size must be at least \a memory_size bytes.
*/
void * memory;
/**
Size of table data memory in bytes, normally size of memory allocated \a memory.
Size must always be specified, even when using function interface and no memory is allocated.
*/
unsigned int memory_size;
/**
Function interface, e.g. get/set.
*/
gs_param_function_interface_t function_interface;
/**
Checksum - based on host order (e.g. le or be).
@see gs_param_table_checksum()
*/
uint16_t checksum;
/**
Checksum - based on big-endian (address converted to big-endian).
@see gs_param_table_checksum_be()
*/
uint16_t checksum_be;
/**
Checksum - based on little-endian (address converted to little-endian).
@see gs_param_table_checksum_le()
*/
uint16_t checksum_le;
/**
Lock.
Internal access/use only, use gs_param_lock() and gs_param_unlock() to lock and un-lock table.
*/
gs_mutex_t lock;
/**
Callback for table (data) change.
*/
void (*callback)(uint16_t addr, gs_param_table_instance_t * tinst);
/**
Store location(s).
CSV format, e.g. \"persistent,protected\".
*/
const char * stores;
/**
Auto-persist.
*/
struct {
/**
Store.
*/
const char * store;
/**
User context(s) for the \a set function.
*/
void * context1;
void * context2;
/**
Set/write parameter.
*/
gs_error_t (*set)(gs_param_table_instance_t * tinst, uint16_t addr, gs_param_type_t type, const void * item, size_t size, uint32_t flags);
} auto_persist;
/**
Function for initializing table.
*/
gs_error_t (*initializer_function)(gs_param_table_instance_t * tinst);
/**
Default values for initializing table.
*/
const void * default_values;
/**
Future flags.
*/
uint32_t flags;
};
#ifdef __cplusplus
}
#endif
#endif
#endif

View File

@ -0,0 +1,60 @@
#ifndef GS_PARAM_PP_I2C_I2C_H
#define GS_PARAM_PP_I2C_I2C_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
/**
@file
I2C param protocol client interface.
*/
#include <gs/param/pp/pp.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Commands.
*/
typedef enum {
/**
Set parameter.
*/
GS_PARAM_I2C_COMMAND_SET = 1,
/**
Get parameter.
*/
GS_PARAM_I2C_COMMAND_GET = 2,
/**
Lock table.
*/
GS_PARAM_I2C_COMMAND_SET_LOCK_WITH_CHECKSUM = 3,
/**
Get table lock state.
*/
GS_PARAM_I2C_COMMAND_GET_LOCK_WITH_CHECKSUM = 4,
/**
Set parameter with checksum.
*/
GS_PARAM_I2C_COMMAND_SET_WITH_CHECKSUM = 10,
/**
Get parameter with checksum.
*/
GS_PARAM_I2C_COMMAND_GET_WITH_CHECKSUM = 11,
} gs_param_i2c_command_t;
/**
Initialize the param protocol handle for I2C.
@param[in] pp handle.
@param[in] bus bus to communicate on.
@param[in] addr address of node.
@param[in] big_endian \a true if slave is big endian. Used to convert to host endian.
@return_gs_error_t
*/
gs_error_t gs_pp_i2c_init(gs_pp_t * pp, uint8_t bus, uint8_t addr, bool big_endian);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,214 @@
#ifndef GS_PARAM_PP_PP_H
#define GS_PARAM_PP_PP_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
/**
@file
Param Protocol (PP) API - generic interface for getting/setting parameters over SPI, I2C, etc.
*/
#include <gs/util/error.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Flags used in gs_pp_xxx() functions.
@{
*/
/**
Use checksum in transfer.
@see gs_pp_checksum8()
*/
#define GS_PP_FLAG_CHECKSUM 0x0001
/**@}*/
/**
Handle for a protocol connection.
*/
typedef struct gs_pp gs_pp_t;
/**
Callback for getting a parameter.
*/
typedef gs_error_t (*gs_pp_get_t)(gs_pp_t * pp, uint8_t table_id, uint16_t addr, void * value, size_t value_size, uint32_t flags);
/**
Callback for setting a parameter.
*/
typedef gs_error_t (*gs_pp_set_t)(gs_pp_t * pp, uint8_t table_id, uint16_t addr, const void * value, size_t value_size, uint32_t flags);
/**
Callback for setting table lock.
*/
typedef gs_error_t (*gs_pp_get_table_lock_t)(gs_pp_t * pp, uint8_t table_id, bool * value, uint32_t flags);
/**
Callback for setting table lock.
*/
typedef gs_error_t (*gs_pp_set_table_lock_t)(gs_pp_t * pp, uint8_t table_id, const bool * value, uint32_t flags);
/**
Handle for a protocol connection.
*/
struct gs_pp {
/**
Endian type of slave.
*/
bool big_endian;
/**
Callback function for \a get.
*/
gs_pp_get_t get;
/**
Callback function for \a set.
*/
gs_pp_set_t set;
/**
Callback function for \a get_table_lock.
*/
gs_pp_get_table_lock_t get_table_lock;
/**
Callback function for \a set_table_lock.
*/
gs_pp_set_table_lock_t set_table_lock;
/**
Protocol specifics.
*/
union {
/**
SPI connection.
*/
struct {
/**
SPI slave id.
*/
uint8_t slave;
} spi;
/**
I2C connection.
*/
struct {
/**
I2C bus.
*/
uint8_t bus;
/**
I2C address.
*/
uint8_t addr;
} i2c;
} pp;
};
/**
Calculate very simple 8 bit checksum.
The checksum is calculated by adding all bytes. If the checksum is 0 (zero), the checksum is set to 1 (one).
@param[in] data data to calculate checksum for.
@param[in] length data length.
@return checksum
*/
uint8_t gs_pp_checksum8(const void * data, size_t length);
/**
Get lock value
@param[in] pp Handle for connection
@param[in] table_id Table ID
@param[out] value Lock state (0 = unlocked, 1 = locked)
@param[in] flags
@return_gs_error_t
*/
gs_error_t gs_pp_get_table_lock(gs_pp_t * pp, uint8_t table_id, bool * value, uint32_t flags);
/**
Set lock value
@param[in] pp Handle for connection
@param[in] table_id Table ID
@param[in] value Lock state (0 = unlocked, 1 = locked)
@param[in] flags
@return_gs_error_t
*/
gs_error_t gs_pp_set_table_lock(gs_pp_t * pp, uint8_t table_id, const bool * value, uint32_t flags);
/**
Get int8.
*/
gs_error_t gs_pp_get_int8(gs_pp_t * pp, uint8_t table_id, uint8_t addr, int8_t * value, size_t count, uint32_t flags);
/**
Set int8.
*/
gs_error_t gs_pp_set_int8(gs_pp_t * pp, uint8_t table_id, uint8_t addr, const int8_t * value, size_t count, uint32_t flags);
/**
Get uint8.
*/
gs_error_t gs_pp_get_uint8(gs_pp_t * pp, uint8_t table_id, uint8_t addr, uint8_t * value, size_t count, uint32_t flags);
/**
Set uint8.
*/
gs_error_t gs_pp_set_uint8(gs_pp_t * pp, uint8_t table_id, uint8_t addr, const uint8_t * value, size_t count, uint32_t flags);
/**
Get int16.
*/
gs_error_t gs_pp_get_int16(gs_pp_t * pp, uint8_t table_id, uint8_t addr, int16_t * value, size_t count, uint32_t flags);
/**
Set int16.
*/
gs_error_t gs_pp_set_int16(gs_pp_t * pp, uint8_t table_id, uint8_t addr, const int16_t * value, size_t count, uint32_t flags);
/**
Get uint16.
*/
gs_error_t gs_pp_get_uint16(gs_pp_t * pp, uint8_t table_id, uint8_t addr, uint16_t * value, size_t count, uint32_t flags);
/**
Set uint16.
*/
gs_error_t gs_pp_set_uint16(gs_pp_t * pp, uint8_t table_id, uint8_t addr, const uint16_t * value, size_t count, uint32_t flags);
/**
Get int32.
*/
gs_error_t gs_pp_get_int32(gs_pp_t * pp, uint8_t table_id, uint8_t addr, int32_t * value, size_t count, uint32_t flags);
/**
Set int32.
*/
gs_error_t gs_pp_set_int32(gs_pp_t * pp, uint8_t table_id, uint8_t addr, const int32_t * value, size_t count, uint32_t flags);
/**
Get uint32.
*/
gs_error_t gs_pp_get_uint32(gs_pp_t * pp, uint8_t table_id, uint8_t addr, uint32_t * value, size_t count, uint32_t flags);
/**
Set uint32.
*/
gs_error_t gs_pp_set_uint32(gs_pp_t * pp, uint8_t table_id, uint8_t addr, const uint32_t * value, size_t count, uint32_t flags);
/**
Get float.
*/
gs_error_t gs_pp_get_float(gs_pp_t * pp, uint8_t table_id, uint8_t addr, float * value, size_t count, uint32_t flags);
/**
Set float.
*/
gs_error_t gs_pp_set_float(gs_pp_t * pp, uint8_t table_id, uint8_t addr, const float * value, size_t count, uint32_t flags);
/**
Register commands.
*/
gs_error_t gs_pp_register_commands(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,29 @@
#ifndef GS_PARAM_PP_SPI_SPI_H
#define GS_PARAM_PP_SPI_SPI_H
/* Copyright (c) 2013-2017 GomSpace A/S. All rights reserved. */
/**
@file
SPI Param Protocol (pp) client interface.
*/
#include <gs/param/pp/pp.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Initialize the param protocol handle for SPI.
@param[in] pp handle.
@param[in] slave slave to communicate with.
@param[in] big_endian \a true if slave is big endian. Used to convert to host endian.
@return_gs_error_t
*/
gs_error_t gs_pp_spi_init(gs_pp_t * pp, uint8_t slave, bool big_endian);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,395 @@
#ifndef GS_PARAM_REMOTE_H
#define GS_PARAM_REMOTE_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
Remote parameter API - pending refactoring.
*/
#include <gs/param/types.h>
#include <gs/util/string.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Magic checksum.
If specifying a magic checksum, the rparam server will ignore/skip checksum validation.
*/
#define GS_RPARAM_MAGIC_CHECKSUM 0x0bb0
/**
Register rparam commands.
@return_gs_error_t
*/
gs_error_t gs_rparam_register_commands(void);
/**
Download all (data) values from a remote table to a local instance.
@param[in] tinst local table instance.
@param[in] node CSP address.
@param[in] table_id remote table id to download.
@param[in] checksum table checksum.
@param[in] timeout_ms timeout.
@return_gs_error_t
*/
gs_error_t gs_rparam_get_full_table(gs_param_table_instance_t * tinst,
uint8_t node,
gs_param_table_id_t table_id,
uint16_t checksum,
uint32_t timeout_ms);
/**
Download a table specification from a remote node, store it in memory and save it to local file system.
@note Will free existing rows - do not use this on table instances with static assigned rows.
Table memory will be (re)allocated to match specification.
@param[in] tinst local table instance.
@param[in] fname name of the file to store the table specification in. If NULL, no file will be stored.
@param[in] node CSP address
@param[in] table_id remote table id to download.
@param[in] timeout_ms timeout.
@param[out] return_checksum fletcher16 checksum of downloaded specification "as is" - before network/host swapping.
@return_gs_error_t
@see gs_param_table_free()
*/
gs_error_t gs_rparam_download_table_spec(gs_param_table_instance_t * tinst,
const char * fname,
uint8_t node,
gs_param_table_id_t table_id,
uint32_t timeout_ms,
uint16_t * return_checksum);
/**
Load a table specification from a local file and store it in memory.
@note Will free existing rows - do not use this on table instances with static assigned rows.
Table memory will be (re)allocated to match specification.
@param[in] tinst local table instance.
@param[in] fname name of the file to load the table specification from.
@param[out] return_checksum fletcher16 checksum stored in file.
@return_gs_error_t
@see gs_param_table_free()
*/
gs_error_t gs_rparam_load_table_spec(gs_param_table_instance_t * tinst, const char* fname, uint16_t * return_checksum);
/**
Copy from one table to another table.
@deprecated Not supported by a param 4 backend and future versions.
@param[in] node CSP address
@param[in] timeout_ms timeout on remote CSP calls
@param[in] from from table-id.
@param[in] to to table-id.
@return_gs_error_t
*/
gs_error_t gs_rparam_copy(uint8_t node, uint32_t timeout_ms, uint8_t from, uint8_t to);
/**
Save table.
@note On a param 4 backend, the table will always be saved to it's primary store.
@param[in] node CSP address
@param[in] timeout_ms timeout on remote CSP calls
@param[in] id table to save.
@param[in] to to file slot - ignored on param 4 backends.
@return_gs_error_t
*/
gs_error_t gs_rparam_save(uint8_t node, uint32_t timeout_ms, gs_param_table_id_t id, uint8_t to);
/**
Save table.
@version 4
@param[in] node CSP address
@param[in] timeout_ms timeout on remote CSP calls
@param[in] table_id remote table id.
@param[in] store store name.
@param[in] slot slot within store.
@return_gs_error_t
*/
gs_error_t gs_rparam_save_to_store(uint8_t node, uint32_t timeout_ms, uint8_t table_id,
const char * store, const char * slot);
/**
Load table from store.
@note On a param 4 backend, the specified table will be loadded from it's primary store.
@param[in] node CSP address
@param[in] timeout_ms timeout on remote CSP calls
@param[in] from from file slot - ignored on param 4 backends.
@param[in] id table to load.
@return_gs_error_t
*/
gs_error_t gs_rparam_load(uint8_t node, uint32_t timeout_ms, uint8_t from, gs_param_table_id_t id);
/**
Load table from store.
@version 4
@param[in] node CSP address
@param[in] timeout_ms timeout on remote CSP calls
@param[in] table_id remote table id.
@param[in] store store name.
@param[in] slot slot within store.
@return_gs_error_t
*/
gs_error_t gs_rparam_load_from_store(uint8_t node, uint32_t timeout_ms, uint8_t table_id,
const char * store, const char * slot);
/**
Get parameter.
@param[in] node CSP address
@param[in] table_id remote table id.
@param[in] addr parameter address (remote table).
@param[in] type parameter type.
@param[in] checksum checksum
@param[in] timeout_ms timeout
@param[out] value returned value (user allocated)
@param[in] value_size size of \a value buffer.
@return_gs_error_t
*/
gs_error_t gs_rparam_get(uint8_t node,
gs_param_table_id_t table_id,
uint16_t addr,
gs_param_type_t type,
uint16_t checksum,
uint32_t timeout_ms,
void * value,
size_t value_size);
/**
Set parameter.
@param[in] node CSP address
@param[in] table_id remote table id.
@param[in] addr parameter address (remote table).
@param[in] type parameter type.
@param[in] checksum checksum
@param[in] timeout_ms timeout
@param[in] value value to set
@param[in] value_size size of \a value.
@return_gs_error_t
*/
gs_error_t gs_rparam_set(uint8_t node,
gs_param_table_id_t table_id,
uint16_t addr,
gs_param_type_t type,
uint16_t checksum,
uint32_t timeout_ms,
const void * value,
size_t value_size);
/**
Get string.
*/
static inline gs_error_t gs_rparam_get_string(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, char * value, size_t value_size)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_STRING, checksum, timeout_ms, value, value_size);
}
/**
Set string.
*/
static inline gs_error_t gs_rparam_set_string(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, const char * value, size_t value_size)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_STRING, checksum, timeout_ms, value, (value_size == 0) ? (strlen(value) + 1) : value_size);
}
/**
Get int8.
*/
static inline gs_error_t gs_rparam_get_int8(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, int8_t * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_INT8, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set int8.
*/
static inline gs_error_t gs_rparam_set_int8(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, int8_t value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_INT8, checksum, timeout_ms, &value, sizeof(value));
}
/**
Get uint8.
*/
static inline gs_error_t gs_rparam_get_uint8(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, uint8_t * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_UINT8, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set uint8.
*/
static inline gs_error_t gs_rparam_set_uint8(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, uint8_t value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_UINT8, checksum, timeout_ms, &value, sizeof(value));
}
/**
Get int16.
*/
static inline gs_error_t gs_rparam_get_int16(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, int16_t * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_INT16, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set int16.
*/
static inline gs_error_t gs_rparam_set_int16(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, int16_t value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_INT16, checksum, timeout_ms, &value, sizeof(value));
}
/**
Get uint16.
*/
static inline gs_error_t gs_rparam_get_uint16(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, uint16_t * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_UINT16, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set uint16.
*/
static inline gs_error_t gs_rparam_set_uint16(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, uint16_t value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_UINT16, checksum, timeout_ms, &value, sizeof(value));
}
/**
Get int32.
*/
static inline gs_error_t gs_rparam_get_int32(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, int32_t * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_INT32, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set int32.
*/
static inline gs_error_t gs_rparam_set_int32(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, int32_t value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_INT32, checksum, timeout_ms, &value, sizeof(value));
}
/**
Get uint32.
*/
static inline gs_error_t gs_rparam_get_uint32(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, uint32_t * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_UINT32, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set uint32.
*/
static inline gs_error_t gs_rparam_set_uint32(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, uint32_t value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_UINT32, checksum, timeout_ms, &value, sizeof(value));
}
/**
Get int64.
*/
static inline gs_error_t gs_rparam_get_int64(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, int64_t * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_INT64, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set int64.
*/
static inline gs_error_t gs_rparam_set_int64(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, int64_t value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_INT64, checksum, timeout_ms, &value, sizeof(value));
}
/**
Get uint64.
*/
static inline gs_error_t gs_rparam_get_uint64(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, uint64_t * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_UINT64, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set uint64.
*/
static inline gs_error_t gs_rparam_set_uint64(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, uint64_t value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_UINT64, checksum, timeout_ms, &value, sizeof(value));
}
/**
Get float.
*/
static inline gs_error_t gs_rparam_get_float(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, float * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_FLOAT, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set float.
*/
static inline gs_error_t gs_rparam_set_float(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, float value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_FLOAT, checksum, timeout_ms, &value, sizeof(value));
}
/**
Get double.
*/
static inline gs_error_t gs_rparam_get_double(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, double * value)
{
return gs_rparam_get(node, table_id, addr, GS_PARAM_DOUBLE, checksum, timeout_ms, value, sizeof(*value));
}
/**
Set double.
*/
static inline gs_error_t gs_rparam_set_double(uint8_t node, gs_param_table_id_t table_id, uint16_t addr,
uint16_t checksum, uint32_t timeout_ms, double value)
{
return gs_rparam_set(node, table_id, addr, GS_PARAM_DOUBLE, checksum, timeout_ms, &value, sizeof(value));
}
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,101 @@
#ifndef GS_PARAM_CLIENT_SERIALIZE_H
#define GS_PARAM_CLIENT_SERIALIZE_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
Serialize API - pending refactoring.
*/
#include <gs/param/types.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Serialize/deserialize flags
Flags must be in range: bit 8 - 15, to avoid clash with other parts of the parameter system.
*/
typedef enum {
GS_PARAM_SF_DRY_RUN = (1 << 8), //!< F_DRY_RUN do not write to memory
GS_PARAM_SF_TO_BIG_ENDIAN = (1 << 9), //!< F_TO_BIG_ENDIAN Convert from host to big endian
GS_PARAM_SF_FROM_BIG_ENDIAN = (1 << 10), //!< F_FROM_BIG_ENDIAN Confert from big endian to host order
GS_PARAM_SF_PACKED = (1 << 11), //!< F_PACKED Do not pack addresses
F_DRY_RUN = GS_PARAM_SF_DRY_RUN,
F_TO_BIG_ENDIAN = GS_PARAM_SF_TO_BIG_ENDIAN,
F_FROM_BIG_ENDIAN = GS_PARAM_SF_FROM_BIG_ENDIAN,
F_PACKED = GS_PARAM_SF_PACKED,
} gs_param_serialize_flags_t;
/**
* In-place conversion of a single parameter from big endian to host byte order
* @param type param type
* @param item pointer to parameter memory
* @return 1 if memory has been swapped, 0 if not
*/
bool gs_param_betoh(gs_param_type_t type, void * item);
/**
* In-place conversion of a single parameter from host byte order to big endian
* @param type param type
* @param item porinter to parameter memory
* @return 1 if memory has been swapped, 0 if not
*/
bool gs_param_htobe(gs_param_type_t type, void * item);
/**
Serialize data
@param[in] tinst table.
@param[in,out] param_pos parameter iterator.
@param[in] flags flags.
@param[out] buf user supplied buffer of \a buf_size.
@param[in] buf_size of size of \a buf
@param[in,out] buf_pos index into \a buf
@return_gs_error_t
*/
gs_error_t gs_param_serialize_full_table(gs_param_table_instance_t * tinst, unsigned int * param_pos, uint32_t flags, uint8_t * buf, unsigned int buf_size, unsigned int * buf_pos);
/**
Serialize single item
@param[in] param parameter to serialize
@param[in] addr Address of item
@param[in] item item to serialize.
@param[in] flags flags.
@param[out] buf user supplied buffer of \a buf_size.
@param[in] buf_size of size of \a buf
@param[in,out] buf_pos index into \a buf
@return_gs_error_t
*/
gs_error_t gs_param_serialize_item(const gs_param_table_row_t * param, uint16_t addr, const void * item, uint32_t flags, uint8_t * buf, unsigned int buf_size, unsigned int * buf_pos);
/**
Deserialize packed parameters into memory
@param[in] tinst table.
@param[in] buf serialized data.
@param[in] buf_size size \a buf containing serialized data
@param[in] flags flags.
@return_gs_error_t
*/
gs_error_t gs_param_deserialize(gs_param_table_instance_t * tinst, const uint8_t * buf, unsigned int buf_size, uint32_t flags);
/**
Deserialize a sginle item from a string into memory
@param[in] tinst table.
@param param Pointer to specific parameter to deserialize
@param addr Address of parameter
@param item Pointer to memory area where item should be written
@param flags Set options using combination of flags
@return_gs_error_t
*/
gs_error_t gs_param_deserialize_item(gs_param_table_instance_t * tinst, const gs_param_table_row_t * param, uint16_t addr, const void * item, uint32_t flags);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,428 @@
#ifndef GS_PARAM_TABLE_H
#define GS_PARAM_TABLE_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
Client table API.
*/
#include <gs/param/types.h>
#include <gs/util/stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Allocate table memory when creating a table.
Flags must be in range: bit 16 - 23, to avoid clash with other parts of the parameter system.
*/
#define GS_PARAM_TABLE_F_ALLOC_MEMORY 0x0100
/**
Allocate table rows.
Flags must be in range: bit 16 - 23, to avoid clash with other parts of the parameter system.
*/
#define GS_PARAM_TABLE_F_ALLOC_ROWS 0x0200
/**
Disable table locking.
Flags must be in range: bit 16 - 23, to avoid clash with other parts of the parameter system.
*/
#define GS_PARAM_TABLE_F_NO_LOCK 0x0400
/**
Calculate memory size based on table rows.
@param[in] rows rows
@param[in] row_count row count.
@return size of table or 0 in case of invalid arguments.
*/
size_t gs_param_calc_table_size(const gs_param_table_row_t * rows, size_t row_count);
/**
Return size of table instance.
*/
size_t gs_param_table_instance_size(void);
/**
Clear (and check size) of memory for table instance.
@param[in] var user allocated space of at least gs_param_table_instance_size() bytes.
@param[in] var_size of \a var.
@return table instance
@see gs_param_table_instance_size()
@see #GS_PARAM_TINST_VAR
*/
gs_param_table_instance_t * gs_param_table_instance_clear(void * var, size_t var_size);
/**
Allocates aligned space on the stack for a table instance structure.
@param[in] var name of table instsance variable.
*/
#define GS_PARAM_TINST_VAR(var) uint8_t var##__data [gs_param_table_instance_size()] __attribute__ ((aligned(4))); gs_param_table_instance_t * var = gs_param_table_instance_clear(var##__data, sizeof(var##__data))
/**
Allocate memory for table instance.
Use gs_param_table_free() to free any internal resources.
Use standard free() to free allocated memory.
@return table instance on success, otherwise NULL.
*/
gs_param_table_instance_t * gs_param_table_instance_alloc(void);
/**
Find row by name.
@param[in] name parameter name.
@param[in] rows rows
@param[in] row_count row count.
@return row or NULL if not found.
*/
const gs_param_table_row_t * gs_param_row_by_name(const char * name, const gs_param_table_row_t * rows, size_t row_count);
/**
Find row by address.
@param[in] addr parameter address.
@param[in] rows rows
@param[in] row_count row count.
@return row or NULL if not found.
*/
const gs_param_table_row_t * gs_param_row_by_address(uint16_t addr, const gs_param_table_row_t * rows, size_t row_count);
/**
Return table memory.
@note handle with care - any read/write should be atomic to prevent inconsistent data.
@param[in] tinst table instance
@param[out] return_size if not NULL, the memory size is returned.
@return pointer to the table's data memory.
*/
void * gs_param_table_get_memory(gs_param_table_instance_t * tinst, size_t * return_size);
/**
Return table rows.
@param[in] tinst table instance
@param[out] return_count if not NULL, the row count is returned.
@return pointer to the table rows.
*/
const gs_param_table_row_t * gs_param_table_get_rows(gs_param_table_instance_t * tinst, size_t * return_count);
/**
Lock table (recursive).
@param[in] tinst table instance
@return_gs_error_t
*/
gs_error_t gs_param_table_lock(gs_param_table_instance_t * tinst);
/**
Unlock table.
Unlock must be called once for every time gs_param_table_lock() has been called.
@param[in] tinst table instance
@return_gs_error_t
*/
gs_error_t gs_param_table_unlock(gs_param_table_instance_t * tinst);
/**
Free internal resources and clears instance.
@param[in] tinst table instance
@return_gs_error_t
*/
gs_error_t gs_param_table_free(gs_param_table_instance_t * tinst);
/**
Print a single parameter on stream.
@param[in] tinst table instanc.
@param[in] row row to print.
@param[in] list_data \a true includes parameter value.
@param[in] flags flags to control output format: #GS_PARAM_F_SHOW_SCIENTIFIC, #GS_PARAM_F_SHOW_HEX.
@param[in] out output stream.
@return_gs_error_t
*/
gs_error_t gs_param_list_single_to_stream(gs_param_table_instance_t * tinst, const gs_param_table_row_t * row, bool list_data, uint32_t flags, FILE * out);
/**
Print a single parameter on stdout.
@param[in] tinst table instanc.
@param[in] row row to print.
@param[in] list_data \a true includes parameter value.
@return_gs_error_t
*/
static inline gs_error_t gs_param_list_single(gs_param_table_instance_t * tinst, const gs_param_table_row_t * row, bool list_data)
{
return gs_param_list_single_to_stream(tinst, row, list_data, 0, stdout);
}
/**
Print entire table on stream.
@param[in] tinst table instanc.
@param[in] list_data \a true includes parameter value.
@param[in] flags flags to control output format: #GS_PARAM_F_SHOW_SCIENTIFIC, #GS_PARAM_F_SHOW_HEX.
@param[in] out output stream.
@return_gs_error_t
*/
gs_error_t gs_param_list_to_stream(gs_param_table_instance_t * tinst, bool list_data, uint32_t flags, FILE * out);
/**
Print entire table on stdout.
@param[in] tinst table instanc.
@param[in] list_data \a true includes parameter value.
@return_gs_error_t
*/
static inline gs_error_t gs_param_list(gs_param_table_instance_t * tinst, bool list_data)
{
return gs_param_list_to_stream(tinst, list_data, 0, stdout);
}
/**
Convert string to parameter.
@param[in] row row defining the parameter to convert.
@param[in] string string to convert.
@param[out] return_value user supplied buffer for returning the value - must be at least the size specified in \a row
@return_gs_error_t
*/
gs_error_t gs_param_from_string(const gs_param_table_row_t * row, const char * string, void * return_value);
/**
Convert parameter to string.
@param[in] row row defining the parameter to convert.
@param[in] value parameter value to convert.
@param[in] with_type \a true includes data type.
@param[in] flags flags to control output format: #GS_PARAM_F_SHOW_SCIENTIFIC, #GS_PARAM_F_SHOW_HEX.
@param[out] buf user supplied buffer of \a buf_size bytes.
@param[in] buf_size size of \a buf in bytes.
@param[in] buf_pos buffer position to insert string.
@param[out] return_buf_written number of bytes written to \a buf.
@return_gs_error_t
*/
gs_error_t gs_param_to_string2(const gs_param_table_row_t * row, const void * value, bool with_type, uint32_t flags, char * buf, unsigned int buf_size, unsigned int buf_pos, unsigned int * return_buf_written);
/**
Convert parameter to string.
@param[in] row row defining the parameter to convert.
@param[in] value parameter value to convert.
@param[in] with_type \a true includes data type.
@param[out] buf user supplied buffer of \a buf_size bytes.
@param[in] buf_size size of \a buf in bytes.
@param[in] buf_pos buffer position to insert string.
@param[out] return_buf_written number of bytes written to \a buf.
@return_gs_error_t
*/
static inline gs_error_t gs_param_to_string(const gs_param_table_row_t * row, const void * value, bool with_type, char * buf, unsigned int buf_size, unsigned int buf_pos, unsigned int * return_buf_written)
{
return gs_param_to_string2(row, value, with_type, 0, buf, buf_size, buf_pos, return_buf_written);
}
/**
Convert parameter type to string.
@param[in] type parameter type.
@return pointer to a static string.
*/
const char * gs_param_type_to_string(gs_param_type_t type);
/**
Return size of parameter type.
@param[in] type parameter type.
@return size of parameter type in bytes.
*/
uint8_t gs_param_type_size(gs_param_type_t type);
/**
Get table checksum - little-endian.
@note Use/exchange gs_param_table_checksum_be(), as this is calculated the same on all platforms.
@param[in] tinst table instance.
@returns 16-bit fletcher checksum
*/
uint16_t gs_param_table_checksum_le(gs_param_table_instance_t * tinst);
/**
Get table checksum - big-endian/network-order (prefered).
@param[in] tinst table instance.
@returns 16-bit fletcher checksum
*/
uint16_t gs_param_table_checksum_be(gs_param_table_instance_t * tinst);
/**
Get table checksum - host-order (not cross-platform).
@deprecated use gs_param_table_checksum_be()
@param[in] tinst table instance.
@returns 16-bit fletcher checksum
*/
uint16_t gs_param_table_checksum(gs_param_table_instance_t * tinst);
/**
Get table checksum - big-endian.
@deprecated use gs_param_table_checksum_be()
@param[in] tinst table instance.
@returns 16-bit fletcher checksum
*/
static inline uint16_t gs_param_table_checksum2(gs_param_table_instance_t * tinst)
{
return gs_param_table_checksum_be(tinst);
}
/**
Get/read parameter from table.
@param[in] tinst table instanc.
@param[in] addr parameter address (offset in table).
@param[in] type parameter type.
@param[out] return_value value of parameter - user supplied memory of at least \a size size.
@param[in] size number of bytes to get/read - must match \a type, e.g. 4 bytes for an uint32_t.
@param[in] flags flags.
@return_gs_error_t
*/
gs_error_t gs_param_get(gs_param_table_instance_t * tinst, uint16_t addr, gs_param_type_t type, void * return_value, size_t size, uint32_t flags);
/**
Set/write parameter in table.
@param[in] tinst table instanc.
@param[in] addr parameter address (offset in table).
@param[in] type parameter type.
@param[in] value value of parameter.
@param[in] size number of bytes to set/write - must match \a type, e.g. 4 bytes for an uint32_t.
@param[in] flags flags.
@return_gs_error_t
*/
gs_error_t gs_param_set(gs_param_table_instance_t * tinst, uint16_t addr, gs_param_type_t type, const void * value, size_t size, uint32_t flags);
/**
Get string parameter.
@param[in] tinst table instanc.
@param[in] addr parameter address (offset in table).
@param[out] buf value of parameter - user supplied memory of at least parameter size + 1 to hold NUL termination.
@param[in] buf_size size of \a buf - ensure room for NUL termination.
@param[in] flags flags.
@return GS_ERROR_OVERFLOW if string + NUL termination exceeds \a buf_size.
@return_gs_error_t
*/
gs_error_t gs_param_get_string(gs_param_table_instance_t * tinst, uint16_t addr, char * buf, size_t buf_size, uint32_t flags);
/**
Set string parameter.
@param[in] tinst table.
@param[in] addr parameter address (offset in table).
@param[in] value string to save - parameter must be able to hold string + NUL termination.
@param[in] flags flags.
@return GS_ERROR_OVERFLOW if string + NUL termination exceeds parameter size.
@return_gs_error_t
*/
gs_error_t gs_param_set_string(gs_param_table_instance_t * tinst, uint16_t addr, const char * value, uint32_t flags);
/**
Get data parameter.
@param[in] tinst table instanc.
@param[in] addr parameter address (offset in table).
@param[out] buf value of parameter - user supplied memory of at least parameter size.
@param[in] buf_size size of \a buf.
@param[in] flags flags.
@return GS_ERROR_OVERFLOW if parameter size is greater than \a buf_size.
@return_gs_error_t
*/
gs_error_t gs_param_get_data(gs_param_table_instance_t * tinst, uint16_t addr, void * buf, size_t buf_size, uint32_t flags);
/**
Set data parameter.
@param[in] tinst table instanc.
@param[in] addr parameter address (offset in table).
@param[in] value value of parameter.
@param[in] value_size size of \a value.
@param[in] flags flags.
@return GS_ERROR_OVERFLOW if parameter size is greater than \a buf_size.
@return_gs_error_t
*/
gs_error_t gs_param_set_data(gs_param_table_instance_t * tinst, uint16_t addr, const void * value, size_t value_size, uint32_t flags);
/**
Macro for expanding get/set functions.
@param[in] name function suffix name.
@param[in] native_type native type
@param[in] param_type parameter type
*/
#define GS_PARAM_PASTE(name, native_type, param_type) \
static inline gs_error_t gs_param_get_##name(gs_param_table_instance_t * tinst, uint16_t addr, native_type * buf, uint32_t flags) { \
return gs_param_get(tinst, addr, param_type, buf, sizeof(*buf), flags); \
} \
static inline native_type gs_param_get_##name##_nc(gs_param_table_instance_t * tinst, uint16_t addr, uint32_t flags) { \
native_type value = 0; \
gs_param_get(tinst, addr, param_type, &value, sizeof(value), flags); \
return value; \
} \
static inline gs_error_t gs_param_set_##name(gs_param_table_instance_t * tinst, uint16_t addr, native_type value, uint32_t flags) { \
return gs_param_set(tinst, addr, param_type, &value, sizeof(value), flags); \
}
/**
Get/set boolean.
*/
GS_PARAM_PASTE(bool, bool, GS_PARAM_BOOL)
/**
Get/set uint8.
*/
GS_PARAM_PASTE(uint8, uint8_t, GS_PARAM_UINT8)
/**
Get/set uint16.
*/
GS_PARAM_PASTE(uint16, uint16_t, GS_PARAM_UINT16)
/**
Get/set uint32.
*/
GS_PARAM_PASTE(uint32, uint32_t, GS_PARAM_UINT32)
/**
Get/set uint64.
*/
GS_PARAM_PASTE(uint64, uint64_t, GS_PARAM_UINT64)
/**
Get/set int8.
*/
GS_PARAM_PASTE(int8, int8_t, GS_PARAM_INT8)
/**
Get/set int16.
*/
GS_PARAM_PASTE(int16, int16_t, GS_PARAM_INT16)
/**
Get/set int32.
*/
GS_PARAM_PASTE(int32, int32_t, GS_PARAM_INT32)
/**
Get/set int64.
*/
GS_PARAM_PASTE(int64, int64_t, GS_PARAM_INT64)
/**
Get/set double.
*/
GS_PARAM_PASTE(double, double, GS_PARAM_DOUBLE)
/**
Get/set float.
*/
GS_PARAM_PASTE(float, float, GS_PARAM_FLOAT)
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,272 @@
#ifndef GS_PARAM_TYPES_H
#define GS_PARAM_TYPES_H
/* Copyright (c) 2013-2018 GomSpace A/S. All rights reserved. */
/**
@file
Parameter types.
*/
#include <gs/util/mutex.h>
#include <gs/util/pgm.h>
#include <gs/util/minmax.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
Macros for accessing table row members.
These macros can be used to access members in a cross-platform way, compensating for the AVR8's memory model.
@{
*/
#define GS_PARAM_ARRAY_SIZE(p) gs_max(GS_PGM_UINT8((p)->array_size), 1)
#define GS_PARAM_SIZE(p) GS_PGM_UINT8((p)->size)
#define GS_PARAM_TYPE(p) GS_PGM_UINT8((p)->type)
#define GS_PARAM_ADDR(p) GS_PGM_UINT16((p)->addr)
#define GS_PARAM_FLAGS(p) GS_PGM_UINT8((p)->flags)
/** @} */
/**
Max parameter name - including 0 termination.
@note In some rare/old table definitions, the name may not be NULL terminated.
*/
#define GS_PARAM_MAX_NAME 14
/**
Parameter flags.
Flags must be in range: bit 0 - 7, to avoid clash with other parts of the parameter system.
*/
typedef enum {
/**
Parameter will be stored in configured auto-persist store when set.
@note Flag must be specified when setting the parameter.
*/
GS_PARAM_F_AUTO_PERSIST = (1 << 0),
/**
@deprecated Not supported in version 4.0
*/
PARAM_F_READONLY = (1 << 1),
/**
Skip callback, when parameter is set.
@note Flag must be specified when setting the parameter.
*/
GS_PARAM_F_NO_CALLBACK = (1 << 2),
/**
Show/display parameter in hex.
*/
GS_PARAM_F_SHOW_HEX = (1 << 3),
/**
Show double/float using scientific notation.
*/
GS_PARAM_F_SHOW_SCIENTIFIC = (1 << 4),
PARAM_F_NOCALLBACK = GS_PARAM_F_NO_CALLBACK,
PARAM_F_PERSIST = GS_PARAM_F_AUTO_PERSIST,
} gs_param_flags_t;
/**
* Parameter types.
*/
typedef enum __attribute__((__packed__)) {
/**
Unsigned 8 bit (uint8_t).
*/
GS_PARAM_UINT8 = 0,
/**
Unsigned 16 bit (uint16_t).
*/
GS_PARAM_UINT16 = 1,
/**
Unsigned 32 bit (uint32_t).
*/
GS_PARAM_UINT32 = 2,
/**
Unsigned 64 bit (uint64_t).
*/
GS_PARAM_UINT64 = 3,
/**
Signed 8 bit (int8_t).
*/
GS_PARAM_INT8 = 4,
/**
Signed 16 bit (int16_t).
*/
GS_PARAM_INT16 = 5,
/**
Signed 32 bit (int32_t).
*/
GS_PARAM_INT32 = 6,
/**
Signed 64 bit (int64_t).
*/
GS_PARAM_INT64 = 7,
/**
@deprecated - use #GS_PARAM_UINT8 and #GS_PARAM_F_SHOW_HEX.
*/
PARAM_X8 = 8,
/**
@deprecated - use #GS_PARAM_UINT16 and #GS_PARAM_F_SHOW_HEX.
*/
PARAM_X16 = 9,
/**
@deprecated - use #GS_PARAM_UINT32 and #GS_PARAM_F_SHOW_HEX.
*/
PARAM_X32 = 10,
/**
@deprecated - use #GS_PARAM_UINT64 and #GS_PARAM_F_SHOW_HEX.
*/
PARAM_X64 = 11,
/**
Double.
*/
GS_PARAM_DOUBLE = 12,
/**
Float.
*/
GS_PARAM_FLOAT = 13,
/**
C or null-terminated string.
@note The specified \a size must include space for the NUL character.
*/
GS_PARAM_STRING = 14,
/**
Data (binary blob).
Binary blob: [0, 0x40, 0x4f] -> '00404f'
*/
GS_PARAM_DATA = 15,
/**
Boolean.
Expected same size as uint8_t.
*/
GS_PARAM_BOOL = 16,
PARAM_UINT8 = GS_PARAM_UINT8,
PARAM_UINT16 = GS_PARAM_UINT16,
PARAM_UINT32 = GS_PARAM_UINT32,
PARAM_UINT64 = GS_PARAM_UINT64,
PARAM_INT8 = GS_PARAM_INT8,
PARAM_INT16 = GS_PARAM_INT16,
PARAM_INT32 = GS_PARAM_INT32,
PARAM_INT64 = GS_PARAM_INT64,
PARAM_DOUBLE = GS_PARAM_DOUBLE,
PARAM_FLOAT = GS_PARAM_FLOAT,
PARAM_STRING = GS_PARAM_STRING,
PARAM_DATA = GS_PARAM_DATA,
PARAM_BOOL = GS_PARAM_BOOL,
} gs_param_type_t;
/**
Table row.
A table row defines one parameter, and a table is defined by one or more rows.
@note Make sure to update gs_param_table_checksum2(), if adding fields > 1 byte.
@note AVR8: Table definitions must be located in \a program memory, i.e. must be const.
*/
typedef struct __attribute__((__packed__)) {
/**
Address (or offset) in table.
*/
uint16_t addr;
/**
Type.
*/
gs_param_type_t type;
/**
Size of element.
uint32_t = 4, string[5] = 5 (4 characters + 1 for NUL), etc.
*/
uint8_t size;
/**
Array size.
Size greater than 1, will make the parameter an array - if the value is 0 or 1, the parameter is not an array.
*/
uint8_t array_size;
/**
Flags.
@see gs_param_flags_t
*/
uint8_t flags;
/**
Name (C string).
@note In some rare/old table definitions, the name may not be NUL terminated.
*/
char name[GS_PARAM_MAX_NAME];
} gs_param_table_row_t;
/**
Table instance.
*/
typedef struct gs_param_table_instance gs_param_table_instance_t;
/**
Table id.
Tables can be associated with a number/id, which normally is unique on a specific node.
*/
typedef uint8_t gs_param_table_id_t;
/**
Undefined table id.
*/
#define GS_PARAM_UNDEFINED_TABLE_ID 255
/**
Function for setting a parameter.
@param[in] context user context/reference.
@param[in] tinst table instance.
@param[in] addr parameter address.
@param[in] type parameter type.
@param[in] item parameter value.
@param[in] size parameter size (e.g. how many bytes to copy from \a item).
@param[in] flags flags related to the operation - these may vary depending on the context.
@return_gs_error_t
*/
typedef gs_error_t (*gs_param_table_function_set_t)(void * context, gs_param_table_instance_t * tinst, uint16_t addr, gs_param_type_t type, const void * item, size_t size, uint32_t flags);
/**
Function for getting a parameter.
@param[in] context user context/reference.
@param[in] tinst table instance.
@param[in] addr parameter address.
@param[in] type parameter type.
@param[out] item parameter buffer (provided by the caller).
@param[in] size parameter size (e.g. how many bytes to copy to \a item).
@param[in] flags flags related to the operation - these may vary depending on the context.
@return_gs_error_t
*/
typedef gs_error_t (*gs_param_table_function_get_t)(void * context, gs_param_table_instance_t * tinst, uint16_t addr, gs_param_type_t type, void * item, size_t size, uint32_t flags);
/**
Function interface for setting and getting parameters.
Functions will be invoked, when set/get is called on the table instance.
*/
typedef struct {
/**
User context, provided in the callback functions.
*/
void * context;
/**
Called when setting a parameter.
*/
gs_param_table_function_set_t set;
/**
Called when getting a parameter.
*/
gs_param_table_function_get_t get;
} gs_param_function_interface_t;
/**
Callback function for changed parameter.
See gs_param_table_create() for details.
*/
typedef void (*gs_param_callback_func_t)(uint16_t addr, gs_param_table_instance_t * tinst);
#ifdef __cplusplus
}
#endif
#endif