From 15fb96bb02b8f50ada82946e10765aebc0f29c66 Mon Sep 17 00:00:00 2001 From: jedi Date: Mon, 19 Jul 2021 23:58:00 +0200 Subject: [PATCH 1/5] stash --- firmware/constcat.h | 65 ++++++++++++++ firmware/web.cpp | 85 ++++++++++++++++++ firmware/webdir/index.html | 171 +++++++++++++++++++++++++++++++++++++ 3 files changed, 321 insertions(+) create mode 100644 firmware/constcat.h diff --git a/firmware/constcat.h b/firmware/constcat.h new file mode 100644 index 0000000..b111512 --- /dev/null +++ b/firmware/constcat.h @@ -0,0 +1,65 @@ +// +// Created by jedi on 23.07.21. +// + +#ifdef __cplusplus + +template +using size=std::integral_constant; + +template +constexpr size length( T const(&)[N] ) { return {}; } +template +constexpr size length( std::array const& ) { return {}; } + +template +using length_t = decltype(length(std::declval())); + +constexpr size_t string_size() { return 0; } +template +constexpr size_t string_size( size_t i, Ts... ts ) { +return (i?i-1:0) + string_size(ts...); +} +template +using string_length=size< string_size( length_t{}... )>; + +template +using combined_string = std::array{}+1>; + +template +constexpr const combined_string +concat_impl( Lhs const& lhs, Rhs const& rhs, seq, seq) +{ +// the '\0' adds to symmetry: +return {{ lhs[I1]..., rhs[I2]..., '\0' }}; +} + +template +constexpr const combined_string +concat(Lhs const& lhs, Rhs const& rhs) +{ +return concat_impl( + lhs, rhs, + gen_seq{}>{}, +gen_seq{}>{} +); +} + +template +constexpr const combined_string +concat(T0 const&t0, T1 const&t1, Ts const&...ts) +{ +return concat(t0, concat(t1, ts...)); +} + +template +constexpr const combined_string +concat(T const&t) { +return concat(t, ""); +} +constexpr const combined_string<> +concat() { + return concat(""); +} + +#endif \ No newline at end of file diff --git a/firmware/web.cpp b/firmware/web.cpp index ed55e2d..b42a32a 100644 --- a/firmware/web.cpp +++ b/firmware/web.cpp @@ -204,7 +204,21 @@ void websocket_task(void *pvParameter) { } + vTaskDelayMs(250); + { + uint8_t response[3]; + uint16_t val; + val = sdk_system_adc_read(); + response[2] = (uint8_t) val; + response[1] = val >> 8; + response[0] = 'V'; + LOCK_TCPIP_CORE(); + websocket_write(pcb, response, 3, WS_BIN_MODE); + UNLOCK_TCPIP_CORE(); + } vTaskDelayMs(500); + //printf("9: %d\n",gpio_read(9)); + //printf("10: %d\n",gpio_read(10)); } syslog_detach(); @@ -247,7 +261,18 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len, bool togl = false; + int8_t en = 0; + /*uint8_t ap_disable_if_sta = 0; + uint8_t ssid_hidden = 0; + uint8_t dns_enable = 0; + uint8_t mdns_enable = 0;*/ + switch (data[0]) { + case 'V': // ADC + /* This should be done on a separate thread in 'real' applications */ + val = sdk_system_adc_read(); + cmd = 'V'; + break; case 'R': // Restart cmd = 'R'; ret = OK; @@ -292,6 +317,41 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len, } cmd = 'C'; break; + case 'S': { + if(data[1] == 'E') + en = 1; + char *ssid = &data[2]; + size_t ssid_len = strlen(ssid); + char *password = &data[3 + ssid_len]; + size_t password_len = strlen(password); + (void) password_len; + + sysparam_set_int8("wifi_sta_enable", en); + sysparam_set_string("wifi_sta_ssid", ssid); + sysparam_set_string("wifi_sta_password", password); + } + cmd = 'S'; + break; + case 'A': { + if(data[1] == 'E') + en = 1; + char *ssid = &data[2]; + size_t ssid_len = strlen(ssid); + char *password = &data[3 + ssid_len]; + size_t password_len = strlen(password); + (void) password_len; + + sysparam_set_int8("wifi_ap_enable", en); + sysparam_set_string("wifi_ap_ssid", ssid); + sysparam_set_string("wifi_ap_password", password); + + //sysparam_set_int8("wifi_ap_disable_if_sta", ap_disable_if_sta); + //sysparam_set_int8("wifi_ap_ssid_hidden", ssid_hidden); + //sysparam_set_int8("wifi_ap_dns", dns_enable); + //sysparam_set_int8("wifi_ap_mdns", mdns_enable); + } + cmd = 'A'; + break; default: printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data); printf("Unknown command %c\n", data[0]); @@ -327,11 +387,36 @@ void websocket_open_cb(struct tcp_pcb *pcb, const char *uri) { } } +/*const char *gpio_cgi_handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) { + for (int i = 0; i < iNumParams; i++) { + if(strcmp(pcParam[i], "on") == 0) { + uint8_t gpio_num = atoi(pcValue[i]); + gpio_enable(gpio_num, GPIO_OUTPUT); + gpio_write(gpio_num, true); + } else if(strcmp(pcParam[i], "off") == 0) { + uint8_t gpio_num = atoi(pcValue[i]); + gpio_enable(gpio_num, GPIO_OUTPUT); + gpio_write(gpio_num, false); + } else if(strcmp(pcParam[i], "toggle") == 0) { + uint8_t gpio_num = atoi(pcValue[i]); + gpio_enable(gpio_num, GPIO_OUTPUT); + gpio_toggle(gpio_num); + } + } + return "/index.html"; +}*/ + extern "C" void httpd_task(void *pvParameters) { (void) pvParameters; while (!uxSemaphoreGetCount(wifi_available_semaphore)) vTaskDelay(500 / portTICK_PERIOD_MS); + /*tCGI pCGIs[] = { + {"/gpio", (tCGIHandler) gpio_cgi_handler}, + }; + + // register handlers and start the server + http_set_cgi_handlers(pCGIs, sizeof(pCGIs) / sizeof(pCGIs[0]));*/ websocket_register_callbacks((tWsOpenHandler) websocket_open_cb, (tWsHandler) websocket_cb); httpd_init(); diff --git a/firmware/webdir/index.html b/firmware/webdir/index.html index 317dc10..dfad951 100644 --- a/firmware/webdir/index.html +++ b/firmware/webdir/index.html @@ -17,6 +17,8 @@ @@ -75,6 +77,125 @@ +
+

I/O

+
+
+

Protocols

+
+
+
+ + +
+
+ + +
+
+
+
+
+

Station Mode current connection

+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + +
+
+
+
+
+

Wifi Settings

+
+
+

AP Mode

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ AP IP + N/A +
+
+ AP MAC + N/A +
+
+ + +
+
+
+
+
+

Station Mode current connection

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ Sation IP + N/A +
+
+ Station MAC + N/A +
+
+ + +
+
+
+

Status

@@ -175,6 +296,16 @@

I/O

+
+
+ Channel 1-6 + SPI Dimmer +
+
+ Channel 7-127 + WS2812 via I2S +
+
+
@@ -343,6 +344,18 @@ return pos; }; + DataView.prototype.setInt8Vec = function (pos, vec) { + for (var i = 0; i < vec.length; i++) { + this.setInt8(pos++, vec[i]); + } + return pos; + }; + + function colorStringToVec(hex) { + var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : null; + } + var ws; var retries; var series = new TimeSeries(); @@ -594,13 +607,15 @@ const ssid = ap_ssid.value; const password = ap_pw.value; - const buffer = new ArrayBuffer(ssid.length + password.length + 4); + const buffer = new ArrayBuffer(ssid.length + password.length + 4 + 8); const view1 = new DataView(buffer); var tx_len = 0; view1.setChar(tx_len++, 'A'); view1.setChar(tx_len++, (en ? "E" : "D")); tx_len = view1.setString(tx_len, ssid); tx_len = view1.setString(tx_len, password); + tx_len = view1.setInt8Vec(tx_len, [192, 168, 111, 1]); + tx_len = view1.setInt8Vec(tx_len, [255, 255, 255, 0]); wsWrite(buffer); } From 03e8e9bf0deabb2ff86d5b6600cb5410d059faca Mon Sep 17 00:00:00 2001 From: jedi Date: Mon, 13 Sep 2021 00:20:08 +0200 Subject: [PATCH 3/5] stash --- firmware/webdir/404.html | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/firmware/webdir/404.html b/firmware/webdir/404.html index ebea9c6..d9b8f79 100644 --- a/firmware/webdir/404.html +++ b/firmware/webdir/404.html @@ -1,22 +1,31 @@ - + - - - - HTTP Server + + fiatlux v0.2 | Error 404 + + + - - -
-

404 - Page not found

-
Sorry, the page you are requesting was not found on this server.
-
+ +
+

Error 404 Not Found

+

+ The page you requested was not found on this system. + Go back +

+
- From b10103377d1d1c11accc9e1fefe590810143252e Mon Sep 17 00:00:00 2001 From: jedi Date: Mon, 4 Jul 2022 21:05:22 +0200 Subject: [PATCH 4/5] update ignore files --- modules/rtos | 2 +- pcb/.gitignore | 4 +++- webapp/.gitignore | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 webapp/.gitignore diff --git a/modules/rtos b/modules/rtos index a821731..b56c7c8 160000 --- a/modules/rtos +++ b/modules/rtos @@ -1 +1 @@ -Subproject commit a8217311e0d8547127b69b7c4ead62ed3aa87b79 +Subproject commit b56c7c8f8f1eb7e233af11357b1cf5d7bc873f2e diff --git a/pcb/.gitignore b/pcb/.gitignore index 5d83bb6..5efb808 100644 --- a/pcb/.gitignore +++ b/pcb/.gitignore @@ -31,6 +31,8 @@ fp-info-cache *.wrl *.step -*-bak +*-backups/ gen/ pcb.zip + +report.txt \ No newline at end of file diff --git a/webapp/.gitignore b/webapp/.gitignore new file mode 100644 index 0000000..dd60b59 --- /dev/null +++ b/webapp/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +src/gen/ +package-lock.json \ No newline at end of file From 8209a9a936a9cf655dbd9f99106cacfc6a2773e0 Mon Sep 17 00:00:00 2001 From: jedi Date: Sun, 12 Feb 2023 08:54:29 +0100 Subject: [PATCH 5/5] minify web content --- .build.yml | 8 ++++-- Makefile | 6 +++- firmware/Makefile | 6 ++-- firmware/mkwebfs.py | 68 ++++++++++++++++++++++++++++----------------- modules/rtos | 2 +- 5 files changed, 57 insertions(+), 33 deletions(-) diff --git a/.build.yml b/.build.yml index af5617d..7ece57b 100644 --- a/.build.yml +++ b/.build.yml @@ -9,17 +9,19 @@ steps: - name: submodules image: alpine/git commands: - - git submodule update --init --recursive + - git submodule update --init --recursive --depth 1 - name: firmware image: docker-repo.service.intern.lab.or.it:5000/fiatlux-build-env depends_on: [ submodules ] commands: - export PATH=$(pwd)/modules/sdk/xtensa-lx106-elf/bin:$PATH + - apt update + - apt install -y minify - make firmware -j$(nproc) - name: pcb - image: setsoft/kicad_auto + image: setsoft/kicad_auto:ki6 commands: - apt update - apt install -y make zip @@ -62,6 +64,6 @@ steps: checksum: - sha512 - md5 - title: buildtest + title: fiatlux when: event: tag diff --git a/Makefile b/Makefile index 0518768..c8f31c2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ - .PHONY: firmware flash firmware_docker case pcb all: firmware case pcb @@ -19,6 +18,11 @@ clean: +@make -C firmware clean +@make -C pcb clean +flash_docker: + sh -c "docker build -t fiatlux_firmware_env docker/firmware" + sh -c "docker run --volume "$$(pwd)"/firmware:/app/firmware --device=/dev/ttyUSB0 fiatlux_firmware_env make -C firmware flash" + + firmware_docker: sh -c "docker build -t fiatlux_firmware_env docker/firmware" sh -c "docker run --volume "$$(pwd)"/firmware:/app/firmware fiatlux_firmware_env make -C firmware html all" diff --git a/firmware/Makefile b/firmware/Makefile index 0842356..976b533 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -2,11 +2,11 @@ PROGRAM=fiatlux EXTRA_CFLAGS=-O3 -Ibuild/gen -DLWIP_NETIF_HOSTNAME=1 -EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/rboot-ota extras/mbedtls extras/httpd extras/sntp extras/cpp_support +EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/rboot-ota extras/mbedtls extras/httpd extras/sntp extras/cpp_support extras/paho_mqtt_c LIBS = hal m -FLASH_MODE = dio +FLASH_MODE = qio include ../modules/rtos/common.mk @@ -15,7 +15,7 @@ html: build/gen/fsdata.c build/gen/fsdata.c: webdir/index.html webdir/404.html webdir/css/picnic.min.css webdir/css/style.css webdir/js/smoothie_min.js @echo "Generating fsdata.." @mkdir -p $(dir $@) - @./mkwebfs.py --gzip -o $@ $^ + @./mkwebfs.py --gzip --minify -o $@ $^ test: unittest systest diff --git a/firmware/mkwebfs.py b/firmware/mkwebfs.py index 667af23..e48548c 100755 --- a/firmware/mkwebfs.py +++ b/firmware/mkwebfs.py @@ -2,6 +2,7 @@ import os import gzip import argparse +import subprocess parser = argparse.ArgumentParser() parser.add_argument('-o', '--output', help='Output file name', default='stdout') @@ -9,6 +10,9 @@ parser.add_argument('-W', '--webroot', help='Output file name', default='webdir/ parser.add_argument('--gzip', dest='gzip', action='store_true') parser.add_argument('--no-gzip', dest='gzip', action='store_false') parser.set_defaults(gzip=False) +parser.add_argument('--minify', dest='minify', action='store_true') +parser.add_argument('--no-minify', dest='minify', action='store_false') +parser.set_defaults(minify=False) parser.add_argument('--header', dest='header', action='store_true') parser.add_argument('--no-header', dest='header', action='store_false') parser.set_defaults(header=True) @@ -16,6 +20,31 @@ parser.add_argument('input', nargs='+', default=os.getcwd()) args = parser.parse_args() +def mimeFromName(name): + if name.endswith(".html") or name.endswith(".htm") or name.endswith(".shtml") or name.endswith( + ".shtm") or name.endswith(".ssi"): + return "text/html" + if name.endswith(".js"): + return "application/x-javascript" + if name.endswith(".css"): + return "text/css" + if name.endswith(".ico"): + return "image/x-icon" + if name.endswith(".gif"): + return "image/gif" + if name.endswith(".png"): + return "image/png" + if name.endswith(".jpg"): + return "image/jpeg" + if name.endswith(".bmp"): + return "image/bmp" + if name.endswith(".class"): + return "application/octet-stream" + if name.endswith(".ram"): + return "audio/x-pn-realaudio" + return "text/plain" + + def dumpBin2CHex(f, b): oStr = "\t" n = 0 @@ -41,40 +70,28 @@ for file in httpFiles: webPath = ("/" + file.removeprefix(args.webroot)).replace("//", "/") print("{} > {}".format(file, webPath)) + mimeType = mimeFromName(file) + if args.header: if ("404" in file): response = b'HTTP/1.0 404 File not found\r\n' else: response = b'HTTP/1.0 200 OK\r\n' response += b"lwIP/1.4.1 (http://savannah.nongnu.org/projects/lwip)\r\n" - fext = file.split('.')[-1] - ctype = b'Content-type: text/plain\r\n' - if (fext.endswith("html") or fext.endswith("htm") or fext.endswith("shtml") or fext.endswith( - "shtm") or fext.endswith("ssi")): - ctype = b'Content-type: text/html\r\n' - if (fext.endswith("js")): - ctype = b'Content-type: application/x-javascript\r\n' - if (fext.endswith("css")): - ctype = b'Content-type: text/css\r\n' - if (fext.endswith("ico")): - ctype = b'Content-type: image/x-icon\r\n' - if (fext.endswith("gif")): - ctype = b'Content-type: image/gif\r\n' - if (fext.endswith("png")): - ctype = b'Content-type: image/png\r\n' - if(fext.endswith("jpg")): - ctype = b'Content-type: image/jpeg\r\n' - if(fext.endswith("bmp")): - ctype = b'Content-type: image/bmp\r\n' - if(fext.endswith("class")): - ctype = b'Content-type: application/octet-stream\r\n' - if(fext.endswith("ram")): - ctype = b'Content-type: audio/x-pn-realaudio\r\n' - response += ctype + response += b'Content-type: ' + mimeType.encode() + b'\r\n' binFile = open(file, 'rb') binData = binFile.read() compEff = False + if args.minify: + p = subprocess.Popen(["minify", "--html-keep-document-tags", "--mime", mimeType], stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + minData = p.communicate(binData)[0] + if len(minData) < len(binData): + print("- Minify: {} -> {}".format(len(binData), len(minData))) + compEff = True + binData = minData + if args.gzip: compData = gzip.compress(binData, 9) if len(compData) < len(binData): @@ -103,7 +120,8 @@ for file in httpFiles: f_fsdata_c.write("};\n\n") f_fsdata_c.write("const struct fsdata_file {}[] = {{{{\n {},\n {}, {} + {}, sizeof({}) - {}, 1 }}}};\n\n" - .format(escFileFile, lastFileStruct, escFileData, escFileData, len(fnameBin), escFileData, len(fnameBin))) + .format(escFileFile, lastFileStruct, escFileData, escFileData, len(fnameBin), escFileData, + len(fnameBin))) # TODO: The last value is 1 if args.header == True lastFileStruct = escFileFile diff --git a/modules/rtos b/modules/rtos index b56c7c8..7faa16b 160000 --- a/modules/rtos +++ b/modules/rtos @@ -1 +1 @@ -Subproject commit b56c7c8f8f1eb7e233af11357b1cf5d7bc873f2e +Subproject commit 7faa16b07ce0d606f9525a316990da5b58e61314