summaryrefslogtreecommitdiff
path: root/fw/esp32/components/eos/cell_sms.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/esp32/components/eos/cell_sms.c')
-rw-r--r--fw/esp32/components/eos/cell_sms.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/fw/esp32/components/eos/cell_sms.c b/fw/esp32/components/eos/cell_sms.c
index 9876ef8..56e282a 100644
--- a/fw/esp32/components/eos/cell_sms.c
+++ b/fw/esp32/components/eos/cell_sms.c
@@ -139,7 +139,7 @@ static int sms_encode(unsigned char *buffer, uint16_t len) {
len -= 2;
if (len < 2) return EOS_ERR;
- switch(buffer[0]) {
+ switch (buffer[0]) {
case EOS_CELL_SMS_ADDRTYPE_INTL:
addr_type = GSM_EXT | GSM_TON_INTERNATIONAL | GSM_NPI_TELEPHONE;
break;
@@ -183,10 +183,11 @@ static int sms_encode(unsigned char *buffer, uint16_t len) {
void eos_cell_sms_handler(unsigned char mtype, unsigned char *buffer, uint16_t buf_len) {
int rv;
- char b[4];
+ buffer++;
+ buf_len--;
switch (mtype) {
- case EOS_CELL_MTYPE_SMS_LIST:
+ case EOS_CELL_MTYPE_SMS_LIST: {
if (buf_len < 1) return;
rv = snprintf(cmd, sizeof(cmd), "AT+CMGL=%d\r", buffer[0]);
@@ -201,7 +202,7 @@ void eos_cell_sms_handler(unsigned char mtype, unsigned char *buffer, uint16_t b
uint16_t len;
rv = at_expect("^\\+CMGL: [0-9]+,[0-9],.*,[0-9]+$", "^OK", 1000);
- if (rv != 1) break;
+ if (rv) break;
rv = eos_modem_readln(pdu, sizeof(pdu), 1000);
if (rv) break;
@@ -220,8 +221,11 @@ void eos_cell_sms_handler(unsigned char mtype, unsigned char *buffer, uint16_t b
eos_modem_give();
break;
+ }
+
+ case EOS_CELL_MTYPE_SMS_SEND: {
+ char b[4];
- case EOS_CELL_MTYPE_SMS_SEND:
rv = sms_encode(buffer, buf_len);
if (rv) return;
@@ -236,14 +240,17 @@ void eos_cell_sms_handler(unsigned char mtype, unsigned char *buffer, uint16_t b
eos_modem_read(b, 4, 1000);
at_cmd(pdu);
rv = at_expect("^\\+CMGS: [0-9]+", "^ERROR", 5000);
- if (rv == 1) rv = at_expect("^OK", "^ERROR", 1000);
+ if (!rv) rv = at_expect("^OK", "^ERROR", 1000);
eos_modem_give();
break;
+ }
}
}
static void sms_received_handler(char *urc, regmatch_t m[]) {
+ unsigned char *buf;
+ uint16_t len;
int ref, rv;
sscanf(urc + m[1].rm_so, "%d", &ref);
@@ -254,26 +261,23 @@ static void sms_received_handler(char *urc, regmatch_t m[]) {
at_cmd(cmd);
rv = at_expect("^\\+CMGR: [0-9],.*,[0-9]+$", "^ERROR", 1000);
- if (rv == 1) {
- unsigned char *buf;
- uint16_t len;
+ if (rv) return;
- rv = eos_modem_readln(pdu, sizeof(pdu), 1000);
- if (rv) return;
+ rv = eos_modem_readln(pdu, sizeof(pdu), 1000);
+ if (rv) return;
- pdu_len = strlen(pdu);
+ pdu_len = strlen(pdu);
- rv = at_expect("^OK", NULL, 1000);
+ rv = at_expect("^OK", NULL, 1000);
- buf = eos_net_alloc();
- buf[0] = EOS_CELL_MTYPE_SMS | EOS_CELL_MTYPE_SMS_MSG_NEW;
- rv = sms_decode(buf + 1, &len);
- if (rv) {
- eos_net_free(buf);
- } else {
- len++;
- eos_net_send(EOS_NET_MTYPE_CELL, buf, len);
- }
+ buf = eos_net_alloc();
+ buf[0] = EOS_CELL_MTYPE_SMS | EOS_CELL_MTYPE_SMS_MSG_NEW;
+ rv = sms_decode(buf + 1, &len);
+ if (rv) {
+ eos_net_free(buf);
+ } else {
+ len++;
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, len);
}
}