mirror of
https://github.com/nasa/openmct.git
synced 2025-04-08 11:54:25 +00:00
pass telemetry down to criteria. criteria listens to corresponding endpoints.
This commit is contained in:
parent
00d1b5e69f
commit
3f61db2067
@ -48,33 +48,32 @@ export default class ConditionClass extends EventEmitter {
|
||||
* @param conditionConfiguration: {id: uuid,trigger: enum, criteria: Array of {id: uuid, operation: enum, input: Array, metaDataKey: string, key: {domainObject.identifier} }
|
||||
* @param openmct
|
||||
*/
|
||||
constructor(conditionConfiguration, openmct) {
|
||||
constructor(conditionConfiguration, openmct, conditionManager) {
|
||||
super();
|
||||
|
||||
this.openmct = openmct;
|
||||
this.conditionManager = conditionManager;
|
||||
this.id = conditionConfiguration.id;
|
||||
this.criteria = [];
|
||||
this.criteriaResults = {};
|
||||
this.result = undefined;
|
||||
this.latestTimestamp = {};
|
||||
|
||||
if (conditionConfiguration.configuration.criteria) {
|
||||
this.createCriteria(conditionConfiguration.configuration.criteria);
|
||||
}
|
||||
this.trigger = conditionConfiguration.configuration.trigger;
|
||||
this.unsubscribes = this.getTelemetrySubscriptions().map(id => {
|
||||
this.on(`subscription:${id}`, this.handleReceivedTelemetry)
|
||||
});
|
||||
this.conditionManager.on('broadcastTelemetry', this.handleBroadcastTelemetry, this);
|
||||
}
|
||||
|
||||
handleReceivedTelemetry(datum) {
|
||||
handleBroadcastTelemetry(datum) {
|
||||
if (!datum || !datum.id) {
|
||||
console.log('no data received');
|
||||
return;
|
||||
}
|
||||
this.criteria.filter(criterion => criterion.telemetryObjectIdAsString === datum.id)
|
||||
.forEach(subscribingCriterion => {
|
||||
subscribingCriterion.emit(`subscription`, datum)
|
||||
});
|
||||
this.criteria.forEach(criterion => {
|
||||
criterion.emit(`subscription:${datum.id}`, datum);
|
||||
});
|
||||
}
|
||||
|
||||
update(conditionConfiguration) {
|
||||
@ -187,7 +186,7 @@ export default class ConditionClass extends EventEmitter {
|
||||
let found = this.findCriterion(criterion.id);
|
||||
if (found) {
|
||||
this.criteria[found.index] = criterion.data;
|
||||
this.subscribe();
|
||||
// this.subscribe();
|
||||
// TODO nothing is listening to this
|
||||
this.emitEvent('conditionUpdated', {
|
||||
trigger: this.trigger,
|
||||
|
@ -90,7 +90,7 @@ export default class ConditionManager extends EventEmitter {
|
||||
}
|
||||
|
||||
initCondition(conditionConfiguration, index) {
|
||||
let condition = new Condition(conditionConfiguration, this.openmct);
|
||||
let condition = new Condition(conditionConfiguration, this.openmct, this);
|
||||
condition.on('conditionResultUpdated', this.handleConditionResult.bind(this));
|
||||
if (index !== undefined) {
|
||||
this.conditionClassCollection.splice(index + 1, 0, condition);
|
||||
@ -263,14 +263,7 @@ export default class ConditionManager extends EventEmitter {
|
||||
}
|
||||
|
||||
broadcastTelemetry(id, datum) {
|
||||
this.conditionClassCollection.filter(condition => {
|
||||
return condition.getTelemetrySubscriptions().includes(id);
|
||||
}).forEach(subscribingCondition => {
|
||||
subscribingCondition.emit(
|
||||
`subscription:${id}`,
|
||||
Object.assign({}, datum, {id: id})
|
||||
);
|
||||
});
|
||||
this.emit(`broadcastTelemetry`, Object.assign({}, datum, {id: id}));
|
||||
}
|
||||
|
||||
persistConditions() {
|
||||
|
@ -40,25 +40,35 @@ export default class ConditionSetTelemetryProvider {
|
||||
}
|
||||
|
||||
request(domainObject, options) {
|
||||
let conditionManager = options.conditionManager || new ConditionManager(domainObject, this.openmct);
|
||||
let conditionManager = options.conditionManager;
|
||||
let newConditionManager = false;
|
||||
if (!conditionManager) {
|
||||
newConditionManager = true;
|
||||
conditionManager = new ConditionManager(domainObject, this.openmct);
|
||||
}
|
||||
|
||||
return conditionManager.requestLADConditionSetOutput()
|
||||
.then(latestOutput => {
|
||||
conditionManager.destroy();
|
||||
conditionManager = undefined;
|
||||
if (newConditionManager) {
|
||||
conditionManager.destroy();
|
||||
conditionManager = undefined;
|
||||
}
|
||||
return latestOutput ? [latestOutput] : [];
|
||||
});
|
||||
}
|
||||
|
||||
subscribe(domainObject, callback, options) {
|
||||
let conditionManager = options.conditionManager || new ConditionManager(domainObject, this.openmct);
|
||||
let conditionManager = options.conditionManager;
|
||||
if (!conditionManager) {
|
||||
conditionManager = new ConditionManager(domainObject, this.openmct);
|
||||
conditionManager.on('conditionSetResultUpdated', callback);
|
||||
return function unsubscribe() {
|
||||
conditionManager.off('conditionSetResultUpdated');
|
||||
conditionManager.destroy();
|
||||
conditionManager = undefined;
|
||||
};
|
||||
}
|
||||
|
||||
conditionManager.on('conditionSetResultUpdated', callback);
|
||||
|
||||
return function unsubscribe() {
|
||||
conditionManager.off('conditionSetResultUpdated');
|
||||
conditionManager.destroy();
|
||||
conditionManager = undefined;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,7 @@ export default {
|
||||
this.composition.off('add', this.addTelemetryObject);
|
||||
this.composition.off('remove', this.removeTelemetryObject);
|
||||
if(this.conditionManager) {
|
||||
this.conditionManager.off('conditionSetResultUpdated', this.handleConditionSetResultUpdated);
|
||||
this.conditionManager.destroy();
|
||||
}
|
||||
if (this.stopObservingForChanges) {
|
||||
@ -121,17 +122,12 @@ export default {
|
||||
this.conditionCollection = this.domainObject.configuration.conditionCollection;
|
||||
this.observeForChanges();
|
||||
this.conditionManager = new ConditionManager(this.domainObject, this.openmct);
|
||||
console.log(`collection condition manager: ${this.conditionManager.id}`);
|
||||
|
||||
let options = { conditionManager: this.conditionManager };
|
||||
this.openmct.telemetry.request(this.domainObject, options)
|
||||
.then(data => this.$emit('conditionSetResultUpdated', data[0]));
|
||||
this.unsubscribe = this.openmct.telemetry.subscribe(
|
||||
this.domainObject,
|
||||
(data) => { this.$emit('conditionSetResultUpdated', data); },
|
||||
options);
|
||||
this.conditionManager.on('conditionSetResultUpdated', this.handleConditionSetResultUpdated);
|
||||
},
|
||||
methods: {
|
||||
handleConditionSetResultUpdated(data) {
|
||||
this.$emit('conditionSetResultUpdated', data)
|
||||
},
|
||||
observeForChanges() {
|
||||
this.stopObservingForChanges = this.openmct.objects.observe(this.domainObject, 'configuration.conditionCollection', (newConditionCollection) => {
|
||||
this.conditionCollection = newConditionCollection;
|
||||
|
@ -46,15 +46,15 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
this.metadata = telemetryDomainObjectDefinition.metadata;
|
||||
// this.subscription = null;
|
||||
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetry);
|
||||
this.on('subscription', this.handleSubscription);
|
||||
// this.objectAPI.get(this.objectAPI.makeKeyString(this.telemetry)).then((obj) => this.initialize(obj));
|
||||
|
||||
this.on(`subscription:${this.telemetryObjectIdAsString}`, this.handleSubscription);
|
||||
this.objectAPI.get(this.telemetryObjectIdAsString).then((obj) => this.initialize(obj));
|
||||
}
|
||||
|
||||
// initialize(obj) {
|
||||
// this.telemetryObject = obj;
|
||||
// this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier);
|
||||
// this.emitEvent('criterionUpdated', this);
|
||||
// }
|
||||
initialize(obj) {
|
||||
this.telemetryObject = obj;
|
||||
this.emitEvent('criterionUpdated', this);
|
||||
}
|
||||
|
||||
formatData(data) {
|
||||
const datum = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user