more drafts

This commit is contained in:
Scott Bell 2024-07-30 16:44:14 +02:00
parent 6c74e84e11
commit f5d7a33915
6 changed files with 217 additions and 15 deletions

View File

@ -10,7 +10,8 @@ const config = {
serviceworker: true
},
globals: {
_: 'readonly'
_: 'readonly',
__OPENMCT_ROOT_RELATIVE__: 'readonly'
},
plugins: ['prettier', 'unicorn', 'simple-import-sort'],
extends: [

View File

View File

@ -20,12 +20,63 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/
export default class ConditionSetTelemetryProvider {
export default class CompsTelemetryProvider {
#telemetryObjects = {};
#telemetryCollections = {};
#composition = [];
#openmct = null;
#sharedWorker = null;
constructor(openmct) {
this.openmct = openmct;
this.#openmct = openmct;
this.#loadComposition();
this.#startSharedWorker();
}
async #loadComposition() {
this.#composition = this.#openmct.composition.get(this.domainObject);
if (this.#composition) {
await this.#composition.load();
// load all of our telemetry objects
this.#composition.forEach(this.#addTelemetryObject);
this.#composition.on('add', this.#addTelemetryObject);
this.#composition.on('remove', this.#removeTelemetryObject);
}
}
destroy() {
this.#composition.off('add', this.#addTelemetryObject);
this.#composition.off('remove', this.removeTelemetryObject);
}
#addTelemetryObject(telemetryObject) {
const keyString = this.#openmct.objects.makeKeyString(telemetryObject.identifier);
this.#telemetryObjects[keyString] = telemetryObject;
this.#telemetryCollections[keyString] =
this.#openmct.telemetry.requestCollection(telemetryObject);
this.#telemetryCollections[keyString].on('add', this.#telemetryProcessor);
this.#telemetryCollections[keyString].on('clear', this.#clearData);
this.#telemetryCollections[keyString].load();
}
#telemetryProcessor(telemetryObjects) {
console.debug('📡 Processing telemetry:', telemetryObjects);
}
#clearData() {
// clear data
console.debug('🆑 Clearing data');
}
#removeTelemetryObject(telemetryObject) {
const keyString = this.openmct.objects.makeKeyString(telemetryObject.identifier);
delete this.#telemetryObjects[keyString];
this.#telemetryCollections[keyString]?.destroy();
delete this.#telemetryCollections[keyString];
}
isTelemetryObject(domainObject) {
return domainObject.type === 'comps';
}
@ -40,8 +91,19 @@ export default class ConditionSetTelemetryProvider {
// eslint-disable-next-line require-await
async request(domainObject, options) {
// TODO: do some math in a worker
return { value: 0 };
// get the telemetry from the collections
const telmetryToSend = {};
Object.keys(this.#telemetryCollections).forEach((keyString) => {
telmetryToSend[keyString] = this.#telemetryCollections[keyString].getAll(
domainObject,
options
);
});
this.#sharedWorker.port.postMessage({
type: 'calculate',
data: telmetryToSend,
expression: 'a + b'
});
}
subscribe(domainObject, callback) {
@ -50,26 +112,28 @@ export default class ConditionSetTelemetryProvider {
}
#startSharedWorker() {
// eslint-disable-next-line no-undef
const sharedWorkerURL = `${this.openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}compsMathWorker.js`;
if (this.#sharedWorker) {
throw new Error('Shared worker already started');
}
const sharedWorkerURL = `${this.#openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}compsMathWorker.js`;
const sharedWorker = new SharedWorker(sharedWorkerURL, `Comps Math Worker`);
sharedWorker.port.onmessage = this.onSharedWorkerMessage.bind(this);
sharedWorker.port.onmessageerror = this.onSharedWorkerMessageError.bind(this);
sharedWorker.port.start();
this.#sharedWorker = new SharedWorker(sharedWorkerURL, `Comps Math Worker`);
this.#sharedWorker.port.onmessage = this.onSharedWorkerMessage.bind(this);
this.#sharedWorker.port.onmessageerror = this.onSharedWorkerMessageError.bind(this);
this.#sharedWorker.port.start();
// send an initial message to the worker
sharedWorker.port.postMessage({ type: 'init' });
this.#sharedWorker.port.postMessage({ type: 'init' });
// for testing, try a message adding two numbers
sharedWorker.port.postMessage({
this.#sharedWorker.port.postMessage({
type: 'calculate',
data: [{ a: 1, b: 2 }],
expression: 'a + b'
});
this.openmct.on('destroy', () => {
sharedWorker.port.close();
this.#openmct.on('destroy', () => {
this.#sharedWorker.port.close();
});
}

View File

@ -0,0 +1,96 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2024, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT 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 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.
*****************************************************************************/
import mount from 'utils/mount';
import CompsView from './components/CompsView.vue';
const DEFAULT_VIEW_PRIORITY = 100;
export default class ConditionSetViewProvider {
constructor(openmct) {
this.openmct = openmct;
this.name = 'Comps View';
this.key = 'comps.view';
this.cssClass = 'icon-telemetry';
}
canView(domainObject, objectPath) {
return domainObject.type === 'comps' && this.openmct.router.isNavigatedObject(objectPath);
}
canEdit(domainObject, objectPath) {
return domainObject.type === 'comps' && this.openmct.router.isNavigatedObject(objectPath);
}
view(domainObject, objectPath) {
let _destroy = null;
let component = null;
return {
show: (container, isEditing) => {
const { vNode, destroy } = mount(
{
el: container,
components: {
CompsView
},
provide: {
openmct: this.openmct,
domainObject,
objectPath
},
data() {
return {
isEditing
};
},
template: '<comps :isEditing="isEditing"></comps>'
},
{
app: this.openmct.app,
element: container
}
);
_destroy = destroy;
component = vNode.componentInstance;
},
onEditModeChange: (isEditing) => {
component.isEditing = isEditing;
},
destroy: () => {
if (_destroy) {
_destroy();
}
component = null;
}
};
}
priority(domainObject) {
if (domainObject.type === 'comps') {
return Number.MAX_VALUE;
} else {
return DEFAULT_VIEW_PRIORITY;
}
}
}

View File

@ -0,0 +1,39 @@
<!--
Open MCT, Copyright (c) 2014-2024, United States Government
as represented by the Administrator of the National Aeronautics and Space
Administration. All rights reserved.
Open MCT 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 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.
-->
<template>
<div class="u-contents"></div>
</template>
<script>
export default {
inject: ['openmct', 'domainObject'],
mounted() { },
beforeUnmount() {
if (this.unobserve) {
this.unobserve();
}
this.openmct.time.off('tick', this.tick);
}
};
</script>

View File

@ -20,6 +20,7 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/
import CompsTelemetryProvider from './CompsTelemetryProvider.js';
import CompsViewProvider from './CompsViewProvider.js';
export default function CompsPlugin() {
return function install(openmct) {
@ -40,5 +41,6 @@ export default function CompsPlugin() {
return openmct.telemetry.isTelemetryObject(child);
});
openmct.telemetry.addProvider(new CompsTelemetryProvider(openmct));
openmct.objectViews.addProvider(new CompsViewProvider(openmct));
};
}