From 7b4848824dcec8c5564bd2b11371f9c5f4a04376 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 23 Aug 2016 01:56:47 +0100 Subject: working --- app/modem.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 116 insertions(+), 14 deletions(-) (limited to 'app/modem.c') diff --git a/app/modem.c b/app/modem.c index b531761..170c7ba 100644 --- a/app/modem.c +++ b/app/modem.c @@ -6,19 +6,24 @@ #define SLEEPY 550 #define BACKOFF 200 +#define N_CMDS 4 + static char modem_buf[BUFFER_SIZE]; -static unsigned modem_ptr = 0; -static char *modem_cmd; +static unsigned modem_ptr; +static char *modem_cmds[N_CMDS]; +static int modem_cmds_ptr; static int timeout; static int sleepy = SLEEPY; +int in_call; +int dialtone; void -modem_send (char *buf) +modem_send (void) { - modem_cmd = buf; + if (!modem_cmds_ptr) return; if (sleepy >= SLEEPY) { @@ -30,29 +35,105 @@ modem_send (char *buf) } sleepy = 0; - printf ("(re)send\r\n"); + printf ("(re)send %s\r\n",modem_cmds[0]); timeout = TIMEOUT; usart2_queue ('\r'); - usart2_tx (modem_cmd, strlen (modem_cmd)); + usart2_tx (modem_cmds[0], strlen (modem_cmds[0])); usart2_queue ('\r'); } +void modem_cmd(char *buf) +{ +if (modem_cmds_ptr==N_CMDS) return; + +modem_cmds[modem_cmds_ptr]=buf; +modem_cmds_ptr++; + +if (modem_cmds_ptr==1) modem_send(); + +} + +void modem_dial (char *buf) { +in_call=1; +modem_cmd(buf); +} + + + +void modem_tone_off() +{ +// modem_cmd ("AT+STTONE=0"); +modem_cmd("AT+SIMTONE=1,400,200,0,10"); +} + +void modem_tone(int i) +{ +static char tone[]={'A','T','+','S','T','T','O','N','E','=','1',',','0','0',',','4','5','0','0','0',0}; + +tone[12]='0'+(i/10); +tone[13]='0'+(i%10); + +modem_cmd(tone); +} + +void modem_tone_nu(void) +{ +modem_cmd("AT+SIMTONE=1,400,200,0,45000"); +} + + void modem_line () { + int i; + printf ("Modem said: %s\r\n", modem_buf); sleepy = 0; - if (!strncmp (modem_buf, "RING", 4)) - ring (4000); - - if (!strncmp (modem_buf, "OK", 2)) + if (!strncmp (modem_buf, "RDY", 4)) { - modem_cmd = NULL; + modem_cmd ("ATZ"); + modem_cmd ("AT+CALM=1"); + modem_cmd ("AT+CLVL=90"); + } + else + if (!strncmp (modem_buf, "RING", 4)) + { + dialstr_clear (); + dialtone = 0; + if (!hook) + { + answer_call (); + } + else + { + ringer_ring (4000); + } + } + else + if (!strncmp (modem_buf, "OK", 2) || !strncmp (modem_buf, "ERROR", 2)) + { + if (modem_cmds_ptr) { + + for (i=1;i