update LwFTP print received data

This commit is contained in:
SeungJu Lim 2024-02-21 18:08:18 +09:00
parent 396912b4c8
commit 531862a0f9
2 changed files with 31 additions and 4 deletions

View File

@ -116,7 +116,8 @@ err_t lwftp_list(lwftp_session_t *s) {
void onDataReceived(void *data, size_t size) { void onDataReceived(void *data, size_t size) {
osDelay(1000); osDelay(1000);
printf("%s\r\n", (char*) data); // printf("%s\r\n", (char*) data);
printf("Received data (%zu bytes): %.*s\n", size, (int)size, (char*)data);
} }
//void lwftp_data_thread(void *arg) { //void lwftp_data_thread(void *arg) {
@ -144,6 +145,8 @@ void onDataReceived(void *data, size_t size) {
void lwftp_data_thread(void *arg) { void lwftp_data_thread(void *arg) {
lwftp_session_t *s = (lwftp_session_t*) arg; lwftp_session_t *s = (lwftp_session_t*) arg;
static struct netbuf *d_buf; static struct netbuf *d_buf;
static char *aggregated_data = NULL;
static size_t total_len = 0;
while (1) { while (1) {
if (s->data_conn != NULL && s->data_state == LWFTP_CONNECTED) { if (s->data_conn != NULL && s->data_state == LWFTP_CONNECTED) {
@ -153,9 +156,33 @@ void lwftp_data_thread(void *arg) {
u16_t len; u16_t len;
do { do {
netbuf_data(d_buf, &data, &len); netbuf_data(d_buf, &data, &len);
onDataReceived(data, len); if (aggregated_data == NULL) {
aggregated_data = (char*) malloc(len);
if (!aggregated_data) {
break;
}
memcpy(aggregated_data, data, len);
total_len = len;
} else {
char *new_data = (char*) realloc(aggregated_data, total_len + len);
if (!new_data) {
free(aggregated_data);
aggregated_data = NULL;
break;
}
aggregated_data = new_data;
memcpy(aggregated_data + total_len, data, len);
total_len += len;
}
} while (netbuf_next(d_buf) >= 0); } while (netbuf_next(d_buf) >= 0);
netbuf_delete(d_buf); netbuf_delete(d_buf);
if (aggregated_data != NULL) {
// onDataReceived(aggregated_data, total_len);
free(aggregated_data);
aggregated_data = NULL;
total_len = 0;
}
} else { } else {
} }
} else { } else {