diff --git a/Application/Inc/Instances.hpp b/Application/Inc/Instances.hpp index e23a76a..3f04e8e 100644 --- a/Application/Inc/Instances.hpp +++ b/Application/Inc/Instances.hpp @@ -21,6 +21,6 @@ extern CustomDAC dac; extern CustomADC adc; extern sml::sm stream_sm; -extern sml::sm, sml::defer_queue> main_sm; +extern sml::sm> main_sm; #endif /* APPLICATION_INC_INSTANCES */ diff --git a/Application/Inc/SerialCOM.hpp b/Application/Inc/SerialCOM.hpp index 3366f90..e07d4fc 100644 --- a/Application/Inc/SerialCOM.hpp +++ b/Application/Inc/SerialCOM.hpp @@ -2,6 +2,7 @@ #define CORE_INC_SERIALCOM #include "algorithm" +#include "array" #include "main.h" #include "string" @@ -23,26 +24,38 @@ class SerialCOM { void sendLn(); void sendString(std::string); - void sendNumber(int); - void sendNumber(float); - void sendNumber(double); - void sendNumber(uint8_t); - void sendNumber(uint16_t); - void sendNumber(uint32_t); - void sendNumber(uint64_t); - void sendNumber(int8_t); - void sendNumber(int16_t); - void sendNumber(int32_t); - void sendNumber(int64_t); - - + void sendNumber(bool); + + + /** + * @brief Append single number to buffer. + * + * @param value all kinds of numbers. + */ + template + void sendNumber(T value) { + m_buffer_msg.append(std::to_string(value)); + } + + /** + * @brief Append array of numbers to buffer. + * + * @param items std::array of numbers. + */ + template + void sendNumber(std::array items) { + for (auto &i : items) { + m_buffer_msg.append(std::to_string(i)); + if (&i != &items.back()) m_buffer_msg.append(", "); + } + } + bool sendOut(); // Tx Rx Memory for DMA to fetch and push uint8_t m_tx_data[UART_BUFFER]; // UART_BUFFER may be re-defined in main.h uint8_t m_rx_data[UART_BUFFER]; - private: // Port UART_HandleTypeDef *m_port; diff --git a/Application/Src/SerialCOM.cpp b/Application/Src/SerialCOM.cpp index 40411d9..b47c88d 100644 --- a/Application/Src/SerialCOM.cpp +++ b/Application/Src/SerialCOM.cpp @@ -25,21 +25,14 @@ void SerialCOM::sendLn() { m_buffer_msg.append("\n"); }; void SerialCOM::sendString(std::string msg) { m_buffer_msg.append(msg); } /** - * @brief Append single number to buffer. - * - * @param value all kinds of numbers. + * @brief Append bool to buffer as text. + * + * @param value bool value. */ -void SerialCOM::sendNumber(int value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(float value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(double value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(uint8_t value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(uint16_t value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(uint32_t value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(uint64_t value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(int8_t value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(int16_t value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(int32_t value) { m_buffer_msg.append(std::to_string(value)); } -void SerialCOM::sendNumber(int64_t value) { m_buffer_msg.append(std::to_string(value)); } +void SerialCOM::sendNumber(bool value) { + value ? m_buffer_msg.append("ON") : m_buffer_msg.append("OFF"); +} + /** * @brief Periodically send uart in DMA mode if buffer !empty. diff --git a/Application/Src/main.cpp b/Application/Src/main.cpp index be0b2df..4c22aff 100644 --- a/Application/Src/main.cpp +++ b/Application/Src/main.cpp @@ -19,7 +19,7 @@ CustomDAC dac{}; CustomADC adc{}; sml::sm stream_sm{&thread}; -sml::sm, sml::defer_queue> main_sm{&thread, &serialCOM}; +sml::sm> main_sm{&thread, &serialCOM}; /** * @brief The application entry point.