Skip to content

Commit 55ed58e

Browse files
author
JLJu
committed
Merge remote-tracking branch 'refs/remotes/BasicAirData/master'
2 parents 20c154e + 84fbb2a commit 55ed58e

2 files changed

Lines changed: 59 additions & 18 deletions

File tree

Binary file not shown.

Software/Microcontroller/Firmware/AsgardADC/AsgardADC.ino

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,39 @@ void setup() {
137137

138138

139139

140+
void getNextFilename(char* namefile)
141+
{
142+
if (strlen(namefile)<13) {
143+
char namefile1[13], newname[13], number[13], nformat[5], *before, *after;
144+
int numbersize = 13 - strlen(namefile);
145+
numbersize = min (numbersize, 4);
146+
sprintf(nformat, "%%0%id", numbersize);
147+
strcpy(namefile1, namefile);
148+
before = strtok (namefile1, "?");
149+
after = strtok (NULL, "?");
150+
bool fileexists = true;
151+
for (int i = 0; i < (pow(10, numbersize)) && fileexists; i++) {
152+
sprintf(number, nformat, i);
153+
strcpy(newname, before);
154+
strcat(newname, number);
155+
strcat(newname, after);
156+
if (!SD.exists(newname)) {
157+
strcpy(namefile, newname);
158+
fileexists = false;
159+
}
160+
}
161+
}
162+
}
163+
164+
165+
void dateTime(uint16_t* date, uint16_t* time) // Callback for file timestamps
166+
{
167+
*date = FAT_DATE(year(), month(), day());
168+
*time = FAT_TIME(hour(), minute(), second());
169+
}
170+
171+
172+
140173
void SDCardCheck()
141174
{
142175
if (!isSDCardPresent) {
@@ -293,7 +326,6 @@ void acquisition()
293326

294327

295328

296-
297329
void sendtoserial(void)
298330
{
299331
char printdata[BUFFERLENGTH];
@@ -649,8 +681,8 @@ void loop() {
649681
// --------------------------------------------------
650682
// #11 - LCS - LOG_CURRENTFILE_SET --> Reply LCA - LOG_CURRENTFILE_ASSERT
651683
// --------------------------------------------------
652-
// Set the current log file to the (EXISTING) log1.csv
653-
// $LCS,log1.csv
684+
// Set the current log file to the LOG.CSV
685+
// $LCS,LOG1.CSV
654686

655687
if (!strcmp(command, "$LCS"))
656688
{
@@ -660,22 +692,24 @@ void loop() {
660692
}
661693
SDCardCheck();
662694
if (isSDCardPresent) {
663-
if (SD.exists(command)) // Only if the file exists is set as current, #13 reply
664-
{
665-
if (isSDCardPresent) {
666-
dataFile.close();
667-
strcpy(AirDataComputer._logfile, command);
668-
//dataFile = SD.open(AirDataComputer._logfile, O_WRITE | O_CREAT | O_APPEND);
669-
dataFile = SD.open(AirDataComputer._logfile, FILE_WRITE);
670-
if (dataFile) { // if the file is available, write to it:
671-
AirDataComputer._status[AIRDC_STATUS_SD] = '1'; // SD Card present
672-
} else { // if the file isn't open, pop up an error:
673-
AirDataComputer._status[AIRDC_STATUS_SD] = '0'; // SD Card not present
674-
goto endeval;
675-
}
676-
}
677-
AirDataComputer._status[AIRDC_STATUS_SD] = '1'; // SD Card present
695+
if (strstr(command, "?") != NULL) getNextFilename(command);
696+
if (!SD.exists(command)) { // The file doesn't exists.
697+
SdFile::dateTimeCallback(dateTime);
698+
File file = SD.open(command, FILE_WRITE); // Creates the file with the right timestamp
699+
file.close();
700+
SdFile::dateTimeCallbackCancel();
678701
}
702+
dataFile.close();
703+
strcpy(AirDataComputer._logfile, command);
704+
//dataFile = SD.open(AirDataComputer._logfile, O_WRITE | O_CREAT | O_APPEND);
705+
dataFile = SD.open(AirDataComputer._logfile, FILE_WRITE);
706+
if (dataFile) { // if the file is available, write to it:
707+
AirDataComputer._status[AIRDC_STATUS_SD] = '1'; // SD Card present
708+
} else { // if the file isn't open, pop up an error:
709+
AirDataComputer._status[AIRDC_STATUS_SD] = '0'; // SD Card not present
710+
goto endeval;
711+
}
712+
AirDataComputer._status[AIRDC_STATUS_SD] = '1'; // SD Card present
679713
}
680714
strcpy (Answer,"$LCA");
681715
strcat (Answer,SEPARATOR);
@@ -864,6 +898,13 @@ void loop() {
864898
{
865899
strcpy (Answer,"$FMA,NEW");
866900
if (!isSDCardPresent) goto endeval;
901+
if (strstr(param, "?") != NULL) getNextFilename(param);
902+
if (!SD.exists(param)) { // The file doesn't exists.
903+
SdFile::dateTimeCallback(dateTime);
904+
File file = SD.open(param, FILE_WRITE); // Creates the file with the right timestamp
905+
file.close();
906+
SdFile::dateTimeCallbackCancel();
907+
}
867908
dir = SD.open(param, FILE_WRITE);
868909
if (SD.exists(param))
869910
{

0 commit comments

Comments
 (0)