@@ -63,6 +63,13 @@ static const char *CO_TAG = "corsacOTA";
63
63
#warning corsacOTA test mode is in use
64
64
#endif
65
65
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
+
66
73
/**
67
74
* @brief corsacOTA websocket control block
68
75
*
@@ -399,7 +406,7 @@ static co_err_t co_websocket_send_echo(void *data, size_t len, int frame_type) {
399
406
#endif // (CO_TEST_MODE == 1)
400
407
401
408
static void co_websocket_process_binary (uint8_t * data , size_t len ) {
402
- // TODO:
409
+ co_websocket_process_dap ( data , len );
403
410
}
404
411
405
412
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
872
879
return ESP_OK ;
873
880
}
874
881
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
+
875
913
int websocket_worker (int fd , uint8_t * base , uint32_t length ) {
876
914
co_cb_t cb ;
877
915
co_socket_cb_t scb ;
@@ -897,12 +935,17 @@ int websocket_worker(int fd, uint8_t *base, uint32_t length) {
897
935
return ret ;
898
936
} while (scb .status == CO_SOCKET_HANDSHAKE );
899
937
938
+ websocket_buffer_malloc ();
939
+
900
940
// websocket data process
901
941
do {
902
942
ret = co_websocket_process (& cb , & scb );
903
943
if (ret != ESP_OK )
904
- return ret ;
944
+ goto out ;
905
945
} while (1 );
906
946
947
+
948
+ out :
949
+ websocket_buffer_free ();
907
950
return 0 ;
908
951
}
0 commit comments