ami-iit / yarp-openmct

Repo for YARP and OpenMCT integration.
BSD 3-Clause "New" or "Revised" License
6 stars 1 forks source link

Move telemetry data type to JS/JSON configuration files #96

Closed nunoguedelha closed 2 years ago

nunoguedelha commented 2 years ago

Again, not a blocking comment but for the future could it make sense to gradually try to move this information from the .js files (that most users will not know how to modify) to the .json files (that instead act as a "configuration" file)?

_Originally posted by @traversaro in https://github.com/ami-iit/yarp-openmct/pull/94#discussion_r813662794_

nunoguedelha commented 2 years ago

Move Domain Object types description to a separate js user interface file

Example of a Domain Object Type definition in openmctStaticServer/domainObjTypes.js: https://github.com/ami-iit/yarp-openmct/blob/299bb801c4c9efb3b24fb1c6af0acbd4cbda57dc/openmctStaticServer/domainObjTypes.js#L2-L7

The Domain Object Types are identified by the respective keys, so far yarpopenmct.sensormeas and yarpopenmct.veccollectionmap. Those keys are used to map the types to the telemetry entries in the dictionaries openmctStaticServer/dictionaryIcubTelemetry.json and openmctStaticServer/dictionaryWalkingControllerTemplate.json.

Note On Javascript Enumerations

reportSchedule is of type ReportSchedule, an equivalent definition of an enumeration type in Javascript. We can use a POJO(Plain Old Javascript Object) or a class for defining an enumeration[1].

References:

This approach has some limitations:

  1. You can modify the enum after instantiation. For example, Direction.sideways = 'sideways'.
  2. If val === undefined, then val === Direction.notAnEnumValue and val === Direction.Downe. So typos in enum properties can cause issues.
  3. No guarantee that property values don't conflict. Direction.Down = 'Up' is valid.

...we can solve (1) and (3) by making the class immutable with Object.freeze()[2].

Using a class adds some overhead but is more elegant from a syntax point of view. We can use Symbol[3] primitives to set the enumeration values (class static properties).

nunoguedelha commented 2 years ago

Define new Domain Object types and improve the types mapping with the existing telemetry entries

Updated types definitions so far are: https://github.com/ami-iit/yarp-openmct/blob/556832d79679cd21c8cfd165e75eff413bd1a626/openmctStaticServer/domainObjTypes.js#L1-L32

The Domain Object Type field "icon" is a cssClass:

a string identifying a CSS class to apply to this clock when it's displayed in the UI. This will be used to represent the time system with an icon. There are a number of built-in icon classes available in Open MCT, ...