Skip to content

Commit dc9c044

Browse files
committed
feat(dap): Add websocket dap implementation
1 parent ef71750 commit dc9c044

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

main/websocket_server.c

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ static const char *CO_TAG = "corsacOTA";
6363
#warning corsacOTA test mode is in use
6464
#endif
6565

66+
extern void free_dap_ringbuf();
67+
extern uint32_t DAP_ExecuteCommand(const uint8_t *request, uint8_t *response);
68+
69+
static void co_websocket_process_dap(uint8_t *data, size_t len);
70+
71+
uint8_t* ws_process_buffer = NULL;
72+
6673
/**
6774
* @brief corsacOTA websocket control block
6875
*
@@ -399,7 +406,7 @@ static co_err_t co_websocket_send_echo(void *data, size_t len, int frame_type) {
399406
#endif // (CO_TEST_MODE == 1)
400407

401408
static void co_websocket_process_binary(uint8_t *data, size_t len) {
402-
// TODO:
409+
co_websocket_process_dap(data, len);
403410
}
404411

405412
static void co_websocket_process_text(uint8_t *data, size_t len) {
@@ -872,6 +879,37 @@ static esp_err_t co_websocket_handshake_process(co_cb_t *cb, co_socket_cb_t *scb
872879
return ESP_OK;
873880
}
874881

882+
static void websocket_buffer_malloc() {
883+
if (ws_process_buffer != NULL)
884+
return;
885+
886+
free_dap_ringbuf();
887+
ws_process_buffer = malloc(1200);
888+
}
889+
890+
static void websocket_buffer_free() {
891+
if (ws_process_buffer != NULL) {
892+
free(ws_process_buffer);
893+
ws_process_buffer = NULL;
894+
}
895+
}
896+
897+
static void co_websocket_process_dap(uint8_t *data, size_t len) {
898+
uint8_t *buf;
899+
int max_offset, res, offset;
900+
901+
max_offset = co_websocket_get_res_payload_offset(1500);
902+
buf = ws_process_buffer + max_offset;
903+
904+
res = DAP_ExecuteCommand(data, buf);
905+
res &= 0xFFFF;
906+
907+
offset = co_websocket_get_res_payload_offset(res);
908+
buf -= offset;
909+
910+
co_websocket_send_frame(buf, res, WS_OPCODE_BINARY);
911+
}
912+
875913
int websocket_worker(int fd, uint8_t *base, uint32_t length) {
876914
co_cb_t cb;
877915
co_socket_cb_t scb;
@@ -897,12 +935,17 @@ int websocket_worker(int fd, uint8_t *base, uint32_t length) {
897935
return ret;
898936
} while (scb.status == CO_SOCKET_HANDSHAKE);
899937

938+
websocket_buffer_malloc();
939+
900940
// websocket data process
901941
do {
902942
ret = co_websocket_process(&cb, &scb);
903943
if (ret != ESP_OK)
904-
return ret;
944+
goto out;
905945
} while (1);
906946

947+
948+
out:
949+
websocket_buffer_free();
907950
return 0;
908951
}

0 commit comments

Comments
 (0)