stm32_serDes_protobuf_project/app/main.c

63 lines
1.5 KiB
C
Raw Normal View History

2024-05-13 15:21:22 +03:00
#include "../bsp/bsp.h"
2024-06-10 13:56:17 +03:00
#include <pb_encode.h>
#include <pb_decode.h>
#include "simple.pb.h"
2024-05-13 15:21:22 +03:00
2024-06-10 13:56:17 +03:00
void serialzie() {
/* This is the buffer where we will store our message. */
uint8_t buffer[128];
size_t message_length;
bool status;
2024-05-13 20:44:16 +03:00
2024-06-10 13:56:17 +03:00
/* Encode our message */
{
SimpleMessage message = SimpleMessage_init_zero;
2024-05-13 20:44:16 +03:00
2024-06-10 13:56:17 +03:00
/* Create a stream that will write to our buffer. */
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
2024-05-13 20:44:16 +03:00
2024-06-10 13:56:17 +03:00
/* 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;
}
2024-05-13 20:44:16 +03:00
2024-05-13 15:21:22 +03:00
int main(void)
{
2024-05-15 02:15:03 +03:00
boardInit();
2024-05-13 15:21:22 +03:00
udpServer_init();
2024-05-15 02:15:03 +03:00
uint32_t cnt = 0;
char numStr[10];
2024-05-13 15:21:22 +03:00
while (1)
{
2024-06-10 13:56:17 +03:00
lwipProcess();
2024-05-13 15:21:22 +03:00
const char *data = "Hello, world!";
2024-05-15 02:15:03 +03:00
sprintf(numStr, "%d", cnt++);
char* strCat = strcat(data, numStr);
2024-06-06 14:12:37 +03:00
// udp_send_data(numStr, strlen(numStr));
2024-06-10 13:56:17 +03:00
serialzie();
2024-06-07 14:19:49 +03:00
// printf("Test\r\n");
2024-05-13 15:21:22 +03:00
GPIO_ToggleBits(GPIOB, GPIO_Pin_14);
2024-06-06 14:12:37 +03:00
delay(100);
2024-05-13 15:21:22 +03:00
}
}
void SystemClock_Config()
{
SystemCoreClock = 180000000;
}