58template<typename SerialIn>
65template<typename SerialOut>
133 if (!line.has_value() || line->empty()) {
141 if (prefix && prefix[0] !=
'\0') {
158 if (view.
empty() || view[0] !=
'{') {
173 FL_WARN(
"[RPC] discarded a " << (
static_cast<unsigned>(line->size())) <<
" byte line that does not begin with '{'; a request that arrived truncated looks exactly like this");
190 return [prefix](
const fl::json& response) {
205 if (prefix && prefix[0] !=
'\0') {
210 serial.
write(data, len);
216 serial.
write(
"\n", 1);
240template<
typename SerialIn>
246template<
typename SerialIn>
256 if (timeoutMs.has_value()) {
257 if (
fl::millis() - startTime >= timeoutMs.value()) {
264 int c = serial.read();
275 if (c == delimiter) {
285 buffer << static_cast<char>(c);
294template<
typename SerialOut>
296 serial.println(str.c_str());
FastLED chrono implementation - duration types for time measurements.
void flush() FL_NO_EXCEPT
static json parse(const fl::string &txt) FL_NO_EXCEPT
string str() const FL_NO_EXCEPT
void remove_suffix(fl::size n) FL_NO_EXCEPT
constexpr const char & back() const FL_NO_EXCEPT
constexpr bool empty() const FL_NO_EXCEPT
void remove_prefix(fl::size n) FL_NO_EXCEPT
bool starts_with(string_view sv) const FL_NO_EXCEPT
constexpr const char & front() const FL_NO_EXCEPT
Delay utilities for FastLED Includes nanosecond-precision delays, cycle counting, and microsecond del...
FastLED's Elegant JSON Library: fl::json
Centralized logging categories for FastLED hardware interfaces and subsystems.
fl::pair< fl::function< fl::optional< fl::json >()>, fl::function< void(const fl::json &)> > createSerialTransport(const char *responsePrefix="REMOTE: ", const char *requestPrefix="") FL_NO_EXCEPT
Create RequestSource and ResponseSink pair for serial I/O.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
fl::optional< fl::string > readLine(char delimiter, char skipChar, fl::optional< u32 > timeoutMs) FL_NO_EXCEPT
bool isspace(char c) FL_NO_EXCEPT
Check if character is whitespace (space, tab, newline, carriage return)
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
size_t write_bytes(const u8 *buffer, size_t size) FL_NO_EXCEPT
fl::ResponseStreamSink createSerialResponseStreamSink(const char *prefix="REMOTE: ") FL_NO_EXCEPT
Create a streamed JSON-RPC ResponseSink that writes directly to serial.
fl::function< void(fl::JsonStreamWriter &)> JsonStreamCallback
fl::function< void(const fl::json &)> createSerialResponseSink(const char *prefix="REMOTE: ") FL_NO_EXCEPT
Create a JSON-RPC ResponseSink that writes to fl:: serial output.
bool flush(u32 timeoutMs) FL_NO_EXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
fl::function< fl::optional< fl::json >()> createSerialRequestSource(const char *prefix="") FL_NO_EXCEPT
constexpr nullopt_t nullopt
fl::string formatJsonResponse(const fl::json &response, const char *prefix) FL_NO_EXCEPT
Serialize JSON response to a string.
void println(const char *str) FL_NO_EXCEPT
constexpr fl::size kDroppedRequestWarnBytes
Create a JSON-RPC RequestSource that reads from fl:: serial input.
fl::optional< fl::string > readSerialLine(SerialIn &serial, char delimiter='\n', fl::optional< u32 > timeoutMs=fl::nullopt) FL_NO_EXCEPT
Read a line from a serial-like input source (blocking with optional timeout)
fl::function< void(fl::JsonStreamCallback)> ResponseStreamSink
int available() FL_NO_EXCEPT
fl::optional< fl::string > readSerialStringUntil(SerialIn &serial, char delimiter, char skipChar, fl::optional< u32 > timeoutMs) FL_NO_EXCEPT
void writeSerialLine(SerialOut &serial, const fl::string &str) FL_NO_EXCEPT
Write a string with newline to a serial-like output.
FASTLED_FORCE_INLINE size_t strlen(const char *s) FL_NO_EXCEPT
void delayMicroseconds(u32 us) FL_NO_EXCEPT
Delay for a given number of microseconds.
Base definition for an LED controller.
int available() const FL_NO_EXCEPT
Serial adapter using fl:: input functions (fl::available, fl::read)
void write(const char *data, fl::size len) FL_NO_EXCEPT
void println(const char *str) FL_NO_EXCEPT
Serial adapter using fl:: output functions (fl::println)