-
Notifications
You must be signed in to change notification settings - Fork 2
/
fun.bak
104 lines (95 loc) · 3.26 KB
/
fun.bak
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
int handle_recv_data( ev_io *w , unsigned int *buufer)
{
//printf("server select wait...\n");
if (FD_ISSET(w->fd, &sds))
{
//printf("server FD_ISSET...\n");
int len=0;
len=recv(w->fd,&buffer[i],sizeof(unsigned int),0);
if(len>0)
{
//printf("server buffer[i]=%d\n",buffer[i]);
//@wei
//buffer[i] is not equaled with 0x0a.it specify the data didn't reach END.
while(buffer[i]!=0x0A)
{
i++;
len=recv(w->fd,&buffer[i],sizeof(unsigned int),0);
//printf("server buffer[i]=%d\n",buffer[i]);
}
if(buffer[0]==0x15)
{
temp=buffer[1];
switch(temp)
{
case 0x01:
printf("COMMAND:-------TOPOINFO--------:\n");
Server_GetZigBeeNwkTopo(w->fd);
break;
case 0x02:
printf("COMMAND:-------GetZigBeeNwkInfo--------:\n");
Server_GetZigBeeNwkInfo(w->fd);
break;
case 0x03:
printf("CMOMAND:-------SET_SENSOR_STATUS:--------:\n");//
Server_SetSensorStatus(w->fd,buffer[2],buffer[3]);
break;
case 0x04:
printf("COMMAND:-------GetRfidId--------:\n");
Server_GetRfidId(w->fd);
break;
case 0x05:
printf("COMMAND:-------GetTempHum--------:\n");
Server_GetTempHum(w->fd);
break;
case 0x06:
printf("COMMAND:-------SendGprsMessage--------:\n");//
Server_SendGprsMessage(w->fd,&buffer[2],buffer[13]);
break;
case 0x07:
printf("COMMAND:-------get GPRSSignal--------:\n");
Server_GetGPRSSignal(w->fd);
break;
case 0x08:
printf("COMMAND:-------clear intrupt--------:\n");
gIntLock=0;
break;
default:
printf("error COMMAND\n");
break;
}
}
else
{
printf("other protrol.\n");
}
}
else if(len ==0)
{
printf("remote socket closed!socket fd: %d\n",w->fd);
close(w->fd);
ev_io_stop(loop, w);
free(w);
return;
}
else
{
if(errno == EAGAIN ||errno == EWOULDBLOCK)
{
printf("errno == EAGAIN ||errno == EWOULDBLOCK\n");
//goto loop;
}
else
{
printf("ret :%d ,close socket fd : %d\n",ret,w->fd);
close(w->fd);
ev_io_stop(loop, w);
free(w);
return;
}
}
}
else{
printf("not server fd.\n");
}
}