Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys: uartpb: use a unique ID to identify each Protobuf message #76

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ FEATURES_REQUIRED += cpp
# Required modules
USEMODULE += cpp11-compat

# Required packages
USEPKG += etl

define remote-flash-recipe
scp $(BINFILE) $(REMOTE_USER)@$(REMOTE_TARGET):/tmp/fw.bin
$(GDB) -nx -batch -ex "target extended-remote $(REMOTE_TARGET):3333" -ex "monitor reset halt" -ex "monitor flash write_image erase /tmp/fw.bin 0x08000000" -ex "monitor reset run"
Expand Down Expand Up @@ -77,6 +80,7 @@ tmp_cxxexflags := $(CXXEXFLAGS)
CXXEXFLAGS = $(filter-out -std=%, $(tmp_cxxexflags))
CXXEXFLAGS += -std=c++17
CXXEXFLAGS += -Wno-pedantic
CXXEXFLAGS += -Wno-cast-align

.PHONY: world
world: all
Expand Down
15 changes: 0 additions & 15 deletions applications/app_test/PB_GameInputMessage.proto

This file was deleted.

16 changes: 0 additions & 16 deletions applications/app_test/PB_GameOutputMessage.proto

This file was deleted.

5 changes: 5 additions & 0 deletions applications/app_test/PB_Score.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";

message PB_Score {
int32 value = 1;
}
20 changes: 13 additions & 7 deletions applications/app_test/app_samples.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Firmware includes
#include "platform.hpp"
#include "trigonometry.h"
#include "uartpb_config.hpp"

#include "app_camp.hpp"
#include "app_samples.hpp"
Expand All @@ -16,9 +15,11 @@ namespace cogip {

namespace app {

static PB_OutputMessage _output_message;
static DetectedSamples _detected_samples;

constexpr cogip::uartpb::uuid_t sample_request_uuid = 3781855956;
constexpr cogip::uartpb::uuid_t sample_response_uuid = 1538397045;

static std::map<CampColor, SamplesMap *> _samples;

typedef struct {
Expand Down Expand Up @@ -57,6 +58,8 @@ void app_samples_init()
return;
}

pf_get_uartpb()->register_message_handler(sample_response_uuid, app_samples_process);

event_queue_init_detached(&_sample_queue);
_sample_event.super.list_node.next = nullptr;

Expand Down Expand Up @@ -170,9 +173,7 @@ const DetectedSamples & app_samples_detect(void)
{
event_queue_claim(&_sample_queue);
cogip::uartpb::UartProtobuf *uartpb = pf_get_uartpb();
_output_message.clear();
_output_message.set_req_samples(true);
uartpb->send_message(_output_message);
uartpb->send_message(sample_request_uuid);
sample_event_t *event = (sample_event_t *)event_wait(&_sample_queue);

auto & samples = event->pb_message.get_samples();
Expand Down Expand Up @@ -203,9 +204,14 @@ const DetectedSamples & app_samples_detect(void)
return _detected_samples;
}

void app_samples_process(const PB_Samples<APP_SAMPLES_MAX_DETECTED> &samples)
void app_samples_process(cogip::uartpb::ReadBuffer *buffer)
{
_sample_event.pb_message = samples;
EmbeddedProto::Error error = _sample_event.pb_message.deserialize(*buffer);
if (error != EmbeddedProto::Error::NO_ERRORS) {
std::cout << "Samples: Protobuf deserialization error: " << static_cast<int>(error) << std::endl;
return;
}

event_post(&_sample_queue, (event_t *)&_sample_event);
}

Expand Down
50 changes: 0 additions & 50 deletions applications/app_test/app_uartpb.cpp

This file was deleted.

1 change: 0 additions & 1 deletion applications/app_test/include/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "app_obstacles.hpp"
#include "app_samples.hpp"
#include "app_shell.hpp"
#include "app_uartpb.hpp"

/*
* Machine parameters
Expand Down
3 changes: 2 additions & 1 deletion applications/app_test/include/app_samples.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "obstacles/Circle.hpp"
#include "uartpb/ReadBuffer.hpp"

#include "PB_Samples.hpp"

Expand Down Expand Up @@ -117,7 +118,7 @@ void app_samples_init();

const DetectedSamples & app_samples_detect(void);

void app_samples_process(const PB_Samples<APP_SAMPLES_MAX_DETECTED> &samples);
void app_samples_process(cogip::uartpb::ReadBuffer *buffer);

}; // namespace app

Expand Down
14 changes: 0 additions & 14 deletions applications/app_test/include/app_uartpb.hpp

This file was deleted.

59 changes: 0 additions & 59 deletions applications/app_test/include/uartpb_config.hpp

This file was deleted.

15 changes: 0 additions & 15 deletions applications/cup2022/PB_GameInputMessage.proto

This file was deleted.

16 changes: 0 additions & 16 deletions applications/cup2022/PB_GameOutputMessage.proto

This file was deleted.

20 changes: 13 additions & 7 deletions applications/cup2022/app_samples.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Firmware includes
#include "platform.hpp"
#include "trigonometry.h"
#include "uartpb_config.hpp"

#include "app_camp.hpp"
#include "app_samples.hpp"
Expand All @@ -16,9 +15,11 @@ namespace cogip {

namespace app {

static PB_OutputMessage _output_message;
static DetectedSamples _detected_samples;

constexpr cogip::uartpb::uuid_t sample_request_uuid = 3781855956;
constexpr cogip::uartpb::uuid_t sample_response_uuid = 1538397045;

static std::map<CampColor, SamplesMap *> _samples;

typedef struct {
Expand Down Expand Up @@ -57,6 +58,8 @@ void app_samples_init()
return;
}

pf_get_uartpb()->register_message_handler(sample_response_uuid, app_samples_process);

event_queue_init_detached(&_sample_queue);
_sample_event.super.list_node.next = nullptr;

Expand Down Expand Up @@ -170,9 +173,7 @@ const DetectedSamples & app_samples_detect(void)
{
event_queue_claim(&_sample_queue);
cogip::uartpb::UartProtobuf *uartpb = pf_get_uartpb();
_output_message.clear();
_output_message.set_req_samples(true);
uartpb->send_message(_output_message);
uartpb->send_message(sample_request_uuid);
sample_event_t *event = (sample_event_t *)event_wait(&_sample_queue);

auto & samples = event->pb_message.get_samples();
Expand Down Expand Up @@ -203,9 +204,14 @@ const DetectedSamples & app_samples_detect(void)
return _detected_samples;
}

void app_samples_process(const PB_Samples<APP_SAMPLES_MAX_DETECTED> &samples)
void app_samples_process(cogip::uartpb::ReadBuffer *buffer)
{
_sample_event.pb_message = samples;
EmbeddedProto::Error error = _sample_event.pb_message.deserialize(*buffer);
if (error != EmbeddedProto::Error::NO_ERRORS) {
std::cout << "Samples: Protobuf deserialization error: " << static_cast<int>(error) << std::endl;
return;
}

event_post(&_sample_queue, (event_t *)&_sample_event);
}

Expand Down
Loading