@openhps/core
Version:
Open Hybrid Positioning System - Core component
91 lines • 3.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalibrationNode = void 0;
const ObjectProcessingNode_1 = require("../ObjectProcessingNode");
/**
* Calibration node for sensors. This node allows intercepts data frames when
* performing user-aided calibration.
* @rdf {@link http://purl.org/poso/CalibrationProcedure}
*/
class CalibrationNode extends ObjectProcessingNode_1.ObjectProcessingNode {
constructor(calibrationOptions) {
super(calibrationOptions);
this.state = CalibrationState.IDLE;
this.once('build', this._onBuild.bind(this));
}
_onBuild() {
this.service = this.model.findService(this.options.service);
if (!this.service) {
throw new Error(`Calibration node requires a calibration service of type '${this.options.service.name}'!`);
}
else {
this.service.node = this;
}
}
processObject(dataObject) {
return new Promise((resolve, reject) => {
if (this.state !== CalibrationState.RUNNING) {
resolve(dataObject);
}
else if (this.objectCallback) {
// Forward to service
Promise.resolve(this.objectCallback(dataObject))
.then((object) => {
resolve(object);
})
.catch(reject);
}
else {
resolve(dataObject);
}
});
}
process(dataFrame) {
return new Promise((resolve, reject) => {
if (this.state === CalibrationState.SUSPENDED) {
// Do not invoke callback but do not forward either
resolve(undefined);
}
else if (this.state === CalibrationState.RUNNING) {
if (this.frameCallback) {
Promise.resolve(this.frameCallback(dataFrame))
.then((frame) => {
var _a;
return super.process((_a = frame) !== null && _a !== void 0 ? _a : dataFrame);
})
.then(() => {
resolve(undefined);
})
.catch(reject);
}
else {
super.process(dataFrame).then(() => {
resolve(undefined);
});
}
}
else {
resolve(dataFrame);
}
});
}
start(objectCallback, frameCallback) {
this.objectCallback = objectCallback;
this.frameCallback = frameCallback;
this.state = CalibrationState.RUNNING;
}
suspend() {
this.state = CalibrationState.SUSPENDED;
}
stop() {
this.state = CalibrationState.IDLE;
}
}
exports.CalibrationNode = CalibrationNode;
var CalibrationState;
(function (CalibrationState) {
CalibrationState[CalibrationState["IDLE"] = 0] = "IDLE";
CalibrationState[CalibrationState["SUSPENDED"] = 1] = "SUSPENDED";
CalibrationState[CalibrationState["RUNNING"] = 2] = "RUNNING";
})(CalibrationState || (CalibrationState = {}));
//# sourceMappingURL=CalibrationNode.js.map