summaryrefslogtreecommitdiffstats
path: root/app/modem.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/modem.c')
-rw-r--r--app/modem.c130
1 files changed, 116 insertions, 14 deletions
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<modem_cmds_ptr;++i) {
+ modem_cmds[i-1]=modem_cmds[i];
+ }
+ modem_cmds_ptr--;
+ modem_cmds[modem_cmds_ptr]=NULL;
+
timeout = 0;
+
+ if (modem_cmds_ptr) modem_send();
}
+ }
+ else
+ if (!strncmp (modem_buf, "NO CARRIER", 10)) {
+ in_call=0;
+ if (!hook)
+ modem_tone_nu();
+ }
}
void
@@ -83,17 +164,38 @@ void
answer_call (void)
{
printf ("Answering call\r\n");
- modem_send ("ATA");
+ dialtone = 0;
+ modem_cmd ("ATA");
+ in_call=1;
}
void
terminate_call (void)
{
printf ("Terminating any call\r\n");
- modem_send ("ATH0");
+ modem_cmd ("ATH0");
+ in_call=0;
}
void
+dialtone_on (void)
+{
+ dialtone = 1;
+ modem_tone(20);
+}
+
+void
+dialtone_off (void)
+{
+ if (!dialtone)
+ return;
+ modem_tone_off();
+
+ dialtone = 0;
+}
+
+
+void
modem_tick (void)
{
@@ -106,7 +208,7 @@ modem_tick (void)
if (timeout)
return;
- modem_send (modem_cmd);
+ modem_send ();
}
void