Skip to content

Commit

Permalink
devtools: use display info
Browse files Browse the repository at this point in the history
  • Loading branch information
kobkaz committed Jan 4, 2024
1 parent 815f7f3 commit fdc6796
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
36 changes: 24 additions & 12 deletions tmtc-c2a/devtools_frontend/src/components/TelemetryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@ import { useParams } from "react-router-dom";
import { Helmet } from "react-helmet-async";
import { TelemetrySchema } from "../proto/tmtc_generic_c2a";

type DisplayInfo = {
formatString: string;
};

const buildTelemetryFieldTreeBlueprintFromSchema = (
tlm: TelemetrySchema,
): TreeNamespace<undefined> => {
const fieldNames = tlm.fields.map((f) => f.name);
const root: TreeNamespace<undefined> = new Map();
for (const fieldName of fieldNames) {
const path = fieldName.split(".");
addToNamespace(root, path, undefined);
): TreeNamespace<DisplayInfo> => {
const root: TreeNamespace<DisplayInfo> = new Map();
for (const field of tlm.fields) {
const path = field.name.split(".");
const formatString = field.metadata?.displayFormat ?? "";
addToNamespace(root, path, { formatString });
}
return root;
};

type TelemetryValuePair = {
displayInfo: DisplayInfo;
converted: TmivField["value"] | null;
raw: TmivField["value"] | null;
};

const buildTelemetryFieldTree = (
blueprint: TreeNamespace<undefined>,
blueprint: TreeNamespace<DisplayInfo>,
fields: TmivField[],
): TreeNamespace<TelemetryValuePair> => {
const convertedFieldMap = new Map<string, TmivField["value"]>();
Expand All @@ -38,15 +43,22 @@ const buildTelemetryFieldTree = (
convertedFieldMap.set(field.name, field.value);
}
}
return mapNamespace(blueprint, (path, _key) => {
return mapNamespace(blueprint, (path, displayInfo) => {
const key = path.join(".");
const converted = convertedFieldMap.get(key) ?? null;
const raw = rawFieldMap.get(key) ?? null;
return { converted, raw };
return { displayInfo, converted, raw };
});
};

const prettyprintValue = (value: TmivField["value"] | null) => {
const prettyprintValue = (
value: TmivField["value"] | null,
displayInfo: DisplayInfo,
) => {
return defaultPrettyPrint(value);
};

const defaultPrettyPrint = (value: TmivField["value"] | null) => {
if (value === null) {
return "****";
}
Expand Down Expand Up @@ -76,7 +88,7 @@ const LeafCell: React.FC<ValueCellProps> = ({ name, value }) => {
<span className="text-slate-300">{name}</span>
<span className="min-w-[2ch]" />
<span className="font-bold text-right">
{prettyprintValue(value.converted)}
{prettyprintValue(value.converted, value.displayInfo)}
</span>
</div>
);
Expand Down Expand Up @@ -149,7 +161,7 @@ const InlineNamespaceContentCell: React.FC<InlineNamespaceContentCellProps> = ({
<span className="ml-[0.5ch]" key={name}>
<span className="text-slate-300">{name}:</span>
<span className="font-bold">
{prettyprintValue(v.value.converted)}
{prettyprintValue(v.value.converted, v.value.displayInfo)}
</span>
</span>
);
Expand Down
35 changes: 30 additions & 5 deletions tmtc-c2a/devtools_frontend/src/proto/tmtc_generic_c2a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ export interface TelemetryFieldSchema {
name: string; // TODO: TelemetryFieldDataType data_type = 3;
}
/**
* TODO: string description = 1;
*
* @generated from protobuf message tmtc_generic_c2a.TelemetryFieldSchemaMetadata
*/
export interface TelemetryFieldSchemaMetadata {
/**
* TODO: string description = 1;
*
* @generated from protobuf field: string display_format = 1;
*/
displayFormat: string;
}
/**
* @generated from protobuf message tmtc_generic_c2a.TelemetryChannelSchema
Expand Down Expand Up @@ -1070,19 +1074,40 @@ export const TelemetryFieldSchema = new TelemetryFieldSchema$Type();
// @generated message type with reflection information, may provide speed optimized methods
class TelemetryFieldSchemaMetadata$Type extends MessageType<TelemetryFieldSchemaMetadata> {
constructor() {
super("tmtc_generic_c2a.TelemetryFieldSchemaMetadata", []);
super("tmtc_generic_c2a.TelemetryFieldSchemaMetadata", [
{ no: 1, name: "display_format", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
]);
}
create(value?: PartialMessage<TelemetryFieldSchemaMetadata>): TelemetryFieldSchemaMetadata {
const message = {};
const message = { displayFormat: "" };
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
if (value !== undefined)
reflectionMergePartial<TelemetryFieldSchemaMetadata>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: TelemetryFieldSchemaMetadata): TelemetryFieldSchemaMetadata {
return target ?? this.create();
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* string display_format */ 1:
message.displayFormat = reader.string();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: TelemetryFieldSchemaMetadata, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* string display_format = 1; */
if (message.displayFormat !== "")
writer.tag(1, WireType.LengthDelimited).string(message.displayFormat);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
Expand Down

0 comments on commit fdc6796

Please sign in to comment.