From 223246228c5224a91147a98dc394ea60efab81ef Mon Sep 17 00:00:00 2001 From: James Maki Date: Wed, 28 Apr 2010 09:57:12 -0500 Subject: optional at command init --- src/atcmd.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 10 deletions(-) (limited to 'src/atcmd.c') diff --git a/src/atcmd.c b/src/atcmd.c index 10470c1..55d2ebc 100644 --- a/src/atcmd.c +++ b/src/atcmd.c @@ -566,6 +566,21 @@ int atcmd_e_write(int fd, int mode) return 0; } +int atcmd_v_write(int fd, int mode) +{ + char buf[ATCMD_LINE_SIZE]; + int tmp; + + atcmd_writeline(fd, "ATV%d", mode); + tmp = atcmd_expect_line(fd, buf, sizeof(buf), "OK"); + if (tmp <= 0) { + log_debug("expected OK but it was not received"); + return -1; + } + + return 0; +} + int atcmd_plus_cmgf_write(int fd, int mode) { char buf[ATCMD_LINE_SIZE]; @@ -1045,30 +1060,39 @@ int atcmd_plus_cpbr_test(int fd, struct phonebook_store *store) int atcmd_init(int fd, int read_timeout) { - char buf[ATCMD_LINE_SIZE]; int tmp; - tmp = tty_set_read_timeout(fd, read_timeout); + tmp = atcmd_v_write(fd, 1); if (tmp < 0) { return tmp; } - atcmd_writeline(fd, "ATV1"); - tmp = atcmd_expect_line(fd, buf, sizeof(buf), "OK"); - if (tmp <= 0) { - log_debug("expected OK but it was not received"); - return -1; - } - tmp = atcmd_e_write(fd, 0); if (tmp < 0) { return tmp; } + return 0; +} + +static int sms_atcmd_init(int fd) +{ + int tmp; + struct msg_store read_store; struct msg_store send_store; struct msg_store new_store; + tmp = atcmd_init(fd, Global.core.read_timeout); + if (tmp < 0) { + return -1; + } + + tmp = atcmd_plus_cmgf_write(fd, SMS_PDU_MODE); + if (tmp < 0) { + return -1; + } + memset(&read_store, 0, sizeof(read_store)); memset(&send_store, 0, sizeof(send_store)); memset(&new_store, 0, sizeof(new_store)); @@ -1079,9 +1103,39 @@ int atcmd_init(int fd, int read_timeout) &send_store.selected, &new_store.selected); if (Global.core.msg_store_read && Global.core.msg_store_send && Global.core.msg_store_new) { - atcmd_plus_cpms_write(fd, Global.core.msg_store_read, + tmp = atcmd_plus_cpms_write(fd, Global.core.msg_store_read, Global.core.msg_store_send, Global.core.msg_store_new); + if (tmp < 0) { + return -1; + } } return 0; } + +int sms_device_open(void) +{ + int fd; + int tmp; + + fd = tty_open(Global.core.device, Global.core.baud_rate); + if (fd < 0) { + return -1; + } + + tmp = tty_set_read_timeout(fd, Global.core.read_timeout); + if (tmp < 0) { + close(fd); + return tmp; + } + + if (Global.core.sms_init) { + tmp = sms_atcmd_init(fd); + if (tmp < 0) { + close(fd); + return tmp; + } + } + + return fd; +} -- cgit v1.2.3