2022-04-09 23:18:14 +02:00
|
|
|
/*
|
|
|
|
* FIMG METADATA TOOL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
|
|
|
|
2022-04-17 04:00:12 +02:00
|
|
|
/* --------------------------------------------------------------------- */
|
2022-07-06 10:27:55 +02:00
|
|
|
int verbosity;
|
|
|
|
|
|
|
|
enum comId { C_timestamp, C_daytime, C_count, C_fval, C_cpid, C_origin,
|
2024-09-29 18:46:38 +02:00
|
|
|
C_idcam, C_reserved, C_all, C_dayhour };
|
2022-04-17 04:00:12 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *name;
|
|
|
|
int id;
|
|
|
|
} Cmd;
|
|
|
|
|
|
|
|
Cmd Cmd_list[] = {
|
|
|
|
{ "timestamp", C_timestamp },
|
2022-07-06 10:27:55 +02:00
|
|
|
{ "daytime", C_daytime },
|
2024-09-29 18:46:38 +02:00
|
|
|
{ "dayhour", C_dayhour },
|
2022-04-17 04:00:12 +02:00
|
|
|
{ "cpid", C_cpid },
|
|
|
|
{ "count", C_count },
|
|
|
|
{ "fval", C_fval },
|
|
|
|
{ "origin", C_origin },
|
2022-04-17 04:25:31 +02:00
|
|
|
{ "idcam", C_idcam },
|
2024-04-08 12:35:51 +02:00
|
|
|
{ "reserved", C_reserved },
|
2022-04-17 04:00:12 +02:00
|
|
|
{ "all", C_all },
|
|
|
|
{ NULL, 0, }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int lookup_cmd(char *txt)
|
|
|
|
{
|
|
|
|
Cmd *cmd;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, txt);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (n=0, cmd=Cmd_list; cmd->name; cmd++, n++) {
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
fprintf(stderr, " try %-12s %3d\n", cmd->name, n);
|
|
|
|
#endif
|
|
|
|
if (!strcmp(cmd->name, txt)) {
|
|
|
|
// fprintf(stderr, "found '%s' at %d\n", txt, n);
|
|
|
|
return cmd->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1; /* NOT FOUND */
|
|
|
|
}
|
2022-04-09 23:18:14 +02:00
|
|
|
/* --------------------------------------------------------------------- */
|
2023-09-11 11:09:31 +02:00
|
|
|
void list_commands(void)
|
|
|
|
{
|
|
|
|
Cmd *cmd;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
fputs("Commands:", stderr);
|
|
|
|
for (n=0, cmd=Cmd_list; cmd->name; cmd++) {
|
|
|
|
n += fprintf(stderr, " %s", cmd->name);
|
|
|
|
if (n > 40) {
|
|
|
|
fputs("\n ", stderr);
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputs("\n", stderr);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2024-04-08 12:35:51 +02:00
|
|
|
int show_reserved(FimgMetaData *pmd)
|
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
for (foo=0; foo<8; foo++) printf("%08x ", pmd->reserved[foo]);
|
|
|
|
puts("");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2022-04-09 23:18:14 +02:00
|
|
|
int get_print_metadata(char *fname, char *command)
|
|
|
|
{
|
2022-04-17 04:00:12 +02:00
|
|
|
int foo, action;
|
2022-04-09 23:18:14 +02:00
|
|
|
FimgMetaData metadata;
|
2024-09-29 18:46:38 +02:00
|
|
|
time_t tstamp;
|
2022-04-09 23:18:14 +02:00
|
|
|
|
2022-04-17 04:00:12 +02:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, fname, command);
|
|
|
|
#endif
|
2022-04-09 23:18:14 +02:00
|
|
|
|
|
|
|
foo = fimg_get_metadata_from_file(fname, &metadata);
|
|
|
|
if (foo) return foo;
|
|
|
|
|
2022-04-17 04:00:12 +02:00
|
|
|
/* switch on command here */
|
|
|
|
action = lookup_cmd(command);
|
|
|
|
// fprintf(stderr, " command '%s' -> %d\n", command, action);
|
2022-04-09 23:18:14 +02:00
|
|
|
|
2024-09-29 18:46:38 +02:00
|
|
|
tstamp = metadata.timestamp.tv_sec;
|
|
|
|
|
2022-04-17 04:00:12 +02:00
|
|
|
switch(action) {
|
|
|
|
case C_timestamp:
|
2024-09-29 18:46:38 +02:00
|
|
|
printf("timestamp %ld\n", tstamp); break;
|
2022-07-06 10:27:55 +02:00
|
|
|
case C_daytime:
|
2024-09-29 18:46:38 +02:00
|
|
|
printf("%s\n", ctime(&tstamp)); break;
|
|
|
|
case C_dayhour:
|
|
|
|
printf("%s\n", ctime(&tstamp)); break;
|
2022-04-17 04:00:12 +02:00
|
|
|
case C_count:
|
|
|
|
printf("count %d\n", metadata.count); break;
|
|
|
|
case C_fval:
|
|
|
|
printf("fval %f\n", metadata.fval); break;
|
|
|
|
case C_cpid:
|
|
|
|
printf("cpid %ld\n", metadata.cpid); break;
|
2022-04-17 04:25:31 +02:00
|
|
|
case C_origin:
|
|
|
|
printf("origin 0x%x\n", metadata.origin); break;
|
|
|
|
case C_idcam:
|
|
|
|
printf("camid \"%s\"\n", metadata.idcam); break;
|
2024-04-08 12:35:51 +02:00
|
|
|
case C_reserved:
|
|
|
|
show_reserved(&metadata); break;
|
2022-04-17 04:00:12 +02:00
|
|
|
case C_all:
|
|
|
|
fimg_show_metadata(&metadata, fname, 0); break;
|
|
|
|
default:
|
2022-07-06 10:27:55 +02:00
|
|
|
fprintf(stderr, "%s WTF?\n", __func__); exit(1);
|
2022-04-17 04:00:12 +02:00
|
|
|
}
|
2022-04-09 23:18:14 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
void help(void)
|
|
|
|
{
|
2022-04-17 04:00:12 +02:00
|
|
|
fprintf(stderr, "*** Fimg Metadata Reader (%s, %s)\n", __DATE__, __TIME__);
|
2022-04-09 23:18:14 +02:00
|
|
|
fimg_print_version(1);
|
2023-09-11 11:09:31 +02:00
|
|
|
list_commands();
|
2022-04-09 23:18:14 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int foo, opt, nbargs;
|
|
|
|
|
|
|
|
while ((opt = getopt(argc, argv, "hv")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'h': help(); break;
|
|
|
|
case 'v': verbosity++; break;
|
2023-05-29 09:06:57 +02:00
|
|
|
default: exit(1);
|
2022-04-09 23:18:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nbargs = argc - optind;
|
|
|
|
// fprintf(stderr, "nbargs = %d\n", nbargs);
|
|
|
|
if (2 != nbargs) {
|
|
|
|
fprintf(stderr, "%s need two args: command & filename\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2022-04-17 04:00:12 +02:00
|
|
|
foo = get_print_metadata(argv[optind+1], argv[optind]);
|
2022-04-09 23:18:14 +02:00
|
|
|
if (foo) fprintf(stderr, "got a %d from job\n", foo);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|