Skip to content

Commit 11aba38

Browse files
committed
fix R&S support in hameg-hmo
1 parent f06f788 commit 11aba38

File tree

3 files changed

+108
-26
lines changed

3 files changed

+108
-26
lines changed

src/hardware/hameg-hmo/api.c

+38-13
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi)
641641
#else
642642
"LSBF",
643643
#endif
644+
ch->index + 1,
644645
ch->index + 1);
645646
break;
646647
case SR_CHANNEL_LOGIC:
@@ -711,6 +712,7 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi)
711712
{
712713
GSList *l;
713714
unsigned int i;
715+
unsigned int k;
714716
gboolean *pod_enabled, setup_changed;
715717
char command[MAX_COMMAND_SIZE];
716718
struct scope_state *state;
@@ -755,16 +757,20 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi)
755757

756758
if (ch->enabled == state->digital_channels[ch->index])
757759
break;
758-
g_snprintf(command, sizeof(command),
759-
(*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
760-
ch->index, ch->enabled);
760+
761+
if (!(model->internal_flags & INTERN_NO_LOGIC_STATE_SET_SUPPORT)) {
762+
g_snprintf(command, sizeof(command),
763+
(*model->scpi_dialect)[SCPI_CMD_SET_DIG_CHAN_STATE],
764+
ch->index, ch->enabled);
761765

762-
if (sr_scpi_send(scpi, command) != SR_OK) {
763-
g_free(pod_enabled);
764-
return SR_ERR;
766+
if (sr_scpi_send(scpi, command) != SR_OK) {
767+
g_free(pod_enabled);
768+
return SR_ERR;
769+
}
770+
771+
state->digital_channels[ch->index] = ch->enabled;
765772
}
766773

767-
state->digital_channels[ch->index] = ch->enabled;
768774
setup_changed = TRUE;
769775
break;
770776
default:
@@ -777,12 +783,31 @@ static int hmo_setup_channels(const struct sr_dev_inst *sdi)
777783
for (i = 0; i < model->digital_pods; i++) {
778784
if (state->digital_pods[i].state == pod_enabled[i])
779785
continue;
780-
g_snprintf(command, sizeof(command),
781-
(*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
782-
i + 1, pod_enabled[i]);
783-
if (sr_scpi_send(scpi, command) != SR_OK) {
784-
ret = SR_ERR;
785-
break;
786+
787+
if (!(model->internal_flags & INTERN_NO_LOGIC_STATE_SET_SUPPORT)) {
788+
/*
789+
* Override digital channel state for all channels of a POD if
790+
* individual channel states can't be set.
791+
*/
792+
for (k = 0; k < DIGITAL_CHANNELS_PER_POD; k++) {
793+
state->digital_channels[k + i * DIGITAL_CHANNELS_PER_POD] = pod_enabled[i];
794+
}
795+
}
796+
797+
if (!(model->internal_flags & INTERN_NO_POD_STATE_SET_SUPPORT)) {
798+
g_snprintf(command, sizeof(command),
799+
(*model->scpi_dialect)[SCPI_CMD_SET_DIG_POD_STATE],
800+
i + 1, pod_enabled[i]);
801+
if (sr_scpi_send(scpi, command) != SR_OK) {
802+
ret = SR_ERR;
803+
break;
804+
}
805+
}
806+
else {
807+
pod_enabled[i] = TRUE;
808+
for (k = 0; k < DIGITAL_CHANNELS_PER_POD; k++) {
809+
state->digital_channels[k + i * DIGITAL_CHANNELS_PER_POD] = TRUE;
810+
}
786811
}
787812
state->digital_pods[i].state = pod_enabled[i];
788813
setup_changed = TRUE;

src/hardware/hameg-hmo/protocol.c

+61-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static const char *hameg_scpi_dialect[] = {
3939
[SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s",
4040
[SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?",
4141
[SCPI_CMD_GET_ANALOG_DATA] = ":FORM:BORD %s;" \
42-
":FORM REAL,32;:CHAN%d:DATA?",
42+
":FORM REAL,32;:CHAN%d:DATA:POIN MAX;:CHAN%d:DATA?",
4343
[SCPI_CMD_GET_VERTICAL_SCALE] = ":CHAN%d:SCAL?",
4444
[SCPI_CMD_SET_VERTICAL_SCALE] = ":CHAN%d:SCAL %s",
4545
[SCPI_CMD_GET_DIG_POD_STATE] = ":POD%d:STAT?",
@@ -81,7 +81,7 @@ static const char *rohde_schwarz_log_not_pod_scpi_dialect[] = {
8181
[SCPI_CMD_SET_COUPLING] = ":CHAN%d:COUP %s",
8282
[SCPI_CMD_GET_SAMPLE_RATE] = ":ACQ:SRAT?",
8383
[SCPI_CMD_GET_ANALOG_DATA] = ":FORM:BORD %s;" \
84-
":FORM REAL,32;:CHAN%d:DATA?",
84+
":FORM REAL,32;:CHAN%d:DATA:POIN MAX;:CHAN%d:DATA?",
8585
[SCPI_CMD_GET_VERTICAL_SCALE] = ":CHAN%d:SCAL?",
8686
[SCPI_CMD_SET_VERTICAL_SCALE] = ":CHAN%d:SCAL %s",
8787
[SCPI_CMD_GET_DIG_POD_STATE] = ":LOG%d:STAT?",
@@ -612,6 +612,9 @@ static struct scope_config scope_models[] = {
612612
.num_ydivs = 8,
613613

614614
.scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
615+
616+
.internal_flags = INTERN_NO_LOGIC_STATE_GET_SUPPORT
617+
| INTERN_NO_LOGIC_STATE_SET_SUPPORT,
615618
},
616619
{
617620
.name = {"RTB2004", NULL},
@@ -652,6 +655,9 @@ static struct scope_config scope_models[] = {
652655
.num_ydivs = 8,
653656

654657
.scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
658+
659+
.internal_flags = INTERN_NO_LOGIC_STATE_GET_SUPPORT
660+
| INTERN_NO_LOGIC_STATE_SET_SUPPORT,
655661
},
656662
{
657663
.name = {"RTM3002", NULL},
@@ -692,6 +698,9 @@ static struct scope_config scope_models[] = {
692698
.num_ydivs = 8,
693699

694700
.scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
701+
702+
.internal_flags = INTERN_NO_LOGIC_STATE_GET_SUPPORT
703+
| INTERN_NO_LOGIC_STATE_SET_SUPPORT,
695704
},
696705
{
697706
.name = {"RTM3004", NULL},
@@ -732,6 +741,9 @@ static struct scope_config scope_models[] = {
732741
.num_ydivs = 8,
733742

734743
.scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
744+
745+
.internal_flags = INTERN_NO_LOGIC_STATE_GET_SUPPORT
746+
| INTERN_NO_LOGIC_STATE_SET_SUPPORT,
735747
},
736748
{
737749
.name = {"RTA4004", NULL},
@@ -772,6 +784,9 @@ static struct scope_config scope_models[] = {
772784
.num_ydivs = 8,
773785

774786
.scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
787+
788+
.internal_flags = INTERN_NO_LOGIC_STATE_GET_SUPPORT
789+
| INTERN_NO_LOGIC_STATE_SET_SUPPORT,
775790
},
776791
{
777792
.name = {"RTH1002", NULL},
@@ -812,6 +827,10 @@ static struct scope_config scope_models[] = {
812827
.num_ydivs = 8,
813828

814829
.scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
830+
831+
.internal_flags = INTERN_NO_LOGIC_STATE_GET_SUPPORT
832+
| INTERN_NO_LOGIC_STATE_SET_SUPPORT
833+
| INTERN_NO_POD_STATE_SET_SUPPORT,
815834
},
816835
{
817836
.name = {"RTH1004", NULL},
@@ -852,6 +871,10 @@ static struct scope_config scope_models[] = {
852871
.num_ydivs = 8,
853872

854873
.scpi_dialect = &rohde_schwarz_log_not_pod_scpi_dialect,
874+
875+
.internal_flags = INTERN_NO_LOGIC_STATE_GET_SUPPORT
876+
| INTERN_NO_LOGIC_STATE_SET_SUPPORT
877+
| INTERN_NO_POD_STATE_SET_SUPPORT,
855878
},
856879
};
857880

@@ -871,8 +894,19 @@ static void scope_state_dump(const struct scope_config *config,
871894
}
872895

873896
for (i = 0; i < config->digital_channels; i++) {
874-
sr_info("State of digital channel %d -> %s", i,
875-
state->digital_channels[i] ? "On" : "Off");
897+
if (!(config->internal_flags & INTERN_NO_LOGIC_STATE_GET_SUPPORT))
898+
{
899+
sr_info("State of digital channel %d -> %s", i,
900+
state->digital_channels[i] ? "On" : "Off");
901+
}
902+
else if (!(config->internal_flags & INTERN_NO_POD_STATE_GET_SUPPORT))
903+
{
904+
sr_info("State of digital channel %d -> %s", i,
905+
state->digital_pods[i / DIGITAL_CHANNELS_PER_POD].state ? "On" : "Off");
906+
}
907+
else {
908+
sr_info("State of digital channel %d -> On", i);
909+
}
876910
}
877911

878912
for (i = 0; i < config->digital_pods; i++) {
@@ -1058,13 +1092,27 @@ static int digital_channel_state_get(struct sr_dev_inst *sdi,
10581092
struct sr_scpi_dev_inst *scpi = sdi->conn;
10591093

10601094
for (i = 0; i < config->digital_channels; i++) {
1061-
g_snprintf(command, sizeof(command),
1062-
(*config->scpi_dialect)[SCPI_CMD_GET_DIG_CHAN_STATE],
1063-
i);
1095+
if (!(config->internal_flags & INTERN_NO_LOGIC_STATE_GET_SUPPORT)) {
1096+
g_snprintf(command, sizeof(command),
1097+
(*config->scpi_dialect)[SCPI_CMD_GET_DIG_CHAN_STATE],
1098+
i);
10641099

1065-
if (sr_scpi_get_bool(scpi, command,
1066-
&state->digital_channels[i]) != SR_OK)
1067-
return SR_ERR;
1100+
if (sr_scpi_get_bool(scpi, command,
1101+
&state->digital_channels[i]) != SR_OK)
1102+
return SR_ERR;
1103+
}
1104+
else if (!(config->internal_flags & INTERN_NO_POD_STATE_GET_SUPPORT)) {
1105+
g_snprintf(command, sizeof(command),
1106+
(*config->scpi_dialect)[SCPI_CMD_GET_DIG_POD_STATE],
1107+
i / DIGITAL_CHANNELS_PER_POD);
1108+
1109+
if (sr_scpi_get_bool(scpi, command,
1110+
&state->digital_channels[i]) != SR_OK)
1111+
return SR_ERR;
1112+
}
1113+
else {
1114+
state->digital_channels[i] = TRUE;
1115+
}
10681116

10691117
ch = get_channel_by_index_and_type(sdi->channels, i, SR_CHANNEL_LOGIC);
10701118
if (ch)
@@ -1518,13 +1566,13 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
15181566

15191567
packet.type = SR_DF_ANALOG;
15201568

1569+
sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
15211570
analog.data = data->data;
15221571
analog.num_samples = data->len / sizeof(float);
15231572
/* Truncate acquisition if a smaller number of samples has been requested. */
15241573
if (devc->samples_limit > 0 && analog.num_samples > devc->samples_limit)
15251574
analog.num_samples = devc->samples_limit;
15261575
/* TODO: Use proper 'digits' value for this device (and its modes). */
1527-
sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
15281576
encoding.is_signed = TRUE;
15291577
if (state->analog_channels[ch->index].probe_unit == 'V') {
15301578
meaning.mq = SR_MQ_VOLTAGE;
@@ -1536,7 +1584,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
15361584
meaning.channels = g_slist_append(NULL, ch);
15371585
packet.payload = &analog;
15381586
sr_session_send(sdi, &packet);
1539-
devc->num_samples = data->len / sizeof(float);
1587+
devc->num_samples += analog.num_samples;
15401588
g_slist_free(meaning.channels);
15411589
g_byte_array_free(data, TRUE);
15421590
data = NULL;
@@ -1613,7 +1661,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data)
16131661
* number of frames or after the specified number of samples, or
16141662
* continue reception by starting over at the first enabled channel.
16151663
*/
1616-
if (++devc->num_frames >= devc->frame_limit || devc->num_samples >= devc->samples_limit) {
1664+
if ((devc->frame_limit && ++devc->num_frames >= devc->frame_limit) || devc->num_samples >= devc->samples_limit) {
16171665
sr_dev_acquisition_stop(sdi);
16181666
hmo_cleanup_logic_data(devc);
16191667
} else {

src/hardware/hameg-hmo/protocol.h

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ struct scope_config {
7777
const unsigned int num_ydivs;
7878

7979
const char *(*scpi_dialect)[];
80+
81+
const uint32_t internal_flags;
8082
};
8183

8284
struct analog_channel_state {
@@ -133,6 +135,13 @@ struct dev_context {
133135
GByteArray *logic_data;
134136
};
135137

138+
enum internal_flags {
139+
INTERN_NO_LOGIC_STATE_GET_SUPPORT = (1 << 0),
140+
INTERN_NO_LOGIC_STATE_SET_SUPPORT = (1 << 1),
141+
INTERN_NO_POD_STATE_GET_SUPPORT = (1 << 2),
142+
INTERN_NO_POD_STATE_SET_SUPPORT = (1 << 3),
143+
};
144+
136145
SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi);
137146
SR_PRIV int hmo_request_data(const struct sr_dev_inst *sdi);
138147
SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data);

0 commit comments

Comments
 (0)