aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2012-10-19 10:14:19 +0800
committerAndy Green <andy.green@linaro.org>2012-10-19 10:14:19 +0800
commit42d8937c72027d1d2ed7ace76439c527ef896a97 (patch)
tree2a0e239040c4fd5be2b49d2903343b218661fd82
parentd05707e4f19a892ed198b72a27ae234fb94059fa (diff)
fix noninteger scroll offset
Signed-off-by: Andy Green <andy.green@linaro.org>
-rw-r--r--aepd/websocket-protocol.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/aepd/websocket-protocol.c b/aepd/websocket-protocol.c
index c2d12a2..ad91c79 100644
--- a/aepd/websocket-protocol.c
+++ b/aepd/websocket-protocol.c
@@ -102,7 +102,7 @@ callback_linaro_aepd(struct libwebsocket_context *context,
double sam[MAX_PROBES * CHANNELS_PER_PROBE * 3];
double sam2[MAX_PROBES * CHANNELS_PER_PROBE * 3];
double d[10];
- char buf[LWS_SEND_BUFFER_PRE_PADDING + 32768 + LWS_SEND_BUFFER_POST_PADDING];
+ char buf[LWS_SEND_BUFFER_PRE_PADDING + 8192 + LWS_SEND_BUFFER_POST_PADDING];
char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
int budget = 10;
int no_valid_sam_flag = 0;
@@ -136,18 +136,20 @@ callback_linaro_aepd(struct libwebsocket_context *context,
pss->ms10_last_caliper = ms10;
l = pss->ringbuffer_tail - pss->caliper_offset[0];
- if (l < 0)
+ while (l < 0)
l += aepd_shared->modulo_integer_chan_size;
- lseek(aepd_shared->fd_fifo_read, l, SEEK_SET);
+ if (lseek(aepd_shared->fd_fifo_read, l, SEEK_SET) < 0)
+ fprintf(stderr, "seek %ld failed\n", l);
if (read(aepd_shared->fd_fifo_read, &sam[0], aepd_shared->chans * sizeof(double) * 3) < 0)
- fprintf(stderr, "fifo read fail\n");
+ fprintf(stderr, "fifo read %ld failed\n", l);
l = pss->ringbuffer_tail - pss->caliper_offset[1];
- if (l < 0)
+ while (l < 0)
l += aepd_shared->modulo_integer_chan_size;
- lseek(aepd_shared->fd_fifo_read, l, SEEK_SET);
+ if (lseek(aepd_shared->fd_fifo_read, l, SEEK_SET) < 0)
+ fprintf(stderr, "seek %ld failed\n", l);
if (read(aepd_shared->fd_fifo_read, &sam2[0], aepd_shared->chans * sizeof(double) * 3) < 0)
- fprintf(stderr, "fifo read fail\n");
+ fprintf(stderr, "fifo read %ld fail\n", l);
extent = (pss->caliper_offset[1] - pss->caliper_offset[0]) / (aepd_shared->chans * sizeof(double) * 3);
@@ -279,15 +281,9 @@ callback_linaro_aepd(struct libwebsocket_context *context,
* Javascript can't cope with binary, so we must ascii-fy it
*/
- if (aepd_shared->chans > 9 || aepd_shared->chans < 0)
- fprintf(stderr, "insane chans %d\n", aepd_shared->chans);
-
m = 0;
for (n = 0; n < aepd_shared->chans; n++) {
- if ((p - &buf[LWS_SEND_BUFFER_PRE_PADDING]) > (sizeof(buf) - 16384))
- fprintf(stderr, "insane buffer usage! budget=%d\n", budget);
-
p += sprintf(p, "%f %f %f",
(sam[m] - pss->sam[m]) / (double)pss->stride,
(sam[m + 1] - pss->sam[m + 1]) / (double)pss->stride,
@@ -309,10 +305,11 @@ callback_linaro_aepd(struct libwebsocket_context *context,
pss->sam_valid = 1;
}
- if ((p - &buf[LWS_SEND_BUFFER_PRE_PADDING]) > (sizeof(buf) - 16384))
+ if ((p - &buf[LWS_SEND_BUFFER_PRE_PADDING]) > (sizeof(buf) - 2048)) {
+ fprintf(stderr, "insane buffer usage %ld! pss->ringbuffer_tail = %ld, budget=%d aepd_shared->chans=%d\n",
+ (p - &buf[LWS_SEND_BUFFER_PRE_PADDING]), pss->ringbuffer_tail, budget, aepd_shared->chans);
budget = 0;
-
-
+ }
}
send:
/*
@@ -358,17 +355,18 @@ send:
break;
case 'r': /* rate or other change */
- puts((char *)in + 1);
+// puts((char *)in + 1);
if (sscanf(((char *)in) + 1, "%lf %lf %lf %lf\n", &d[0], &d[1], &d[2], &d[3]) == 4) {
pss->stride = (int)d[0];
pss->viewport_offset_time = d[3];
// fprintf(stderr, "d[0] = %f, d[1] = %f, d[2] = %f\n", d[0], d[1], d[2]);
l = aepd_shared->fifo_pos - ((int)d[1] * pss->stride * aepd_shared->chans * sizeof(double) * 3);
- l += (pss->viewport_offset_time / 0.0001) * aepd_shared->chans * sizeof(double) * 3;
+ l += (int)((pss->viewport_offset_time / 0.0001)) * aepd_shared->chans * sizeof(double) * 3;
if (pss->viewport_offset_time)
pss->viewport_budget = d[1];
pss->ringbuffer_tail = l;
+// fprintf(stderr, " setting pss->ringbuffer_tail = %ld, aepd_shared->fifo_pos=%ld, d[1]=%f\n", pss->ringbuffer_tail, aepd_shared->fifo_pos, d[1]);
aepd_shared->stop_flag = ((int)d[2]) ^ 1;
pss->issue_timestamp = 1;
pss->seen_rate = 1;