Skip to content

Commit 01b10a5

Browse files
Closes #79 - Assign the right timestamp to the files on SD
1 parent 4999f1e commit 01b10a5

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

Software/Microcontroller/Firmware/AsgardADC/AsgardADC.ino

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ void setup() {
136136
}
137137

138138

139+
void dateTime(uint16_t* date, uint16_t* time) // Callback for file timestamps
140+
{
141+
*date = FAT_DATE(year(), month(), day());
142+
*time = FAT_TIME(hour(), minute(), second());
143+
}
144+
139145

140146
void SDCardCheck()
141147
{
@@ -649,8 +655,8 @@ void loop() {
649655
// --------------------------------------------------
650656
// #11 - LCS - LOG_CURRENTFILE_SET --> Reply LCA - LOG_CURRENTFILE_ASSERT
651657
// --------------------------------------------------
652-
// Set the current log file to the (EXISTING) log1.csv
653-
// $LCS,log1.csv
658+
// Set the current log file to the LOG.CSV
659+
// $LCS,LOG1.CSV
654660

655661
if (!strcmp(command, "$LCS"))
656662
{
@@ -660,22 +666,23 @@ void loop() {
660666
}
661667
SDCardCheck();
662668
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
669+
if (!SD.exists(command)) { // The file doesn't exists.
670+
SdFile::dateTimeCallback(dateTime);
671+
File file = SD.open(command, FILE_WRITE); // Creates the file with the right timestamp
672+
file.close();
673+
SdFile::dateTimeCallbackCancel();
678674
}
675+
dataFile.close();
676+
strcpy(AirDataComputer._logfile, command);
677+
//dataFile = SD.open(AirDataComputer._logfile, O_WRITE | O_CREAT | O_APPEND);
678+
dataFile = SD.open(AirDataComputer._logfile, FILE_WRITE);
679+
if (dataFile) { // if the file is available, write to it:
680+
AirDataComputer._status[AIRDC_STATUS_SD] = '1'; // SD Card present
681+
} else { // if the file isn't open, pop up an error:
682+
AirDataComputer._status[AIRDC_STATUS_SD] = '0'; // SD Card not present
683+
goto endeval;
684+
}
685+
AirDataComputer._status[AIRDC_STATUS_SD] = '1'; // SD Card present
679686
}
680687
strcpy (Answer,"$LCA");
681688
strcat (Answer,SEPARATOR);
@@ -864,6 +871,12 @@ void loop() {
864871
{
865872
strcpy (Answer,"$FMA,NEW");
866873
if (!isSDCardPresent) goto endeval;
874+
if (!SD.exists(param)) { // The file doesn't exists.
875+
SdFile::dateTimeCallback(dateTime);
876+
File file = SD.open(param, FILE_WRITE); // Creates the file with the right timestamp
877+
file.close();
878+
SdFile::dateTimeCallbackCancel();
879+
}
867880
dir = SD.open(param, FILE_WRITE);
868881
if (SD.exists(param))
869882
{

0 commit comments

Comments
 (0)