arachnid-labs-re-load-pro: Add support for setting SR_CONF_ENABLED.

The firmware has "on\n" and "off\n" commands since 1.10, so use them.

Apparently you can only set the state (on/off) of the load, but it's
not possible to query the current state.
This commit is contained in:
Uwe Hermann 2016-02-08 08:52:23 +01:00
parent 6e68da5140
commit 8501448cfe
3 changed files with 21 additions and 4 deletions

View File

@ -43,7 +43,7 @@ static const uint32_t devopts[] = {
}; };
static const uint32_t devopts_cg[] = { static const uint32_t devopts_cg[] = {
SR_CONF_ENABLED | SR_CONF_GET, SR_CONF_ENABLED | SR_CONF_SET,
SR_CONF_REGULATION | SR_CONF_GET, SR_CONF_REGULATION | SR_CONF_GET,
SR_CONF_VOLTAGE | SR_CONF_GET, SR_CONF_VOLTAGE | SR_CONF_GET,
SR_CONF_CURRENT | SR_CONF_GET, SR_CONF_CURRENT | SR_CONF_GET,
@ -242,6 +242,7 @@ static int config_get(uint32_t key, GVariant **data,
* - SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD * - SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD
* - SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE * - SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE
* - SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD * - SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD
* - SR_CONF_ENABLED (state cannot be queried, only set)
*/ */
ret = SR_OK; ret = SR_OK;
@ -252,9 +253,6 @@ static int config_get(uint32_t key, GVariant **data,
case SR_CONF_LIMIT_MSEC: case SR_CONF_LIMIT_MSEC:
*data = g_variant_new_uint64(devc->limit_msec); *data = g_variant_new_uint64(devc->limit_msec);
break; break;
case SR_CONF_ENABLED:
*data = g_variant_new_boolean(TRUE); /* Always on. */
break;
case SR_CONF_REGULATION: case SR_CONF_REGULATION:
*data = g_variant_new_string("CC"); /* Always CC mode. */ *data = g_variant_new_string("CC"); /* Always CC mode. */
break; break;
@ -312,6 +310,9 @@ static int config_set(uint32_t key, GVariant *data,
case SR_CONF_LIMIT_MSEC: case SR_CONF_LIMIT_MSEC:
devc->limit_msec = g_variant_get_uint64(data); devc->limit_msec = g_variant_get_uint64(data);
break; break;
case SR_CONF_ENABLED:
ret = reloadpro_set_on_off(sdi, g_variant_get_boolean(data));
break;
case SR_CONF_CURRENT_LIMIT: case SR_CONF_CURRENT_LIMIT:
ret = reloadpro_set_current_limit(sdi, ret = reloadpro_set_current_limit(sdi,
g_variant_get_double(data)); g_variant_get_double(data));

View File

@ -89,6 +89,21 @@ SR_PRIV int reloadpro_set_current_limit(const struct sr_dev_inst *sdi,
return SR_OK; return SR_OK;
} }
SR_PRIV int reloadpro_set_on_off(const struct sr_dev_inst *sdi, gboolean on)
{
int ret;
char buf[100];
const char *cmd;
cmd = (on) ? "on\n" : "off\n";
if ((ret = send_cmd(sdi, cmd, (char *)&buf, sizeof(buf))) < 0) {
sr_err("Error sending on/off command: %d.", ret);
return SR_ERR;
}
return SR_OK;
}
SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi, SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi,
float *current) float *current)
{ {

View File

@ -43,6 +43,7 @@ struct dev_context {
SR_PRIV int reloadpro_set_current_limit(const struct sr_dev_inst *sdi, SR_PRIV int reloadpro_set_current_limit(const struct sr_dev_inst *sdi,
float current); float current);
SR_PRIV int reloadpro_set_on_off(const struct sr_dev_inst *sdi, gboolean on);
SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi, SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi,
float *current); float *current);
SR_PRIV int reloadpro_get_voltage_current(const struct sr_dev_inst *sdi, SR_PRIV int reloadpro_get_voltage_current(const struct sr_dev_inst *sdi,