I'm trying to port tinySA.ino over to the RPi.
toggle quoted message
Show quoted text
Appears that the serial command interpreter is highly dependent on the timing of each incoming character. A better way to do this is to wait for a '\n' character to indicate a complete command before processing it. And I'd separate each line into tokens with whitespace, either spaces or tabs. So to write 34 to register 12, the 'x' command becomes the character sequence? "x 12 34\n" Any extra whitespace is ignored:? "x? ? ? 12? ?\t 34? \t? ?\n" The C strings library makes this easy, code looks something like this. Note that each call to strtok() is modifiying linebuf[] by placing a '\0' after the next token, then returning a pointer for the start of that token within linebuf[] #include <strings.h> #define LNBUFSZ 82? ? ? ? ? ? ? // 80 chars plus two for \n and \0 void main() { ? ? char linebuf[LNBUFSZ];? ? ? char* token; ? ? while (1) { ? ? ? ? fgets(linebuf, LNBUFSZ, stdin);? ? // Read chars up to and including the next '\n'
? ? ? ? token = strtok(linebuf, " \t\n");? ? ? ? ? ? ? //? Any whitespace of spaces, tabs or newlines is not a token
? ? ? ? if (!strcmp(token,"x")) {? ? ? ? ? //? "x? addr" to read a register,? ?"x addr data" to write
? ? ? ? ? ? int regaddr, regdata;
? ? ? ? ? ? token = strtok(NULL, " \n\t");? ? // NULL says to continue operating on the same string
? ? ? ? ? ? if (token!=NULL)? regaddr = atoi(token);? else { print("Error, no args to command x \n"); break; }
? ? ? ? ? ? token = strtok(NULL, " \t\n");
? ? ? ? ? ? if (token!=NULL)? regwrite(regaddr, atoi(regdata));? ? else { print(atoi(regread(addr))); } ? ? ? ? } else if (!strcmp(token,"h"))? halt_and_catch_fire(); ? ? ? ? } else { ? ? ? ? ? ? ? ? ... ? ? ? ? } else print("Error, bad command \n"); ? ? } } ? ??
Jerry, KE7ER ?
On Sat, Jan 25, 2020 at 06:08 PM, m0wid wrote:When testing with the Arduino terminal commands the ESP32 responds as you would expect, but when driven by the TinySA.exe TinySA.exe hung after around 100 samples.? |