diff options
Diffstat (limited to 'fw/fe310/test')
-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 |
7 files changed, 93 insertions, 60 deletions
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) { |