add pbuf_copy_partial moc so I don't need if TESTING preprocessor directive
This commit is contained in:
2023-11-30 10:17:57 +01:00
parent f16e92b7d8
commit d7ff0010bd
3 changed files with 10 additions and 6 deletions

View File

@@ -149,3 +149,8 @@ size_t tcp_sndbuf(void* pcb) {
void pbuf_free(struct pbuf* p) { void pbuf_free(struct pbuf* p) {
UNUSED(p); UNUSED(p);
} }
uint16_t pbuf_copy_partial(const struct pbuf* buf, void* dataptr, uint16_t len, uint16_t offset) {
memcpy(dataptr, ((uint8_t*)(buf->payload)) + offset, len);
return len;
}

View File

@@ -101,7 +101,7 @@ typedef err_t (*tcp_accept_fn)(void* arg, struct tcp_pcb* newpcb, err_t err);
uint32_t logger_get_timestamp(void); uint32_t logger_get_timestamp(void);
void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT* font); void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT* font);
void lcd_draw_img_from_fs(char* filename, uint32_t x_pos, uint32_t y_pos); void lcd_draw_img_from_fs(char* filename, uint32_t x_pos, uint32_t y_pos);
void lcd_draw_gif_from_fs(char* filename, uint32_t x_pos, uint32_t y_pos); void lcd_draw_gif_from_fs(char* filename, uint32_t x_pos, uint32_t y_pos);
void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos); void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos);
@@ -129,6 +129,8 @@ void pbuf_free(struct pbuf* p);
size_t tcp_sndbuf(void* pcb); size_t tcp_sndbuf(void* pcb);
uint16_t pbuf_copy_partial(const struct pbuf* buf, void* dataptr, uint16_t len, uint16_t offset);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -209,11 +209,8 @@ static err_t tcp_cmd_recv_new(void* arg, struct tcp_pcb* pcb, struct pbuf* p, er
LOG_WARN(TAG, "Command too long"); LOG_WARN(TAG, "Command too long");
} }
size_t len = p->tot_len >= MAX_CMD_LEN ? MAX_CMD_LEN : p->tot_len; size_t len = p->tot_len >= MAX_CMD_LEN ? MAX_CMD_LEN : p->tot_len;
#if TESTING
memcpy(cmd, p->payload, len);
#else
pbuf_copy_partial(p, cmd, len, 0); pbuf_copy_partial(p, cmd, len, 0);
#endif
cmd[len] = '\0'; cmd[len] = '\0';
remove_newline(cmd); remove_newline(cmd);