template<typename Config> void SystemSetupConsole<Config>::read_line(char *dst, int max_len) { serialReadLine(&serial, dst, max_len, 0); //no timeout print("\r\n"); while (0 < serial.available()) serial.read(); }
//get the acknowledgement * (or print the error) //returns 0 upon success, -1 if error int get_ack_star(BHand *hand){ int err; int bytesRead; char astbuf = 0; int tries = 1000; while(astbuf != '*' && astbuf != '\n' && tries-- > 0){ err = serialRead(&(hand->port), &astbuf, 1, &bytesRead); usleep(1000); } //error in reading if(err || bytesRead != 1){ printf("get_ack_star: error in reading, err=%d, bytesRead=%d\n", err, bytesRead); return -1; } //hand error (put error in buffer) if(astbuf == '\n'){ char buffer[255]; serialReadLine(&(hand->port), buffer, &bytesRead, '>', 1000); printf("get_ack_star error:\n%s\n\n", buffer); return -1; } return 0; }
template<typename Config> void SystemSetupConsole<Config>::read_multiline(char *dst, int max_len) { char *ptr = dst; int len = max_len; while(len > 3) { serialReadLine(&serial, ptr, len, 0); //no timeout print("\r\n"); int l = strlen(ptr); len -= l; ptr += l; if (len > 3) { if (l != 0) { *ptr++ = '\r'; *ptr++ = '\n'; } *ptr = '\0'; } if (l == 0) return; } while (0 < serial.available()) serial.read(); }