Modem: Implement ATDL (dial last number)

This commit is contained in:
Alexander Babikov 2024-04-01 11:56:01 +05:00
parent e641365866
commit ba499b9563
No known key found for this signature in database
GPG key ID: 1FD93764F31AAF86

View file

@ -106,6 +106,7 @@ typedef struct modem_t
char cmdbuf[512];
char numberinprogress[NUMBER_BUFFER_SIZE];
char lastnumber[NUMBER_BUFFER_SIZE];
uint32_t cmdpos;
uint32_t port;
int plusinc, flowcontrol;
@ -600,6 +601,7 @@ modem_reset(modem_t* modem)
modem_enter_idle_state(modem);
modem->cmdpos = 0;
modem->cmdbuf[0] = 0;
modem->lastnumber[0] = 0;
modem->numberinprogress[0] = 0;
modem->flowcontrol = 0;
modem->cmdpause = 0;
@ -637,6 +639,7 @@ modem_dial(modem_t* modem, const char* str)
{
char buf[NUMBER_BUFFER_SIZE] = "";
strncpy(buf, str, sizeof(buf) - 1);
strncpy(modem->lastnumber, str, sizeof(modem->lastnumber) - 1);
// Scan host for port
uint16_t port;
char * hasport = strrchr(buf,':');
@ -738,8 +741,17 @@ modem_do_command(modem_t* modem)
const char *mappedaddr = NULL;
size_t i = 0;
if (*foundstr == 'T' || *foundstr == 'P')
if (*foundstr == 'T' || *foundstr == 'P') // Tone/pulse dialing
foundstr++;
else if (*foundstr == 'L') { // Redial last number
if (modem->lastnumber[0] == 0)
modem_send_res(modem, ResERROR);
else {
pclog("Redialing number %s\n", modem->lastnumber);
modem_dial(modem, modem->lastnumber);
}
return;
}
if ((!foundstr[0] && !modem->numberinprogress[0]) || ((strlen(modem->numberinprogress) + strlen(foundstr)) > (NUMBER_BUFFER_SIZE - 1))) {
// Check for empty or too long strings