X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fpipistrello-ols%2Fprotocol.c;h=17fe031db4b70587ce5f80c06b13002ca56f95c8;hb=62974b235a5c5aeaacad5d28a50aef39f528dccd;hp=62d77e96576ffc88e8507766c3e459ed1527b91d;hpb=aed4ad0beaf64062752039a13f9a95326aa1df87;p=libsigrok.git
diff --git a/src/hardware/pipistrello-ols/protocol.c b/src/hardware/pipistrello-ols/protocol.c
index 62d77e96..17fe031d 100644
--- a/src/hardware/pipistrello-ols/protocol.c
+++ b/src/hardware/pipistrello-ols/protocol.c
@@ -17,10 +17,10 @@
* along with this program. If not, see .
*/
+#include
#include "protocol.h"
extern SR_PRIV struct sr_dev_driver p_ols_driver_info;
-static struct sr_dev_driver *di = &p_ols_driver_info;
SR_PRIV int write_shortcommand(struct dev_context *devc, uint8_t command)
{
@@ -219,15 +219,15 @@ SR_PRIV int pols_convert_trigger(const struct sr_dev_inst *sdi)
SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, struct dev_context *devc)
{
struct sr_dev_inst *sdi;
- struct sr_channel *ch;
uint32_t tmp_int, ui;
uint8_t key, type, token;
GString *tmp_str, *devname, *version;
guchar tmp_c;
int index, i;
- sdi = sr_dev_inst_new(SR_ST_INACTIVE, NULL, NULL, NULL);
- sdi->driver = di;
+ sdi = g_malloc0(sizeof(struct sr_dev_inst));
+ sdi->status = SR_ST_INACTIVE;
+ sdi->driver = &p_ols_driver_info;
sdi->priv = devc;
devname = g_string_new("");
@@ -287,12 +287,9 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str
switch (token) {
case 0x00:
/* Number of usable channels */
- for (ui = 0; ui < tmp_int; ui++) {
- if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE,
- p_ols_channel_names[ui])))
- return 0;
- sdi->channels = g_slist_append(sdi->channels, ch);
- }
+ for (ui = 0; ui < tmp_int; ui++)
+ sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE,
+ p_ols_channel_names[ui]);
break;
case 0x01:
/* Amount of sample memory available (bytes) */
@@ -303,7 +300,7 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str
/* what is this for? */
break;
case 0x03:
- /* Maximum sample rate (hz) */
+ /* Maximum sample rate (Hz) */
devc->max_samplerate = tmp_int;
break;
case 0x04:
@@ -324,12 +321,9 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str
switch (token) {
case 0x00:
/* Number of usable channels */
- for (ui = 0; ui < tmp_c; ui++) {
- if (!(ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE,
- p_ols_channel_names[ui])))
- return 0;
- sdi->channels = g_slist_append(sdi->channels, ch);
- }
+ for (ui = 0; ui < tmp_c; ui++)
+ sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE,
+ p_ols_channel_names[ui]);
break;
case 0x01:
/* protocol version */
@@ -391,7 +385,6 @@ SR_PRIV int p_ols_set_samplerate(const struct sr_dev_inst *sdi,
return SR_OK;
}
-
SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
{
struct dev_context *devc;
@@ -513,7 +506,9 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
}
/* Clear out the most significant bit of the sample */
devc->tmp_sample[devc->num_bytes - 1] &= 0x7f;
- sr_spew("Expanded sample 1: 0x%.8x.", devc->tmp_sample);
+ sr_spew("Expanded sample 1: 0x%.2x%.2x%.2x%.2x.",
+ devc->tmp_sample[3], devc->tmp_sample[2],
+ devc->tmp_sample[1], devc->tmp_sample[0]);
/* expand second sample */
memset(devc->tmp_sample2, 0, 4);
@@ -529,7 +524,9 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
}
/* Clear out the most significant bit of the sample */
devc->tmp_sample2[devc->num_bytes - 1] &= 0x7f;
- sr_spew("Expanded sample 2: 0x%.8x.", devc->tmp_sample2);
+ sr_spew("Expanded sample 2: 0x%.2x%.2x%.2x%.2x.",
+ devc->tmp_sample2[3], devc->tmp_sample2[2],
+ devc->tmp_sample2[1], devc->tmp_sample2[0]);
/*
* OLS sends its sample buffer backwards.
@@ -627,8 +624,9 @@ SR_PRIV int p_ols_receive_data(int fd, int revents, void *cb_data)
}
return TRUE;
} else {
- do bytes_read = ftdi_read_data(devc->ftdic, devc->ftdi_buf, FTDI_BUF_SIZE);
- while (bytes_read > 0);
+ do {
+ bytes_read = ftdi_read_data(devc->ftdic, devc->ftdi_buf, FTDI_BUF_SIZE);
+ } while (bytes_read > 0);
/*
* We've acquired all the samples we asked for -- we're done.