Skip to content

Commit 84fbb2a

Browse files
Use a new progressive number using the ? character in the filename
1 parent 01b10a5 commit 84fbb2a

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Binary file not shown.

Software/Microcontroller/Firmware/AsgardADC/AsgardADC.ino

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,40 @@ void setup() {
136136
}
137137

138138

139+
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+
139165
void dateTime(uint16_t* date, uint16_t* time) // Callback for file timestamps
140166
{
141167
*date = FAT_DATE(year(), month(), day());
142168
*time = FAT_TIME(hour(), minute(), second());
143169
}
144170

145171

172+
146173
void SDCardCheck()
147174
{
148175
if (!isSDCardPresent) {
@@ -299,7 +326,6 @@ void acquisition()
299326

300327

301328

302-
303329
void sendtoserial(void)
304330
{
305331
char printdata[BUFFERLENGTH];
@@ -666,6 +692,7 @@ void loop() {
666692
}
667693
SDCardCheck();
668694
if (isSDCardPresent) {
695+
if (strstr(command, "?") != NULL) getNextFilename(command);
669696
if (!SD.exists(command)) { // The file doesn't exists.
670697
SdFile::dateTimeCallback(dateTime);
671698
File file = SD.open(command, FILE_WRITE); // Creates the file with the right timestamp
@@ -871,6 +898,7 @@ void loop() {
871898
{
872899
strcpy (Answer,"$FMA,NEW");
873900
if (!isSDCardPresent) goto endeval;
901+
if (strstr(param, "?") != NULL) getNextFilename(param);
874902
if (!SD.exists(param)) { // The file doesn't exists.
875903
SdFile::dateTimeCallback(dateTime);
876904
File file = SD.open(param, FILE_WRITE); // Creates the file with the right timestamp

0 commit comments

Comments
 (0)