Skip to content

Commit fcd992b

Browse files
committed
Switch HTML generation function to JSON
1 parent a04efc9 commit fcd992b

File tree

2 files changed

+73
-11
lines changed

2 files changed

+73
-11
lines changed

util.c

+68-8
Original file line numberDiff line numberDiff line change
@@ -537,17 +537,20 @@ int UTIL_print_sensor_metadata(struct UTILTelemetryInfo *points,
537537
return 0;
538538
}
539539

540-
int UTIL_print_html_telem_dict(struct UTILTelemetryInfo *points,
540+
int UTIL_print_json_telem_dict(struct UTILTelemetryInfo *points,
541541
struct UTILEventInfo *events, int argc, char **argv)
542542
{
543543
int opt;
544+
int first = 1;
544545
int mode = 0;
545546
struct UTILTelemetryInfo *curr;
546547
struct StringList {
547548
const char *name;
548549
struct StringList *next;
549550
} *itr, *head = NULL;
550551
struct UTILEventInfo *eitr;
552+
struct UTILBitfieldInfo *bitr;
553+
const char *type;
551554

552555
#ifdef __APPLE__
553556
optind = 1;
@@ -574,6 +577,7 @@ int UTIL_print_html_telem_dict(struct UTILTelemetryInfo *points,
574577
if (optind < (argc))
575578
goto usage;
576579

580+
first = 1;
577581
for (curr = points; curr->id; curr++) {
578582
int ignore = 0;
579583

@@ -586,15 +590,71 @@ int UTIL_print_html_telem_dict(struct UTILTelemetryInfo *points,
586590
if (ignore)
587591
continue;
588592

589-
if (mode == 1)
590-
printf("<A HREF=\"#tlm_%s\">%s</A>\n", curr->id, curr->name);
591-
}
593+
if (mode == 1 && !curr->computed_by)
594+
type = "sensor";
595+
else if (mode == 3 && curr->computed_by)
596+
type = "virtual_sensor";
597+
else
598+
continue;
599+
600+
if (!first)
601+
printf(",\n");
602+
printf("{\n");
603+
printf(" \"type\": \"%s\",\n", type);
604+
printf(" \"key\": \"%s\",\n", curr->id);
605+
printf(" \"location\": \"%s\",\n", curr->location);
606+
printf(" \"subsystem\": \"%s\",\n", curr->group);
607+
printf(" \"units\": \"%s\",\n", curr->units);
608+
printf(" \"divisor\": %lf,\n", curr->divisor);
609+
printf(" \"offset\": %lf,\n", curr->offset);
610+
printf(" \"name\": \"%s\",\n", curr->name);
611+
if (curr->computed_by)
612+
printf(" \"function\": \"%s\",\n", curr->computed_by);
613+
614+
if (curr->bitfields) {
615+
int efirst = 1;
616+
printf(" \"enums\": [\n");
617+
for (bitr = curr->bitfields; bitr->set_label; bitr++) {
618+
if (!efirst)
619+
printf(",\n");
620+
621+
printf(" {\n");
622+
printf(" \"value\": %u,\n", bitr->value);
623+
if (bitr->clear_label)
624+
printf(" \"unset\": \"%s\",\n", bitr->clear_label);
625+
printf(" \"label\": \"%s\"\n", bitr->set_label);
626+
printf(" }");
627+
628+
efirst = 0;
629+
}
630+
printf(" ],\n");
631+
}
592632

593-
for (eitr = events; eitr->id; eitr++) {
594-
if (mode == 2)
595-
printf("<A HREF=\"#evt_%u_%u\">%s</A>\n",
596-
socket_get_addr_by_name(eitr->port_name), eitr->id, eitr->name);
633+
printf(" \"description\": \"%s\"\n", curr->desc);
634+
635+
printf("}");
636+
first = 0;
637+
}
638+
if (!first)
639+
printf("\n");
640+
641+
first = 1;
642+
for (eitr = events; mode == 2 && eitr->id; eitr++) {
643+
if (!first)
644+
printf(",\n");
645+
printf("{\n");
646+
647+
printf(" \"port_name\" : \"%s\",\n", eitr->port_name);
648+
printf(" \"port\" : %u,\n", socket_get_addr_by_name(eitr->port_name));
649+
printf(" \"id\" : =%u,\n", eitr->id);
650+
printf(" \"name\" : \"%s\",\n", eitr->name);
651+
printf(" \"description\" : \"%s\"\n", eitr->desc);
652+
653+
printf("}");
654+
first = 0;
597655
}
656+
if (!first)
657+
printf("\n");
598658

599659
return 0;
600660

util.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ struct UTILEventInfo {
9797
extern int UTIL_print_datalogger_info(struct UTILTelemetryInfo *points,
9898
const char *dl_name, const char *telem_path, int argc, char **argv);
9999

100-
/** Print the telemetry information in a format for use in
100+
/** Print the telemetry information in a format for use in the
101101
* telemetry export process
102102
**/
103103
extern int UTIL_print_sensor_metadata(struct UTILTelemetryInfo *points,
104104
struct UTILEventInfo *events);
105105

106-
/*** Print the telemetry in html format ***/
107-
extern int UTIL_print_html_telem_dict(struct UTILTelemetryInfo *points,
106+
/*** Print the telemetry in JSON format, intended for use in
107+
* auto-generated documentation and other programs.
108+
***/
109+
extern int UTIL_print_json_telem_dict(struct UTILTelemetryInfo *points,
108110
struct UTILEventInfo *events, int argc, char **argv);
109111

110112
#ifdef __cplusplus

0 commit comments

Comments
 (0)