aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2012-10-19 14:02:28 +0800
committerAndy Green <andy.green@linaro.org>2012-10-19 14:02:28 +0800
commitcf911ae7b4c9206423c67a3ec1acf29522e3ea8b (patch)
treefd0c7aaceaea5357fabd4b86d66fd600221d1727
parentf8113c99e76c066b6873067544fba007b6ab817f (diff)
caliper local storage fix make sample buffer use more defensive
Signed-off-by: Andy Green <andy.green@linaro.org>
-rw-r--r--aepd/share/aepscope.html29
-rw-r--r--aepd/websocket-protocol.c17
2 files changed, 39 insertions, 7 deletions
diff --git a/aepd/share/aepscope.html b/aepd/share/aepscope.html
index 82515a8..fa7ac6e 100644
--- a/aepd/share/aepscope.html
+++ b/aepd/share/aepscope.html
@@ -73,9 +73,9 @@ div.group img {
<div class="control"><input type="checkbox" id="run" checked="checked" onchange="update_options();">Run</input></div>
<div id="val" class="info">&nbsp;</div>
</div></td>
- <td height="100%"><div class="group">
+ <td height="100%" style="width:100px;"><div class="group">
<div class="control"><input type="checkbox" id="measure" checked="checked" onchange="update_measure();">Measure</input></div>
- <div id="val2" class="info"></div>
+ <div id="val2" class="caliper_invalid"></div>
</div></td>
</tr>
</table>
@@ -167,6 +167,9 @@ var rates = [ 10000, 5000, 2000, 1000, 500, 200, 100, 50,
var intervals = [ 50, 20, 10, 5, 2, 1, 1, 0.5, 0.25, 0.1, 0.05, 0.05, 0.025, 0.025, 0.01 ];
var sigs = [ 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 2, 3, 3, 2 ];
+cal_pos[0] = 100;
+cal_pos[1] = 200;
+
function event_wheel(e)
{
var f;
@@ -264,7 +267,10 @@ function caliper_changed()
if (f < 0)
f = -f;
- document.getElementById("val2").textContent = units(f)+"s / "+ units(1/f)+"Hz";
+ document.getElementById("val2").innerHTML = units(f)+"s<br>"+ units(1 / f)+"Hz";
+
+ localStorage["aepd.caliper0"] = cal_pos[0];
+ localStorage["aepd.caliper1"] = cal_pos[1];
/*
* caliper position in s behind rhs
@@ -295,9 +301,22 @@ rate = read_local_stg("aepd.rate", "rate", rate);
watts_fullscale = read_local_stg("aepd.scale", "scale", watts_fullscale);
if (localStorage["aepd.measure"])
document.getElementById("measure").checked = localStorage["aepd.measure"];
+
+cal_pos[0] = parseFloat(read_local_stg("aepd.caliper0", "", 100));
+cal_pos[1] = parseFloat(read_local_stg("aepd.caliper1", "", 200));
update_measure();
-cal_pos[0] = read_local_stg("aepd.caliper0", "", 100);
-cal_pos[1] = read_local_stg("aepd.caliper1", "", 200);
+
+if (cal_pos[0] < 0 || isNaN(cal_pos[0]))
+ cal_pos[0] = 100;
+if (cal_pos[1] < 0 || isNaN(cal_pos[1]))
+ cal_pos[1] = 200;
+
+if (cal_pos[0] >= xlen)
+ cal_pos[0] = xlen - 1;
+if (cal_pos[1] > xlen)
+ cal_pos[1] = xlen - 1;
+
+
caliper_changed();
const CHFLAG_TOPLEVEL = 1;
diff --git a/aepd/websocket-protocol.c b/aepd/websocket-protocol.c
index 97d78cb..eecd922 100644
--- a/aepd/websocket-protocol.c
+++ b/aepd/websocket-protocol.c
@@ -103,7 +103,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 + 8192 + LWS_SEND_BUFFER_POST_PADDING];
+ char buf[LWS_SEND_BUFFER_PRE_PADDING + 16384 + LWS_SEND_BUFFER_POST_PADDING];
char *p = &buf[LWS_SEND_BUFFER_PRE_PADDING];
int budget = 10;
int no_valid_sam_flag = 0;
@@ -144,6 +144,10 @@ callback_linaro_aepd(struct libwebsocket_context *context,
pss->caliper_time[1] > aepd_shared->fifo_head_time)
goto bad_caliper;
+ if (pss->caliper_time[0] < 0 ||
+ pss->caliper_time[1] < 0)
+ goto bad_caliper;
+
l = pss->ringbuffer_tail - pss->caliper_offset[0];
if (l < 0)
l += aepd_shared->modulo_integer_chan_size;
@@ -262,7 +266,7 @@ bad_caliper:
if (!pss->seen_rate || !aepd_shared->chans)
return 0;
- while (budget--) {
+ while (budget-- && (p - &buf[LWS_SEND_BUFFER_PRE_PADDING]) < (sizeof(buf) - 4096)) {
if (pss->ringbuffer_tail <= (long)aepd_shared->fifo_pos)
extent = aepd_shared->fifo_pos - pss->ringbuffer_tail;
@@ -360,6 +364,15 @@ send:
switch (*(char *)in) {
case 'c': /* calipers changed */
if (sscanf(((char *)in) + 1, "%lf %lf\n", &d[0], &d[1]) == 2) {
+
+ if (d[0] != d[0] || d[1] != d[1]) { /* NaN */
+ pss->caliper_offset[0] = -1;
+ pss->caliper_time[0] = -1;
+ pss->caliper_offset[1] = -1;
+ pss->caliper_time[1] = -1;
+ break;
+ }
+
if (d[0] > d[1]) {
d[2] = d[1];
d[1] = d[0];