Changeset - f38d55cb0429
[Not reviewed]
default
0 3 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-19 14:55:10
ethanzonca@CL-ENS241-08.cedarville.edu
Add option to error logging to not flash the LED. This is useful for soft failures such as a slave timeout.
3 files changed with 21 insertions and 15 deletions:
0 comments (0 inline, 0 general)
master/master/lib/logger.c
Show inline comments
 
@@ -63,13 +63,13 @@ struct fat_file_struct* fd_errorlog;
 
 
void logger_setup()
 
{
 
 
	if(!sd_raw_init())
 
	{
 
		error_log(ERROR_SD_INIT);
 
		error_log(ERROR_SD_INIT, true);
 
		return;
 
	}
 
 
	// TODO: Check SD card switch to see if inserted.
 
	// this was included in the library, but is commented out right now
 
	
 
@@ -77,36 +77,36 @@ void logger_setup()
 
	partition = partition_open(sd_raw_read, sd_raw_read_interval, sd_raw_write, sd_raw_write_interval, 0);
 
	
 
	// Check that partition was created correctly
 
	if(!partition)
 
	{
 
		// Error opening partition. MBR might be screwed up.
 
		error_log(ERROR_SD_PARTITION);
 
		error_log(ERROR_SD_PARTITION, true);
 
		return;
 
	}
 
	
 
	
 
	// Open FAT filesystem
 
	fs = fat_open(partition);
 
	if(!fs)
 
	{
 
		// opening filesystem failed
 
		error_log(ERROR_SD_PARTITION);
 
		error_log(ERROR_SD_PARTITION, true);
 
		return;
 
	}
 
	
 
	// Open root directory
 
	struct fat_dir_entry_struct rootDirEntry;
 
	fat_get_dir_entry_of_path(fs, "/", &rootDirEntry);
 

	
 
	dd = fat_open_dir(fs, &rootDirEntry);
 
	if(!dd)
 
	{
 
		// opening root directory failed
 
		_delay_ms(10);
 
		error_log(ERROR_SD_FILE);
 
		error_log(ERROR_SD_FILE, true);
 
		return;
 
	}
 
	
 
		
 
	// we pre-increment logid here because it starts at 255, then wraps to 0
 
	uint8_t logid = eeprom_read_byte(LOGGER_ID_EEPROM_ADDR) + 1;
 
@@ -119,28 +119,28 @@ void logger_setup()
 
	// Form filename
 
	snprintf(errorFilename, 17, "run%derror.csv",logid);
 
	struct fat_dir_entry_struct errorDirEntry;
 
	if(fat_create_file(dd, errorFilename, &errorDirEntry) == 0)
 
	{
 
		serial0_sendString("Error create errorlog\r\n");
 
		error_log(ERROR_SD_FILE);
 
		error_log(ERROR_SD_FILE, true);
 
	}
 
	// Search for file in current directory and open it
 
	fd_errorlog = open_file_in_dir(fs, dd, errorFilename);
 
	if(!fd_errorlog)
 
	{
 
		serial0_sendString("Error open errorlog!\r\n");
 
		error_log(ERROR_SD_FILE);
 
		error_log(ERROR_SD_FILE, true);
 
		return;
 
	}
 
	errorOffset=0;
 
	if(!fat_seek_file(fd_errorlog, &errorOffset, FAT_SEEK_SET))
 
	{
 
		// Error seeking to file
 
		serial0_sendString("Error seek errorlog!\r\n");
 
		error_log(ERROR_SD_FILE);
 
		error_log(ERROR_SD_FILE, true);
 
		fat_close_file(fd_errorlog);
 
		return;
 
	}
 
	
 
		
 
	int32_t dataOffset = 0;
 
@@ -150,28 +150,28 @@ void logger_setup()
 
	snprintf(dataFilename, 17, "run%ddata.csv",logid);
 
	struct fat_dir_entry_struct dataDirEntry;
 
	// Create new data log file
 
	if(fat_create_file(dd, dataFilename, &dataDirEntry) == 0) 
 
	{
 
		serial0_sendString("Error create datalog\r\n");
 
		error_log(ERROR_SD_FILE);
 
		error_log(ERROR_SD_FILE, true);
 
	}
 
	// Search for file in current directory and open it
 
	fd_datalog = open_file_in_dir(fs, dd, dataFilename);
 
	if(!fd_datalog)
 
	{
 
		serial0_sendString("Error open datalog!\r\n");
 
		error_log(ERROR_SD_FILE);
 
		error_log(ERROR_SD_FILE, true);
 
		return;
 
	}
 
	dataOffset=0;
 
	if(!fat_seek_file(fd_datalog, &dataOffset, FAT_SEEK_SET))
 
	{
 
		// Error seeking to file
 
		serial0_sendString("Error seek datalog!\r\n");
 
		error_log(ERROR_SD_FILE);
 
		error_log(ERROR_SD_FILE, true);
 
		fat_close_file(fd_datalog);
 
		return;
 
	}
 
	
 
	
 
	// Write header information
 
@@ -189,25 +189,29 @@ void logger_log(char *buffer)
 
	{
 
		// Error writing to file
 
		return;
 
	}
 
}
 
 
void error_log(uint8_t errNo)
 
void error_log(uint8_t errNo, bool flashLED)
 
{
 
	char labelBuffer[32];
 
	labelBuffer[0] = 0x00;
 
	
 
	if(errNo <= MAX_ERRNO) 
 
	{
 
	strncpy_P(labelBuffer,(char*)pgm_read_word(&(errorMessageLookup[errNo])),32);
 
		strncpy_P(labelBuffer,(char*)pgm_read_word(&(errorMessageLookup[errNo])),32);
 
	}
 
	char errorLine[128];
 
	snprintf(errorLine, 128, "%lu, %u, %s,\r\n", time_millis(), errNo, labelBuffer);
 
	error_log_rawwrite(errorLine);
 
	led_errorcode(errNo);
 
	
 
	if(flashLED) 
 
	{
 
		led_errorcode(errNo);
 
	}	
 
}
 
 
void error_log_rawwrite(char *buffer) 
 
{
 
	uint8_t len = strlen(buffer);
 
	if(fat_write_file(fd_errorlog, (uint8_t*) buffer, len) != len)
master/master/lib/logger.h
Show inline comments
 
@@ -11,16 +11,18 @@
 
 */
 
 
 
#ifndef LOGGER_H_
 
#define LOGGER_H_
 
 
#include <stdbool.h>
 
 
void logger_setup();
 
uint8_t logger_writeLine(char* dateLine, uint8_t length);
 
struct fat_file_struct* open_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name);
 
uint8_t find_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry);
 
void error_log(uint8_t errNo);
 
void error_log(uint8_t errNo, bool flashLED);
 
void error_log_rawwrite(char *buffer);
 
void logger_log(char *buffer);
 
void logger_closeLog();
 
 
#endif /* LOGGER_H_ */
 
\ No newline at end of file
master/master/lib/slavesensors.c
Show inline comments
 
@@ -487,13 +487,13 @@ void slavesensors_process(uint8_t parseR
 
	{
 
		// Wait for data
 
		if(requesting && time_millis() - beginRequest > 1000) {
 
			// if we're requesting, we have no data, and we're over the timeout, this is bad!
 
			// setParserState(STATE_RESET); - meh, can't do this because it freaking increments the cirbufptr
 
			gotoNextSlaveOrSensor(true);
 
			error_log(ERROR_SLAVETIMEOUT);
 
			error_log(ERROR_SLAVETIMEOUT, false); // log error, don't blink LED
 
		}
 
	}
 
	
 
	// Finished reception of a message (one sensor data value). If not finished, send out command to get the next one
 
	else if(parseResult == PARSERESULT_PARSEOK)
 
	{
0 comments (0 inline, 0 general)