Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit6191cd2e94c8ff5e43d0c49c04b45ed7bdbdb813 (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-05-28 11:46:13 +0300
Committer
 Syndamia <kamen@syndamia.com>
2024-05-28 11:46:13 +0300
Files217acba8bfe3e8e17f2989ff925fa7e5d2cb626a
uni-projects-6191cd2e94c8ff5e43d0c49c04b45ed7bdbdb813.tar
uni-projects-6191cd2e94c8ff5e43d0c49c04b45ed7bdbdb813.tar.gz
uni-projects-6191cd2e94c8ff5e43d0c49c04b45ed7bdbdb813.zip
Parent7bd9f1df7f9636e3b63ed40c16966d1e54377a98 (diff)
[iot/goam] Exported common post request logic to a common function
diff --git a/Year 3/Internet of things/goam/main/main.h b/Year 3/Internet of things/goam/main/main.h
index 3745494..27eb2e3 100644
--- a/Year 3/Internet of things/goam/main/main.h
+++ b/Year 3/Internet of things/goam/main/main.h
@@ -1,5 +1,5 @@
#pragma once
-void main_store_saveimage(uint32_t value);
+void main_store_saveimage(int32_t value);
void main_store_resolution(int32_t value);
void main_store_invertion(int32_t value);
diff --git a/Year 3/Internet of things/goam/main/webserver.c b/Year 3/Internet of things/goam/main/webserver.c
index b2a4843..7d4f4e0 100644
--- a/Year 3/Internet of things/goam/main/webserver.c
+++ b/Year 3/Internet of things/goam/main/webserver.c
@@ -115,14 +115,21 @@ static const httpd_uri_t post_network = {
.handler = post_network_handler,
};
-static esp_err_t post_imagesave_handler(httpd_req_t *req) {
+static void main_store_request(httpd_req_t *req, void (*main_store)(int32_t)) {
char* buffer = malloc(req->content_len + 1);
httpd_req_recv(req, buffer, req->content_len);
- main_store_saveimage((int32_t)(*(strchr(buffer, '=') + 1) - '0'));
+ char* numstart = strchr(buffer, '=') + 1;
+ if (*numstart == '%') numstart++;
+ main_store((int32_t)strtol(numstart, NULL, 16));
- httpd_resp_send(req, "", 0);
free(buffer);
+}
+
+static esp_err_t post_imagesave_handler(httpd_req_t *req) {
+ main_store_request(req, main_store_saveimage);
+
+ httpd_resp_send(req, "", 0);
logi_post(req);
return ESP_OK;
@@ -134,13 +141,9 @@ static const httpd_uri_t post_imagesave = {
};
static esp_err_t post_resolution_handler(httpd_req_t *req) {
- char* buffer = malloc(req->content_len + 1);
- httpd_req_recv(req, buffer, req->content_len);
-
- main_store_resolution((int32_t)(strtol(strchr(buffer, '=') + 2, NULL, 16)));
+ main_store_request(req, main_store_resolution);
httpd_resp_send(req, "", 0);
- free(buffer);
logi_post(req);
return ESP_OK;
@@ -152,13 +155,9 @@ static const httpd_uri_t post_resolution = {
};
static esp_err_t post_invertion_handler(httpd_req_t *req) {
- char* buffer = malloc(req->content_len + 1);
- httpd_req_recv(req, buffer, req->content_len);
-
- main_store_invertion((int32_t)(strtol(strchr(buffer, '=') + 2, NULL, 16)));
+ main_store_request(req, main_store_invertion);
httpd_resp_send(req, "", 0);
- free(buffer);
logi_post(req);
return ESP_OK;
diff --git a/Year 3/Internet of things/goam/webserver/index.html b/Year 3/Internet of things/goam/webserver/index.html
index a8cdff6..2b581e8 100644
--- a/Year 3/Internet of things/goam/webserver/index.html
+++ b/Year 3/Internet of things/goam/webserver/index.html
@@ -73,8 +73,8 @@ iframe {
<form action="/imagesave" target="dummyframe" method="POST">
<select name="imagesave">
<option value="0">Only save to camera</option>
- <option value="1">Only send to <code>/camera</code> listeners</option>
- <option value="2" selected>Save and send</option>
+ <option value="&#x01;">Only send to <code>/camera</code> listeners</option>
+ <option value="&#x02;" selected>Save and send</option>
</select>
<input class="button" type="submit" value="Apply">
</form>