Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bugs in OpenLog.ino #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions firmware/OpenLog_Firmware/OpenLog/OpenLog.ino
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void(* Reset_AVR) (void) = 0; //Way of resetting the ATmega
#define CFG_FILENAME "config.txt\0" //This is the name of the file that contains the unit settings

#define MAX_CFG "115200,255,255,1,1,1,1,255,255\0" // This is used to calculate the longest possible configuration string. These actual values are not used
#define CFG_LENGTH (strlen(MAX_CFG) + 1) //Length of text found in config file. strlen ignores \0 so we have to add it back
#define CFG_LENGTH (strlen(MAX_CFG) + 1) //Length of text found in config file. strlen ignores \0 so we have to add it back
#define SEQ_FILENAME "SEQLOG00.TXT\0" //This is the name for the file when you're in sequential mode

//Internal EEPROM locations for the user settings
Expand Down Expand Up @@ -1175,7 +1175,7 @@ long readBaud(void)
void commandShell(void)
{
SdFile tempFile;
sd.chdir("/", true); //Change to root directory
sd.chdir(); //Change to root directory

char commandBuffer[30];
byte tempVar;
Expand Down Expand Up @@ -1233,8 +1233,18 @@ void commandShell(void)
#ifdef INCLUDE_SIMPLE_EMBEDDED
commandSucceeded = 1;
#endif

}
else if (strcmp_P(commandArg, PSTR("#")) == 0)
{
//Print the current file number
NewSerial.println(getFileNumber());

#ifdef INCLUDE_SIMPLE_EMBEDDED
commandSucceeded = 1;
#endif

}
else if (strcmp_P(commandArg, PSTR("?")) == 0)
{
//Print available commands
Expand Down Expand Up @@ -1376,6 +1386,7 @@ void commandShell(void)
uint32_t filesDeleted = 0;

char fname[13]; //Used to store the file and directory names as we step through this directory
size_t fsize = 13;

strupr(commandArg);

Expand All @@ -1384,7 +1395,7 @@ void commandShell(void)
{
if (tempFile.isFile()) // Remove only files
{
if (tempFile.getSFN(fname)) // Get the filename of the object we're looking at
if (tempFile.getSFN(fname,fsize)) // Get the filename of the object we're looking at
{
if (wildcmp(commandArg, fname)) // See if it matches the wildcard
{
Expand Down Expand Up @@ -1650,20 +1661,20 @@ void commandShell(void)
}

NewSerial.print(F("\n\rVersion: "));
NewSerial.print(cid.prv_n, DEC);
NewSerial.print(cid.prvN(), DEC);
NewSerial.print(F("."));
NewSerial.println(cid.prv_m, DEC);
NewSerial.println(cid.prvM(), DEC);

NewSerial.print(F("Serial number: "));
NewSerial.println(cid.psn);
NewSerial.println(cid.psn());

NewSerial.print(F("Manufacturing date: "));
NewSerial.print(cid.mdt_month);
NewSerial.print(cid.mdtMonth());
NewSerial.print(F("/"));
NewSerial.println(2000 + cid.mdt_year_low + (cid.mdt_year_high << 4));
NewSerial.println(cid.mdtYear()); // 2000 + cid.mdt_year_low + (cid.mdt_year_high << 4));

csd_t csd;
uint32_t cardSize = sd.card()->cardSize();
uint32_t cardSize = sd.card()->sectorCount(); // was cardSize();
if (cardSize == 0 || !sd.card()->readCSD(&csd)) {
NewSerial.println(F("readCSD failed"));
continue;
Expand Down Expand Up @@ -1888,6 +1899,20 @@ byte readLine(char* readBuffer, byte bufferLength)
return readLength;
}

unsigned int getFileNumber(void)
{
byte msb, lsb;
unsigned int newFileNumber;
//Combine two 8-bit EEPROM spots into one 16-bit number
lsb = EEPROM.read(LOCATION_FILE_NUMBER_LSB);
msb = EEPROM.read(LOCATION_FILE_NUMBER_MSB);
newFileNumber = msb;
newFileNumber = newFileNumber << 8;
newFileNumber |= lsb;

return newFileNumber;
}

void printMenu(void)
{
byte msb, lsb;
Expand Down Expand Up @@ -2335,7 +2360,7 @@ byte wildcmp(const char* wild, const char* string)
#define FILENAME_EXT_SIZE 13
#define LS_FIELD_SIZE (FILENAME_EXT_SIZE + 1)
#define SUBDIR_INDENT 2
#define DIR_SIZE (sizeof(dir_t))
#define DIR_SIZE (sizeof(DirFat_t))

/*
NAME:
Expand Down Expand Up @@ -2430,12 +2455,13 @@ byte lsPrintNext(FatFile * theDir, char * cmdStr, byte flags, byte indent)
byte status; // return status
SdFile tempFile;
char fname[FILENAME_EXT_SIZE];
size_t fsize = 13;

// Find next available object to display in the specified directory
while ((open_stat = tempFile.openNext(theDir, O_READ)))
{
// if (tempFile.getFilename(fname)) // Get the filename of the object we're looking at
if (tempFile.getSFN(fname)) // Get the filename of the object we're looking at
if (tempFile.getSFN(fname,fsize)) // Get the filename of the object we're looking at
{
if (tempFile.isDir() || tempFile.isFile() || tempFile.isSubDir())
{
Expand Down