Skip to content

Commit

Permalink
[iCubTelemVizServer] Minor refactoring
Browse files Browse the repository at this point in the history
- `ICubTelemetry.parser` will later be replaced by a function which parses
  and eventually sends the data. For now it only parses the data and forwards
  it to the notifier.
- `this.forwardYarpDataToNotifier` processes the Yarp data (parse, forward to
  notifier), or does nothing.
- Rename the functions accordingly.
  • Loading branch information
nunoguedelha committed Sep 15, 2022
1 parent 0b48ccf commit ebd123e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions iCubTelemVizServer/iCubTelemVizServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ Object.keys(portInConfig).forEach(function (id) {
switch (portInConfig[id]["portType"]) {
case 'bottle':
portIn.onRead(function (bottle){
icubtelemetry.forwardYarpDataToNotifier[id](id,bottle.toArray());
icubtelemetry.processOrDropYarpData[id](id,bottle.toArray());
});
break;
case 'image':
portIn.onRead(function (image){
icubtelemetry.forwardYarpDataToNotifier[id](id,getDataURIscheme(image.getCompressionType(),image.toBinary()));
icubtelemetry.processOrDropYarpData[id](id,getDataURIscheme(image.getCompressionType(),image.toBinary()));
});
break;
default:
Expand Down
14 changes: 7 additions & 7 deletions iCubTelemVizServer/icubtelemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ function ICubTelemetry(portInConfig) {
this.state["sens.rightFootToetipFT"] = JSON.parse(JSON.stringify(this.state["sens.leftArmFT"]));
this.state["yarplogger.walkingModule"] = JSON.parse(JSON.stringify(this.state["yarplogger.yarpRobotInterface"]));

this.parser = {};
this.parseNforwardDataToNotifier = {};
Object.keys(portInConfig).forEach((key) => {
switch (portInConfig[key].parser.type) {
case "internal":
switch ((portInConfig[key]).parser.outputFormat) {
case "vectorCollection":
this.state[key] = {};
this.parser[key] = this.parseVectorCollectionMap.bind(this);
this.parseNforwardDataToNotifier[key] = this.parseVectorCollectionMap.bind(this);
break;
case "fromId":
this.parser[key] = this.parseFromId.bind(this);
this.parseNforwardDataToNotifier[key] = this.parseFromId.bind(this);
break;
default:
console.error('Unsupported output format');
Expand All @@ -141,8 +141,8 @@ function ICubTelemetry(portInConfig) {
console.error('Unsupported parser type.');
}
}, this);
this.forwardYarpDataToNotifier = {};
Object.keys(portInConfig).forEach((key) => {this.forwardYarpDataToNotifier[key] = (id,data) => {}});
this.processOrDropYarpData = {};
Object.keys(portInConfig).forEach((key) => {this.processOrDropYarpData[key] = (id,data) => {}});

this.connectNetworkSource = (id) => {};
this.disconnectNetworkSource = (id) => {};
Expand Down Expand Up @@ -175,14 +175,14 @@ ICubTelemetry.prototype.defineNetworkConnector = function (connectCallback,disco
}

ICubTelemetry.prototype.connectTelemSrcToNotifier = function (id) {
this.forwardYarpDataToNotifier[id] = this.parser[id];
this.processOrDropYarpData[id] = this.parseNforwardDataToNotifier[id];
this.connectNetworkSource(id);
return (() => {this.disconnectTelemSrcFromNotifier(id)}).bind(this);
}

ICubTelemetry.prototype.disconnectTelemSrcFromNotifier = function (id) {
this.disconnectNetworkSource(id);
this.forwardYarpDataToNotifier[id] = (id,data) => {};
this.processOrDropYarpData[id] = (id,data) => {};
}

ICubTelemetry.prototype.startNotifier = function () {
Expand Down

0 comments on commit ebd123e

Please sign in to comment.