1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

add node id to web mockup javascript

This commit is contained in:
Steffen Vogel 2016-11-07 21:30:28 -05:00
parent d67821dda4
commit dd7e0443ce
3 changed files with 8 additions and 5 deletions

View file

@ -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. */

View file

@ -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

View file

@ -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);