return SR_OK;
}
-static int send_config_update_key(const struct sr_dev_inst *sdi,
- uint32_t key, GVariant *var)
-{
- struct sr_config *cfg;
- struct sr_datafeed_packet packet;
- struct sr_datafeed_meta meta;
- int ret;
-
- cfg = sr_config_new(key, var);
- if (!cfg)
- return SR_ERR;
-
- memset(&meta, 0, sizeof(meta));
-
- packet.type = SR_DF_META;
- packet.payload = &meta;
-
- meta.config = g_slist_append(NULL, cfg);
-
- ret = sr_session_send(sdi, &packet);
- g_slist_free(meta.config);
- sr_config_free(cfg);
-
- return ret;
-}
-
static void handle_packet(const struct sr_dev_inst *sdi)
{
struct sr_datafeed_packet packet;
if (g_str_has_prefix((const char *)devc->buf, "overtemp")) {
sr_warn("Overtemperature condition!");
devc->otp_active = TRUE;
- send_config_update_key(sdi, SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE,
+ sr_session_send_meta(sdi, SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE,
g_variant_new_boolean(TRUE));
return;
}
if (g_str_has_prefix((const char *)devc->buf, "undervolt")) {
sr_warn("Undervoltage condition!");
devc->uvc_active = TRUE;
- send_config_update_key(sdi, SR_CONF_UNDER_VOLTAGE_CONDITION_ACTIVE,
+ sr_session_send_meta(sdi, SR_CONF_UNDER_VOLTAGE_CONDITION_ACTIVE,
g_variant_new_boolean(TRUE));
return;
}
devc->current_limit = g_ascii_strtod(tokens[1], NULL) / 1000;
g_strfreev(tokens);
g_cond_signal(&devc->current_limit_cond);
- send_config_update_key(sdi, SR_CONF_CURRENT_LIMIT,
+ sr_session_send_meta(sdi, SR_CONF_CURRENT_LIMIT,
g_variant_new_double(devc->current_limit));
return;
}
g_strfreev(tokens);
g_cond_signal(&devc->uvc_threshold_cond);
if (devc->uvc_threshold == .0) {
- send_config_update_key(sdi, SR_CONF_UNDER_VOLTAGE_CONDITION,
+ sr_session_send_meta(sdi, SR_CONF_UNDER_VOLTAGE_CONDITION,
g_variant_new_boolean(FALSE));
} else {
- send_config_update_key(sdi, SR_CONF_UNDER_VOLTAGE_CONDITION,
+ sr_session_send_meta(sdi, SR_CONF_UNDER_VOLTAGE_CONDITION,
g_variant_new_boolean(TRUE));
- send_config_update_key(sdi,
+ sr_session_send_meta(sdi,
SR_CONF_UNDER_VOLTAGE_CONDITION_THRESHOLD,
g_variant_new_double(devc->uvc_threshold));
}
is_valid, timeout_ms, baudrate);
}
-static int send_config_update(struct sr_dev_inst *sdi, struct sr_config *cfg)
-{
- struct sr_datafeed_packet packet;
- struct sr_datafeed_meta meta;
- int ret;
-
- memset(&meta, 0, sizeof(meta));
-
- packet.type = SR_DF_META;
- packet.payload = &meta;
-
- meta.config = g_slist_append(NULL, cfg);
-
- ret = sr_session_send(sdi, &packet);
-
- g_slist_free(meta.config);
-
- return ret;
-}
-
-static int send_config_update_key(struct sr_dev_inst *sdi, uint32_t key,
- GVariant *var)
-{
- struct sr_config *cfg;
- int ret;
-
- cfg = sr_config_new(key, var);
- if (!cfg)
- return SR_ERR;
-
- ret = send_config_update(sdi, cfg);
- sr_config_free(cfg);
-
- return ret;
-}
-
/*
* Cyrustek ES51919 LCR chipset host protocol.
*
return FALSE;
}
-static int do_config_update(struct sr_dev_inst *sdi, uint32_t key,
- GVariant *var)
-{
- return send_config_update_key(sdi, key, var);
-}
-
static int send_freq_update(struct sr_dev_inst *sdi, unsigned int freq)
{
- return do_config_update(sdi, SR_CONF_OUTPUT_FREQUENCY,
+ return sr_session_send_meta(sdi, SR_CONF_OUTPUT_FREQUENCY,
g_variant_new_double(frequencies[freq]));
}
static int send_model_update(struct sr_dev_inst *sdi, unsigned int model)
{
- return do_config_update(sdi, SR_CONF_EQUIV_CIRCUIT_MODEL,
+ return sr_session_send_meta(sdi, SR_CONF_EQUIV_CIRCUIT_MODEL,
g_variant_new_string(models[model]));
}
SR_PRIV int sr_session_source_remove_channel(struct sr_session *session,
GIOChannel *channel);
+SR_PRIV int sr_session_send_meta(const struct sr_dev_inst *sdi,
+ uint32_t key, GVariant *var);
SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
const struct sr_datafeed_packet *packet);
SR_PRIV int sr_sessionfile_check(const char *filename);
}
}
+/**
+ * Helper to send a meta datafeed package (SR_DF_META) to the session bus.
+ *
+ * @param sdi The device instance to send the package from. Must not be NULL.
+ * @param key The config key to send to the session bus.
+ * @param var The value to send to the session bus.
+ *
+ * @retval SR_OK Success.
+ * @retval SR_ERR_ARG Invalid argument.
+ *
+ * @private
+ */
+SR_PRIV int sr_session_send_meta(const struct sr_dev_inst *sdi,
+ uint32_t key, GVariant *var)
+{
+ struct sr_config *cfg;
+ struct sr_datafeed_packet packet;
+ struct sr_datafeed_meta meta;
+ int ret;
+
+ cfg = sr_config_new(key, var);
+ if (!cfg)
+ return SR_ERR;
+
+ memset(&meta, 0, sizeof(meta));
+
+ packet.type = SR_DF_META;
+ packet.payload = &meta;
+
+ meta.config = g_slist_append(NULL, cfg);
+
+ ret = sr_session_send(sdi, &packet);
+ g_slist_free(meta.config);
+ sr_config_free(cfg);
+
+ return ret;
+}
+
/**
* Send a packet to whatever is listening on the datafeed bus.
*