1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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);
}
|