# HG changeset patch # User ethanzonca@CL-SEC241-08.cedarville.edu # Date 2012-11-15 15:50:20 # Node ID 94648aa82312e79fb27aeb20be8db33a58f13516 # Parent 137d4566a1d4bd2fcdd0a86e7114b5edcd24c391 Cleanup of logger diff --git a/master/master/lib/logger.c b/master/master/lib/logger.c --- a/master/master/lib/logger.c +++ b/master/master/lib/logger.c @@ -5,6 +5,8 @@ * Author: mkanning */ +#include "../config.h" +#include #include #include #include @@ -16,7 +18,7 @@ #include "sd/sd_raw.h" #include "sd/sd_raw_config.h" #include "logger.h" -#include "../config.h" + /* //config edits @@ -78,7 +80,8 @@ void logger_setup() if(!dd) { // opening root directory failed - PORTA |= 0b00000101; + //PORTA |= 0b00000101; + _delay_ms(10); return; } @@ -86,27 +89,32 @@ void logger_setup() // Create new log file uint8_t logid = eeprom_read_byte(LOGGER_ID_EEPROM_ADDR); char filename[48]; + // we pre-increment logid here because it starts at 255, then wraps to 0 sprintf(filename, "data%d.csv",++logid); - // @TODO: Catch errors here + + // TODO: Catch errors here fat_create_file(dd, filename, &directory); eeprom_update_byte(LOGGER_ID_EEPROM_ADDR, logid); - - /* search file in current directory and open it */ - fd = open_file_in_dir(fs, dd, filename); //logger.h + // Search for file in current directory and open it + fd = open_file_in_dir(fs, dd, filename); if(!fd) { - PORTA |= 0b00000110; + _delay_ms(10); + //PORTA |= 0b00000110; return; } - int32_t offset = 0; //strtolong(offset_value); - if(!fat_seek_file(fd, &offset, FAT_SEEK_SET)) //seek to begin or end or what ?? + // Seek to beginning of file + // TODO: Is this needed? + int32_t offset = 0; + if(!fat_seek_file(fd, &offset, FAT_SEEK_SET)) { - //error seek to file handling - PORTA |= 0b00000111; + // Error seeking to file + //PORTA |= 0b00000111; + _delay_ms(10); fat_close_file(fd); return; } @@ -122,23 +130,16 @@ void logger_log(char *buffer) { uint8_t len = strlen(buffer); if(fat_write_file(fd, (uint8_t*) buffer, len) != len) { - //uart_puts_p(PSTR("error writing to file\n")); + // Error writing to file return; } } void logger_closeLog() { - - fat_close_file(fd); //may want to leave file open ?? - - /* close directory */ - fat_close_dir(dd); //fat.c - - /* close file system */ - fat_close(fs); //fat.c - - /* close partition */ - partition_close(partition); //partition.c + fat_close_file(fd); + fat_close_dir(dd); + fat_close(fs); + partition_close(partition); } diff --git a/master/master/lib/sd/sd_raw.c b/master/master/lib/sd/sd_raw.c --- a/master/master/lib/sd/sd_raw.c +++ b/master/master/lib/sd/sd_raw.c @@ -393,9 +393,9 @@ uint8_t sd_raw_rec_byte() /* send dummy data for receiving some */ SPDR0 = 0xff; - PORTA = 0x01; + //PORTA = 0x01; while(!(SPSR0 & (1 << SPIF0))); - PORTA = 0x02; + //PORTA = 0x02; SPSR0 &= ~(1 << SPIF0); return SPDR0; diff --git a/master/master/master.c b/master/master/master.c --- a/master/master/master.c +++ b/master/master/master.c @@ -36,12 +36,14 @@ int main(void) //micro_setup(); led_setup(); - //serial_setup(); // Config serial ports + + logger_setup(); // this takes a few ms + afsk_setup(); - logger_setup(); // this takes a few ms - - while(1) + while(afsk_busy()); + + while(1) { logger_log("123,43,1,2,4,3\n");