Browse Source

wip stuff

Thomas Buck 1 year 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
 #define LWIP_HTTPD_CUSTOM_FILES 1
79
 #define LWIP_HTTPD_CUSTOM_FILES 1
80
 #define LWIP_HTTPD_FILE_EXTENSION 1
80
 #define LWIP_HTTPD_FILE_EXTENSION 1
81
 #define LWIP_HTTPD_DYNAMIC_HEADERS 1
81
 #define LWIP_HTTPD_DYNAMIC_HEADERS 1
82
+#define LWIP_HTTPD_FILE_EXTENSION 1
82
 #define HTTPD_FSDATA_FILE "httpd_fsdata.c"
83
 #define HTTPD_FSDATA_FILE "httpd_fsdata.c"
83
 
84
 
84
 #endif /* __LWIPOPTS_H__ */
85
 #endif /* __LWIPOPTS_H__ */

+ 3
- 1
fs/index.html View File

3
         <title>Volcano Remote</title>
3
         <title>Volcano Remote</title>
4
     </head>
4
     </head>
5
     <body>
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
     </body>
9
     </body>
8
 </html>
10
 </html>

+ 2
- 2
include/log.h View File

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

+ 36
- 1
src/http.c View File

31
 #include "debug_disk.h"
31
 #include "debug_disk.h"
32
 #include "http.h"
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
 void http_init(void) {
38
 void http_init(void) {
35
     httpd_init();
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
 int fs_open_custom(struct fs_file *file, const char *name) {
50
 int fs_open_custom(struct fs_file *file, const char *name) {
39
     debug("'%s'", name);
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
     // TODO only do this when not mounted via USB
75
     // TODO only do this when not mounted via USB
42
     debug_disk_mount();
76
     debug_disk_mount();
43
 
77
 
47
         FSIZE_t len = f_size(&f);
81
         FSIZE_t len = f_size(&f);
48
         char *data = malloc(len);
82
         char *data = malloc(len);
49
         if (!data) {
83
         if (!data) {
50
-            debug("error: not enough memory");
84
+            debug("error: not enough memory %ld", len);
51
             f_close(&f);
85
             f_close(&f);
52
             debug_disk_unmount();
86
             debug_disk_unmount();
53
             return 0;
87
             return 0;
60
         }
94
         }
61
 
95
 
62
         memset(file, 0, sizeof(struct fs_file));
96
         memset(file, 0, sizeof(struct fs_file));
97
+        file->pextension = NULL;
63
         file->data = data;
98
         file->data = data;
64
         file->len = len;
99
         file->len = len;
65
         file->index = file->len;
100
         file->index = file->len;

Loading…
Cancel
Save