This commit is contained in:
Vasily Markov 2024-06-10 13:56:17 +03:00
parent 120010f39c
commit e94442e12b
4 changed files with 37 additions and 44 deletions

View File

@ -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

View File

@ -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

View File

@ -1,37 +1,37 @@
#include "../bsp/bsp.h"
// #include <pb_encode.h>
// #include <pb_decode.h>
// #include "simple.pb.h"
#include <pb_encode.h>
#include <pb_decode.h>
#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);

View File

@ -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");