diff --git a/sw/airborne/mcu_periph/udp.c b/sw/airborne/mcu_periph/udp.c index 9278c39b3d..bd22e23ab6 100644 --- a/sw/airborne/mcu_periph/udp.c +++ b/sw/airborne/mcu_periph/udp.c @@ -27,6 +27,8 @@ #include "mcu_periph/udp.h" +#include + /* Print the configurations */ #if USE_UDP0 struct udp_periph udp0; @@ -63,7 +65,7 @@ void udp_periph_init(struct udp_periph *p, char *host, int port_out, int port_in p->device.periph = (void *)p; p->device.check_free_space = (check_free_space_t) udp_check_free_space; p->device.put_byte = (put_byte_t) udp_put_byte; - p->device.put_buffer = (put_buffer_t) udp_send_raw; + p->device.put_buffer = (put_buffer_t) udp_put_buffer; p->device.send_message = (send_message_t) udp_send_message; p->device.char_available = (char_available_t) udp_char_available; p->device.get_byte = (get_byte_t) udp_getch; @@ -98,3 +100,12 @@ void WEAK udp_put_byte(struct udp_periph *p, long fd __attribute__((unused)), ui p->tx_insert_idx++; } +void WEAK udp_put_buffer(struct udp_periph *p, long fd __attribute__((unused)), const uint8_t *data, uint16_t len) +{ + if (p->tx_insert_idx + len >= UDP_TX_BUFFER_SIZE) { + return; // no room + } + + memcpy(&(p->tx_buf[p->tx_insert_idx]), data, len); + p->tx_insert_idx += len; +} diff --git a/sw/airborne/mcu_periph/udp.h b/sw/airborne/mcu_periph/udp.h index 8c0992a017..91926cb9c1 100644 --- a/sw/airborne/mcu_periph/udp.h +++ b/sw/airborne/mcu_periph/udp.h @@ -58,6 +58,7 @@ extern void udp_arch_periph_init(struct udp_periph *p, char *host, int port_ extern void udp_send_message(struct udp_periph *p, long fd); extern void udp_send_raw(struct udp_periph *p, long fd, uint8_t *buffer, uint16_t size); extern void udp_receive(struct udp_periph *p); +extern void udp_put_buffer(struct udp_periph *p, long fd, const uint8_t *data, uint16_t len); #if USE_UDP0 extern struct udp_periph udp0;