Merge branch 'at-write-repeat' into 'master'

at_send_command: call write(2) in a loop

See merge request mobian1/devices/eg25-manager!30
This commit is contained in:
Arnaud Ferraris
2021-10-02 12:14:44 +00:00

View File

@@ -9,6 +9,7 @@
#include "gpio.h"
#include "gnss.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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,11 +83,31 @@ 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);
g_message("Sending command: %s", g_strstrip(command));
do {
ret = write(manager->at_fd, &command[pos], len);
if (ret < 0) {
switch (errno) {
case EAGAIN:
case EINTR:
/* Try again. */
break;
default:
g_warning("error sending AT command: %s", strerror(errno));
at_next_command(manager);
return FALSE;
}
}
else {
len -= ret;
pos += ret;
}
} while (len > 0);
g_message("Successfully sent command: %s", g_strstrip(command));
} else {
/* Allow the modem to enter soft sleep again when we sent the AT command*/
gpio_sequence_sleep(manager);