diff --git a/app/app.c b/app/app.c index 7a444c3..e2e3b39 100644 --- a/app/app.c +++ b/app/app.c @@ -6,24 +6,19 @@ #define SER_BUF_SIZE 128 uint8_t ser_buffer[SER_BUF_SIZE]; - uint8_t serialize(uint8_t* buffer, size_t* len) { size_t message_length = 0; bool status = 0; static uint32_t cnt = 0; SimpleMessage message = SimpleMessage_init_zero; - /* Create a stream that will write to our buffer. */ pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); - /* Fill in the lucky number */ message.number = cnt++; - /* Now we are ready to encode the message! */ + status = pb_encode(&stream, SimpleMessage_fields, &message); *len = stream.bytes_written; - - /* Then just check for any errors.. */ if (!status) { printf("Encoding failed: %s\n", PB_GET_ERROR(&stream)); @@ -33,9 +28,9 @@ uint8_t serialize(uint8_t* buffer, size_t* len) { return 0; } - - void sendData(sd_callback_t send_data_callback) { + if (get_dbg_uart() == NULL) + return; size_t ser_len = 0; serialize(ser_buffer, &ser_len); send_data_callback(ser_buffer, ser_len); diff --git a/app/main.c b/app/main.c index 8b5858f..12b9fbe 100644 --- a/app/main.c +++ b/app/main.c @@ -1,8 +1,6 @@ #include "../bsp/bsp.h" #include "app.h" - - int main(void) { boardInit(); diff --git a/bsp/bsp.c b/bsp/bsp.c index 633299a..98161ef 100644 --- a/bsp/bsp.c +++ b/bsp/bsp.c @@ -7,6 +7,10 @@ static USART_TypeDef* dbg_uart = NULL; static lwip_status_t lwip_status = {.link_status = LINK_DOWN}; +USART_TypeDef* get_dbg_uart() { + return &dbg_uart; +} + lwip_status_t* getLwipStatus() { return &lwip_status; } diff --git a/bsp/bsp.h b/bsp/bsp.h index 7f0a990..77e896d 100644 --- a/bsp/bsp.h +++ b/bsp/bsp.h @@ -22,5 +22,6 @@ typedef struct { void boardInit(); lwip_status_t* getLwipStatus(); +USART_TypeDef* get_dbg_uart(); void send_uart(const uint8_t*, uint8_t); #endif \ No newline at end of file