#define ELM327_MAGIC_CHAR 'y'
#define ELM327_MAGIC_STRING "y"
+#define ELM327_READY_CHAR '>'
/* Bits in elm->cmds_todo */
static DEFINE_SPINLOCK(elmcan_discdata_lock);
+static inline void elm327_panic(struct elmcan *elm);
+
/************************************************************************
*/
set_bit(TTY_DO_WRITE_WAKEUP, &elm->tty->flags);
actual = elm->tty->ops->write(elm->tty, elm->txbuf, len);
+ if (actual < 0) {
+ pr_err("Failed to write to tty for %s.\n", elm->dev->name);
+ elm327_panic(elm);
+ }
+
elm->txleft = len - actual;
elm->txhead = elm->txbuf + actual;
}
elm->state = ELM_GETPROMPT;
i++;
break;
- } else if (elm->rxbuf[i] == '>') {
+ } else if (elm->rxbuf[i] == ELM327_READY_CHAR) {
elm327_send(elm, ELM327_MAGIC_STRING, 1);
i++;
break;
case ELM_GETPROMPT:
/* Wait for '>' */
- if (elm->rxbuf[elm->rxfill - 1] == '>') {
+ if (elm->rxbuf[elm->rxfill - 1] == ELM327_READY_CHAR) {
elm327_handle_prompt(elm);
}
elm327_panic(elm);
} else if (len == elm->rxfill) {
if (elm->state == ELM_RECEIVING
- && elm->rxbuf[elm->rxfill - 1] == '>') {
+ && elm->rxbuf[elm->rxfill - 1] == ELM327_READY_CHAR) {
/* The ELM327's AT ST response timeout ran out,
* so we got a prompt.
* Clear RX buffer and restart listening.