summaryrefslogtreecommitdiff
path: root/fw/esp32
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-02-27 03:17:28 +0100
committerUros Majstorovic <majstor@majstor.org>2021-02-27 03:17:28 +0100
commit9ce2ce35d5f94c5d0b83ca8d9ceb21c8c1cf3cd4 (patch)
tree6436b73665b3f093f498398d43a020b1a71e1137 /fw/esp32
parentfe1d292f241bc7a024a9c20627f6300f3ebc433b (diff)
cell/wifi refactoring
Diffstat (limited to 'fw/esp32')
-rw-r--r--fw/esp32/components/eos/cell.c16
-rw-r--r--fw/esp32/components/eos/cell_modem.c2
-rw-r--r--fw/esp32/components/eos/cell_pcm.c4
-rw-r--r--fw/esp32/components/eos/cell_pdp.c (renamed from fw/esp32/components/eos/cell_data.c)8
-rw-r--r--fw/esp32/components/eos/cell_voice.c4
-rw-r--r--fw/esp32/components/eos/include/cell.h36
-rw-r--r--fw/esp32/components/eos/include/wifi.h9
-rwxr-xr-xfw/esp32/components/eos/wifi.c35
8 files changed, 55 insertions, 59 deletions
diff --git a/fw/esp32/components/eos/cell.c b/fw/esp32/components/eos/cell.c
index 886cc7a..b31e973 100644
--- a/fw/esp32/components/eos/cell.c
+++ b/fw/esp32/components/eos/cell.c
@@ -49,18 +49,6 @@ static void _cell_handler(unsigned char _mtype, unsigned char *buffer, uint16_t
case EOS_CELL_MTYPE_UART_GIVE:
eos_modem_set_mode(cell_mode);
break;
-
- case EOS_CELL_MTYPE_PCM_DATA:
- eos_cell_pcm_push(buffer+1, size-1);
- break;
-
- case EOS_CELL_MTYPE_PCM_START:
- eos_cell_pcm_start();
- break;
-
- case EOS_CELL_MTYPE_PCM_STOP:
- eos_cell_pcm_stop();
- break;
}
break;
@@ -76,8 +64,8 @@ static void _cell_handler(unsigned char _mtype, unsigned char *buffer, uint16_t
eos_cell_ussd_handler(mtype & ~EOS_CELL_MTYPE_MASK, buffer, size);
break;
- case EOS_CELL_MTYPE_DATA:
- eos_cell_data_handler(mtype & ~EOS_CELL_MTYPE_MASK, buffer, size);
+ case EOS_CELL_MTYPE_PDP:
+ eos_cell_pdp_handler(mtype & ~EOS_CELL_MTYPE_MASK, buffer, size);
break;
}
}
diff --git a/fw/esp32/components/eos/cell_modem.c b/fw/esp32/components/eos/cell_modem.c
index 3bbce90..58dc97c 100644
--- a/fw/esp32/components/eos/cell_modem.c
+++ b/fw/esp32/components/eos/cell_modem.c
@@ -364,7 +364,7 @@ static void ppp_status_cb(ppp_pcb *pcb, int err_code, void *ctx) {
ESP_LOGI(TAG," his_ipaddr = %s\n", ipaddr_ntoa(&pppif->gw));
ESP_LOGI(TAG," netmask = %s\n", ipaddr_ntoa(&pppif->netmask));
rbuf = eos_net_alloc();
- rbuf[0] = EOS_CELL_MTYPE_DATA | EOS_CELL_MTYPE_DATA_CONNECT;
+ rbuf[0] = EOS_CELL_MTYPE_PDP | EOS_CELL_MTYPE_PDP_CONNECT;
rbuf[1] = EOS_OK;
eos_net_send(EOS_NET_MTYPE_CELL, rbuf, 2);
return;
diff --git a/fw/esp32/components/eos/cell_pcm.c b/fw/esp32/components/eos/cell_pcm.c
index 4930d66..cf3eeb7 100644
--- a/fw/esp32/components/eos/cell_pcm.c
+++ b/fw/esp32/components/eos/cell_pcm.c
@@ -61,14 +61,14 @@ static void i2s_event_task(void *pvParameters) {
// Event of I2S receiving data
if (!hold_cnt) {
buf = eos_net_alloc();
- buf[0] = EOS_CELL_MTYPE_DEV | EOS_CELL_MTYPE_PCM_DATA;
+ buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_PCM;
bytes_r = eos_cell_pcm_read(buf + 1, PCM_MIC_WM);
eos_net_send(EOS_NET_MTYPE_CELL, buf, bytes_r + 1);
} else {
hold_cnt--;
if (hold_buf == NULL) {
hold_buf = eos_net_alloc();
- hold_buf[0] = EOS_CELL_MTYPE_DEV | EOS_CELL_MTYPE_PCM_DATA;
+ hold_buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_PCM;
}
if (1 + hold_bytes_r + PCM_MIC_WM <= EOS_NET_SIZE_BUF) hold_bytes_r += eos_cell_pcm_read(hold_buf + 1 + hold_bytes_r, PCM_MIC_WM);
if (hold_cnt == 0) {
diff --git a/fw/esp32/components/eos/cell_data.c b/fw/esp32/components/eos/cell_pdp.c
index f9a755f..1aa0575 100644
--- a/fw/esp32/components/eos/cell_data.c
+++ b/fw/esp32/components/eos/cell_pdp.c
@@ -6,13 +6,13 @@
#include "eos.h"
#include "cell.h"
-void eos_cell_data_handler(unsigned char mtype, unsigned char *buffer, uint16_t size) {
+void eos_cell_pdp_handler(unsigned char mtype, unsigned char *buffer, uint16_t size) {
char *apn, *user, *pass;
buffer += 1;
size -= 1;
switch (mtype) {
- case EOS_CELL_MTYPE_DATA_CONFIGURE:
+ case EOS_CELL_MTYPE_PDP_CONFIG:
apn = (char *)buffer;
user = apn + strlen(apn) + 1;
pass = user + strlen(user) + 1;
@@ -20,11 +20,11 @@ void eos_cell_data_handler(unsigned char mtype, unsigned char *buffer, uint16_t
eos_ppp_set_auth(user, pass);
break;
- case EOS_CELL_MTYPE_DATA_CONNECT:
+ case EOS_CELL_MTYPE_PDP_CONNECT:
eos_ppp_connect();
break;
- case EOS_CELL_MTYPE_DATA_DISCONNECT:
+ case EOS_CELL_MTYPE_PDP_DISCONNECT:
eos_ppp_disconnect();
break;
}
diff --git a/fw/esp32/components/eos/cell_voice.c b/fw/esp32/components/eos/cell_voice.c
index f820b63..f0655bd 100644
--- a/fw/esp32/components/eos/cell_voice.c
+++ b/fw/esp32/components/eos/cell_voice.c
@@ -57,6 +57,10 @@ void eos_cell_voice_handler(unsigned char mtype, unsigned char *buffer, uint16_t
eos_modem_give();
break;
+
+ case EOS_CELL_MTYPE_VOICE_PCM:
+ eos_cell_pcm_push(buffer+1, size-1);
+ break;
}
}
diff --git a/fw/esp32/components/eos/include/cell.h b/fw/esp32/components/eos/include/cell.h
index 07d1144..fa9a0e2 100644
--- a/fw/esp32/components/eos/include/cell.h
+++ b/fw/esp32/components/eos/include/cell.h
@@ -6,7 +6,7 @@
#define EOS_CELL_MTYPE_SMS 0x30
#define EOS_CELL_MTYPE_CBS 0x40
#define EOS_CELL_MTYPE_USSD 0x50
-#define EOS_CELL_MTYPE_DATA 0x70
+#define EOS_CELL_MTYPE_PDP 0x60
#define EOS_CELL_MTYPE_MASK 0xf0
#define EOS_CELL_MAX_MTYPE 8
@@ -16,20 +16,18 @@
#define EOS_CELL_MTYPE_UART_DATA 2
#define EOS_CELL_MTYPE_UART_TAKE 3
#define EOS_CELL_MTYPE_UART_GIVE 4
-#define EOS_CELL_MTYPE_PCM_DATA 5
-#define EOS_CELL_MTYPE_PCM_START 6
-#define EOS_CELL_MTYPE_PCM_STOP 7
-#define EOS_CELL_MTYPE_RESET 8
-
-#define EOS_CELL_MTYPE_VOICE_DIAL 1
-#define EOS_CELL_MTYPE_VOICE_RING 2
-#define EOS_CELL_MTYPE_VOICE_ANSWER 3
-#define EOS_CELL_MTYPE_VOICE_HANGUP 4
-#define EOS_CELL_MTYPE_VOICE_BEGIN 5
-#define EOS_CELL_MTYPE_VOICE_END 6
-#define EOS_CELL_MTYPE_VOICE_MISS 7
-#define EOS_CELL_MTYPE_VOICE_BUSY 8
-#define EOS_CELL_MTYPE_VOICE_ERR 9
+#define EOS_CELL_MTYPE_RESET 5
+
+#define EOS_CELL_MTYPE_VOICE_PCM 1
+#define EOS_CELL_MTYPE_VOICE_DIAL 2
+#define EOS_CELL_MTYPE_VOICE_RING 3
+#define EOS_CELL_MTYPE_VOICE_ANSWER 4
+#define EOS_CELL_MTYPE_VOICE_HANGUP 5
+#define EOS_CELL_MTYPE_VOICE_BEGIN 6
+#define EOS_CELL_MTYPE_VOICE_END 7
+#define EOS_CELL_MTYPE_VOICE_MISS 8
+#define EOS_CELL_MTYPE_VOICE_BUSY 9
+#define EOS_CELL_MTYPE_VOICE_ERR 10
#define EOS_CELL_MTYPE_SMS_LIST 1
#define EOS_CELL_MTYPE_SMS_SEND 2
@@ -40,9 +38,9 @@
#define EOS_CELL_MTYPE_USSD_REPLY 2
#define EOS_CELL_MTYPE_USSD_CANCEL 3
-#define EOS_CELL_MTYPE_DATA_CONFIGURE 1
-#define EOS_CELL_MTYPE_DATA_CONNECT 2
-#define EOS_CELL_MTYPE_DATA_DISCONNECT 3
+#define EOS_CELL_MTYPE_PDP_CONFIG 1
+#define EOS_CELL_MTYPE_PDP_CONNECT 2
+#define EOS_CELL_MTYPE_PDP_DISCONNECT 3
#define EOS_CELL_SMS_ADDRTYPE_INTL 1
#define EOS_CELL_SMS_ADDRTYPE_ALPHA 2
@@ -86,7 +84,7 @@ void eos_cell_pcm_stop(void);
void eos_cell_voice_handler(unsigned char mtype, unsigned char *buffer, uint16_t size);
void eos_cell_sms_handler(unsigned char mtype, unsigned char *buffer, uint16_t size);
void eos_cell_ussd_handler(unsigned char mtype, unsigned char *buffer, uint16_t size);
-void eos_cell_data_handler(unsigned char mtype, unsigned char *buffer, uint16_t size);
+void eos_cell_pdp_handler(unsigned char mtype, unsigned char *buffer, uint16_t size);
void eos_cell_voice_init(void);
void eos_cell_sms_init(void);
diff --git a/fw/esp32/components/eos/include/wifi.h b/fw/esp32/components/eos/include/wifi.h
index d579fc5..11bccec 100644
--- a/fw/esp32/components/eos/include/wifi.h
+++ b/fw/esp32/components/eos/include/wifi.h
@@ -1,12 +1,13 @@
#define EOS_WIFI_MTYPE_SCAN 1
-#define EOS_WIFI_MTYPE_CONNECT 2
-#define EOS_WIFI_MTYPE_DISCONNECT 3
+#define EOS_WIFI_MTYPE_CONFIG 2
+#define EOS_WIFI_MTYPE_CONNECT 3
+#define EOS_WIFI_MTYPE_DISCONNECT 4
-#define EOS_WIFI_MAX_MTYPE 4
+#define EOS_WIFI_MAX_MTYPE 5
void eos_wifi_init(void);
int eos_wifi_scan(void);
-int eos_wifi_set_auth(char *ssid, char *pass);
+int eos_wifi_set_config(char *ssid, char *pass);
int eos_wifi_connect(void);
int eos_wifi_disconnect(void);
diff --git a/fw/esp32/components/eos/wifi.c b/fw/esp32/components/eos/wifi.c
index 7fae635..05c91c1 100755
--- a/fw/esp32/components/eos/wifi.c
+++ b/fw/esp32/components/eos/wifi.c
@@ -126,14 +126,8 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t e
if (_disconnect) {
rbuf = eos_net_alloc();
- if (_action == WIFI_ACTION_CONNECT) {
- rbuf[0] = EOS_WIFI_MTYPE_CONNECT;
- rbuf[1] = EOS_ERR;
- eos_net_send(EOS_NET_MTYPE_WIFI, rbuf, 2);
- } else {
- rbuf[0] = EOS_WIFI_MTYPE_DISCONNECT;
- eos_net_send(EOS_NET_MTYPE_WIFI, rbuf, 1);
- }
+ rbuf[0] = EOS_WIFI_MTYPE_DISCONNECT;
+ eos_net_send(EOS_NET_MTYPE_WIFI, rbuf, 1);
if (!_action) ret = esp_wifi_stop();
} else {
ret = esp_wifi_connect();
@@ -175,26 +169,37 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, int32_t e
}
static void wifi_handler(unsigned char _mtype, unsigned char *buffer, uint16_t size) {
- int rv = EOS_OK;
- uint8_t mtype = buffer[0];
+ uint8_t mtype;
+ int rv;
char *ssid, *pass;
+ if (size < 1) return;
+
+ mtype = buffer[0];
+ rv = EOS_OK;
+ buffer += 1;
+ size -= 1;
+
switch (mtype) {
case EOS_WIFI_MTYPE_SCAN:
rv = eos_wifi_scan();
break;
+ case EOS_WIFI_MTYPE_CONFIG:
+ ssid = (char *)buffer;
+ pass = ssid + strlen(ssid) + 1;
+ rv = eos_wifi_set_config(ssid, pass);
+ break;
+
case EOS_WIFI_MTYPE_CONNECT:
- ssid = (char *)buffer+1;
- pass = ssid+strlen(ssid)+1;
- rv = eos_wifi_set_auth(ssid, pass);
- if (!rv) rv = eos_wifi_connect();
+ rv = eos_wifi_connect();
break;
case EOS_WIFI_MTYPE_DISCONNECT:
rv = eos_wifi_disconnect();
break;
}
+
if (rv) ESP_LOGE(TAG, "MSG HANDLER ERR:%d MSG:%d", rv, mtype);
}
@@ -264,7 +269,7 @@ int eos_wifi_scan(void) {
return rv;
}
-int eos_wifi_set_auth(char *ssid, char *pass) {
+int eos_wifi_set_config(char *ssid, char *pass) {
int rv = EOS_OK;
xSemaphoreTake(mutex, portMAX_DELAY);