From e94442e12be7ffcf4545cb8deb4ccd586c4b1872 Mon Sep 17 00:00:00 2001 From: Vasily Markov Date: Mon, 10 Jun 2024 13:56:17 +0300 Subject: [PATCH] Fix --- CMakeLists.txt | 9 +------ app/CMakeLists.txt | 8 +++--- app/main.c | 62 +++++++++++++++++++++++----------------------- bsp/lwip/lwip.c | 2 +- 4 files changed, 37 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 920fa4a..c27f7c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,4 @@ project(stm32) add_subdirectory(app) #application add_subdirectory(bsp) #board support package, lwip -add_subdirectory(libs/stm32f4xx) #stm32f4xx library - - - - - - - +add_subdirectory(libs/stm32f4xx) #stm32f4xx library \ No newline at end of file diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index b791b89..a86e9e2 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,9 +1,9 @@ set(elf_file stm32.elf) -# set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/nanopb/extra) -# find_package(Nanopb REQUIRED) +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/nanopb/extra) +find_package(Nanopb REQUIRED) -# nanopb_generate_cpp(TARGET proto simple.proto) +nanopb_generate_cpp(TARGET proto simple.proto) add_executable(${elf_file} main.c @@ -12,7 +12,7 @@ add_executable(${elf_file} target_link_libraries(${elf_file} PUBLIC bsp - # proto + proto ) target_include_directories(${elf_file} PRIVATE diff --git a/app/main.c b/app/main.c index 7d7722e..4c2a594 100644 --- a/app/main.c +++ b/app/main.c @@ -1,37 +1,37 @@ #include "../bsp/bsp.h" -// #include -// #include -// #include "simple.pb.h" +#include +#include +#include "simple.pb.h" -// void serialzie() { -// /* This is the buffer where we will store our message. */ -// uint8_t buffer[128]; -// size_t message_length; -// bool status; +void serialzie() { + /* This is the buffer where we will store our message. */ + uint8_t buffer[128]; + size_t message_length; + bool status; -// /* Encode our message */ -// { -// SimpleMessage message = SimpleMessage_init_zero; + /* Encode our message */ + { + 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)); + /* 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 = 42; -// /* Now we are ready to encode the message! */ -// status = pb_encode(&stream, SimpleMessage_fields, &message); -// message_length = stream.bytes_written; -// printf('%d\r\n', buffer); -// // udp_send_data(buffer, message_length); -// /* Then just check for any errors.. */ -// if (!status) -// { -// printf("Encoding failed: %s\n", PB_GET_ERROR(&stream)); -// return 1; -// } -// } -// return 0; -// } + /* Fill in the lucky number */ + message.number = 42; + /* Now we are ready to encode the message! */ + status = pb_encode(&stream, SimpleMessage_fields, &message); + message_length = stream.bytes_written; + + udp_send_data(buffer, message_length); + /* Then just check for any errors.. */ + if (!status) + { + printf("Encoding failed: %s\n", PB_GET_ERROR(&stream)); + return 1; + } + } + return 0; +} int main(void) { @@ -42,12 +42,12 @@ int main(void) while (1) { - // lwipProcess(); + lwipProcess(); const char *data = "Hello, world!"; sprintf(numStr, "%d", cnt++); char* strCat = strcat(data, numStr); // udp_send_data(numStr, strlen(numStr)); - // serialzie(); + serialzie(); // printf("Test\r\n"); GPIO_ToggleBits(GPIOB, GPIO_Pin_14); delay(100); diff --git a/bsp/lwip/lwip.c b/bsp/lwip/lwip.c index 663a72e..7be6f71 100644 --- a/bsp/lwip/lwip.c +++ b/bsp/lwip/lwip.c @@ -52,7 +52,7 @@ void udpServer_init(void) if (err == ERR_OK) { // printf("UDP bind\r\n"); } - // IP4_ADDR(&remote_ip, 192, 168, 1, 111); + IP4_ADDR(&remote_ip, 192, 168, 1, 111); // err= udp_connect(upcb, &remote_ip, remote_port); if (err == ERR_OK) { // printf("UDP connect\r\n");