When using the standard lambda for UART debug, the output string in the log includes the delimiter.
Example log output:
15:57:30 [D] [uart_debug:158] <<< “1-0:71.7.0(000.8*A)\r\n”.
____________________________________________^^^^
Question: Is there a cleaner or smarter way to strip the trailing \r\n than the rather bloated solution 2 below?
- Standard UARTDebug that includes the delimiter:
uart:
. . .
debug:
direction: RX
dummy_receiver: false
after:
delimiter: "\r\n"
timeout: 500ms
sequence:
- lambda: UARTDebug::log_string(direction, bytes);
- Bloated lambda to strip trailing “\r\n”:
uart:
. . .
debug:
direction: RX
dummy_receiver: false
after:
delimiter: "\r\n"
timeout: 500ms
sequence:
lambda: |-
auto it = std::find(bytes.begin(), bytes.end(), '\r');
size_t pos = (it != bytes.end()) ? std::distance(bytes.begin(), it) : bytes.size();
std::vector<uint8_t> out(bytes.begin(), bytes.begin() + pos);
UARTDebug::log_string(direction, out);