Browse Source

wip stuff

Thomas Buck 4 months ago
parent
commit
7b74adb189
4 changed files with 42 additions and 4 deletions
  1. 1
    0
      conf/lwipopts.h
  2. 3
    1
      fs/index.html
  3. 2
    2
      include/log.h
  4. 36
    1
      src/http.c

+ 1
- 0
conf/lwipopts.h View File

@@ -79,6 +79,7 @@
79 79
 #define LWIP_HTTPD_CUSTOM_FILES 1
80 80
 #define LWIP_HTTPD_FILE_EXTENSION 1
81 81
 #define LWIP_HTTPD_DYNAMIC_HEADERS 1
82
+#define LWIP_HTTPD_FILE_EXTENSION 1
82 83
 #define HTTPD_FSDATA_FILE "httpd_fsdata.c"
83 84
 
84 85
 #endif /* __LWIPOPTS_H__ */

+ 3
- 1
fs/index.html View File

@@ -3,6 +3,8 @@
3 3
         <title>Volcano Remote</title>
4 4
     </head>
5 5
     <body>
6
-        <h1>Hello World</h1>
6
+        <h1>Volcano Remote</h1>
7
+        <p><a href="src.tar.xz">local source code archive</a></p>
8
+        <p><a href="README.md">README from USB</a></p>
7 9
     </body>
8 10
 </html>

+ 2
- 2
include/log.h View File

@@ -27,9 +27,9 @@
27 27
 // will be re-played from buffer when terminal connects
28 28
 #ifndef PICOWOTA
29 29
 #define debug(fmt, ...) debug_log(true, \
30
-        "%08lu %s: " fmt "\r\n", \
30
+        "%08lu %s:%d: " fmt "\r\n", \
31 31
         to_ms_since_boot(get_absolute_time()), \
32
-        __func__, \
32
+        __func__, __LINE__, \
33 33
         ##__VA_ARGS__)
34 34
 #else // PICOWOTA
35 35
 #define debug(fmt, ...) debug_log(true, \

+ 36
- 1
src/http.c View File

@@ -31,13 +31,47 @@
31 31
 #include "debug_disk.h"
32 32
 #include "http.h"
33 33
 
34
+static char *fs_log_write_buf = NULL;
35
+static size_t fs_log_write_count = 0;
36
+static size_t fs_log_write_len = 0;
37
+
34 38
 void http_init(void) {
35 39
     httpd_init();
36 40
 }
37 41
 
42
+static void fs_log_write(const void *b, size_t l) {
43
+    if ((fs_log_write_count + l) > fs_log_write_len) {
44
+        l = fs_log_write_len - fs_log_write_count;
45
+    }
46
+    memcpy(fs_log_write_buf + fs_log_write_count, b, l);
47
+    fs_log_write_count += l;
48
+}
49
+
38 50
 int fs_open_custom(struct fs_file *file, const char *name) {
39 51
     debug("'%s'", name);
40 52
 
53
+    if (strcmp(name, "/log.json") == 0) {
54
+        size_t log_len = rb_len(log_get());
55
+        char *log = malloc(log_len);
56
+        if (!log) {
57
+            debug("error: not enough memory %d", log_len);
58
+            return 0;
59
+        }
60
+
61
+        fs_log_write_buf = log;
62
+        fs_log_write_count = 0;
63
+        fs_log_write_len = log_len;
64
+        rb_dump(log_get(), fs_log_write, 0);
65
+
66
+        memset(file, 0, sizeof(struct fs_file));
67
+        file->pextension = "/log.json";
68
+        file->data = log;
69
+        file->len = log_len;
70
+        file->index = file->len;
71
+        file->flags = FS_FILE_FLAGS_HEADER_PERSISTENT;
72
+        return 1;
73
+    }
74
+
41 75
     // TODO only do this when not mounted via USB
42 76
     debug_disk_mount();
43 77
 
@@ -47,7 +81,7 @@ int fs_open_custom(struct fs_file *file, const char *name) {
47 81
         FSIZE_t len = f_size(&f);
48 82
         char *data = malloc(len);
49 83
         if (!data) {
50
-            debug("error: not enough memory");
84
+            debug("error: not enough memory %ld", len);
51 85
             f_close(&f);
52 86
             debug_disk_unmount();
53 87
             return 0;
@@ -60,6 +94,7 @@ int fs_open_custom(struct fs_file *file, const char *name) {
60 94
         }
61 95
 
62 96
         memset(file, 0, sizeof(struct fs_file));
97
+        file->pextension = NULL;
63 98
         file->data = data;
64 99
         file->len = len;
65 100
         file->index = file->len;

Loading…
Cancel
Save