Compare commits

...

1 Commits

Author SHA1 Message Date
262354c8cf [Enumerations] WIP for enumerated telemetry provider 2016-03-16 19:10:58 -07:00
4 changed files with 341 additions and 2 deletions

View File

@ -0,0 +1,111 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global define*/
define([
"./src/EnumeratedTelemetryProvider",
'legacyRegistry'
], function (
EnumeratedTelemetryProvider,
legacyRegistry
) {
"use strict";
legacyRegistry.register("example/enumeratedTelemetry", {
"name": "Enumerated telemetry generator",
"description": "Example telemetry source that provides enumerated telemetry.",
"extensions": {
"components": [
{
"implementation": EnumeratedTelemetryProvider,
"type": "provider",
"provides": "telemetryService",
"depends": [
"$q",
"$interval"
]
}
],
"types": [
{
"key": "example.telemetry.enumerated",
"name": "Enumerated Telemetry Generator",
"glyph": "T",
"description": "Generated enumerated telemetry data",
"features": "creation",
"model": {
"telemetry": {
}
},
"telemetry": {
"source": "example.telemetry.enumerated",
"domains": [
{
"key": "time",
"name": "Time"
}
],
"ranges": [
{
"key": "eu",
"name": "Engineering Unit"
},
{
"key": "eu",
"name": "Enum",
"type": "enum",
"format": "enum",
"enumerations": [
{
"key": "eu",
"format": "enum",
"value": 0,
"string": "OFF"
},
{
"key": "eu",
"format": "enum",
"value": 1,
"string": "IDLE"
},
{
"key": "eu",
"format": "enum",
"value": 2,
"string": "RECEIVE"
},
{
"key": "eu",
"format": "enum",
"value": 3,
"string": "TRANSMIT"
}
]
}
]
}
}
]
}
});
});

View File

@ -0,0 +1,163 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
define(
["./EnumeratedTelemetrySeries"],
function (EnumeratedTelemetrySeries) {
"use strict";
function EnumeratedTelemetryProvider($q, $interval) {
this.$q = $q;
this.$interval = $interval;
}
EnumeratedTelemetryProvider.prototype.matchRequest = function (
request
) {
return request.source === 'example.telemetry.enumerated';
};
// Return a telemetry series between start and end time with
// 1000 telemetry points.
EnumeratedTelemetryProvider.prototype.getSeries = function (
start,
end,
request
) {
var elapsedSeconds = (end - start) / 1000,
valueEvery = elapsedSeconds / 1000,
currentSecond = 0,
values = [],
currentValue = 0;
while (currentSecond < elapsedSeconds) {
values.push({
time: +new Date(+start + (currentSecond * 1000)),
eu: currentValue
});
if ((values.length % Math.pow(3, currentValue + 1)) === 0) {
if (currentValue === 3) {
currentValue = 0;
} else {
currentValue += 1;
}
}
currentSecond += valueEvery;
}
return new EnumeratedTelemetrySeries(values);
};
EnumeratedTelemetryProvider.prototype.requestTelemetry = function (
requests
) {
var validRequests = requests.filter(this.matchRequest),
generatedTelemetry = {},
response = {
'example.telemetry.enumerated': generatedTelemetry
};
validRequests.forEach(function (validRequest) {
var start = validRequest.start,
end = validRequest.end;
if (!end) {
end = new Date(Date.now());
}
if (!start) {
start = new Date(Date.UTC(
end.getUTCFullYear(),
end.getUTCMonth(),
end.getUTCDate() - 1,
end.getUTCHours(),
end.getUTCMinutes(),
end.getUTCSeconds(),
end.getUTCMilliseconds()
));
}
generatedTelemetry[validRequest.key] =
this.getSeries(start, end);
}, this);
return this.$q.resolve(response);
};
EnumeratedTelemetryProvider.prototype.makeTelemetryEmitter = function (
request,
callback
) {
var valueEvery = 1000,
currentSecond = 0,
valuesGenerated = 0,
currentValue = 0,
interval;
interval = this.$interval(function () {
var value = {
time: +new Date(Date.now()),
eu: currentValue
},
series = new EnumeratedTelemetrySeries([value]);
valuesGenerated += 1;
if ((valuesGenerated % Math.pow(3, currentValue + 1)) === 0) {
if (currentValue === 3) {
currentValue = 0;
} else {
currentValue += 1;
}
}
callback(series);
}, valueEvery);
return function () {
this.$interval.cancel(interval);
}.bind(this);
}
EnumeratedTelemetryProvider.prototype.subscribe = function (
callback,
requests
) {
var validRequests = requests.filter(this.matchRequest),
unsubscribes = validRequests.map(function (request) {
var cb = function (series) {
var telem = {},
response = {
'example.telemetry.enumerated': telem
};
telem[request.key] = series;
callback(response);
}
return this.makeTelemetryEmitter(request, cb);
}, this)
return function () {
unsubscribes.forEach(function(unsubscribe) {
unsubscribe();
});
};
};
return EnumeratedTelemetryProvider;
}
);

View File

@ -0,0 +1,63 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
define([
], function (
) {
'use strict';
function EnumeratedTelemetrySeries(data) {
this.data = data;
}
EnumeratedTelemetrySeries.prototype.getPointCount = function (index) {
return this.data.length;
};
EnumeratedTelemetrySeries.prototype.getDatum = function (index) {
if (index > this.data.length || index < 0) {
throw new Error('IndexOutOfRange: index not available in series.');
}
return this.data[index];
};
EnumeratedTelemetrySeries.prototype.getRangeValue = function (
index,
range
) {
range = range || 'eu';
return this.getDatum(index)[range];
};
EnumeratedTelemetrySeries.prototype.getDomainValue = function (
index,
domain
) {
domain = domain || 'time';
return this.getDatum(index)[domain];
};
return EnumeratedTelemetrySeries;
});

View File

@ -93,7 +93,9 @@ define([
'./example/imagery/bundle',
'./example/eventGenerator/bundle',
'./example/generator/bundle'
'./example/generator/bundle',
'./example/enumeratedTelemetry/bundle'
], function (Main, legacyRegistry) {
'use strict';
@ -103,4 +105,4 @@ define([
return new Main().run(legacyRegistry);
}
};
});
});