+ char *cmd, *func;
+ int res;
+
+ res = 0;
+
+ /* Command string to read current function. */
+ cmd = g_strdup_printf("FUNC%d?", idx + 1);
+ sr_dbg("Sent command: %s.", cmd);
+
+ if (!(devc = sdi->priv))
+ return TRUE;
+
+ /* Default settings. */
+ analog[idx].meaning->mq = 0;
+ analog[idx].meaning->unit = 0;
+ analog[idx].meaning->mqflags = 0;
+
+ /* Get a response to the FUNC? command. */
+ res = fl45_scpi_get_response(sdi, cmd);
+ if (res == SR_ERR)
+ return res;
+ sr_dbg("Response to FUNC: %s.", devc->response);
+
+ /* Set up analog mq, unit and flags. */
+ if (res == SR_OK && devc->response != NULL) {
+ func = devc->response;
+ if (strcmp(func, "AAC") == 0) {
+ analog[idx].meaning->mq = SR_MQ_CURRENT;
+ analog[idx].meaning->unit = SR_UNIT_AMPERE;
+ analog[idx].meaning->mqflags = SR_MQFLAG_AC;
+ } else if (strcmp(func, "AACDC") == 0) {
+ analog[idx].meaning->mq = SR_MQ_CURRENT;
+ analog[idx].meaning->unit = SR_UNIT_AMPERE;
+ analog[idx].meaning->mqflags = SR_MQFLAG_AC;
+ } else if (strcmp(func, "ADC") == 0) {
+ analog[idx].meaning->mq = SR_MQ_CURRENT;
+ analog[idx].meaning->unit = SR_UNIT_AMPERE;
+ analog[idx].meaning->mqflags = SR_MQFLAG_DC;
+ } else if (strcmp(func, "CONT") == 0) {
+ analog[idx].meaning->mq = SR_MQ_CONTINUITY;
+ analog->meaning->unit = SR_UNIT_BOOLEAN;
+ } else if (strcmp(func, "DIODE") == 0) {
+ analog[idx].meaning->mq = SR_MQ_VOLTAGE;
+ analog[idx].meaning->unit = SR_UNIT_VOLT;
+ analog[idx].meaning->mqflags = SR_MQFLAG_DIODE;
+ } else if (strcmp(func, "FREQ") == 0) {
+ analog[idx].meaning->mq = SR_MQ_FREQUENCY;
+ analog[idx].meaning->unit = SR_UNIT_HERTZ;
+ } else if (strcmp(func, "OHMS") == 0) {
+ analog[idx].meaning->mq = SR_MQ_RESISTANCE;
+ analog[idx].meaning->unit = SR_UNIT_OHM;
+ } else if (strcmp(func, "VAC") == 0) {
+ analog[idx].meaning->mq = SR_MQ_VOLTAGE;
+ analog[idx].meaning->unit = SR_UNIT_VOLT;
+ analog[idx].meaning->mqflags = SR_MQFLAG_AC;
+ } else if (strcmp(func, "VACDC") == 0) {
+ analog[idx].meaning->mq = SR_MQ_VOLTAGE;
+ analog[idx].meaning->unit = SR_UNIT_VOLT;
+ analog[idx].meaning->mqflags |= SR_MQFLAG_AC;
+ analog[idx].meaning->mqflags |= SR_MQFLAG_DC;
+ } else if (strcmp(func, "VDC") == 0) {
+ analog[idx].meaning->mq = SR_MQ_VOLTAGE;
+ analog[idx].meaning->unit = SR_UNIT_VOLT;
+ analog[idx].meaning->mqflags = SR_MQFLAG_DC;
+ }
+ }
+
+ /* Is the meter in autorange mode? */
+ res = fl45_scpi_get_response(sdi, "AUTO?");
+ if (res == SR_ERR)
+ return res;
+ sr_dbg("Response to AUTO: %s.", devc->response);
+ if (res == SR_OK && devc->response != NULL) {
+ if (strcmp(devc->response, "1") == 0)
+ analog[idx].meaning->mqflags |= SR_MQFLAG_AUTORANGE;
+ }
+
+ return SR_OK;
+}
+
+SR_PRIV int fl45_get_modifiers(const struct sr_dev_inst *sdi,
+ struct sr_datafeed_analog *analog, int idx)
+{
+ struct dev_context *devc;
+ int res, mod;
+
+ if (!(devc = sdi->priv))
+ return TRUE;
+
+ /* Get modifier value. */
+ res = fl45_scpi_get_response(sdi, "MOD?");
+ if (res == SR_ERR)
+ return res;
+ sr_dbg("Response to MOD: %s.", devc->response);
+ if (res == SR_OK && devc->response != NULL) {
+ mod = atoi(devc->response);
+ if (mod & 0x01) {
+ analog[idx].meaning->mqflags |= SR_MQFLAG_MIN;
+ sr_dbg("MIN bit set: %s.", "1");
+ }
+ if (mod & 0x02) {
+ analog[idx].meaning->mqflags |= SR_MQFLAG_MAX;
+ sr_dbg("MAX bit set: %s.", "2");
+ }
+ if (mod & 0x04) {
+ analog[idx].meaning->mqflags |= SR_MQFLAG_HOLD;
+ sr_dbg("HOLD bit set: %s.", "4");
+ }
+ if (mod & 0x08) {
+ sr_dbg("dB bit set: %s.", "8");
+ analog[idx].meaning->mq = SR_MQ_POWER_FACTOR;
+ analog[idx].meaning->unit = SR_UNIT_DECIBEL_MW;
+ analog[idx].meaning->mqflags = 0;
+ analog[idx].encoding->digits = 2;
+ analog[idx].spec->spec_digits = 2;
+ }
+ if (mod & 0x10) {
+ sr_dbg("dB Power mod bit set: %s.", "16");
+ analog[idx].meaning->mq = SR_MQ_POWER;
+ analog[idx].meaning->unit = SR_UNIT_DECIBEL_SPL;
+ analog[idx].meaning->mqflags = 0;
+ analog[idx].encoding->digits = 2;
+ analog[idx].spec->spec_digits = 2;
+ }
+ if (mod & 0x20) {
+ sr_dbg("REL bit set: %s.", "32");
+ analog[idx].meaning->mqflags |= SR_MQFLAG_HOLD;
+ }
+ }
+
+ return SR_OK;
+}
+
+int get_reading_dd(char *reading, size_t size)
+{
+ int pe, pd, digits;
+ unsigned int i;
+ char expstr[3];
+ char *eptr;
+ long exp;
+
+ /* Calculate required precision. */
+
+ pe = pd = digits = 0;
+
+ /* Get positions for '.' end 'E'. */
+ for (i = 0; i < size; i++) {
+ if (reading[i] == '.')
+ pd = i;
+ if (reading[i] == 'E') {
+ pe = i;
+ break;
+ }
+ }
+
+ digits = (pe - pd) - 1;
+
+ /* Get exponent element. */
+ expstr[0] = reading[pe + 1];
+ expstr[1] = reading[pe + 2];
+ expstr[2] = '\0';
+ errno = 0;
+ exp = strtol(expstr, &eptr, 10);
+ if (errno != 0)
+ return 2;
+ /* A negative exponent increses digits, a positive one reduces. */
+ exp = exp * (-1);
+
+ /* Adjust digits taking into account exponent. */
+ digits = digits + exp;
+
+ return digits;
+}
+
+SR_PRIV int fl45_scpi_receive_data(int fd, int revents, void *cb_data)
+{
+ struct sr_dev_inst *sdi;
+ struct dev_context *devc;
+ struct sr_datafeed_packet packet;
+ struct sr_datafeed_analog analog[2];
+ struct sr_analog_encoding encoding[2];
+ struct sr_analog_meaning meaning[2];
+ struct sr_analog_spec spec[2];
+ struct sr_channel *channel;
+ char *reading;
+ float fv;
+ int res, digits;
+ unsigned int i;
+ int sent_ch[2];