Skip to content

Commit b5ee1cd

Browse files
Add files timestamp in the FMA,LST message
1 parent a5ed1ba commit b5ee1cd

2 files changed

Lines changed: 66 additions & 24 deletions

File tree

Binary file not shown.

Software/Microcontroller/Firmware/AsgardADC/AsgardADC.ino

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/* Work in progress Asgard ADC Firmware Relase 0.4.0 16/01/2018
1+
/* Work in progress Asgard ADC Firmware Relase 0.5.0 06/02/2018
22
This is a preliminary release, work in progress. Misbehaviour is plausible.
33
AsgardADC.ino - Air Data Computer Firmware
4-
Conform to ADC Common Mesage Set 0.4
4+
Conform to ADC Common Mesage Set 0.5
55
Firmware for Teensy 3.6 MCU
66
Created by JLJ and GC, BasicAirData Team www.basicairdata.eu
77
@@ -30,7 +30,7 @@
3030
--------------------------------------------------------------------------
3131
*/
3232

33-
33+
#include <Time.h>
3434
#include <TimeLib.h>
3535
#include <Metro.h>
3636
#include <AirDC.h>
@@ -41,9 +41,9 @@
4141
#include <SSC.h> // Library for SSC series sensors, support two bus I2C
4242

4343
#define ADC_NAME "ASGARD" // The name of the ADC device
44-
#define PROTOCOL_VERSION "0.4" // The version of the communication protocol
44+
#define PROTOCOL_VERSION "0.5" // The version of the communication protocol
4545

46-
#define BUFFERLENGTH 512 // The length of string buffers
46+
#define BUFFERLENGTH 2048 // The length of string buffers
4747
#define DELIMITER '\n'
4848
#define SEPARATOR ","
4949
#define LEAVE_AS_IS "="
@@ -885,34 +885,76 @@ endread:
885885
if (!strcmp(command, "LST")) { // List files on the SD
886886
strcpy (Answer, "$FMA,LST");
887887
if (!isSDCardPresent) goto endeval;
888-
dir = SD.open("/"); // open root
889888

889+
SdFile root;
890+
root.openRoot(volume);
891+
dir_t p;
892+
char* pfilename;
893+
uint8_t result;
894+
tmElements_t ts;
895+
896+
//Serial.println(micros());
890897
// Send a string with the total number of files to be sent
891898
n = 0;
892-
while (true) {
893-
File entry = dir.openNextFile();
894-
if (!entry) break;
895-
if (!entry.isDirectory()) n++;
896-
entry.close();
899+
root.rewind();
900+
result = root.readDir(&p);
901+
while (result) {
902+
if (!(p.attributes & (0X08 | 0X10))) { // if the entry is a file, not a subdir
903+
pfilename = (char*)&p.name[0];
904+
if (*pfilename != '.') n++;
905+
}
906+
result = root.readDir(&p);
897907
}
898-
dir.close();
899-
dir = SD.open("/"); // open root
900908
strcat (Answer, SEPARATOR);
901909
itoa(n, workbuff, 10); // Append number of files
902910
strcat (Answer, workbuff);
903-
while (true) {
904-
File entry2 = dir.openNextFile();
905-
if (!entry2) break;
906-
if (!entry2.isDirectory()) {
907-
strcat (Answer, SEPARATOR);
908-
strcat (Answer, entry2.name()); // Send out filename
909-
strcat (Answer, SEPARATOR);
910-
ltoa(entry2.size(), workbuff, 10);
911-
strcat (Answer, workbuff); // Send out file size
911+
//Serial.println(micros());
912+
913+
root.rewind();
914+
result = root.readDir(&p);
915+
while (result) {
916+
if (!(p.attributes & (0X08 | 0X10))) { // if the entry is a file, not a subdir
917+
pfilename = (char*)&p.name[0];
918+
if (*pfilename != '.') {
919+
strcat (Answer, SEPARATOR);
920+
char fname[14];
921+
int fi = 0;
922+
for (int i = 0; i < 8; i++) {
923+
if (pfilename[i] != ' ') {
924+
fname[fi] = pfilename[i];
925+
fi++;
926+
}
927+
}
928+
fname[fi] = '.';
929+
fi++;
930+
for (int i = 8; i < 11; i++) {
931+
if (pfilename[i] != ' ') {
932+
fname[fi] = pfilename[i];
933+
fi++;
934+
}
935+
}
936+
fname[fi] = '\0';
937+
strcat (Answer, fname);
938+
strcat (Answer, SEPARATOR);
939+
ltoa(p.fileSize, workbuff, 10);
940+
strcat (Answer, workbuff); // Send out file size
941+
strcat (Answer, SEPARATOR);
942+
943+
ts.Year = 10 + (p.creationDate >> 9); // YEAR
944+
ts.Month = (p.creationDate >> 5) & 0XF; // MONTH
945+
ts.Day = p.creationDate & 0X1F; // DAY
946+
ts.Hour = p.creationTime >> 11; // HOUR
947+
ts.Minute = (p.creationTime >> 5) & 0X3F; // MINUTE
948+
ts.Second = 2*(p.creationTime & 0X1F); // SECOND
949+
950+
ultoa(makeTime(ts), workbuff, 10);
951+
strcat (Answer, workbuff); // Send out file size
952+
//Serial.println((unsigned long)makeTime(ts));
953+
}
912954
}
913-
entry2.close();
955+
result = root.readDir(&p);
914956
}
915-
dir.close();
957+
//Serial.println(micros());
916958
goto endeval;
917959
}
918960

0 commit comments

Comments
 (0)