diff --git a/include/villas/webmsg_format.h b/include/villas/webmsg_format.h index 55f885980..c6b0e0d4d 100644 --- a/include/villas/webmsg_format.h +++ b/include/villas/webmsg_format.h @@ -49,9 +49,9 @@ /** Initialize a message with default values */ #define WEBMSG_INIT(len, seq) (struct msg) {\ - .version = MSG_VERSION, \ - .type = MSG_TYPE_DATA, \ - .endian = MSG_ENDIAN_HOST, \ + .version = WEBMSG_VERSION, \ + .type = WEBMSG_TYPE_DATA, \ + .endian = WEBMSG_ENDIAN_HOST, \ .length = len, \ .sequence = seq \ } @@ -80,7 +80,7 @@ struct webmsg unsigned version: 4; /**< Specifies the format of the remaining message (see MGS_VERSION) */ #endif - uint8_t node_id; /**< The node index from / to which this sample received / sent to. + uint8_t id; /**< The node index from / to which this sample received / sent to. * Corresponds to the index of the node in the http://localhost/nodes.json array. */ uint16_t length; /**< The number of values in msg::data[]. Endianess is specified in msg::endian. */ diff --git a/web/socket/app.js b/web/socket/app.js index a1b584dca..8bf88f94b 100644 --- a/web/socket/app.js +++ b/web/socket/app.js @@ -174,7 +174,7 @@ function wsConnect(url, protocol) { connection.onmessage = function(e) { var msgs = Msg.fromArrayBufferVector(e.data); - console.log('Received ' + msgs.length + ' messages with ' + msgs[0].data.length + ' values: ' + msgs[0].timestamp); + console.log('Received ' + msgs.length + ' messages with ' + msgs[0].data.length + ' values from id ' + msgs[0].id + ' with timestamp ' + msgs[0].timestamp); for (var j = 0; j < plotData.length; j++) { // remove old diff --git a/web/socket/msg.js b/web/socket/msg.js index a23795197..75436e396 100644 --- a/web/socket/msg.js +++ b/web/socket/msg.js @@ -20,6 +20,7 @@ function Msg(c, d) this.endian = typeof c.endian === 'undefined' ? Msg.prototype.ENDIAN_LITTLE : c.endian; this.version = typeof c.version === 'undefined' ? Msg.prototype.VERSION : c.version; this.type = typeof c.type === 'undefined' ? Msg.prototype.TYPE_DATA : c.type; + this.id = typeof c.id === 'undefined' ? -1 : c.id; this.timestamp = typeof c.timestamp === 'undefined' ? Date.now() : c.timestamp; if (Array.isArray(d)) { @@ -55,6 +56,7 @@ Msg.fromArrayBuffer = function(data) endian: (bits >> Msg.prototype.OFFSET_ENDIAN) & 0x1, version: (bits >> Msg.prototype.OFFSET_VERSION) & 0xF, type: (bits >> Msg.prototype.OFFSET_TYPE) & 0x3, + id: data.getUint8( 0x01, endian), length: data.getUint16(0x02, endian), sequence: data.getUint32(0x04, endian), timestamp: data.getUint32(0x08, endian) * 1e3 + @@ -109,6 +111,7 @@ Msg.prototype.toArrayBuffer = function() var nsec = (this.timestamp - sec * 1e3) * 1e6; view.setUint8( 0x00, bits, true); + view.setUint8( 0x01, this.id, true); view.setUint16(0x02, this.length, true); view.setUint32(0x04, this.sequence, true); view.setUint32(0x08, sec, true);