X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fatten-pps3xxx%2Fprotocol.c;h=7cf0f9342e3d8bf8447e8d920672e5863a98f79b;hb=e26a443aadd8ad75dc45d58ffa51e8e86fbb804f;hp=95137d2e9a8164e86041d5184129ab749173c75f;hpb=081c214eace0c9088cbcbd9a3d448f6fac5e98f4;p=libsigrok.git
diff --git a/src/hardware/atten-pps3xxx/protocol.c b/src/hardware/atten-pps3xxx/protocol.c
index 95137d2e..7cf0f934 100644
--- a/src/hardware/atten-pps3xxx/protocol.c
+++ b/src/hardware/atten-pps3xxx/protocol.c
@@ -17,11 +17,11 @@
* along with this program. If not, see .
*/
+#include
#include
-#include
#include "protocol.h"
-static void dump_packet(char *msg, uint8_t *packet)
+static void dump_packet(const char *msg, uint8_t *packet)
{
int i;
char str[128];
@@ -38,36 +38,47 @@ static void handle_packet(const struct sr_dev_inst *sdi)
struct dev_context *devc;
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
+ struct sr_analog_encoding encoding;
+ struct sr_analog_meaning meaning;
+ struct sr_analog_spec spec;
float value, data[MAX_CHANNELS];
int offset, i;
devc = sdi->priv;
dump_packet("received", devc->packet);
+
+ /* Note: digits/spec_digits will be overridden later. */
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
+
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
- analog.channels = sdi->channels;
+ analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
- analog.mq = SR_MQ_VOLTAGE;
- analog.unit = SR_UNIT_VOLT;
- analog.mqflags = SR_MQFLAG_DC;
+ analog.meaning->mq = SR_MQ_VOLTAGE;
+ analog.meaning->unit = SR_UNIT_VOLT;
+ analog.meaning->mqflags = SR_MQFLAG_DC;
+ analog.encoding->digits = 2;
+ analog.spec->spec_digits = 2;
analog.data = data;
for (i = 0; i < devc->model->num_channels; i++) {
offset = 2 + i * 4;
value = ((devc->packet[offset] << 8) + devc->packet[offset + 1]) / 100.0;
- analog.data[i] = value;
+ ((float *)analog.data)[i] = value;
devc->config[i].output_voltage_last = value;
}
sr_session_send(sdi, &packet);
- analog.mq = SR_MQ_CURRENT;
- analog.unit = SR_UNIT_AMPERE;
- analog.mqflags = 0;
+ analog.meaning->mq = SR_MQ_CURRENT;
+ analog.meaning->unit = SR_UNIT_AMPERE;
+ analog.meaning->mqflags = 0;
+ analog.encoding->digits = 3;
+ analog.spec->spec_digits = 3;
analog.data = data;
for (i = 0; i < devc->model->num_channels; i++) {
offset = 4 + i * 4;
value = ((devc->packet[offset] << 8) + devc->packet[offset + 1]) / 1000.0;
- analog.data[i] = value;
+ ((float *)analog.data)[i] = value;
devc->config[i].output_current_last = value;
}
sr_session_send(sdi, &packet);
@@ -83,10 +94,12 @@ static void handle_packet(const struct sr_dev_inst *sdi)
SR_PRIV void send_packet(const struct sr_dev_inst *sdi, uint8_t *packet)
{
+ struct dev_context *devc;
struct sr_serial_dev_inst *serial;
+ devc = sdi->priv;
serial = sdi->conn;
- if (serial_write_blocking(serial, packet, PACKET_SIZE) < PACKET_SIZE)
+ if (serial_write_blocking(serial, packet, PACKET_SIZE, devc->delay_ms) < PACKET_SIZE)
sr_dbg("Failed to send packet.");
dump_packet("sent", packet);
}
@@ -131,7 +144,6 @@ SR_PRIV int atten_pps3xxx_receive_data(int fd, int revents, void *cb_data)
struct dev_context *devc;
const struct sr_dev_inst *sdi;
struct sr_serial_dev_inst *serial;
- struct sr_datafeed_packet packet;
unsigned char c;
(void)fd;
@@ -154,12 +166,10 @@ SR_PRIV int atten_pps3xxx_receive_data(int fd, int revents, void *cb_data)
send_config(sdi);
else {
serial_source_remove(sdi->session, serial);
- packet.type = SR_DF_END;
- sr_session_send(sdi, &packet);
+ std_session_send_df_end(sdi);
}
}
}
return TRUE;
}
-