-/* Callback handling data */
-static int receive_data(int fd, int revents, void *user_data)
-{
- struct datafeed_packet packet;
- char c[BUFSIZE];
- uint64_t z;
-#ifdef DEMO_ANALOG
- struct analog_sample *sample;
- unsigned int i, x;
- int sample_size = sizeof(struct analog_sample) +
- (NUM_PROBES * sizeof(struct analog_probe));
- char *buf;
-#endif
-
- /* Avoid compiler warnings. */
- fd = fd;
- revents = revents;
-
- do {
- g_io_channel_read_chars(channels[0],
- (gchar *) &c, BUFSIZE, (gsize *) &z, NULL);
-
- if (z > 0) {
-#ifdef DEMO_ANALOG
- packet.type = DF_ANALOG;
-
- packet.length = (z / 3) * sample_size;
- packet.unitsize = sample_size;
-
- buf = malloc(sample_size * packet.length);
- if (!buf)
- return FALSE;
-
- /* Craft our packet. */
- for (i = 0; i < z / 3; i++) {
- sample = (struct analog_sample *) (buf + (i * sample_size));
- sample->num_probes = NUM_PROBES;
-
- /* 8 Logic probes */
- for (x = 0; x < NUM_PROBES - 1; x++) {
- sample->probes[x].val =
- (c[i * 3] >> x) & 1;
- sample->probes[x].res = 1;
- }
-
- /* 1 Analog probe, 16 bit adc */
- for (; x < NUM_PROBES; x++) {
- sample->probes[x].val =
- *(uint16_t *) (c + i * 3 + 1);
- sample->probes[x].val &= ((1 << 16) - 1);
- sample->probes[x].res = 16;
- }
-
- }
-
- packet.payload = buf;
- session_bus(user_data, &packet);
- free(buf);
-#else
- packet.type = DF_LOGIC;
- packet.length = z;
- packet.unitsize = 1;
- packet.payload = c;
- session_bus(user_data, &packet);
-#endif
- }
- } while (z > 0);