-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdictionary-plugin.js
208 lines (190 loc) · 7.61 KB
/
dictionary-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Prepare closure variables for function 'requestLatestTelemetrySample()'
let telemServerAddress = {host:'',port:''};
function getElemFromComposedKey(dictionary,telemetryEntryKey) {
let keyPath = telemetryEntryKey.split('.');
if (keyPath.shift() !== dictionary.key) {
console.error('Inconsistent dictionary key and telemetry key sub-namespace!');
}
return keyPath.reduce((parentElem,currentKey) => {
return parentElem.telemetryEntries.filter(function (m) {
return currentKey === m.key;
})[0];
},dictionary);
}
function requestLatestTelemetrySample(telemetryEntryKey) {
var url = 'http://' + telemServerAddress.host + ':' + telemServerAddress.port + '/history/' +
telemetryEntryKey +
'/latest';
return http.get(url)
.then(function (resp) {
return resp.data[0];
});
}
function requestFolderTelemetryEntryKeys(folderDomainObjectKey) {
var url = `http://${telemServerAddress.host}:${telemServerAddress.port}/wearableMetadata/${folderDomainObjectKey}/childTelemEntryKeys`;
return http.get(url)
.then(function (resp) {
return resp.data[0];
}).catch((errorMessage) => {
console.error(errorMessage);
throw new Error(errorMessage);
});
}
function requestTelemetryEntryNames(telemetryEntryKey) {
let splitComposedKey = telemetryEntryKey.split('.');
let entryKey = splitComposedKey.pop();
var url = `http://${telemServerAddress.host}:${telemServerAddress.port}/wearableMetadata/${splitComposedKey.join('.')}/${entryKey}/name`;
return http.get(url)
.then(function (resp) {
return resp.data[0];
}).catch((errorMessage) => {
console.error(errorMessage);
throw new Error(errorMessage);
});
}
function getFolderTelemetryEntryIdentifiers(dictionary,folderDomainObjectKey) {
if ((telemetryEntries = getElemFromComposedKey(dictionary, folderDomainObjectKey).telemetryEntries).length > 0) {
return Promise.resolve(telemetryEntries.map(function (entry) {
return {key: entry.key, namespace: entry.namespace};
}));
}
return requestFolderTelemetryEntryKeys(folderDomainObjectKey).then(function (keys) {
return keys.map(function (k) {
return {key: k, namespace: undefined};
});
});
}
function getDictionary(identifier) {
let subNamespace = identifier.key.split('.')[0];
if (dictionaryID2file[subNamespace] !== undefined) {
return http.get(dictionaryID2file[subNamespace])
.then(function (result) {
return result.data;
});
} else {
return Promise.reject(`Unknown sub-namespace ${subNamespace}!!`);
}
}
function generateObject(identifier,dictionary) {
var telemetryEntry = getElemFromComposedKey(dictionary,identifier.key);
return {
identifier: identifier,
name: telemetryEntry.name,
type: telemetryEntry.type,
telemetry: function () {
if (telemetryEntry.type !== 'folder') return {
values: telemetryEntry.values
};
return undefined;
}(),
location: identifier.namespace + ':' + dictionary.key
};
}
function generateObject4iFeelSuitTelemetry(identifier,parentKey,dictionary) {
return requestTelemetryEntryNames(identifier.key).then(function (telemetryName) {
return {
identifier: identifier,
name: telemetryName,
type: dictionary.telemetryEntryBase.type,
telemetry: {
values: [
...dictionary.presetValuesBase[parentKey],
dictionary.presetValuesBase.status,
dictionary.presetValuesBase.timestamp
]
},
location: identifier.namespace + ':' + dictionary.key
};
});
}
class ObjectProvider {
get(identifier) {
return getDictionary(identifier).then(function (dictionary) {
if (identifier.key === dictionary.key) {
return {
identifier: identifier,
name: dictionary.name,
type: 'folder',
location: 'ROOT'
};
}
if (identifier.key.split('.')[0] === VECTORCOLLECTIONS_DOMAIN_OBJECTS_SUBNAMESPACE) {
return requestLatestTelemetrySample(identifier.key)
.then(function (sample) {
return expandTelemetryMetadataInDict(DOMAIN_OBJECTS_TYPES, telemetryMetadataBaseDflt, dictionary, sample);
}).then(function (modifiedDictionary) {
return generateObject(identifier,modifiedDictionary);
});
}
if (dictionary.key === 'iFeelSuitTelemetry') {
let splitComposedKey = identifier.key.split('.');
splitComposedKey.pop();
if (getElemFromComposedKey(dictionary,splitComposedKey.join('.')).telemetryEntries.length == 0) {
return generateObject4iFeelSuitTelemetry(identifier,splitComposedKey.pop(),dictionary);
}
}
return generateObject(identifier,dictionary);
}.bind(this)).catch((errorMessage) => {
console.error(errorMessage);
throw new Error(errorMessage);
});
}
}
var compositionProvider = {
appliesTo: function (domainObject) {
return domainObject.identifier.namespace === YARPOPENMCT_DICTIONARY_PLUGIN_NAMESPACE
&& domainObject.type === 'folder';
},
load: function (domainObject) {
return getDictionary(domainObject.identifier).then(function (dictionary) {
return getFolderTelemetryEntryIdentifiers(dictionary,domainObject.identifier.key).then(function (ids) {
return ids.map(function (id) {
if (id.namespace !== undefined) {
return id;
}
return {
namespace: domainObject.identifier.namespace,
key: [domainObject.identifier.key,id.key].join('.')
};
});
});
});
}
};
function DictionaryPlugin(telemServerHost,telemServerPort) {
return function install(openmct) {
telemServerAddress.host = telemServerHost;
telemServerAddress.port = telemServerPort;
Object.keys(DOMAIN_OBJECTS_TYPES).forEach((type) => {
openmct.types.addType(type, Object.assign({},{
name: DOMAIN_OBJECTS_TYPES[type].name,
description: DOMAIN_OBJECTS_TYPES[type].description,
cssClass: DOMAIN_OBJECTS_TYPES[type].icon
}));
});
openmct.objects.addRoot([
{
namespace: YARPOPENMCT_DICTIONARY_PLUGIN_NAMESPACE,
key: 'icubtelemetry'
},
{
namespace: YARPOPENMCT_DICTIONARY_PLUGIN_NAMESPACE,
key: 'processLogging'
},
{
namespace: YARPOPENMCT_DICTIONARY_PLUGIN_NAMESPACE,
key: 'vectorCollectionsTelemetry'
},
{
namespace: YARPOPENMCT_DICTIONARY_PLUGIN_NAMESPACE,
key: 'iFeelSuitTelemetry'
},
{
namespace: YARPOPENMCT_DICTIONARY_PLUGIN_NAMESPACE,
key: 'mySavedPanels'
}
]);
openmct.objects.addProvider(YARPOPENMCT_DICTIONARY_PLUGIN_NAMESPACE, new ObjectProvider());
openmct.composition.addProvider(compositionProvider);
};
};