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"
|
|
|
|
|
|
|
|
int verbosity;
|
|
|
|
|
2022-04-17 04:00:12 +02:00
|
|
|
/* --------------------------------------------------------------------- */
|
2022-04-17 04:25:31 +02:00
|
|
|
enum comId { C_timestamp, C_count, C_fval, C_cpid, C_origin,
|
|
|
|
C_idcam, C_all };
|
2022-04-17 04:00:12 +02:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *name;
|
|
|
|
int id;
|
|
|
|
} Cmd;
|
|
|
|
|
|
|
|
Cmd Cmd_list[] = {
|
|
|
|
{ "timestamp", C_timestamp },
|
|
|
|
{ "cpid", C_cpid },
|
|
|
|
{ "count", C_count },
|
|
|
|
{ "fval", C_fval },
|
|
|
|
{ "origin", C_origin },
|
2022-04-17 04:25:31 +02:00
|
|
|
{ "idcam", C_idcam },
|
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
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2022-04-17 04:00:12 +02:00
|
|
|
switch(action) {
|
|
|
|
case C_timestamp:
|
|
|
|
printf("ts %ld\n", metadata.timestamp.tv_sec); break;
|
|
|
|
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;
|
2022-04-17 04:00:12 +02:00
|
|
|
case C_all:
|
|
|
|
fimg_show_metadata(&metadata, fname, 0); break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "WTF?\n"); exit(1);
|
|
|
|
}
|
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);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int foo, opt, nbargs;
|
|
|
|
char *fname;
|
|
|
|
|
|
|
|
while ((opt = getopt(argc, argv, "hv")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'h': help(); break;
|
|
|
|
case 'v': verbosity++; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|