Create a JSON-RPC RequestSource that reads from fl:: serial input.
- Parameters
-
| prefix | Optional prefix to strip from input lines (default: "") |
- Returns
- RequestSource callback suitable for fl::Remote constructor
- Note
- Composes transport layer (serial I/O) with protocol layer (JSON-RPC normalization)
Example:
fl::unique_ptr< fl::Remote > remote
JSON-RPC server with scheduling support.
fl::function< fl::optional< fl::json >()> createSerialRequestSource(const char *prefix="")
Create a JSON-RPC RequestSource that reads from fl:: serial input.
fl::function< void(const fl::json &)> createSerialResponseSink(const char *prefix="REMOTE: ")
Create a JSON-RPC ResponseSink that writes to fl:: serial output.
Definition at line 109 of file serial.h.
109 {
111
113 if (avail <= 0) {
115 }
116
117
118
119
120
122 if (!line.has_value() || line->empty()) {
124 }
125
126
127 fl::string_view view = *line;
128
129
130 if (prefix && prefix[0] != '\0') {
133 }
134 }
135
136
139 }
140
141
144 }
145
146
147 if (view.
empty() || view[0] !=
'{') {
149 }
150
151
152 fl::string input(view);
154 };
155}
static json parse(const fl::string &txt) FL_NOEXCEPT
constexpr bool empty() const FL_NOEXCEPT
void remove_suffix(fl::size n) FL_NOEXCEPT
constexpr const char & front() const FL_NOEXCEPT
bool starts_with(string_view sv) const FL_NOEXCEPT
constexpr const char & back() const FL_NOEXCEPT
void remove_prefix(fl::size n) FL_NOEXCEPT
size_t strlen(const char *s) FL_NOEXCEPT
constexpr nullopt_t nullopt
bool isspace(char c) FL_NOEXCEPT
Check if character is whitespace (space, tab, newline, carriage return)
fl::optional< fl::string > readLine(char delimiter, char skipChar, fl::optional< u32 > timeoutMs)
References available(), fl::string_view::back(), fl::string_view::empty(), fl::string_view::front(), isspace(), nullopt, fl::json::parse(), readLine(), fl::string_view::remove_prefix(), fl::string_view::remove_suffix(), fl::string_view::starts_with(), and strlen().
Referenced by autoResearchLowMemorySetup(), and createSerialTransport().