@@ -14,16 +14,21 @@ class Serial {
1414 virtual ~Serial (){};
1515
1616 // Must be greater than protobuf payload size
17- static constexpr size_t UART_BUFFER_SIZE{512 };
17+ static constexpr size_t UART_BUFFER_SIZE{64 };
1818
1919 // Tx Rx Memory for DMA
20- std::array<uint8_t , UART_BUFFER_SIZE> tx;
20+ std::array<uint8_t , UART_BUFFER_SIZE * 4 > tx;
2121 std::array<uint8_t , UART_BUFFER_SIZE> rx;
2222
2323 // / @brief Initialize Serial
2424 // / @param Ports Vector of UART_HandleTypeDef pointer
2525 void setPort (std::vector<UART_HandleTypeDef *> Ports) { ports = Ports; }
2626
27+ // / @brief Get high water mark
28+ // / @return High water mark
29+ // / @note High water mark is the maximum size of the tx_cache
30+ uint16_t getHighWaterMark () { return high_water_mark; }
31+
2732 // / @brief Send a new line character
2833 void sendLn () { tx_cache.append (" \n " ); };
2934
@@ -71,6 +76,47 @@ class Serial {
7176 }
7277 }
7378
79+ // / @brief Sending number with message
80+ // / @tparam T Data type
81+ // / @param msg Message to be sent
82+ // / @param value number to be buffered
83+ template <class T >
84+ void sendCombined (std::string msg, T value) {
85+ sendString (msg);
86+ sendString (" :\t\t\t " );
87+ sendNumber (value);
88+ sendLn ();
89+ }
90+
91+ // / @brief Sending 1D array with message
92+ // / @tparam T Data type
93+ // / @tparam N 1D array size
94+ // / @param msg Message to be sent
95+ // / @param elements Array to be buffered
96+ // / @param value number to be buffered
97+ template <class T , size_t N>
98+ void sendCombined (std::string msg, std::array<T, N> elements) {
99+ sendString (msg);
100+ sendString (" :\t\t\t " );
101+ sendNumber (elements);
102+ sendLn ();
103+ }
104+
105+ // / @brief Sending 2D array with message
106+ // / @tparam T Data type
107+ // / @tparam N 2D array size
108+ // / @tparam M 1D array size
109+ // / @param msg Message to be sent
110+ // / @param elements Array to be buffered
111+ // / @param value number to be buffered
112+ template <class T , size_t N, size_t M>
113+ void sendCombined (std::string msg, std::array<std::array<T, M>, N> elements) {
114+ sendString (msg);
115+ sendString (" :\t\t\t " );
116+ sendNumber (elements);
117+ sendLn ();
118+ }
119+
74120 // / @brief Buffer a protobuf payload to be sent
75121 // / @param msg protobuf payload
76122 // / @param size size of the payload
@@ -84,6 +130,7 @@ class Serial {
84130 // / @return True if data is sent
85131 bool commit () {
86132 if (!tx_cache.empty ()) {
133+ if (tx_cache.size () > high_water_mark) high_water_mark = tx_cache.size ();
87134 if (tx_cache.size () < (UART_BUFFER_SIZE)) {
88135 std::copy (tx_cache.begin (), tx_cache.end (), tx.data ());
89136 tx_size = tx_cache.size ();
@@ -120,6 +167,9 @@ class Serial {
120167 // Sending buffer size
121168 uint16_t tx_size{};
122169 uint16_t pb_size{};
170+
171+ // High water mark
172+ uint16_t high_water_mark{};
123173};
124174
125175#endif /* CORE_INC_SERIAL */
0 commit comments