From 4dfc42565c2d1f5b900d8d725126bfde886a8423 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 Aug 2016 23:04:53 +0100 Subject: tidy --- app/modem.c | 130 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 57 deletions(-) (limited to 'app/modem.c') diff --git a/app/modem.c b/app/modem.c index fa6a57a..b531761 100644 --- a/app/modem.c +++ b/app/modem.c @@ -7,93 +7,109 @@ #define BACKOFF 200 static char modem_buf[BUFFER_SIZE]; -static unsigned modem_ptr=0; +static unsigned modem_ptr = 0; static char *modem_cmd; static int timeout; -static int sleepy=SLEEPY; +static int sleepy = SLEEPY; -void modem_send(char *buf) +void +modem_send (char *buf) { -modem_cmd=buf; - -if (sleepy>=SLEEPY) { - printf("modem is sleepy\r\n"); - usart2_queue('\r'); - sleepy=0; - timeout=BACKOFF; - return; + modem_cmd = buf; + + if (sleepy >= SLEEPY) + { + printf ("modem is sleepy\r\n"); + usart2_queue ('\r'); + sleepy = 0; + timeout = BACKOFF; + return; + } + sleepy = 0; + + printf ("(re)send\r\n"); + timeout = TIMEOUT; + usart2_queue ('\r'); + usart2_tx (modem_cmd, strlen (modem_cmd)); + usart2_queue ('\r'); } - sleepy=0; -printf("(re)send\r\n"); -timeout=TIMEOUT; -usart2_queue('\r'); -usart2_tx(modem_cmd,strlen(modem_cmd)); -usart2_queue('\r'); -} - -void modem_line() +void +modem_line () { -printf("Modem said: %s\r\n",modem_buf); + printf ("Modem said: %s\r\n", modem_buf); -sleepy=0; + sleepy = 0; -if (!strncmp(modem_buf,"RING",4)) - ring(4000); + if (!strncmp (modem_buf, "RING", 4)) + ring (4000); -if (!strncmp(modem_buf,"OK",2)) { - modem_cmd=NULL; - timeout=0; -} + if (!strncmp (modem_buf, "OK", 2)) + { + modem_cmd = NULL; + timeout = 0; + } } -void modem_byte(uint8_t b) +void +modem_byte (uint8_t b) { -if (b=='\n') return; + if (b == '\n') + return; -if (b=='\r') { - if (modem_ptr) - modem_line(); - modem_ptr=0; - modem_buf[modem_ptr]=0; - return; -} - -if (modem_ptr>=(sizeof(modem_buf)-1)) - return; + if (b == '\r') + { + if (modem_ptr) + modem_line (); + modem_ptr = 0; + modem_buf[modem_ptr] = 0; + return; + } + + if (modem_ptr >= (sizeof (modem_buf) - 1)) + return; -modem_buf[modem_ptr]=b; -modem_ptr++; -modem_buf[modem_ptr]=0; + modem_buf[modem_ptr] = b; + modem_ptr++; + modem_buf[modem_ptr] = 0; } -void answer_call(void) +void +answer_call (void) { - printf("Answering call\r\n"); - modem_send("ATA"); + printf ("Answering call\r\n"); + modem_send ("ATA"); } -void terminate_call(void) { - printf("Terminating any call\r\n"); - modem_send("ATH0"); +void +terminate_call (void) +{ + printf ("Terminating any call\r\n"); + modem_send ("ATH0"); } -void modem_tick(void) { +void +modem_tick (void) +{ -if (sleepy