|
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 |
2 | 2 | This is a preliminary release, work in progress. Misbehaviour is plausible. |
3 | 3 | AsgardADC.ino - Air Data Computer Firmware |
4 | | - Conform to ADC Common Mesage Set 0.4 |
| 4 | + Conform to ADC Common Mesage Set 0.5 |
5 | 5 | Firmware for Teensy 3.6 MCU |
6 | 6 | Created by JLJ and GC, BasicAirData Team www.basicairdata.eu |
7 | 7 |
|
|
30 | 30 | -------------------------------------------------------------------------- |
31 | 31 | */ |
32 | 32 |
|
33 | | - |
| 33 | +#include <Time.h> |
34 | 34 | #include <TimeLib.h> |
35 | 35 | #include <Metro.h> |
36 | 36 | #include <AirDC.h> |
|
41 | 41 | #include <SSC.h> // Library for SSC series sensors, support two bus I2C |
42 | 42 |
|
43 | 43 | #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 |
45 | 45 |
|
46 | | -#define BUFFERLENGTH 512 // The length of string buffers |
| 46 | +#define BUFFERLENGTH 2048 // The length of string buffers |
47 | 47 | #define DELIMITER '\n' |
48 | 48 | #define SEPARATOR "," |
49 | 49 | #define LEAVE_AS_IS "=" |
@@ -885,34 +885,76 @@ endread: |
885 | 885 | if (!strcmp(command, "LST")) { // List files on the SD |
886 | 886 | strcpy (Answer, "$FMA,LST"); |
887 | 887 | if (!isSDCardPresent) goto endeval; |
888 | | - dir = SD.open("/"); // open root |
889 | 888 |
|
| 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()); |
890 | 897 | // Send a string with the total number of files to be sent |
891 | 898 | 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); |
897 | 907 | } |
898 | | - dir.close(); |
899 | | - dir = SD.open("/"); // open root |
900 | 908 | strcat (Answer, SEPARATOR); |
901 | 909 | itoa(n, workbuff, 10); // Append number of files |
902 | 910 | 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 | + } |
912 | 954 | } |
913 | | - entry2.close(); |
| 955 | + result = root.readDir(&p); |
914 | 956 | } |
915 | | - dir.close(); |
| 957 | + //Serial.println(micros()); |
916 | 958 | goto endeval; |
917 | 959 | } |
918 | 960 |
|
|
0 commit comments