]> sigrok.org Git - libsigrok.git/blobdiff - hardware/openbench-logic-sniffer/ols.c
output_text: Allocate enough memory for output
[libsigrok.git] / hardware / openbench-logic-sniffer / ols.c
index cbe145d88a9901b8fab68232c11f532ce24e7670..582a258c9b881abc3d7f427dc554028dae082232 100644 (file)
 #endif
 #include <glib.h>
 #include <sigrok.h>
+#include <sigrok-internal.h>
+
+#ifdef _WIN32
+#define O_NONBLOCK FIONBIO
+#endif
 
 #define NUM_PROBES                     32
 #define NUM_TRIGGER_STAGES             4
@@ -115,7 +120,7 @@ static int send_shortcommand(int fd, uint8_t command)
 
        g_debug("ols: sending cmd 0x%.2x", command);
        buf[0] = command;
-       if (write(fd, buf, 1) != 1)
+       if (serial_write(fd, buf, 1) != 1)
                return SIGROK_ERR;
 
        return SIGROK_OK;
@@ -131,7 +136,7 @@ static int send_longcommand(int fd, uint8_t command, uint32_t data)
        buf[2] = (data & 0xff0000) >> 16;
        buf[3] = (data & 0xff00) >> 8;
        buf[4] = data & 0xff;
-       if (write(fd, buf, 5) != 5)
+       if (serial_write(fd, buf, 5) != 5)
                return SIGROK_ERR;
 
        return SIGROK_OK;
@@ -276,7 +281,7 @@ static int hw_init(char *deviceinfo)
        g_poll(fds, devcnt, 1);
        for (i = 0; i < devcnt; i++) {
                if (fds[i].revents == G_IO_IN) {
-                       if (read(fds[i].fd, buf, 4) == 4) {
+                       if (serial_read(fds[i].fd, buf, 4) == 4) {
                                if (!strncmp(buf, "1SLO", 4)
                                    || !strncmp(buf, "1ALS", 4)) {
                                        if (!strncmp(buf, "1SLO", 4))
@@ -511,7 +516,7 @@ static int receive_data(int fd, int revents, void *user_data)
 
        if (revents == G_IO_IN
            && num_transfers / num_channels <= limit_samples) {
-               if (read(fd, &byte, 1) != 1)
+               if (serial_read(fd, &byte, 1) != 1)
                        return FALSE;
 
                sample[num_bytes++] = byte;
@@ -604,8 +609,9 @@ static int receive_data(int fd, int revents, void *user_data)
                         */
                        if (trigger_at > 0) {
                                /* there are pre-trigger samples, send those first */
-                               packet.type = DF_LOGIC32;
+                               packet.type = DF_LOGIC;
                                packet.length = trigger_at * 4;
+                               packet.unitsize = 4;
                                packet.payload = raw_sample_buf;
                                session_bus(user_data, &packet);
                        }
@@ -614,13 +620,15 @@ static int receive_data(int fd, int revents, void *user_data)
                        packet.length = 0;
                        session_bus(user_data, &packet);
 
-                       packet.type = DF_LOGIC32;
+                       packet.type = DF_LOGIC;
                        packet.length = (limit_samples * 4) - (trigger_at * 4);
+                       packet.unitsize = 4;
                        packet.payload = raw_sample_buf + trigger_at * 4;
                        session_bus(user_data, &packet);
                } else {
-                       packet.type = DF_LOGIC32;
+                       packet.type = DF_LOGIC;
                        packet.length = limit_samples * 4;
+                       packet.unitsize = 4;
                        packet.payload = raw_sample_buf;
                        session_bus(user_data, &packet);
                }
@@ -757,7 +765,8 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
        gettimeofday(&header->starttime, NULL);
        header->samplerate = cur_samplerate;
        header->protocol_id = PROTO_RAW;
-       header->num_probes = NUM_PROBES;
+       header->num_logic_probes = NUM_PROBES;
+       header->num_analog_probes = 0;
        session_bus(session_device_id, packet);
        g_free(header);
        g_free(packet);
@@ -769,7 +778,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id)
 {
        struct datafeed_packet packet;
 
-       /* QUICK HACK */
+       /* Avoid compiler warnings. */
        device_index = device_index;
 
        packet.type = DF_END;