aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2012-10-14 12:42:07 +0800
committerAndy Green <andy.green@linaro.org>2012-10-15 07:37:49 +0800
commitd47d0471297aae19f56f5dab9e6be03cff2035c0 (patch)
tree55534ec11b95d1abba8f29517924c6fb55b7893a
parent68d6c70d6b330941a5f22a35269d63d9d920064a (diff)
send channel metadata on websocket
Signed-off-by: Andy Green <andy.green@linaro.org>
-rw-r--r--aepd/main.c2
-rw-r--r--aepd/share/aepscope.html50
-rw-r--r--aepd/websocket-protocol.c22
3 files changed, 59 insertions, 15 deletions
diff --git a/aepd/main.c b/aepd/main.c
index c11c91e..f8e917d 100644
--- a/aepd/main.c
+++ b/aepd/main.c
@@ -197,7 +197,7 @@ int main(int argc, char *argv[])
aep_context.original_count_channel_names = aep_context.count_channel_names;
- configure(&aep_context, NULL, "xx", aep_context.config_filepath, NULL);
+ configure(&aep_context, NULL, "/virtual", aep_context.config_filepath, NULL);
/*
diff --git a/aepd/share/aepscope.html b/aepd/share/aepscope.html
index c66e82b..dc68053 100644
--- a/aepd/share/aepscope.html
+++ b/aepd/share/aepscope.html
@@ -110,16 +110,11 @@ var ylen = 400;
var bounce = 0;
var last_head = -1;
-var colours = new Array();
-colours[0] = "#ff0000";
-colours[1] = "#c00000";
-colours[2] = "#a00000";
-colours[3] = "#e0e000";
-colours[4] = "#0000c0";
-colours[5] = "#a0c0e0";
-colours[6] = "#e000e0";
-colours[7] = "#0000ff";
-colours[8] = "#000000";
+var ch_name = new Array();
+var ch_supply = new Array();
+var ch_colour = new Array();
+var ch_class = new Array();
+var ov;
function get_appropriate_ws_url()
@@ -148,7 +143,7 @@ function get_appropriate_ws_url()
function conn_retry()
{
- var r1, r2, r3, x, y, chan, z, block;
+ var r1, r2, r3, x, y, chan, z, block, channel_data = 0;
if (connection)
return;
@@ -166,12 +161,32 @@ function conn_retry()
socket.onmessage = function got_packet(msg) {
+ if (msg.data[0] == '=')
+ channel_data = 1;
+ else
+ channel_data = 0;
+
z = msg.data.split(';');
+ ov = 0;
block = 0;
while (block < (z.length - 1)) {
y = z[block].split(',');
+
+ if (channel_data) {
+ if (!block)
+ ch_name[ov] = y[0].substr(1);
+ else
+ ch_name[ov] = y[0];
+ ch_supply[ov] = y[1];
+ ch_colour[ov] = y[2];
+ ch_class[ov++] = y[3];
+ block++;
+ continue;
+ }
+
+
chan = 0;
while (chan < (y.length - 1)) {
@@ -211,9 +226,18 @@ function conn_retry()
ring_head = 0;
total++;
-
block++;
}
+
+ if (channel_data) {
+ tab = "<table>";
+ for (n = 0; n < ov; n++) {
+ tab += '<tr><td style="background-color: '+ch_colour[n]+'">&nbsp;&nbsp;</td><td>' + ch_name[n] +"</td></tr>";
+ }
+ tab += "</table>";
+
+ document.getElementById("cha").innerHTML = tab;
+ }
}
socket.onclose = function(){
@@ -285,7 +309,7 @@ function show(cv)
while (chan < chans) {
ctx.lineWidth = 1;
- ctx.strokeStyle = colours[chan];
+ ctx.strokeStyle = ch_colour[chan];
ctx.beginPath();
diff --git a/aepd/websocket-protocol.c b/aepd/websocket-protocol.c
index cd81512..591b6cf 100644
--- a/aepd/websocket-protocol.c
+++ b/aepd/websocket-protocol.c
@@ -79,8 +79,10 @@ struct per_session_data__linaro_aepd {
double sam[MAX_PROBES * CHANNELS_PER_PROBE * 3];
int sam_valid;
int stride;
+ int channels_sent_flag;
};
+extern struct aep_context aep_context;
static int
callback_linaro_aepd(struct libwebsocket_context *context,
@@ -104,10 +106,28 @@ callback_linaro_aepd(struct libwebsocket_context *context,
pss->sam_valid = 0;
pss->wsi = wsi;
pss->stride = 100;
+ pss->channels_sent_flag = 0;
break;
case LWS_CALLBACK_SERVER_WRITEABLE:
+ if (!pss->channels_sent_flag) {
+
+ /* signal it's a message with channel names */
+ *p++ = '=';
+
+ for (n = 0; n < aep_context.aep_shared->chans + aep_context.aep_shared->vchans; n++)
+ p += sprintf(p, "%s,%s,%s,%s,;",
+ aep_context.aep_shared->channel_name[n],
+ aep_context.aep_shared->supply[n],
+ aep_context.aep_shared->colour[n],
+ aep_context.aep_shared->class[n]);
+
+ pss->channels_sent_flag = 1;
+
+ goto send;
+ }
+
/*
* aggregate up to 'budget' results in one websocket message
*/
@@ -160,7 +180,7 @@ callback_linaro_aepd(struct libwebsocket_context *context,
memcpy(&pss->sam[0], &sam[0], aepd_shared->chans * sizeof(double) * 3);
pss->sam_valid = 1;
}
-
+send:
/*
* if we generated something, send it. We are guaranteed not to block
* because we got here by POLLOUT seen on the socket