Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Apr 7, 2024
1 parent 490ed28 commit 52bc382
Show file tree
Hide file tree
Showing 44 changed files with 501 additions and 5,655 deletions.
4 changes: 2 additions & 2 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.648459580" name="Floating-point ABI" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1044600179" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.756928727" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32L476RGTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L4xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32L476xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.720046019" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="4" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.720046019" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="80" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.417945529" name="Toolchain" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_cpp.1406644272" name="Runtime library" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_cpp" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_cpp.value.standard_c_standard_cpp" valueType="enumerated"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.945127982" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
Expand Down Expand Up @@ -158,7 +158,7 @@
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.957922821" name="Floating-point ABI" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.639014010" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.163780197" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.6 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || STM32L476RGTx || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L4xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32L476xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || || || " valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.546784113" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="4" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.debug.option.cpuclock.546784113" name="Cpu clock frequence" superClass="com.st.stm32cube.ide.mcu.debug.option.cpuclock" useByScannerDiscovery="false" value="80" valueType="string"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.303558056" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
<builder buildPath="${workspace_loc:/task4}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1702507879" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.528778541" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
Expand Down
26 changes: 12 additions & 14 deletions .mxproject

Large diffs are not rendered by default.

44 changes: 19 additions & 25 deletions Core/External/Proto/Buffer/Request/request_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
#include "request_buffer.h"

template<uint32_t BUFFER_SIZE>
RequestBuffer<BUFFER_SIZE>::RequestBuffer() : index(0), size(0), bytes{0} {
RequestBuffer::RequestBuffer() : index(0), size(0), bytes{nullptr} {
}

//template<uint32_t BUFFER_SIZE>
//uint8_t* RequestBuffer<BUFFER_SIZE>::get_raw_buffer() {
// return this->bytes[0];
//}

template<uint32_t BUFFER_SIZE>
void RequestBuffer<BUFFER_SIZE>::set_raw_buffer(uint8_t* src) {
void RequestBuffer::set_raw_buffer(uint8_t* src) {
this->bytes = src;
};

template<uint32_t BUFFER_SIZE>
uint32_t RequestBuffer<BUFFER_SIZE>::get_size() const {
void RequestBuffer::clear() {
this->index = 0;
}

uint32_t RequestBuffer::get_size() const {
return index;
}

template<uint32_t BUFFER_SIZE>
uint32_t RequestBuffer<BUFFER_SIZE>::get_max_size() const {
uint32_t RequestBuffer::get_max_size() const {
return size;
}

template<uint32_t BUFFER_SIZE>
bool RequestBuffer<BUFFER_SIZE>::peek(uint8_t &byte) const {
void RequestBuffer::set_max_size(uint32_t value) {
this->size = value;
}

bool RequestBuffer::peek(uint8_t &byte) const {
bool result = this->index < this->size;
if (result) {
byte = *this->bytes[this->index];
byte = this->bytes[this->index];
}

return result;
}

template<uint32_t BUFFER_SIZE>
bool RequestBuffer<BUFFER_SIZE>::advance() {

bool RequestBuffer::advance() {
const bool result = this->index < this->size;
if (result) {
++this->index;
}
return result;
}

template<uint32_t BUFFER_SIZE>
bool RequestBuffer<BUFFER_SIZE>::advance(const uint32_t src) {
bool RequestBuffer::advance(const uint32_t src) {
this->index += src;
const bool result = this->index < this->size;
if (result) {
Expand All @@ -54,15 +51,12 @@ bool RequestBuffer<BUFFER_SIZE>::advance(const uint32_t src) {
return result;
}

template<uint32_t BUFFER_SIZE>
bool RequestBuffer<BUFFER_SIZE>::pop(uint8_t &byte) {
bool RequestBuffer::pop(uint8_t &byte) {
bool result = this->index < this->size;
if (result) {
byte = *this->bytes[this->index];
byte = this->bytes[this->index];
++this->index;
}

return result;
}

template class RequestBuffer<DEFAULT_REQUEST_BUFFER_SIZE>;
32 changes: 16 additions & 16 deletions Core/External/Proto/Buffer/Request/request_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,27 @@

#include <cstdio>

#define DEFAULT_REQUEST_BUFFER_SIZE 6

/**
* Represents request buffer implementation for protocol buffers serialization.
*
* @tparam BUFFER_SIZE - given size of the internal request buffer.
*/
template<uint32_t BUFFER_SIZE>
class RequestBuffer : public EmbeddedProto::ReadBufferInterface {
public:
RequestBuffer();

~RequestBuffer() override = default;

// /**
// * Retrieves raw buffer used for direct data injection.
// *
// * @return raw buffer reference.
// */
// uint8_t* get_raw_buffer();

/**
* Retrieves raw buffer used for direct data injection.
* Sets raw buffer used for direct data injection.
*
* @return raw buffer reference.
* @param src - given buffer to be set.
*/
void set_raw_buffer(uint8_t* src);

/**
* Resets index value for buffer.
*/
void clear();

/**
* @see EmbeddedProto::ReadBufferInterface
*/
Expand All @@ -43,6 +36,13 @@ class RequestBuffer : public EmbeddedProto::ReadBufferInterface {
*/
[[nodiscard]] uint32_t get_max_size() const override;

/**
* Sets buffer max size.
*
* @param value - given buffer max size.
*/
void set_max_size(uint32_t value);

/**
* @see EmbeddedProto::ReadBufferInterface
*/
Expand Down Expand Up @@ -72,12 +72,12 @@ class RequestBuffer : public EmbeddedProto::ReadBufferInterface {
/**
* Represents max size of the buffer.
*/
uint32_t size = BUFFER_SIZE;
uint32_t size;

/**
* Represents current buffer data.
*/
uint8_t *bytes[BUFFER_SIZE];
uint8_t *bytes;
};

#endif //LIGHT_DETECTOR_REQUEST_BUFFER_H
54 changes: 24 additions & 30 deletions Core/External/Proto/Buffer/Response/response_buffer.cpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,46 @@
#include "response_buffer.h"

template<uint32_t BUFFER_SIZE>
ResponseBuffer<BUFFER_SIZE>::ResponseBuffer() : bytes_used(0), bytes{0} {
ResponseBuffer::ResponseBuffer() : index(0), size(0), bytes{nullptr} {
}

template<uint32_t BUFFER_SIZE>
uint8_t *ResponseBuffer<BUFFER_SIZE>::get_raw_buffer() {
return bytes[0];
uint8_t *ResponseBuffer::get_raw_buffer() {
return bytes;
}

template<uint32_t BUFFER_SIZE>
void ResponseBuffer<BUFFER_SIZE>::clear() {
bytes_used = 0;
void ResponseBuffer::clear() {
index = 0;
}

template<uint32_t BUFFER_SIZE>
uint32_t ResponseBuffer<BUFFER_SIZE>::get_size() const {
return bytes_used;
uint32_t ResponseBuffer::get_size() const {
return index;
}

template<uint32_t BUFFER_SIZE>
uint32_t ResponseBuffer<BUFFER_SIZE>::get_max_size() const {
return BUFFER_SIZE;
uint32_t ResponseBuffer::get_max_size() const {
return size;
}

template<uint32_t BUFFER_SIZE>
uint32_t ResponseBuffer<BUFFER_SIZE>::get_available_size() const {
return -bytes_used;
void ResponseBuffer::set_max_size(uint32_t value) {
this->size = value;
}

template<uint32_t BUFFER_SIZE>
bool ResponseBuffer<BUFFER_SIZE>::push(const uint8_t byte) {
bool result = BUFFER_SIZE > bytes_used;
uint32_t ResponseBuffer::get_available_size() const {
return -index;
}

bool ResponseBuffer::push(const uint8_t byte) {
bool result = size > index;
if (result) {
(*bytes[bytes_used]) = byte;
++bytes_used;
bytes[index] = byte;
++index;
}
return result;
}

template<uint32_t BUFFER_SIZE>
bool ResponseBuffer<BUFFER_SIZE>::push(const uint8_t *src, const uint32_t length) {
bool result = BUFFER_SIZE >= (bytes_used + length);
bool ResponseBuffer::push(const uint8_t *src, const uint32_t length) {
bool result = size >= (index + length);
if (result) {
memcpy(bytes + bytes_used, src, length);
bytes_used += length;
memcpy(bytes + index, src, length);
index += length;
}
return result;
}

template class ResponseBuffer<DEFAULT_RESPONSE_BUFFER_SIZE>;
}
21 changes: 14 additions & 7 deletions Core/External/Proto/Buffer/Response/response_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
#include <cstdio>
#include <cstring>

#define DEFAULT_RESPONSE_BUFFER_SIZE 6

/**
* Represents response buffer implementation for protocol buffers serialization.
*
* @tparam BUFFER_SIZE - given size of the internal response buffer.
*/
template<uint32_t BUFFER_SIZE>
class ResponseBuffer : public EmbeddedProto::WriteBufferInterface {
public:
ResponseBuffer();
Expand Down Expand Up @@ -42,6 +37,13 @@ class ResponseBuffer : public EmbeddedProto::WriteBufferInterface {
*/
[[nodiscard]] uint32_t get_max_size() const override;

/**
* Sets buffer max size.
*
* @param value - given buffer max size.
*/
void set_max_size(uint32_t value);

/**
* @see EmbeddedProto::WriteBufferInterface
*/
Expand All @@ -61,12 +63,17 @@ class ResponseBuffer : public EmbeddedProto::WriteBufferInterface {
/**
* Represents amount of currently used bytes by buffer.
*/
uint32_t bytes_used;
uint32_t index;

/**
* Represents max size of the buffer.
*/
uint32_t size;

/**
* Represents current buffer data.
*/
uint8_t *bytes[BUFFER_SIZE];
uint8_t *bytes;
};

#endif //LIGHT_DETECTOR_RESPONSE_BUFFER_H
20 changes: 9 additions & 11 deletions Core/External/Proto/Codec/proto_codec.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#include "proto_codec.h"
#include "indicator.h"

RequestBuffer<DEFAULT_REQUEST_BUFFER_SIZE> ProtoCodec::request_buffer =
RequestBuffer<DEFAULT_REQUEST_BUFFER_SIZE>();
RequestBuffer ProtoCodec::request_buffer = RequestBuffer();

ResponseBuffer<DEFAULT_RESPONSE_BUFFER_SIZE> ProtoCodec::response_buffer =
ResponseBuffer<DEFAULT_RESPONSE_BUFFER_SIZE>();
ResponseBuffer ProtoCodec::response_buffer = ResponseBuffer();

light_detector::RequestContainer ProtoCodec::request_container =
light_detector::RequestContainer();

RequestBuffer<DEFAULT_REQUEST_BUFFER_SIZE>& ProtoCodec::get_request_buffer() {
return request_buffer;
RequestBuffer* ProtoCodec::get_request_buffer() {
return &request_buffer;
}

ResponseBuffer<DEFAULT_RESPONSE_BUFFER_SIZE>& ProtoCodec::get_response_buffer() {
return response_buffer;
ResponseBuffer* ProtoCodec::get_response_buffer() {
return &response_buffer;
}

int ProtoCodec::decode_request_container() {
request_container.clear();

if (request_container.deserialize(request_buffer) == ::EmbeddedProto::Error::NO_ERRORS) {
State::get_request_container_sequence()->add(request_container);


State::get_request_container_sequence().add(request_container);
request_buffer.clear();

return EXIT_SUCCESS;
}


return EXIT_FAILURE;
}

Expand Down
8 changes: 4 additions & 4 deletions Core/External/Proto/Codec/proto_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class ProtoCodec {
*
* @return common instance of request buffer.
*/
static RequestBuffer<DEFAULT_REQUEST_BUFFER_SIZE>& get_request_buffer();
static RequestBuffer* get_request_buffer();

/**
* Retrieves common response buffer instance.
*
* @return common instance of response buffer.
*/
static ResponseBuffer<DEFAULT_RESPONSE_BUFFER_SIZE>& get_response_buffer();
static ResponseBuffer* get_response_buffer();

/**
* Attempts to decode request container, looking for raw data from request buffer. If the decoding is
Expand All @@ -51,12 +51,12 @@ class ProtoCodec {
/**
* Represents common instance of request buffer.
*/
static RequestBuffer<DEFAULT_REQUEST_BUFFER_SIZE> request_buffer;
static RequestBuffer request_buffer;

/**
* Represents common instance of response buffer.
*/
static ResponseBuffer<DEFAULT_RESPONSE_BUFFER_SIZE> response_buffer;
static ResponseBuffer response_buffer;

/**
* Represents common request container instance.
Expand Down
Loading

0 comments on commit 52bc382

Please sign in to comment.