cem-dt-885x: Support for changing frequency weighting
This commit is contained in:
parent
fd8854c4d0
commit
be73391982
|
@ -17,6 +17,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
#define SERIALCOMM "9600/8n1"
|
#define SERIALCOMM "9600/8n1"
|
||||||
|
@ -32,8 +33,13 @@ static const int32_t hwcaps[] = {
|
||||||
SR_CONF_LIMIT_SAMPLES,
|
SR_CONF_LIMIT_SAMPLES,
|
||||||
SR_CONF_CONTINUOUS,
|
SR_CONF_CONTINUOUS,
|
||||||
SR_CONF_DATALOG,
|
SR_CONF_DATALOG,
|
||||||
|
SR_CONF_SPL_WEIGHT_FREQ,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *weight_freq[] = {
|
||||||
|
"A",
|
||||||
|
"C",
|
||||||
|
};
|
||||||
|
|
||||||
SR_PRIV struct sr_dev_driver cem_dt_885x_driver_info;
|
SR_PRIV struct sr_dev_driver cem_dt_885x_driver_info;
|
||||||
static struct sr_dev_driver *di = &cem_dt_885x_driver_info;
|
static struct sr_dev_driver *di = &cem_dt_885x_driver_info;
|
||||||
|
@ -159,6 +165,7 @@ static int cleanup(void)
|
||||||
static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
|
static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
int tmp;
|
||||||
|
|
||||||
if (!sdi)
|
if (!sdi)
|
||||||
return SR_ERR_ARG;
|
return SR_ERR_ARG;
|
||||||
|
@ -171,6 +178,15 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
|
||||||
case SR_CONF_DATALOG:
|
case SR_CONF_DATALOG:
|
||||||
*data = g_variant_new_boolean(cem_dt_885x_recording_get(sdi));
|
*data = g_variant_new_boolean(cem_dt_885x_recording_get(sdi));
|
||||||
break;
|
break;
|
||||||
|
case SR_CONF_SPL_WEIGHT_FREQ:
|
||||||
|
tmp = cem_dt_885x_weight_freq_get(sdi);
|
||||||
|
if (tmp == SR_MQFLAG_SPL_FREQ_WEIGHT_A)
|
||||||
|
*data = g_variant_new_string("A");
|
||||||
|
else if (tmp == SR_MQFLAG_SPL_FREQ_WEIGHT_C)
|
||||||
|
*data = g_variant_new_string("C");
|
||||||
|
else
|
||||||
|
return SR_ERR;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +199,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
uint64_t tmp_u64;
|
uint64_t tmp_u64;
|
||||||
int ret;
|
int ret;
|
||||||
|
const char *tmp_str;
|
||||||
|
|
||||||
if (sdi->status != SR_ST_ACTIVE)
|
if (sdi->status != SR_ST_ACTIVE)
|
||||||
return SR_ERR_DEV_CLOSED;
|
return SR_ERR_DEV_CLOSED;
|
||||||
|
@ -208,6 +225,17 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
|
||||||
ret = cem_dt_885x_recording_set(sdi, FALSE);
|
ret = cem_dt_885x_recording_set(sdi, FALSE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SR_CONF_SPL_WEIGHT_FREQ:
|
||||||
|
tmp_str = g_variant_get_string(data, NULL);
|
||||||
|
if (!strcmp(tmp_str, "A"))
|
||||||
|
ret = cem_dt_885x_weight_freq_set(sdi,
|
||||||
|
SR_MQFLAG_SPL_FREQ_WEIGHT_A);
|
||||||
|
else if (!strcmp(tmp_str, "C"))
|
||||||
|
ret = cem_dt_885x_weight_freq_set(sdi,
|
||||||
|
SR_MQFLAG_SPL_FREQ_WEIGHT_C);
|
||||||
|
else
|
||||||
|
return SR_ERR_ARG;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ret = SR_ERR_NA;
|
ret = SR_ERR_NA;
|
||||||
}
|
}
|
||||||
|
@ -231,6 +259,9 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
|
||||||
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
|
||||||
hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
|
hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
|
||||||
break;
|
break;
|
||||||
|
case SR_CONF_SPL_WEIGHT_FREQ:
|
||||||
|
*data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,7 +318,8 @@ static int wait_for_token(const struct sr_dev_inst *sdi, char *tokens, int timeo
|
||||||
|
|
||||||
/* cmd is the command to send, tokens are the tokens that denote the state
|
/* cmd is the command to send, tokens are the tokens that denote the state
|
||||||
* which the command affects. The first token is the desired state. */
|
* which the command affects. The first token is the desired state. */
|
||||||
SR_PRIV int cem_dt_885x_toggle(const struct sr_dev_inst *sdi, uint8_t cmd, char *tokens)
|
SR_PRIV int cem_dt_885x_toggle(const struct sr_dev_inst *sdi, uint8_t cmd,
|
||||||
|
char *tokens, int timeout)
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
@ -332,8 +333,7 @@ SR_PRIV int cem_dt_885x_toggle(const struct sr_dev_inst *sdi, uint8_t cmd, char
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (serial_write(serial, (const void *)&cmd, 1) != 1)
|
if (serial_write(serial, (const void *)&cmd, 1) != 1)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
/* Notifications are sent at 2Hz minimum */
|
if (wait_for_token(sdi, tokens, timeout) == SR_ERR)
|
||||||
if (wait_for_token(sdi, tokens, 510) == SR_ERR)
|
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
if (devc->token == tokens[0])
|
if (devc->token == tokens[0])
|
||||||
/* It worked. */
|
/* It worked. */
|
||||||
|
@ -391,7 +391,72 @@ SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean st
|
||||||
/* Nothing to do. */
|
/* Nothing to do. */
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
|
||||||
ret = cem_dt_885x_toggle(sdi, CMD_TOGGLE_RECORDING, tokens);
|
/* Recording state notifications are sent at 2Hz, so allow just over
|
||||||
|
* that, 510ms, for the state to come in. */
|
||||||
|
ret = cem_dt_885x_toggle(sdi, CMD_TOGGLE_RECORDING, tokens, 510);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
SR_PRIV int cem_dt_885x_weight_freq_get(const struct sr_dev_inst *sdi)
|
||||||
|
{
|
||||||
|
struct dev_context *devc;
|
||||||
|
int cur_setting;
|
||||||
|
char tokens[5];
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
|
|
||||||
|
cur_setting = devc->cur_mqflags & (SR_MQFLAG_SPL_FREQ_WEIGHT_A | SR_MQFLAG_SPL_FREQ_WEIGHT_C);
|
||||||
|
if (cur_setting == 0) {
|
||||||
|
/* Didn't pick up device state yet. */
|
||||||
|
tokens[0] = TOKEN_WEIGHT_FREQ_A;
|
||||||
|
tokens[1] = TOKEN_WEIGHT_FREQ_C;
|
||||||
|
tokens[2] = -1;
|
||||||
|
if (wait_for_token(sdi, tokens, 0) != SR_OK)
|
||||||
|
return SR_ERR;
|
||||||
|
if (devc->token == TOKEN_WEIGHT_FREQ_A)
|
||||||
|
return SR_MQFLAG_SPL_FREQ_WEIGHT_A;
|
||||||
|
else
|
||||||
|
return SR_MQFLAG_SPL_FREQ_WEIGHT_C;
|
||||||
|
} else
|
||||||
|
return cur_setting;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SR_PRIV int cem_dt_885x_weight_freq_set(const struct sr_dev_inst *sdi, int freqw)
|
||||||
|
{
|
||||||
|
struct dev_context *devc;
|
||||||
|
int cur_setting, ret;
|
||||||
|
char tokens[5];
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
|
|
||||||
|
cur_setting = devc->cur_mqflags & (SR_MQFLAG_SPL_FREQ_WEIGHT_A | SR_MQFLAG_SPL_FREQ_WEIGHT_C);
|
||||||
|
if (cur_setting == freqw)
|
||||||
|
/* Already set to this frequency weighting. */
|
||||||
|
return SR_OK;
|
||||||
|
|
||||||
|
/* The toggle below needs the desired state in first position. */
|
||||||
|
if (freqw == SR_MQFLAG_SPL_FREQ_WEIGHT_A) {
|
||||||
|
tokens[0] = TOKEN_WEIGHT_FREQ_A;
|
||||||
|
tokens[1] = TOKEN_WEIGHT_FREQ_C;
|
||||||
|
} else {
|
||||||
|
tokens[0] = TOKEN_WEIGHT_FREQ_C;
|
||||||
|
tokens[1] = TOKEN_WEIGHT_FREQ_A;
|
||||||
|
}
|
||||||
|
tokens[2] = -1;
|
||||||
|
|
||||||
|
if (cur_setting == 0) {
|
||||||
|
/* Didn't pick up device state yet. */
|
||||||
|
if (wait_for_token(sdi, tokens, 0) != SR_OK)
|
||||||
|
return SR_ERR;
|
||||||
|
if (devc->token == tokens[0])
|
||||||
|
/* Nothing to do. */
|
||||||
|
return SR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 10ms timeout seems to work best for this. */
|
||||||
|
ret = cem_dt_885x_toggle(sdi, CMD_TOGGLE_WEIGHT_FREQ, tokens, 10);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ enum {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CMD_TOGGLE_RECORDING = 0x55,
|
CMD_TOGGLE_RECORDING = 0x55,
|
||||||
|
CMD_TOGGLE_WEIGHT_FREQ = 0x99,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Private, per-device-instance driver context. */
|
/** Private, per-device-instance driver context. */
|
||||||
|
@ -104,5 +105,7 @@ enum {
|
||||||
SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data);
|
SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data);
|
||||||
SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean start);
|
SR_PRIV int cem_dt_885x_recording_set(const struct sr_dev_inst *sdi, gboolean start);
|
||||||
SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi);
|
SR_PRIV gboolean cem_dt_885x_recording_get(const struct sr_dev_inst *sdi);
|
||||||
|
SR_PRIV int cem_dt_885x_weight_freq_get(const struct sr_dev_inst *sdi);
|
||||||
|
SR_PRIV int cem_dt_885x_weight_freq_set(const struct sr_dev_inst *sdi, int freqw);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue