33// tinySSB for ESP32
44// Aug 2022 <christian.tschudin@unibas.ch>
55
6+ // --------------------------------------------------------------------------
7+
8+ void listDir (fs ::FS & fs , const char * dirname , uint8_t levels )
9+ {
10+ Serial .printf ("Listing directory: %s\r\n" , dirname );
11+
12+ File root = fs .open (dirname );
13+ if (!root ) {
14+ Serial .println ("- failed to open directory" );
15+ return ;
16+ }
17+ if (!root .isDirectory ()) {
18+ Serial .println (" - not a directory" );
19+ return ;
20+ }
21+
22+ File file = root .openNextFile ();
23+ int cnt = 0 ;
24+ while (file ) {
25+ cnt ++ ;
26+ if (file .isDirectory ()) {
27+ Serial .printf (" DIR : %s\r\n" , file .name ());
28+ if (levels )
29+ listDir (fs , file .path (), levels - 1 );
30+ } else
31+ Serial .printf (" FILE: %s\tSIZE: %d\r\n" , file .name (), file .size ());
32+ file = root .openNextFile ();
33+ }
34+ if (cnt == 0 )
35+ Serial .printf (" EMPTY\r\n" );
36+ }
37+
38+ // --------------------------------------------------------------------------
39+
640void cmd_rx (String cmd ) {
741 cmd .toLowerCase ();
842 cmd .trim ();
@@ -17,6 +51,7 @@ void cmd_rx(String cmd) {
1751 Serial .println (" d dump DMXT and CHKT" );
1852 Serial .println (" f list file system" );
1953 Serial .println (" g dump GOset" );
54+ Serial .println (" i pretty print the confIg values" );
2055 Serial .println (" k+<key> add new key (globally)" );
2156 Serial .println (" k-<key> remove key (globally)" );
2257#if defined(LORA_LOG )
@@ -100,14 +135,20 @@ void cmd_rx(String cmd) {
100135 case 'f' : // Directory dump
101136 Serial .printf ("File system: %d total bytes, %d used\r\n" ,
102137 MyFS .totalBytes (), MyFS .usedBytes ());
103- listDir (MyFS , FEED_DIR , 2 );
138+ listDir (MyFS , "/" , 2 ); // FEED_DIR, 2);
104139 break ;
105140 case 'g' : // GOset dump
106141 Serial .printf ("GOset: %d entries\r\n" , theGOset -> goset_len );
107142 for (int i = 0 ; i < theGOset -> goset_len ; i ++ )
108143 Serial .printf ("%2d %s\r\n" , i ,
109144 to_hex (theGOset -> get_key (i ), GOSET_KEY_LEN , 0 ));
110145 break ;
146+ case 'i' : { // config values
147+ // FIXME: we should not print the mgmt signing key to the console ?
148+ String s = bipf2String (the_config , "\r\n" , 0 );
149+ Serial .printf ("Configuration values:\r\n%s\r\n" , s .c_str ());
150+ break ;
151+ }
111152 case 'k' : { // allow/deny key
112153 if (cmd .length () != 2 * GOSET_KEY_LEN + 2 ) { Serial .printf ("invalid key length\r\n" ); break ; }
113154 if (!(cmd [1 ] == '+' or cmd [1 ] == '-' )) { Serial .printf ("invalid command: %s\r\n" , cmd [1 ]); break ; }
@@ -121,16 +162,16 @@ void cmd_rx(String cmd) {
121162#if defined(LORA_LOG )
122163 case 'l' : // list Log file
123164 lora_log .close ();
124- lora_log = MyFS .open ("/lora_log.txt" , FILE_READ );
165+ lora_log = MyFS .open (LORA_LOG_FILENAME , FILE_READ );
125166 while (lora_log .available ()) {
126167 Serial .write (lora_log .read ());
127168 }
128169 lora_log .close ();
129- lora_log = MyFS .open ("/lora_log.txt" , FILE_APPEND );
170+ lora_log = MyFS .open (LORA_LOG_FILENAME , FILE_APPEND );
130171 break ;
131172 case 'm' : // empty Log file
132173 lora_log .close ();
133- lora_log = MyFS .open ("/lora_log.txt" , FILE_WRITE );
174+ lora_log = MyFS .open (LORA_LOG_FILENAME , FILE_WRITE );
134175 break ;
135176#endif
136177 case 'r' : // reset
@@ -174,6 +215,8 @@ void cmd_rx(String cmd) {
174215 Serial .printf ("sending reboot request to %s\r\n" , to_hex (id , MGMT_ID_LEN , 0 ));
175216 mgmt_send_request ('x' , id );
176217 } else {
218+ lora_log .printf (">> reboot cmd\n" );
219+ lora_log .close ();
177220 Serial .println ("rebooting ...\n" );
178221 esp_restart ();
179222 }
0 commit comments