Remove newline requirement for serial json parsing#45
Open
Conversation
- Rewrite serial buffer builder to not need newline termination:
- Let ArduinoJson decide if serial buffer is terminated
- Remove characters preceding '{'
- Restart buffer if new '{' is received
jonnew
requested changes
Mar 6, 2026
Member
jonnew
left a comment
There was a problem hiding this comment.
There needs to be something that flushes standard in an resets the serial_buffer when the remote_avialabel transitions from low to high, e.g.
static int process_serial_commands(context_t *ctx)
{
static char serial_buffer[MAX_SERIAL_BUFFER_LENGTH] = {0};
static uint16_t serial_buffer_index = 0;
static bool last_remote_available = false;
if (!last_remote_available && remote_available(ctx))
{
// TODO: reset buffer and flush stdin
last_remote_available = true;
} else {
last_remote_available = false;
return ERROR_REMOTE_INTERFACE_LOCKED;
}
or perhaps something a bit less dumb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
{DeserializeJsonfrom parsing strings or arrays instead of JSON objects (i.e. handles the case when a double quotes"or open square bracket[precedes your JSON which would otherwise brick serial inputs until the string or array is terminated)ParseObjectmethod{is receivedI tried using
std::cininstead of constructing our own buffer. There were some problems associated with that.Originally, the
process_serial_commandswas only called when a new character was received from the serial port. This meant that if I sent a message like "a{turn:1}" or "{enable:true}{turn:1}", only the first item would be parses (in the first case, an invalid input "a"; in the second case, a valid JSON), and the second item wouldn't be parsed until another character was received. If I remove the guard,std::cinwould block when it's empty, and there doesn't seem to be any standard way to check ifstd::cinis empty without blocking.