add some types
This commit is contained in:
parent
2e36581665
commit
0f2af76156
|
@ -68,19 +68,39 @@ if (process.env.BASE_URL) {
|
||||||
console.log("got a thing")
|
console.log("got a thing")
|
||||||
console.log(process.env.BASE_URL)
|
console.log(process.env.BASE_URL)
|
||||||
}
|
}
|
||||||
interface Board {
|
interface SkylabField {
|
||||||
name: string
|
name: string
|
||||||
type: string
|
type: string
|
||||||
units?: string
|
units?: string
|
||||||
conversion?: number
|
conversion?: number
|
||||||
|
bits?: {
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
interface SkylabPacket {
|
||||||
|
name: string
|
||||||
|
description?: string
|
||||||
|
id: number
|
||||||
|
endian?: string
|
||||||
|
is_extended: boolean
|
||||||
|
repeat?: number
|
||||||
|
offset?: number
|
||||||
|
data: [SkylabField]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Schema {
|
interface SkylabBoard {
|
||||||
|
name: string
|
||||||
|
transmit: [string]
|
||||||
|
receive: [string]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SkylabSchema {
|
||||||
|
packets: [SkylabPacket]
|
||||||
|
boards: [SkylabBoard]
|
||||||
}
|
}
|
||||||
|
|
||||||
let schemaCached = null;
|
let schemaCached = null;
|
||||||
function getSchema() {
|
function getSchema(): Promise<SkylabSchema> {
|
||||||
if (schemaCached === null) {
|
if (schemaCached === null) {
|
||||||
return fetch(`${process.env.BASE_URL}/api/v1/schema`).then((resp) => {
|
return fetch(`${process.env.BASE_URL}/api/v1/schema`).then((resp) => {
|
||||||
const res = resp.json()
|
const res = resp.json()
|
||||||
|
@ -141,7 +161,7 @@ const objectProvider = {
|
||||||
identifier: id,
|
identifier: id,
|
||||||
name: fieldName,
|
name: fieldName,
|
||||||
type: 'umnsvp-datum',
|
type: 'umnsvp-datum',
|
||||||
// annotate a special index
|
conversion: schema.packets.find((x) => x.name === pktName).data.find((f) => f.name === fieldName).conversion,
|
||||||
telemetry: {
|
telemetry: {
|
||||||
values: [
|
values: [
|
||||||
{
|
{
|
||||||
|
@ -171,6 +191,11 @@ const objectProvider = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface Datum {
|
||||||
|
ts: number
|
||||||
|
val: number
|
||||||
|
}
|
||||||
const TelemHistoryProvider = {
|
const TelemHistoryProvider = {
|
||||||
supportsRequest: function (dObj) {
|
supportsRequest: function (dObj) {
|
||||||
return dObj.type === 'umnsvp-datum'
|
return dObj.type === 'umnsvp-datum'
|
||||||
|
@ -184,16 +209,30 @@ const TelemHistoryProvider = {
|
||||||
})
|
})
|
||||||
console.log((opt.end - opt.start) / opt.size)
|
console.log((opt.end - opt.start) / opt.size)
|
||||||
return fetch(url + params).then((resp) => {
|
return fetch(url + params).then((resp) => {
|
||||||
return resp.json()
|
resp.json().then((result: [Datum]) => {
|
||||||
|
|
||||||
|
if (dObj.conversion && dObj.conversion != 0) {
|
||||||
|
// apply conversion
|
||||||
|
result.map((dat) => {
|
||||||
|
dat.val = dat.val * dObj.conversion
|
||||||
|
return dat
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PacketData {
|
||||||
|
ts: number
|
||||||
|
name: string
|
||||||
|
data: object
|
||||||
|
}
|
||||||
|
|
||||||
function TelemRealtimeProvider() {
|
function TelemRealtimeProvider() {
|
||||||
return function (openmct) {
|
return function (openmct: openmct.OpenMCT) {
|
||||||
|
|
||||||
const simpleIndicator = openmct.indicators.simpleIndicator();
|
const simpleIndicator = openmct.indicators.simpleIndicator();
|
||||||
openmct.indicators.add(simpleIndicator);
|
openmct.indicators.add(simpleIndicator);
|
||||||
|
@ -203,18 +242,21 @@ function TelemRealtimeProvider() {
|
||||||
let connection = new WebSocket(url)
|
let connection = new WebSocket(url)
|
||||||
// connections contains name: callback mapping
|
// connections contains name: callback mapping
|
||||||
const callbacks = {}
|
const callbacks = {}
|
||||||
|
|
||||||
|
const conversions: Map<string, number> = new Map()
|
||||||
// names contains a set of *packet names*
|
// names contains a set of *packet names*
|
||||||
const names = new Set()
|
const names = new Set()
|
||||||
|
|
||||||
function handleMessage(event) {
|
function handleMessage(event) {
|
||||||
const data = JSON.parse(event.data)
|
const data: PacketData = JSON.parse(event.data)
|
||||||
for (const [key, value] of Object.entries(data.data)) {
|
for (const [key, value] of Object.entries(data.data)) { // for each of the fields in the data
|
||||||
const id = `${data.name}.${key}`
|
const id = `${data.name}.${key}` // if we have a matching callback for that field.
|
||||||
if (id in callbacks) {
|
if (id in callbacks) {
|
||||||
// we should construct a telem point and make a callback.
|
// we should construct a telem point and make a callback.
|
||||||
|
// compute if we need to scale the value.
|
||||||
callbacks[id]({
|
callbacks[id]({
|
||||||
"ts": data.ts,
|
"ts": data.ts,
|
||||||
"val": value
|
"val": value * conversions.get(id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,6 +284,7 @@ function TelemRealtimeProvider() {
|
||||||
// add our callback to the dictionary,
|
// add our callback to the dictionary,
|
||||||
// add the packet name to the set
|
// add the packet name to the set
|
||||||
callbacks[key] = callback
|
callbacks[key] = callback
|
||||||
|
conversions.set(key, dObj.conversion || 1)
|
||||||
names.add(pktName)
|
names.add(pktName)
|
||||||
// update the websocket URL with the new name.
|
// update the websocket URL with the new name.
|
||||||
updateWebsocket()
|
updateWebsocket()
|
||||||
|
@ -255,6 +298,7 @@ function TelemRealtimeProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
delete callbacks[key]
|
delete callbacks[key]
|
||||||
|
conversions.delete(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,4 +329,4 @@ function GotelemPlugin() {
|
||||||
openmct.install(GotelemPlugin())
|
openmct.install(GotelemPlugin())
|
||||||
|
|
||||||
//@ts-expect-error openmct
|
//@ts-expect-error openmct
|
||||||
openmct.start();
|
openmct.start()
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
<script src="openmct/openmct.js"></script>
|
<script src="openmct/openmct.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<div id="app"></div>
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"checkJs": true,
|
"checkJs": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"moduleResolution": "Bundler",
|
// "moduleResolution": "NodeNext",
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"openmct": ["./node_modules/openmct/dist/openmct.d.ts"]
|
"openmct": ["./node_modules/openmct/dist/openmct.d.ts"]
|
||||||
|
|
Loading…
Reference in a new issue