diff options
author | Uros Majstorovic <majstor@majstor.org> | 2021-02-27 03:17:28 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2021-02-27 03:17:28 +0100 |
commit | 9ce2ce35d5f94c5d0b83ca8d9ceb21c8c1cf3cd4 (patch) | |
tree | 6436b73665b3f093f498398d43a020b1a71e1137 /fw/fe310 | |
parent | fe1d292f241bc7a024a9c20627f6300f3ebc433b (diff) |
cell/wifi refactoring
Diffstat (limited to 'fw/fe310')
-rw-r--r-- | fw/fe310/eos/cell.h | 34 | ||||
-rw-r--r-- | fw/fe310/eos/wifi.c | 25 | ||||
-rw-r--r-- | fw/fe310/eos/wifi.h | 11 | ||||
-rw-r--r-- | fw/fe310/test/Makefile | 2 | ||||
-rw-r--r-- | fw/fe310/test/cell_data.h | 4 | ||||
-rw-r--r-- | fw/fe310/test/cell_pdp.c (renamed from fw/fe310/test/cell_data.c) | 62 | ||||
-rw-r--r-- | fw/fe310/test/cell_pdp.h | 4 | ||||
-rw-r--r-- | fw/fe310/test/main.c | 9 | ||||
-rw-r--r-- | fw/fe310/test/phone.c | 39 | ||||
-rw-r--r-- | fw/fe310/test/wifi.c | 33 |
10 files changed, 113 insertions, 110 deletions
diff --git a/fw/fe310/eos/cell.h b/fw/fe310/eos/cell.h index 90bb349..0fc2052 100644 --- a/fw/fe310/eos/cell.h +++ b/fw/fe310/eos/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 diff --git a/fw/fe310/eos/wifi.c b/fw/fe310/eos/wifi.c index c3449e8..ca29a95 100644 --- a/fw/fe310/eos/wifi.c +++ b/fw/fe310/eos/wifi.c @@ -43,28 +43,3 @@ eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype) { if (mtype < EOS_WIFI_MAX_MTYPE) return evt_handler[mtype]; return NULL; } - -void eos_wifi_scan(void) { - unsigned char *buffer = eos_net_alloc(); - buffer[0] = EOS_WIFI_MTYPE_SCAN; - eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0); -} - -void eos_wifi_connect(const char *ssid, const char *pass) { - int ssid_len = strlen(ssid); - int pass_len = strlen(pass); - unsigned char *buffer = eos_net_alloc(); - - buffer[0] = EOS_WIFI_MTYPE_CONNECT; - strcpy(buffer+1, ssid); - buffer[ssid_len+1] = 0; - strcpy(buffer+ssid_len+2, pass); - buffer[ssid_len+pass_len+2] = 0; - eos_net_send(EOS_NET_MTYPE_WIFI, buffer, ssid_len+pass_len+3, 0); -} - -void eos_wifi_disconnect(void) { - unsigned char *buffer = eos_net_alloc(); - buffer[0] = EOS_WIFI_MTYPE_DISCONNECT; - eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0); -} diff --git a/fw/fe310/eos/wifi.h b/fw/fe310/eos/wifi.h index 57048af..bb629ed 100644 --- a/fw/fe310/eos/wifi.h +++ b/fw/fe310/eos/wifi.h @@ -2,15 +2,12 @@ #include "event.h" #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); void eos_wifi_set_handler(unsigned char mtype, eos_evt_handler_t handler); eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype); - -void eos_wifi_scan(void); -void eos_wifi_connect(const char *ssid, const char *pass); -void eos_wifi_disconnect(void); diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile index 53e6f2d..aef5f29 100644 --- a/fw/fe310/test/Makefile +++ b/fw/fe310/test/Makefile @@ -3,7 +3,7 @@ include ../common.mk CFLAGS += -I../eos -I../bsp/include -I../bsp/drivers LDFLAGS = $(CFLAGS) -L.. -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -Wl,--end-group -T../bsp/default.lds -DEPS = main.o status.o phone.o wifi.o cell_data.o modem.o +DEPS = main.o status.o cell_dev.o cell_pdp.o phone.o modem.o wifi.o TARGET = phone all: $(TARGET) diff --git a/fw/fe310/test/cell_data.h b/fw/fe310/test/cell_data.h deleted file mode 100644 index 69ae2ef..0000000 --- a/fw/fe310/test/cell_data.h +++ /dev/null @@ -1,4 +0,0 @@ -void app_cell_data(EVEWindow *window, EVEViewStack *stack); -void app_cell_data_action(EVEForm *form); -void app_cell_data_close(EVEForm *form); -void app_cell_data_init(void);
\ No newline at end of file diff --git a/fw/fe310/test/cell_data.c b/fw/fe310/test/cell_pdp.c index 007fa0b..955b42e 100644 --- a/fw/fe310/test/cell_data.c +++ b/fw/fe310/test/cell_pdp.c @@ -26,17 +26,42 @@ #include <app/root.h> #include "status.h" -#include "cell_data.h" +#include "cell_pdp.h" extern EVEFont *_app_font_default; -static void cell_data_handler(unsigned char type, unsigned char *buffer, uint16_t size) { +static void cell_pdp_connect(char *apn, char *user, char *pass) { + unsigned char *buffer, *p; + + buffer = eos_net_alloc(); + buffer[0] = EOS_CELL_MTYPE_PDP | EOS_CELL_MTYPE_PDP_CONFIG; + p = buffer + 1; + strcpy(p, user); + p += strlen(user) + 1; + strcpy(p, user); + p += strlen(user) + 1; + strcpy(p, pass); + p += strlen(pass) + 1; + eos_net_send(EOS_NET_MTYPE_CELL, buffer, p - buffer, 1); + + buffer = eos_net_alloc(); + buffer[0] = EOS_CELL_MTYPE_PDP | EOS_CELL_MTYPE_PDP_CONNECT; + eos_net_send(EOS_NET_MTYPE_CELL, buffer, 1, 0); +} + +static void cell_pdp_disconnect(void) { + unsigned char *buffer = eos_net_alloc(); + buffer[0] = EOS_CELL_MTYPE_PDP | EOS_CELL_MTYPE_PDP_DISCONNECT; + eos_net_send(EOS_NET_MTYPE_CELL, buffer, 1, 0); +} + +static void cell_pdp_handler(unsigned char type, unsigned char *buffer, uint16_t size) { switch (type) { - case EOS_CELL_MTYPE_DATA_CONNECT: + case EOS_CELL_MTYPE_PDP_CONNECT: app_status_msg_set("Cell data connected", 1); break; - case EOS_CELL_MTYPE_DATA_DISCONNECT: + case EOS_CELL_MTYPE_PDP_DISCONNECT: app_status_msg_set("Cell data disconnected", 1); break; @@ -46,7 +71,7 @@ static void cell_data_handler(unsigned char type, unsigned char *buffer, uint16_ eos_net_free(buffer, 0); } -void app_cell_data(EVEWindow *window, EVEViewStack *stack) { +void app_cell_pdp(EVEWindow *window, EVEViewStack *stack) { APPWidgetSpec spec[] = { { .label.g.w = APP_SCREEN_W / 3, @@ -80,36 +105,21 @@ void app_cell_data(EVEWindow *window, EVEViewStack *stack) { }, }; - EVEForm *form = app_form_create(window, stack, spec, 3, app_cell_data_action, app_cell_data_close); + EVEForm *form = app_form_create(window, stack, spec, 3, app_cell_pdp_action, app_cell_pdp_close); } -void app_cell_data_action(EVEForm *form) { - unsigned char *buf = eos_net_alloc(); - unsigned char *p; +void app_cell_pdp_action(EVEForm *form) { EVEStrWidget *apn = (EVEStrWidget *)eve_form_widget(form, 0); EVEStrWidget *user = (EVEStrWidget *)eve_form_widget(form, 1); EVEStrWidget *pass = (EVEStrWidget *)eve_form_widget(form, 2); - buf[0] = EOS_CELL_MTYPE_DATA | EOS_CELL_MTYPE_DATA_CONFIGURE; - p = buf + 1; - strcpy(p, apn->str); - p += strlen(apn->str) + 1; - strcpy(p, user->str); - p += strlen(user->str) + 1; - strcpy(p, pass->str); - p += strlen(pass->str) + 1; - eos_net_send(EOS_NET_MTYPE_CELL, buf, p - buf, 1); - - eos_net_acquire(); - buf = eos_net_alloc(); - buf[0] = EOS_CELL_MTYPE_DATA | EOS_CELL_MTYPE_DATA_CONNECT; - eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0); + cell_pdp_connect(apn->str, user->str, pass->str); } -void app_cell_data_close(EVEForm *form) { +void app_cell_pdp_close(EVEForm *form) { app_form_destroy(form); } -void app_cell_data_init(void) { - eos_cell_set_handler(EOS_CELL_MTYPE_DATA, cell_data_handler); +void app_cell_pdp_init(void) { + eos_cell_set_handler(EOS_CELL_MTYPE_PDP, cell_pdp_handler); } diff --git a/fw/fe310/test/cell_pdp.h b/fw/fe310/test/cell_pdp.h new file mode 100644 index 0000000..3c28176 --- /dev/null +++ b/fw/fe310/test/cell_pdp.h @@ -0,0 +1,4 @@ +void app_cell_pdp(EVEWindow *window, EVEViewStack *stack); +void app_cell_pdp_action(EVEForm *form); +void app_cell_pdp_close(EVEForm *form); +void app_cell_pdp_init(void);
\ No newline at end of file diff --git a/fw/fe310/test/main.c b/fw/fe310/test/main.c index 095746d..6801b97 100644 --- a/fw/fe310/test/main.c +++ b/fw/fe310/test/main.c @@ -26,10 +26,11 @@ #include <app/root.h> #include "status.h" +#include "cell_dev.h" +#include "cell_pdp.h" #include "phone.h" -#include "wifi.h" -#include "cell_data.h" #include "modem.h" +#include "wifi.h" extern EVEFont *_app_font_default; @@ -54,7 +55,7 @@ void app_home_page(EVEWindow *window, EVEViewStack *stack) { .widget.g.w = APP_SCREEN_W, .widget.spec.page.font = _app_font_default, .widget.spec.page.title = "Cellular data", - .widget.spec.page.constructor = app_cell_data + .widget.spec.page.constructor = app_cell_pdp }, { .widget.type = EVE_WIDGET_TYPE_PAGE, @@ -77,7 +78,7 @@ int main() { app_status_init(); app_phone_init(); app_wifi_init(); - app_cell_data_init(); + app_cell_pdp_init(); eos_evtq_loop(); } diff --git a/fw/fe310/test/phone.c b/fw/fe310/test/phone.c index 6f88698..2832fc4 100644 --- a/fw/fe310/test/phone.c +++ b/fw/fe310/test/phone.c @@ -43,19 +43,13 @@ static uint8_t spk_arr[ABUF_SIZE]; static unsigned char voice_state = 0; -static void cell_dev_handler(unsigned char type, unsigned char *buffer, uint16_t len) { - switch (type) { - case EOS_CELL_MTYPE_READY: - app_status_msg_set("Modem ready", 1); - break; +static void handle_mic(unsigned char type) { + uint16_t size; + unsigned char *buf = eos_net_alloc(); - case EOS_CELL_MTYPE_PCM_DATA: - if (voice_state == VOICE_STATE_CIP) { - eos_i2s_spk_write(buffer+1, len-1); - } - break; - } - eos_net_free(buffer, 0); + buf[0] = EOS_CELL_MTYPE_VOICE_PCM; + size = eos_i2s_mic_read(buf+1, MIC_WM); + eos_net_send(EOS_NET_MTYPE_CELL, buf, size+1, 0); } static void cell_voice_handler(unsigned char type, unsigned char *buffer, uint16_t len) { @@ -68,31 +62,31 @@ static void cell_voice_handler(unsigned char type, unsigned char *buffer, uint16 voice_state = VOICE_STATE_RING; sprintf(msg, "RING:%s", buffer+1); break; + case EOS_CELL_MTYPE_VOICE_MISS: voice_state = VOICE_STATE_IDLE; break; + case EOS_CELL_MTYPE_VOICE_BEGIN: voice_state = VOICE_STATE_CIP; eos_i2s_start(8000, EOS_I2S_FMT_PCM16); break; + case EOS_CELL_MTYPE_VOICE_END: voice_state = VOICE_STATE_IDLE; eos_i2s_stop(); break; + + case EOS_CELL_MTYPE_VOICE_PCM: + if (voice_state == VOICE_STATE_CIP) { + eos_i2s_spk_write(buffer+1, len-1); + } + break; } app_status_msg_set(msg, 1); eos_net_free(buffer, 0); } -static void handle_mic(unsigned char type) { - uint16_t size; - unsigned char *buf = eos_net_alloc(); - - buf[0] = EOS_CELL_MTYPE_PCM_DATA; - size = eos_i2s_mic_read(buf+1, MIC_WM); - eos_net_send(EOS_NET_MTYPE_CELL, buf, size+1, 0); -} - void app_phone(EVEWindow *window, EVEViewStack *stack) { char *title = "Phone:"; uint16_t w = eve_font_str_w(_app_font_default, title) + 10; @@ -122,12 +116,11 @@ void app_phone_action(EVEForm *form) { eos_net_send(EOS_NET_MTYPE_CELL, buf, 1 + strlen(w->str), 0); voice_state = VOICE_STATE_DIAL; - sprintf(msg, "DIAL:%s", w->str); + sprintf(msg, "DIAL:%s", w->str); app_status_msg_set(msg, 0); } void app_phone_init(void) { - eos_cell_set_handler(EOS_CELL_MTYPE_DEV, cell_dev_handler); eos_cell_set_handler(EOS_CELL_MTYPE_VOICE, cell_voice_handler); eos_i2s_mic_init(mic_arr, ABUF_SIZE); diff --git a/fw/fe310/test/wifi.c b/fw/fe310/test/wifi.c index 595a87c..86f6b62 100644 --- a/fw/fe310/test/wifi.c +++ b/fw/fe310/test/wifi.c @@ -30,6 +30,35 @@ extern EVEFont *_app_font_default; +static void wifi_scan(void) { + unsigned char *buffer = eos_net_alloc(); + buffer[0] = EOS_WIFI_MTYPE_SCAN; + eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0); +} + +static void wifi_connect(const char *ssid, const char *pass) { + unsigned char *buffer, *p; + + buffer = eos_net_alloc(); + buffer[0] = EOS_WIFI_MTYPE_CONFIG; + p = buffer + 1; + strcpy(p, ssid); + p += strlen(ssid) + 1; + strcpy(p, pass); + p += strlen(pass) + 1; + eos_net_send(EOS_NET_MTYPE_WIFI, buffer, p - buffer, 1); + + buffer = eos_net_alloc(); + buffer[0] = EOS_WIFI_MTYPE_CONNECT; + eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0); +} + +static void wifi_disconnect(void) { + unsigned char *buffer = eos_net_alloc(); + buffer[0] = EOS_WIFI_MTYPE_DISCONNECT; + eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0); +} + void wifi_scan_handler(unsigned char type, unsigned char *buffer, uint16_t size) { EVEScreen *screen = app_screen(); EVEWindow *window = eve_window_get(screen, "main"); @@ -86,7 +115,7 @@ void app_wifi(EVEWindow *window, EVEViewStack *stack) { }; EVEForm *form = app_form_create(window, stack, spec, 3, app_wifi_action, app_wifi_close); - eos_wifi_scan(); + wifi_scan(); } void app_wifi_action(EVEForm *form) { @@ -94,7 +123,7 @@ void app_wifi_action(EVEForm *form) { EVEStrWidget *str = (EVEStrWidget *)eve_form_widget(form, 2); char *ssid = eve_selectw_option_get_select(sel); - eos_wifi_connect(ssid, str->str); + if (ssid) wifi_connect(ssid, str->str); } void app_wifi_close(EVEForm *form) { |