nasa / openmct-tutorial

A tutorial for OpenMCT that guides you through integrating historical and realtime telemetry.
Other
246 stars 104 forks source link

Help needed with Object Provider and Object composer. #34

Open rivermoon21 opened 5 years ago

rivermoon21 commented 5 years ago

Hello, I am trying to build and display an object that has a root folder, subsystems, and the subsystem's data point. However, when I try in the code, the subsystems appear repeatedly every time [as shown in pic]. objectproviderinfinite

Can you guys help me figure out what I need to add to my Object Provider or Composition provider? I thought it would display it by adding the 'telemetry' argument

here is my json file (similar to tutorial found online):

 {
        "name": "Spacecraft",
        "type": 'folder',
        "namespace": "public.namespace",
        "key": "sc",
        "subsystems": [
             {
                 "name": "Propulsion",
                 "key": "prop",
                 "namespace": "public.namespace",
                 "measurements": [
                     {
                         "name": "Fuel",
                         "key": "prop.fuel",
                         "units": "kilograms",
                         "type": "float",
                     },
                     {
                         "name": "Thrusters",
                         "key": "prop.thrusters",
                         "units": "None",
                         "type": "string",
                     }
                 ]
             },
             {
                 "name": "Communications",
                 "key": "comms",
                 "namespace": "public.namespace",
                 "measurements": [
                     {
                         "name": "Received",
                         "key": "comms.recd",
                         "units": "bytes",
                         "type": "integer",
                     },
                     {
                         "name": "Sent",
                         "key": "comms.sent",
                         "units": "bytes",
                         "type": "integer",
                     }
                 ]
             },
             {
                 "name": "Power",
                 "key": "pwr",
                 "namespace": "public.namespace",
                 "measurements": [
                     {
                         "name": "Generator Temperature",
                         "key": "pwr.temp",
                         "units": "\u0080C",
                         "type": "float",
                     },
                     {
                         "name": "Generator Current",
                         "key": "pwr.c",
                         "units": "A",
                         "type": "float",
                     },
                     {
                         "name": "Generator Voltage",
                         "key": "pwr.v",
                         "units": "V",
                         "type": "float",
                     }
                 ]
             }
        ]
     }

And Object Provider:

        openmct.objects.addProvider('public.namespace', {
            get: function (identifier) {
                 return objectPromise.then(function(data) {
                    if(identifier.key === 'my-root-major-key')
                    {
                       return{
                          identifier: identifier,
                          name: data.name,
                          type: data.type,
                       }
                    }
                    else {
                       var measurement = data.subsystems.filter(function (m) {
                             return m.key === identifier.key;
                       })[0];
                       // include subsystem name
                       if (!measurement.key.toString().includes('.')) {
                          return {
                             identifier: identifier,
                             name: measurement.name,
                             type: 'folder',
                             telemetry: {
                                 values: measurement.measurements,
                                 type: 'example.telemetry',
                                 key: ''
                             },
                             location: 'public.namespace:my-root-major-key:'
                          };
                       }
                    }
                 });
            }
        });

And Composition Provider:

        openmct.composition.addProvider({
            appliesTo: function (domainObject) {
               return domainObject.identifier.namespace === 'public.namespace' &&
                    domainObject.type === 'folder';
            },
            load: function (domainObject) {
                return objectPromise.then(function (data) {
                        return data.subsystems.map(function (m) {
                            return {
                                namespace: 'public.namespace',
                                key: m.key,
                            };
                        });
                    });
            }
        });