-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgrs.c
150 lines (120 loc) · 2.87 KB
/
msgrs.c
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <rtthread.h>
#include "../ipmsg.h"
#include <string.h>
#define DBG_TAG "msgrs"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
#if (defined(SOC_W600_A8xx))
#include "wm_fwup.h"
static T_BOOTER _booter;
static int file_notify(struct ipmsg_filehandler *h, ipmsg_fileevent_t e, void *arg)
{
LOG_I("notify %d", e);
switch (e)
{
case IPMSG_FE_OPEN:
h->usrdata = 0;
h->param = 0;
break;
case IPMSG_FE_COMPLETE:
tls_fwup_img_update_header(&_booter);
break;
}
return 0;
}
static int file_data(struct ipmsg_filehandler *h, void *buf, int size)
{
if (h->usrdata == 0)
{
memcpy(&_booter, buf, sizeof(_booter));
tls_fwup_img_write(h->usrdata, (char*)buf + sizeof(_booter), size - sizeof(_booter));
h->usrdata += (size - sizeof(_booter));
}
else
{
tls_fwup_img_write(h->usrdata, buf, size);
h->usrdata += size;
}
return size;
}
#else
static int file_notify(struct ipmsg_filehandler *h, ipmsg_fileevent_t e, void *arg)
{
LOG_I("notify %d", e);
return 0;
}
static int file_data(struct ipmsg_filehandler *h, void *buf, int size)
{
LOG_I("data %d", size);
return size;
}
#endif
static void text_msg(ipmsg_t *im, uint32_t ip, const char *buf)
{
if (strncmp(buf, "rename ", 7) == 0)
{
ipmsg_user_set(im, buf + 7);
ipmsg_msg_send(im, ip, "YiJingGaiLe");
return;
}
if (strncmp(buf, "reboot", 7) == 0)
{
ipmsg_msg_send(im, ip, "ShaoHouChongQi");
rt_thread_mdelay(100);
rt_hw_cpu_reset();
return;
}
ipmsg_msg_send(im, ip, "ShouDao");
}
static int fileattach_msg(ipmsg_t *im, ipmsg_filehandler_t *fh)
{
int ret = 0;
fh->data = file_data;
fh->notify = file_notify;
return ret;
}
static const ipmsg_msghandler_t _h =
{
text_msg,
fileattach_msg,
};
static void msg_server(void *p)
{
ipmsg_t im;
rt_tick_t t = 0;
while (1)
{
rt_thread_mdelay(5000);
if (ipmsg_msgserver_init(&im, 2425) == 0)
break;
}
LOG_D("login");
ipmsg_login(&im);
while (1)
{
if ((rt_tick_get() - t) > (RT_TICK_PER_SECOND * 60))
{
t = rt_tick_get();
ipmsg_login(&im);
}
ipmsg_msg_recv(&im, 100, &_h);
}
ipmsg_msgserver_deinit(&im);
}
int ipmsg_msgrs_init(void)
{
rt_thread_t tid;
int ret = -1;
tid = rt_thread_create("ipmsg-m",
msg_server,
0,
2048,
22,
20);
if (tid)
{
ret = rt_thread_startup(tid);
}
return ret;
}
INIT_APP_EXPORT(ipmsg_msgrs_init);