summaryrefslogtreecommitdiff
path: root/fw/fe310/phone/sms.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/phone/sms.c')
-rw-r--r--fw/fe310/phone/sms.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/fw/fe310/phone/sms.c b/fw/fe310/phone/sms.c
new file mode 100644
index 0000000..d2819c9
--- /dev/null
+++ b/fw/fe310/phone/sms.c
@@ -0,0 +1,109 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <eos.h>
+#include <soc/i2s.h>
+#include <dev/net.h>
+#include <net/cell.h>
+
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
+
+#include "app/app.h"
+#include "app/status.h"
+
+#include "sms.h"
+
+static void handle_cell_sms(unsigned char type, unsigned char *buffer, uint16_t len) {
+ int rv;
+
+ switch (type) {
+ case EOS_CELL_MTYPE_SMS_MSG: {
+ char num[EOS_CELL_MAX_DIAL_STR + 1], text[EOS_CELL_MAX_SMS_TEXT + 1];
+
+ rv = eos_cell_sms_recv(buffer, len, num, sizeof(num), text, sizeof(text));
+ if (rv) {
+ APP_LOG(APP_LOG_ERR, "SMS PARSE ERR:%d\n", rv);
+ break;
+ }
+ APP_LOG(APP_LOG_DEBUG, "SMS From:%s\n%s\n", num, text);
+ break;
+ }
+ }
+ eos_net_free(buffer, 0);
+}
+
+static void send(char *num, char *text) {
+ int rv;
+
+ if (strlen(num)) {
+ app_status_set_msg("SMS SENT");
+ rv = eos_cell_sms_send(num, text, NULL, 0);
+ if (rv) APP_LOG(APP_LOG_ERR, "SMS SEND ERR:%d\n", rv);
+ }
+
+}
+
+void sms_init(void) {
+ eos_cell_set_handler(EOS_CELL_MTYPE_SMS, handle_cell_sms);
+}
+
+int sms_app(EVEWindow *window, EVEViewStack *stack) {
+ EVEFormSpec spec[] = {
+ {
+ .label.title = "Text:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.tspec.str.str_size = EOS_CELL_MAX_SMS_TEXT + 1,
+ },
+ APP_SPACERW(APP_SCREEN_W, 50),
+ {
+ .label.title = "Phone:",
+
+ .widget.type = EVE_WIDGET_TYPE_STR,
+ .widget.tspec.str.str_size = EOS_CELL_MAX_DIAL_STR + 1,
+ },
+ };
+
+ EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), NULL, sms_close);
+ if (page == NULL) {
+ APP_LOG(APP_LOG_ERR, "OUT OF MEMORY\n");
+ return EVE_ERR_NOMEM;
+ }
+
+ return EVE_OK;
+}
+
+int sms_uievt(EVEPage *page, uint16_t evt, void *param) {
+ int ret = 0;
+
+ switch (evt) {
+ case EVE_UIEVT_WIDGET_FOCUS_OUT: {
+ if (param == eve_page_widget(page, 1)) {
+ EVEStrWidget *num = param;
+ EVEStrWidget *text = (EVEStrWidget *)eve_page_widget(page, 0);
+
+ send(num->str, text->str);
+ }
+ break;
+ }
+
+ default: {
+ ret = eve_form_uievt(page, evt, param);
+ break;
+ }
+ }
+
+ return ret;
+}
+
+void sms_close(EVEPage *page) {
+ eve_form_destroy(page);
+}