mirror of
https://github.com/nasa/openmct.git
synced 2025-06-21 16:49:42 +00:00
[Telemetry] Begin adding telemetry handler
Begin adding a general purpose handler for telemetry which extends on the behavior associated with the telemetrySubscriber by supporting access to historical data as well. WTD-806.
This commit is contained in:
81
platform/telemetry/src/TelemetryHandle.js
Normal file
81
platform/telemetry/src/TelemetryHandle.js
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function TelemetryHandle($q, subscription) {
|
||||||
|
var seriesMap = {},
|
||||||
|
self = Object.create(subscription);
|
||||||
|
|
||||||
|
function requestSeries(telemetryObject, request, callback) {
|
||||||
|
var id = telemetryObject.getId(),
|
||||||
|
telemetry = telemetryObject.getCapability('telemetry');
|
||||||
|
|
||||||
|
function receiveSeries(series) {
|
||||||
|
// Store it for subsequent lookup
|
||||||
|
seriesMap[id] = series;
|
||||||
|
// Notify callback of new series data, if there is one
|
||||||
|
if (callback) {
|
||||||
|
callback(telemetryObject, series);
|
||||||
|
}
|
||||||
|
// Pass it along for promise-chaining
|
||||||
|
return series;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue the request via the object's telemetry capability
|
||||||
|
return telemetry.requestData(request).then(receiveSeries);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the most recently obtained telemetry data series associated
|
||||||
|
* with this domain object.
|
||||||
|
* @param {DomainObject} the domain object which has telemetry
|
||||||
|
* data associated with it
|
||||||
|
* @return {TelemetrySeries} the most recent telemetry series
|
||||||
|
* (or undefined if there is not one)
|
||||||
|
*/
|
||||||
|
self.getSeries = function (domainObject) {
|
||||||
|
var id = domainObject.getId();
|
||||||
|
return seriesMap[id];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the request duration.
|
||||||
|
* @param {object|number} request the duration of historical
|
||||||
|
* data to look at; or, the request to issue
|
||||||
|
* @param {Function} [callback] a callback that will be
|
||||||
|
* invoked as new data becomes available, with the
|
||||||
|
* domain object for which new data is available.
|
||||||
|
*/
|
||||||
|
self.request = function (request, callback) {
|
||||||
|
// Issue (and handle) the new request from this object
|
||||||
|
function issueRequest(telemetryObject) {
|
||||||
|
return requestSeries(telemetryObject, request, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map the request to all telemetry objects
|
||||||
|
function issueRequests(telemetryObjects) {
|
||||||
|
return $q.all(telemetryObjects.map(issueRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the request is a simple number, treat it as a duration
|
||||||
|
request = (typeof request === 'number') ?
|
||||||
|
{ duration: request } : request;
|
||||||
|
|
||||||
|
// Look up telemetry-providing objects from the subscription,
|
||||||
|
// then issue new requests.
|
||||||
|
return subscription.promiseTelemetryObjects()
|
||||||
|
.then(issueRequests);
|
||||||
|
};
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TelemetryHandle;
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
33
platform/telemetry/src/TelemetryHandler.js
Normal file
33
platform/telemetry/src/TelemetryHandler.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
['./TelemetryHandle'],
|
||||||
|
function (TelemetryHandle) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A TelemetryRequester provides an easy interface to request
|
||||||
|
* telemetry associated with a set of domain objects.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @param $q Angular's $q
|
||||||
|
*/
|
||||||
|
function TelemetryHandler($q, telemetrySubscriber) {
|
||||||
|
return {
|
||||||
|
handle: function (domainObject, callback, lossless) {
|
||||||
|
var subscription = telemetrySubscriber.subscribe(
|
||||||
|
domainObject,
|
||||||
|
callback,
|
||||||
|
lossless
|
||||||
|
);
|
||||||
|
|
||||||
|
return new TelemetryHandle($q, subscription);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return TelemetryHandler;
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
@ -1,34 +0,0 @@
|
|||||||
/*global define*/
|
|
||||||
|
|
||||||
define(
|
|
||||||
['./TelemetryDelegator'],
|
|
||||||
function (TelemetryDelegator) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A TelemetryRequester provides an easy interface to request
|
|
||||||
* telemetry associated with a set of domain objects.
|
|
||||||
*
|
|
||||||
* @constructor
|
|
||||||
* @param $q Angular's $q
|
|
||||||
*/
|
|
||||||
function TelemetryRequester($q) {
|
|
||||||
var delegator = new TelemetryDelegator($q);
|
|
||||||
|
|
||||||
// Look up domain objects which have telemetry capabilities.
|
|
||||||
// This will either be the object in view, or object that
|
|
||||||
// this object delegates its telemetry capability to.
|
|
||||||
function promiseRelevantObjects(domainObject) {
|
|
||||||
return delegator.promiseTelemetryObjects(domainObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return TelemetryRequester;
|
|
||||||
|
|
||||||
}
|
|
||||||
);
|
|
@ -33,6 +33,7 @@ define(
|
|||||||
function TelemetrySubscription($q, $timeout, domainObject, callback, lossless) {
|
function TelemetrySubscription($q, $timeout, domainObject, callback, lossless) {
|
||||||
var delegator = new TelemetryDelegator($q),
|
var delegator = new TelemetryDelegator($q),
|
||||||
unsubscribePromise,
|
unsubscribePromise,
|
||||||
|
telemetryObjectPromise,
|
||||||
latestValues = {},
|
latestValues = {},
|
||||||
telemetryObjects = [],
|
telemetryObjects = [],
|
||||||
pool = lossless ? new TelemetryQueue() : new TelemetryTable(),
|
pool = lossless ? new TelemetryQueue() : new TelemetryTable(),
|
||||||
@ -137,8 +138,8 @@ define(
|
|||||||
// will be unsubscribe functions. (This must be a promise
|
// will be unsubscribe functions. (This must be a promise
|
||||||
// because delegation is supported, and retrieving delegate
|
// because delegation is supported, and retrieving delegate
|
||||||
// telemetry-capable objects may be an asynchronous operation.)
|
// telemetry-capable objects may be an asynchronous operation.)
|
||||||
unsubscribePromise =
|
telemetryObjectPromise = promiseRelevantObjects(domainObject);
|
||||||
promiseRelevantObjects(domainObject)
|
unsubscribePromise = telemetryObjectPromise
|
||||||
.then(cacheObjectReferences)
|
.then(cacheObjectReferences)
|
||||||
.then(subscribeAll);
|
.then(subscribeAll);
|
||||||
|
|
||||||
@ -224,6 +225,17 @@ define(
|
|||||||
*/
|
*/
|
||||||
getMetadata: function () {
|
getMetadata: function () {
|
||||||
return metadatas;
|
return metadatas;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Get a promise for all telemetry-providing objects
|
||||||
|
* associated with this subscription.
|
||||||
|
* @returns {Promise.<DomainObject[]>} a promise for
|
||||||
|
* telemetry-providing objects
|
||||||
|
*/
|
||||||
|
promiseTelemetryObjects: function () {
|
||||||
|
// Unsubscribe promise is available after objects
|
||||||
|
// are loaded.
|
||||||
|
return telemetryObjectPromise;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user