mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-30 07:42:23 +02:00
at: make sure we read the full response before processing it
This commit is contained in:
26
src/at.c
26
src/at.c
@@ -31,7 +31,7 @@ static int configure_serial(const char *tty)
|
|||||||
struct termios ttycfg;
|
struct termios ttycfg;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(tty, O_RDWR | O_NOCTTY);
|
fd = open(tty, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||||
if (fd > 0) {
|
if (fd > 0) {
|
||||||
tcgetattr(fd, &ttycfg);
|
tcgetattr(fd, &ttycfg);
|
||||||
ttycfg.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON);
|
ttycfg.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON);
|
||||||
@@ -143,7 +143,6 @@ static int append_at_command(struct EG25Manager *manager,
|
|||||||
if (!at_cmd)
|
if (!at_cmd)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
at_cmd->retries = 0;
|
|
||||||
at_cmd->cmd = g_strdup(cmd);
|
at_cmd->cmd = g_strdup(cmd);
|
||||||
if (subcmd)
|
if (subcmd)
|
||||||
at_cmd->subcmd = g_strdup(subcmd);
|
at_cmd->subcmd = g_strdup(subcmd);
|
||||||
@@ -157,22 +156,33 @@ static int append_at_command(struct EG25Manager *manager,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define READ_BUFFER_SIZE 256
|
||||||
|
|
||||||
static gboolean modem_response(gint fd,
|
static gboolean modem_response(gint fd,
|
||||||
GIOCondition event,
|
GIOCondition event,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
struct EG25Manager *manager = data;
|
struct EG25Manager *manager = data;
|
||||||
char response[256];
|
char response[READ_BUFFER_SIZE*4+1];
|
||||||
int ret;
|
char tmp[READ_BUFFER_SIZE];
|
||||||
|
ssize_t ret, pos = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: several reads can be necessary to get the full response, we could
|
* Several reads can be necessary to get the full response, so we loop
|
||||||
* loop until we read 0 chars with a reasonable delay between attempts
|
* until we read 0 chars with a reasonable delay between attempts
|
||||||
* (remember the transfer rate is 115200 here)
|
* (remember the transfer rate is 115200 here)
|
||||||
*/
|
*/
|
||||||
ret = read(fd, response, sizeof(response));
|
do {
|
||||||
|
ret = read(fd, tmp, sizeof(tmp));
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
response[ret] = 0;
|
memcpy(&response[pos], tmp, ret);
|
||||||
|
pos += ret;
|
||||||
|
usleep(10000);
|
||||||
|
}
|
||||||
|
} while (ret > 0 && pos < (sizeof(response) - 1));
|
||||||
|
|
||||||
|
if (pos > 0) {
|
||||||
|
response[pos] = 0;
|
||||||
g_strstrip(response);
|
g_strstrip(response);
|
||||||
if (strlen(response) == 0)
|
if (strlen(response) == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
Reference in New Issue
Block a user