diff options
| author | Keith Packard <keithp@keithp.com> | 2009-11-22 01:10:44 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2009-11-22 01:10:44 -0800 | 
| commit | d6ba07e885bdc62ba64719c9d8cc42fcecbcb09d (patch) | |
| tree | 61cb9db84c208b96c828e38223827bc23d25c4c4 /ao-tools/ao-view/aoview_file.c | |
| parent | 06cebd1026dc1bd6ee51526fa2d02905df3b3b37 (diff) | |
Automatically extract flight number for eeprom and telem filenames.
Extract flight number from either telemetry or eeprom files and use
that in the resulting filenames. To ensure that files remain unique,
add a new field, -seq-%03d. This is appended only when the sequence
number is non-zero as it shouldn't occur in normal usage.
This also eliminates some duplicate filename creation code in the
library and aoview sources.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/ao-view/aoview_file.c')
| -rw-r--r-- | ao-tools/ao-view/aoview_file.c | 53 | 
1 files changed, 26 insertions, 27 deletions
diff --git a/ao-tools/ao-view/aoview_file.c b/ao-tools/ao-view/aoview_file.c index 5288c2f7..292887a0 100644 --- a/ao-tools/ao-view/aoview_file.c +++ b/ao-tools/ao-view/aoview_file.c @@ -28,6 +28,7 @@ struct aoview_file {  	char	*name;  	int	failed;  	int	serial; +	int	flight;  	int	sequence;  }; @@ -94,6 +95,7 @@ gboolean  aoview_file_start(struct aoview_file *file)  {  	char		base[50]; +	char		seq[20];  	struct tm	tm;  	time_t		now;  	char		*full; @@ -105,34 +107,17 @@ aoview_file_start(struct aoview_file *file)  	if (file->failed)  		return FALSE; -	now = time(NULL); -	(void) localtime_r(&now, &tm); -	aoview_mkdir(aoview_file_dir); -	for (;;) { -		snprintf(base, sizeof (base), "%04d-%02d-%02d-serial-%03d-flight-%03d.%s", -			tm.tm_year + 1900, -			tm.tm_mon + 1, -			tm.tm_mday, -			file->serial, -			file->sequence, -			file->ext); -		full = aoview_fullname(aoview_file_dir, base); -		r = access(full, F_OK); -		if (r < 0) { -			file->file = fopen(full, "w"); -			if (!file->file) { -				aoview_file_open_failed(full); -				free(full); -				file->failed = 1; -				return FALSE; -			} else { -				setlinebuf(file->file); -				file->name = full; -				return TRUE; -			} -		} +	full = cc_make_filename(file->serial, file->flight, file->ext); +	file->file = fopen(full, "w"); +	if (!file->file) { +		aoview_file_open_failed(full);  		free(full); -		file->sequence++; +		file->failed = 1; +		return FALSE; +	} else { +		setlinebuf(file->file); +		file->name = full; +		return TRUE;  	}  } @@ -196,6 +181,20 @@ aoview_file_get_serial(struct aoview_file *file)  }  void +aoview_file_set_flight(struct aoview_file *file, int flight) +{ +	if (flight != file->flight) +		aoview_file_finish(file); +	file->flight = flight; +} + +int +aoview_file_get_flight(struct aoview_file *file) +{ +	return file->flight; +} + +void  aoview_file_init(GladeXML *xml)  {  	GConfClient	*gconf_client;  | 
