diff options
| author | Keith Packard <keithp@keithp.com> | 2013-03-31 16:11:27 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-03-31 16:11:27 -0700 | 
| commit | c2de64b10894b366398a8b37ebd2305d9be46d46 (patch) | |
| tree | 2660ca4afaf6872040afc7b51300374f667ca473 /src | |
| parent | 659a6915f5ba5129096e55ccc04c975d216546ae (diff) | |
altos: Create the log file if it doesn't already exist
open will return failure unless the file already exists.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/drivers/ao_log_fat.c | 25 | 
1 files changed, 18 insertions, 7 deletions
diff --git a/src/drivers/ao_log_fat.c b/src/drivers/ao_log_fat.c index 684148b7..2741555f 100644 --- a/src/drivers/ao_log_fat.c +++ b/src/drivers/ao_log_fat.c @@ -20,23 +20,34 @@  #include "ao_fat.h"  static uint8_t	log_year, log_month, log_day; -static uint8_t	log_running; +static uint8_t	log_open;  static uint8_t	log_mutex;  static void  ao_log_open(void)  {  	char	name[12]; +	int8_t	status;  	sprintf(name,"%04d%02d%02dLOG", 2000 + log_year, log_month, log_day); -	if (ao_fat_open(name, AO_FAT_OPEN_WRITE) == AO_FAT_SUCCESS) -		log_running = 1; +	status = ao_fat_open(name, AO_FAT_OPEN_WRITE); +	switch (status) { +	case AO_FAT_SUCCESS: +		ao_fat_seek(0, AO_FAT_SEEK_END); +		log_open = 1; +		break; +	case -AO_FAT_ENOENT: +		status = ao_fat_creat(name); +		if (status == AO_FAT_SUCCESS) +			log_open = 1; +		break; +	}   }  static void  ao_log_close(void)  { -	log_running = 0; +	log_open = 0;  	ao_fat_close();  } @@ -52,20 +63,20 @@ ao_log_mega(struct ao_log_mega *log)  	uint8_t	wrote = 0;  	ao_mutex_get(&log_mutex);  	if (log->type == AO_LOG_GPS_TIME) { -		if (log_running && +		if (log_open &&  		    (log_year != log->u.gps.year ||  		     log_month != log->u.gps.month ||  		     log_day != log->u.gps.day)) {  			ao_log_close();  		} -		if (!log_running) { +		if (!log_open) {  			log_year = log->u.gps.year;  			log_month = log->u.gps.month;  			log_day = log->u.gps.day;  			ao_log_open();  		}  	} -	if (log_running) { +	if (log_open) {  		wrote = ao_fat_write(log, sizeof (*log)) == AO_FAT_SUCCESS;  		ao_fat_sync();  	}  | 
