feat(dap): Add websocket dap implementation
(cherry picked from commit dc9c044eea3145c26ba32e200b874a89b80697a3)
This commit is contained in:
parent
d63df67c14
commit
5f98deefdf
|
@ -62,6 +62,13 @@ static const char *CO_TAG = "corsacOTA";
|
||||||
#warning corsacOTA test mode is in use
|
#warning corsacOTA test mode is in use
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern void free_dap_ringbuf();
|
||||||
|
extern uint32_t DAP_ExecuteCommand(const uint8_t *request, uint8_t *response);
|
||||||
|
|
||||||
|
static void co_websocket_process_dap(uint8_t *data, size_t len);
|
||||||
|
|
||||||
|
uint8_t* ws_process_buffer = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief corsacOTA websocket control block
|
* @brief corsacOTA websocket control block
|
||||||
*
|
*
|
||||||
|
@ -394,7 +401,7 @@ cleanup:
|
||||||
#endif // (CO_TEST_MODE == 1)
|
#endif // (CO_TEST_MODE == 1)
|
||||||
|
|
||||||
static void co_websocket_process_binary(uint8_t *data, size_t len) {
|
static void co_websocket_process_binary(uint8_t *data, size_t len) {
|
||||||
// TODO:
|
co_websocket_process_dap(data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void co_websocket_process_text(uint8_t *data, size_t len) {
|
static void co_websocket_process_text(uint8_t *data, size_t len) {
|
||||||
|
@ -867,6 +874,37 @@ static esp_err_t co_websocket_handshake_process(co_cb_t *cb, co_socket_cb_t *scb
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void websocket_buffer_malloc() {
|
||||||
|
if (ws_process_buffer != NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
free_dap_ringbuf();
|
||||||
|
ws_process_buffer = malloc(1200);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void websocket_buffer_free() {
|
||||||
|
if (ws_process_buffer != NULL) {
|
||||||
|
free(ws_process_buffer);
|
||||||
|
ws_process_buffer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void co_websocket_process_dap(uint8_t *data, size_t len) {
|
||||||
|
uint8_t *buf;
|
||||||
|
int max_offset, res, offset;
|
||||||
|
|
||||||
|
max_offset = co_websocket_get_res_payload_offset(1500);
|
||||||
|
buf = ws_process_buffer + max_offset;
|
||||||
|
|
||||||
|
res = DAP_ExecuteCommand(data, buf);
|
||||||
|
res &= 0xFFFF;
|
||||||
|
|
||||||
|
offset = co_websocket_get_res_payload_offset(res);
|
||||||
|
buf -= offset;
|
||||||
|
|
||||||
|
co_websocket_send_frame(buf, res, WS_OPCODE_BINARY);
|
||||||
|
}
|
||||||
|
|
||||||
int websocket_worker(int fd, uint8_t *base, uint32_t length) {
|
int websocket_worker(int fd, uint8_t *base, uint32_t length) {
|
||||||
co_cb_t cb;
|
co_cb_t cb;
|
||||||
co_socket_cb_t scb;
|
co_socket_cb_t scb;
|
||||||
|
@ -892,12 +930,17 @@ int websocket_worker(int fd, uint8_t *base, uint32_t length) {
|
||||||
return ret;
|
return ret;
|
||||||
} while (scb.status == CO_SOCKET_HANDSHAKE);
|
} while (scb.status == CO_SOCKET_HANDSHAKE);
|
||||||
|
|
||||||
|
websocket_buffer_malloc();
|
||||||
|
|
||||||
// websocket data process
|
// websocket data process
|
||||||
do {
|
do {
|
||||||
ret = co_websocket_process(&cb, &scb);
|
ret = co_websocket_process(&cb, &scb);
|
||||||
if (ret != ESP_OK)
|
if (ret != ESP_OK)
|
||||||
return ret;
|
goto out;
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
||||||
|
|
||||||
|
out:
|
||||||
|
websocket_buffer_free();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue