mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-03-23 23:48:07 +08:00
Merge 2 consecutive logfiles back into 1 file (e.g. server was restarted during flight)
This commit is contained in:
committed by
Felix Ruess
parent
9893a2a7e1
commit
97858cb80d
1
.gitignore
vendored
1
.gitignore
vendored
@@ -143,6 +143,7 @@
|
||||
# /sw/tools/
|
||||
/sw/tools/fp_parser.ml
|
||||
/sw/tools/wiki_gen/wiki_gen
|
||||
/sw/tools/mergelogs
|
||||
|
||||
# /sw/ground_segment/misc
|
||||
/sw/ground_segment/misc/davis2ivy
|
||||
|
||||
@@ -30,7 +30,7 @@ OCAMLNETCMA=$(shell ocamlfind query -r -a-format -predicates byte netstring)
|
||||
OCAMLLEX=ocamllex
|
||||
OCAMLYACC=ocamlyacc
|
||||
|
||||
all: gen_common.cmo gen_aircraft.out gen_airframe.out gen_messages2.out gen_messages.out gen_ubx.out gen_mtk.out gen_flight_plan.out gen_radio.out gen_periodic.out gen_settings.out gen_xsens.out gen_modules.out find_free_msg_id.out gen_srtm.out
|
||||
all: gen_common.cmo gen_aircraft.out gen_airframe.out gen_messages2.out gen_messages.out gen_ubx.out gen_mtk.out gen_flight_plan.out gen_radio.out gen_periodic.out gen_settings.out gen_xsens.out gen_modules.out find_free_msg_id.out gen_srtm.out mergelogs
|
||||
|
||||
FP_CMO = fp_proc.cmo gen_flight_plan.cmo
|
||||
ABS_FP = $(FP_CMO:%=$$PAPARAZZI_SRC/sw/tools/%)
|
||||
@@ -44,6 +44,9 @@ gen_flight_plan.cmo : fp_proc.cmi
|
||||
|
||||
gen_common.cmo : gen_common.cmi
|
||||
|
||||
mergelogs: mergelogs.c
|
||||
gcc mergelogs.c -o mergelogs
|
||||
|
||||
%.out : %.ml gen_common.ml Makefile
|
||||
@echo OC $<
|
||||
$(Q)$(OCAMLC) $(INCLUDES) -o $@ unix.cma str.cma ivy-ocaml.cma xml-light.cma lib-pprz.cma gen_common.cmo $<
|
||||
@@ -72,4 +75,4 @@ gen_common.cmo : gen_common.cmi
|
||||
$(Q)$(OCAMLYACC) $<
|
||||
|
||||
clean:
|
||||
rm -f *.cm* *.out *~ fp_parser.ml fp_parser.mli
|
||||
rm -f *.cm* *.out *~ fp_parser.ml fp_parser.mli mergelogs
|
||||
|
||||
89
sw/tools/mergelogs.c
Normal file
89
sw/tools/mergelogs.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
char buf[200];
|
||||
|
||||
float get_time(char* str)
|
||||
{
|
||||
float time = 0.0f;
|
||||
sscanf(str,"%f", &time);
|
||||
return time;
|
||||
}
|
||||
|
||||
void add_time(char* str, float offset, FILE* fp)
|
||||
{
|
||||
float time = 0.0f;
|
||||
char* c = strchr(str, ' ');
|
||||
if (c == 0)
|
||||
return;
|
||||
|
||||
sscanf(str,"%f", &time);
|
||||
fprintf(fp, "%.3f%s", time+offset, c);
|
||||
}
|
||||
|
||||
int merge(char* fn1, char* fn2)
|
||||
{
|
||||
FILE* f1 = fopen(fn1,"r+w");
|
||||
FILE* f2 = fopen(fn2,"r");
|
||||
int res = 0;
|
||||
char str[200];
|
||||
float offset = 0.0f;
|
||||
int firstline = 1;
|
||||
|
||||
if ((f1 > 0) && (f2 > 0))
|
||||
{
|
||||
//
|
||||
printf("Searching End Time in File '%s'\n",fn1);
|
||||
|
||||
while(fgets(str,sizeof(str),f1) != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
printf("Last Line:\n%s\n",str);
|
||||
offset = get_time(str);
|
||||
printf("Last Time Stamp: %f\n", offset);
|
||||
|
||||
while(fgets(str,sizeof(str),f2) != NULL)
|
||||
{
|
||||
// Find initial time
|
||||
//if (firstline)
|
||||
//{
|
||||
// firstline = 0;
|
||||
// offset -= get_time(str);
|
||||
//}
|
||||
|
||||
// Change Time and add to first file:
|
||||
add_time(str, offset, f1);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"Failed to open file\n");
|
||||
res = -1;
|
||||
}
|
||||
|
||||
if (f1 > 0)
|
||||
fclose(f1);
|
||||
if (f2 > 0)
|
||||
fclose(f2);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
fprintf(stderr, "Program needs 2 logfile names to merge\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Merging '%s' and '%s'\n",argv[1], argv[2]);
|
||||
|
||||
return merge(argv[1],argv[2]);
|
||||
}
|
||||
Reference in New Issue
Block a user