5. Usage examples
One source tree, several SDK versions. Guard on sid_sdk_version.h (§1).
#include <sid_sdk_version.h>
#if SID_SDK_MAJOR_VERSION >= 2
#define APP_HAS_GSK 1
#include <sid_gsk_config.h>
#endif
Then wrap the sid_gsk_config.h include, both assertions, the app_gsk_config definition and the .gsk_config initializer below in #if APP_HAS_GSK.
Configure GSK at initialization.
#include <sid_900_cfg.h>
#include <sid_api.h>
#include <sid_ble_link_config_ifc.h>
#include <sid_error.h>
#include <sid_gsk_config.h>
#include <stddef.h>
#define APP_GSK_IDLE_TIMEOUT_SEC 60u
#define APP_GSK_ACK_MISS_THRESHOLD 6u
/* sid_init() clamps silently, so assert here instead of expecting an error return. */
_Static_assert(APP_GSK_IDLE_TIMEOUT_SEC >= SID_GSK_IDLE_TIMEOUT_MIN_SEC
&& APP_GSK_IDLE_TIMEOUT_SEC <= SID_GSK_IDLE_TIMEOUT_MAX_SEC,
"idle_timeout_sec out of range");
_Static_assert(APP_GSK_ACK_MISS_THRESHOLD >= SID_GSK_APP_ACK_MISS_MIN
&& APP_GSK_ACK_MISS_THRESHOLD <= SID_GSK_APP_ACK_MISS_MAX,
"app_ack_miss_threshold out of range");
static const struct sid_gsk_config app_gsk_config = {
.idle_timeout_sec = APP_GSK_IDLE_TIMEOUT_SEC,
.app_ack_miss_threshold = APP_GSK_ACK_MISS_THRESHOLD,
};
/* The first three are reached through retained pointers and must not be automatics; dev_ch is
* copied. Fill all four in before calling sid_init(); the declarations below are placeholders. */
static struct sid_event_callbacks app_callbacks;
static struct sid_ble_link_config app_ble_config; // .create_ble_adapter and .config must be set
static struct sid_sub_ghz_links_config app_sub_ghz_config;
static struct sid_end_device_characteristics app_dev_ch;
static struct sid_handle *app_handle;
sid_error_t app_sidewalk_init(void)
{
struct sid_config config = {
// GSK applies to the sub-GHz link in this mask (§2.3).
// A LoRa product uses SID_LINK_TYPE_1 | SID_LINK_TYPE_3 instead; nothing else here changes.
.link_mask = SID_LINK_TYPE_1 | SID_LINK_TYPE_2,
.dev_ch = app_dev_ch,
.callbacks = &app_callbacks,
.link_config = &app_ble_config,
.sub_ghz_link_config = &app_sub_ghz_config,
.gsk_config = &app_gsk_config, // NULL selects all three defaults (§3)
};
sid_error_t err = sid_init(&config, &app_handle);
if (err != SID_ERROR_NONE) {
return err;
}
err = sid_start(app_handle, config.link_mask);
if (err != SID_ERROR_NONE) {
(void)sid_deinit(app_handle);
app_handle = NULL;
}
return err;
}