mirror of
https://github.com/nasa/openmct.git
synced 2025-01-02 03:16:41 +00:00
subscribe to telemetry
This commit is contained in:
parent
60aecfe27e
commit
243b9cac24
@ -67,6 +67,7 @@ export default class ConditionClass extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleReceivedTelemetry(datum) {
|
handleReceivedTelemetry(datum) {
|
||||||
|
console.log(`received datum`);
|
||||||
if (!datum || !datum.id) {
|
if (!datum || !datum.id) {
|
||||||
console.log('no data received');
|
console.log('no data received');
|
||||||
return;
|
return;
|
||||||
|
@ -32,14 +32,41 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
this.timeAPI = this.openmct.time;
|
this.timeAPI = this.openmct.time;
|
||||||
this.latestTimestamp = {};
|
this.latestTimestamp = {};
|
||||||
this.composition = this.openmct.composition.get(conditionSetDomainObject);
|
this.composition = this.openmct.composition.get(conditionSetDomainObject);
|
||||||
|
this.composition.on('add', this.addTelemetry, this)
|
||||||
|
this.composition.on('remove', this.removeTelemetry, this)
|
||||||
|
|
||||||
this.loaded = this.composition.load();
|
this.loaded = this.composition.load();
|
||||||
|
this.subscriptions = {};
|
||||||
this.initialize();
|
this.initialize();
|
||||||
|
|
||||||
this.stopObservingForChanges = this.openmct.objects.observe(this.conditionSetDomainObject, '*', (newDomainObject) => {
|
this.stopObservingForChanges = this.openmct.objects.observe(this.conditionSetDomainObject, '*', (newDomainObject) => {
|
||||||
this.conditionSetDomainObject = newDomainObject;
|
this.conditionSetDomainObject = newDomainObject;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.subscribeToTelemetry();
|
addTelemetry(endpoint) {
|
||||||
|
const id = this.openmct.objects.makeKeyString(endpoint.identifier);
|
||||||
|
if (this.subscriptions[id]) {
|
||||||
|
console.log('subscription already exists');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.subscriptions[id] = this.openmct.telemetry.subscribe(
|
||||||
|
endpoint,
|
||||||
|
this.broadcastTelemetry
|
||||||
|
.bind(this, id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeTelemetry(endpointIdentifier) {
|
||||||
|
const id = this.openmct.objects.makeKeyString(endpointIdentifier);
|
||||||
|
if (!this.subscriptions[id]) {
|
||||||
|
console.log('no subscription to remove');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.subscriptions[id]();
|
||||||
|
delete this.subscriptions[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
@ -248,18 +275,20 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToTelemetry() {
|
// subscribeToTelemetry() {
|
||||||
this.load().then((endpoints) => {
|
|
||||||
this.unsubscribes = endpoints.map(endpoint => {
|
// this.load().then((endpoints) => {
|
||||||
this.openmct.telemetry.subscribe(
|
// this.unsubscribes = endpoints.map(endpoint => {
|
||||||
endpoint,
|
// this.openmct.telemetry.subscribe(
|
||||||
this.broadcastTelemetry
|
// endpoint,
|
||||||
.bind(this, this.openmct.objects.makeKeyString(endpoint.identifier)));
|
// this.broadcastTelemetry
|
||||||
});
|
// .bind(this, this.openmct.objects.makeKeyString(endpoint.identifier)));
|
||||||
});
|
// });
|
||||||
}
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
broadcastTelemetry(id, datum) {
|
broadcastTelemetry(id, datum) {
|
||||||
|
console.log(this.conditionClassCollection);
|
||||||
this.conditionClassCollection.filter(condition => {
|
this.conditionClassCollection.filter(condition => {
|
||||||
return condition.getTelemetrySubscriptions().includes(id);
|
return condition.getTelemetrySubscriptions().includes(id);
|
||||||
}).forEach(subscribingCondition => {
|
}).forEach(subscribingCondition => {
|
||||||
@ -275,6 +304,8 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
this.composition.off('add', this.addTelemetry, this)
|
||||||
|
this.composition.off('remove', this.removeTelemetry, this)
|
||||||
if(this.stopObservingForChanges) {
|
if(this.stopObservingForChanges) {
|
||||||
this.stopObservingForChanges();
|
this.stopObservingForChanges();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user