Skip to content

Commit

Permalink
[iCubTelemVizServer] Add ports, parsing and notification of Yarp Text…
Browse files Browse the repository at this point in the history
… Logging data (#138)

- [config] Add port configuration (manual setting after running the logged processes)
  => To be improved.
- [icubtelemetry] Add the respective entries in the `state` structure property.
- [icubtelemetry] Add a parser converting a bottle string to a nested array then a JSON
  object, used in the parsing of the Yarp Text Logging data.
  • Loading branch information
nunoguedelha committed Sep 12, 2022
1 parent 47a887c commit c9b285d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
24 changes: 22 additions & 2 deletions common/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

var yarp = require('YarpJS');

/**
* Signal string to code conversion from the POSIX standard
*
Expand Down Expand Up @@ -135,7 +137,9 @@ function evalTemplateLiteralInJSON(jsonObjectWithTemplateLiterals, ...args) {

/**
* Generates the values template blocks (generatedValuesBase) from the parameters in valuesTemplateGeneratorParams.
* @type {{MyCounter: MyCounter, jsonExportScript: (function(Object, string): string), signalName2exitCodeMap: (function(string)), signalName2codeMap: {SIGQUIT: number, SIGINT: number, SIGALRM: number, SIGHUP: number, SIGABRT: number, SIGTERM: number, SIGKILL: number}, evalTemplateLiteralInJSON: (function(Object): Object)}}
*
* @param {object} dictionary2expand - JSON dictionary with the parameters for generating the generatedValuesBase blocks.
* @returns {object} - expanded dictionary.
*/
function expandTelemetryDictionary(dictionary2expand) {
// Run a first interpolation
Expand Down Expand Up @@ -170,11 +174,27 @@ function expandTelemetryDictionary(dictionary2expand) {
return dictionary2expand;
}

/**
* Convert Bottle from string to JSON format
*
* @param {string} bottleAsString - JSON dictionary with the parameters for generating the generatedValuesBase blocks.
* @returns {object} - JSON formatted object.
*/
function yarpBottleString2JSON(bottleAsString) {
let bottleAsJSON = {};
let bottleAsNestedArray = yarp.Bottle().fromString(bottleAsString).toArray();
bottleAsNestedArray.forEach((elem) => {
bottleAsJSON[elem[0]] = elem[1];
});
return bottleAsJSON;
}

module.exports = {
signalName2codeMap: signalName2codeMap,
signalName2exitCodeMap: signalName2exitCodeMap,
MyCounter: MyCounter,
jsonExportScript: jsonExportScript,
evalTemplateLiteralInJSON: evalTemplateLiteralInJSON,
expandTelemetryDictionary: expandTelemetryDictionary
expandTelemetryDictionary: expandTelemetryDictionary,
yarpBottleString2JSON: yarpBottleString2JSON
};
18 changes: 18 additions & 0 deletions conf/servers.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,24 @@
"type": "internal",
"outputFormat": "vectorCollection"
}
},
"processTextLogging.yarpRobotInterface": {
"yarpName": "/log/iiticublap199/yarprobotinterfa[yarprobotinterface]/1205",
"localName": "${this.localYarpPortPrefix}/proc-yarprobotinterface-yarptextlogging:i",
"portType": "bottle",
"parser": {
"type": "internal",
"outputFormat": "fromId"
}
},
"processTextLogging.walkingModule": {
"yarpName": "/log/iiticublap199/WalkingModule-0.[walkingModule]/1470",
"localName": "${this.localYarpPortPrefix}/proc-walkingmodule-yarptextlogging:i",
"portType": "bottle",
"parser": {
"type": "internal",
"outputFormat": "fromId"
}
}
}
}
18 changes: 18 additions & 0 deletions iCubTelemVizServer/icubtelemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

// Handle errors
var assert = require('assert');
const {yarpBottleString2JSON} = require('../common/utils');

const NOTIFIER_REPEAT_INTERVAL_MS = 10;
const TELEMETRY_DATA_DEPTH_MS = 60 * 1000;

Expand Down Expand Up @@ -85,6 +87,9 @@ function ICubTelemetry(portInConfig) {
},
"sens.batteryStatus": {
"voltage": 0, "current": 0, "charge": 0, "temperature": 0, "status": 0
},
"processTextLogging.yarpRobotInterface": {
"message": "", "level": "", "filename": "", "line": 0, "function": "", "hostname": "", "pid": 0, "cmd": "", "args": "", "thread_id": 0 , "component": "", "id": "", "systemtime": 0, "networktime": 0, "externaltime": 0, "backtrace": ""
}
};

Expand Down Expand Up @@ -113,6 +118,8 @@ function ICubTelemetry(portInConfig) {
this.state["sens.leftFootToetipFT"] = JSON.parse(JSON.stringify(this.state["sens.leftArmFT"]));
this.state["sens.rightFootHeelFT"] = JSON.parse(JSON.stringify(this.state["sens.leftArmFT"]));
this.state["sens.rightFootToetipFT"] = JSON.parse(JSON.stringify(this.state["sens.leftArmFT"]));
this.state["sens.rightFootToetipFT"] = JSON.parse(JSON.stringify(this.state["sens.leftArmFT"]));
this.state["processTextLogging.walkingModule"] = JSON.parse(JSON.stringify(this.state["processTextLogging.yarpRobotInterface"]));

this.parser = {};
Object.keys(portInConfig).forEach((key) => {
Expand Down Expand Up @@ -334,6 +341,17 @@ ICubTelemetry.prototype.parseFromId = function (id,sensorSample) {
this.state[id].temperature = sensorSample[3];
this.state[id].status = sensorSample[4];
break;
case "processTextLogging.yarpRobotInterface":
case "processTextLogging.walkingModule":
// Parse hostname, pid, port.
let pid, hostname;
[,hostname,,pid] = sensorSample[0].match(/[^\/]*\/log\/(.+)\/(.+)\/([0-9]+)/);
// Parse other information: level, systemtime, etc.
Object.assign(this.state[id],
{"pid": Number(pid), "hostname": hostname},
yarpBottleString2JSON(sensorSample[1])
);
break;
default:
this.state[id] = sensorSample;
}
Expand Down

0 comments on commit c9b285d

Please sign in to comment.