diff --git a/src/at.c b/src/at.c index 2527bca..4d3b3f3 100644 --- a/src/at.c +++ b/src/at.c @@ -9,6 +9,7 @@ #include "gpio.h" #include "gnss.h" +#include #include #include #include @@ -50,7 +51,7 @@ gboolean at_send_command(struct EG25Manager *manager) { char command[256]; struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL; - int ret, len = 0; + int ret, len = 0, pos = 0; if (at_cmd) { /* Wake up the modem from soft sleep before sending an AT command */ @@ -82,9 +83,27 @@ gboolean at_send_command(struct EG25Manager *manager) manager->at_callback = at_cmd->callback; - ret = write(manager->at_fd, command, len); - if (ret < len) - g_warning("Couldn't write full AT command: wrote %d/%d bytes", ret, len); + do { + ret = write(manager->at_fd, &command[pos], len); + + if (ret < 0) { + switch (errno) { + case EAGAIN: + case EINTR: + /* Try again. */ + break; + + default: + g_warning("write(2): %s", strerror(errno)); + at_next_command(manager); + return FALSE; + } + } + else { + len -= ret; + pos += ret; + } + } while (len > 0); g_message("Sending command: %s", g_strstrip(command)); } else {