?? tcpapp.lst
字號:
C51 COMPILER V7.00 TCPAPP 07/28/2005 15:30:01 PAGE 1
C51 COMPILER V7.00, COMPILATION OF MODULE TCPAPP
OBJECT MODULE PLACED IN D:\工作目錄\采集器~1\FORMAL\TCPAPP.OBJ
COMPILER INVOKED BY: C:\KEIL10\C51\BIN\C51.EXE D:\工作目錄\采集器~1\FORMAL\TCPAPP.C DB SB OE
stmt level source
1 /*2003.01.03 modi*/
2 /* 監聽程序后一切重新開始*/
3 /* 串口接收修改為一種類似fifo的結構*/
4 /*在程序里面,判斷是否主動報警,使用這樣一種方法:如果已連接,則使用連接的,否則使用新的*/
5 //freedom about 4k
6 #define ETH_RECV_ADDR 0x1000
7 //about 2k
8 #define ETH_SEND_ADDR 0x1800
9 //about 2k
10 #define SERI_SEND_ADDR 0x2000
11 //about 4k
12 #define SERI_RECE_ADDR 0x3000
13 //about 8k
14 #define SOCKET_ADDR 0x5000
15 //about 12k
16
17
18 //#define REMO_PORT 8000
19 //#define LOCAL_PORT 9000
20 #define tcp_WAITTIMEOUT 60000 /* 可以忍受的最長的等待時間,單位是10ms*/
21
22
23 #include <89c52.h>
24 #include <iptcp.h>
25 #include <card.h>
*** WARNING C280 IN LINE 113 OF X25045.H: 'j': unreferenced local variable
*** WARNING C280 IN LINE 185 OF X25045.H: 'defalut': unreferenced label
*** WARNING C280 IN LINE 49 OF CARD.H: 'tempint': unreferenced local variable
*** WARNING C280 IN LINE 50 OF CARD.H: 'addr': unreferenced local variable
26 #include <x25045.h>
27 #include <8019app.h>
*** WARNING C280 IN LINE 272 OF 8019APP.H: 'temp': unreferenced local variable
*** WARNING C280 IN LINE 273 OF 8019APP.H: 'tempint': unreferenced local variable
28 #include <dmtcp.h>
*** WARNING C280 IN LINE 41 OF ARP.H: 'fail': unreferenced label
*** ERROR C200 IN LINE 59 OF ARP.H: left side of '.' requires struct/union
29
30 //dats in card.h
31 extern eth_address xdata card_mac;
32 extern ulong xdata gate_ip;
33 extern ulong xdata local_ip;
34 extern uint xdata REMO_PORT,LOCAL_PORT;
35 extern uint xdata baudrate;
36 extern uchar xdata *mac;
37
38 uchar xdata *rcv_hdr;
39 uchar xdata *recv_eth;
40 uchar xdata *send_eth;
41
42 uchar xdata *seristart;
43 uchar xdata *seriend;
44
45 uint data_send(uchar xdata *data_addr,uint len,uint local_port,ulong destip,uint remo_port);
46
47 bit txok,rxok;
C51 COMPILER V7.00 TCPAPP 07/28/2005 15:30:01 PAGE 2
48 /*txok 從串口上收到數據,要發送給網絡*/
49 /*rxok 從網絡上收到數據,要發送給串口*/
50 uchar ser_recving;
51
52 tcp_Socket xdata *s;
53
54 uchar code setsip[]={'S','E','T','S','I','P',':'};
55 uchar code setsal[]={'S','E','T','S','A','L',':'};
56
57 uchar code setsma[]={'S','E','T','S','M','A',':'};
58 uchar code setsgt[]={'S','E','T','S','G','T',':'};
59 uchar code setspt[]={'S','E','T','S','P','T',':'};
60 uchar code setsbd[] ={'S','E','T','S','B','D',':'};
61 uchar code setmask[] = {'S','E','T','S','M','K',':'};/*子網掩碼*/
62
63 uchar code TCP_conf[] ={'C','O','N','F','T','C','P',':'};
64 uchar code UDP_conf[] ={'C','O','N','F','U','D','P',':'};
65 /*如果有必要,在發送數據前設置*/
66
67 uchar code setok[10]={'S','E','T','S','B','E','O','K',0x0d,0x0a};
68 uchar code err[5]={'E','R','R',0x0d,0x0a};
69
70 int main(void)
71 {
72 1 uchar xdata *datasend;
73 1 uchar idata temp;
74 1 uint idata tempint;
75 1 watchdog(3);//no dog
76 1 // writebyte(0,0);
77 1 datasend = 0;
78 1 txok=FALSE;
79 1 rxok=FALSE;
80 1 memset(datasend,0,0x8000);
81 1 mac=0;
82 1 s =SOCKET_ADDR;
83 1 datasend=SERI_RECE_ADDR;
84 1
85 1 recv_eth=ETH_RECV_ADDR;
86 1 rcv_hdr =ETH_RECV_ADDR-SIZE_OF_8019_HDR;
87 1 send_eth=ETH_SEND_ADDR;
88 1
89 1 init_card(); //card.h
90 1 init_8019(); //8019app.h
91 1 com_init(); //card.h
92 1 timer0_init_10ms();//time.h
93 1
94 1 EA=1;
95 1
96 1 tcp_listen(LOCAL_PORT);
97 1
98 1 while(1)
99 1 {
100 2 tick();
101 2 if(txok)
102 2 {
103 3 cope_serial();
104 3 }
105 2 if((!rxok)&&(curr_conf.length!=0))
106 2 {
107 3 cope_eth();
108 3 }
109 2 }
C51 COMPILER V7.00 TCPAPP 07/28/2005 15:30:01 PAGE 3
110 1 }
111
112
113
114 uint data_send(uchar xdata *data_addr,uint len,uint local_port,ulong destip,uint remo_port)
115 {
116 1 // if(curr_conf.type==UDP_PROTO)return(udp_out(len,data_addr,destip,remo_port));
117 1
118 1 if ( s->hisaddr != destip )
119 1 {
120 2 tcp_abort();
121 2 }
122 1 if ( s->state != tcp_StateESTAB )
123 1 {
124 2 destip=alert_ip;
125 2 remo_port=REMO_PORT;
126 2 if ( !tcp_open(local_port,destip,remo_port ))return(0);
127 2 if ( !sock_wait_established(tcp_LONGTIMEOUT))return(0);
128 2 }
129 1 if ( !tcp_write(data_addr,len))return(0);
130 1 while(s->datalen)
131 1 {
132 2 tick();
133 2 if(!chk_timeout(tcp_TIMEOUT))break;
134 2 }
135 1 if((s->state==tcp_StateCLOSED)||(s->state==tcp_StateLISTEN))return(FALSE);
136 1 return(len-s->datalen);
137 1 }
138
139 void cope_eth(void)
140 {
141 1 uchar xdata *addr;
142 1 uchar xdata *f_addr;
143 1 uchar temp;
144 1 addr=SERI_SEND_ADDR;
145 1 f_addr=SERI_RECE_ADDR;
146 1
147 1 memcpy(f_addr,setok,10);
148 1 /*如果數據是設置本網絡通的,不發送到串口,向網絡發送設置成功,并初始化板卡*/
149 1
150 1 if(curr_conf.length==13)
151 1 {
152 2 /*設置報警ip*/
153 2 if(memcmp (setsal, addr, 7)==0)
154 2 {
155 3 udp_out(10,f_addr,curr_conf.dst_ip,REMO_PORT);
156 3
157 3 tcp_abort();
158 3 for(temp=0;temp<4;temp++)
159 3 {
160 4 writebyte(addr[temp+7],temp+25);
161 4 }
162 3 init_card();
163 3 curr_conf.length=0;
164 3 tcp_listen(LOCAL_PORT);
165 3 rxok=FALSE;
166 3 return;
167 3 }
168 2
169 2
170 2 /*設置ip*/
171 2 if(memcmp (setmask, addr, 7)==0)
C51 COMPILER V7.00 TCPAPP 07/28/2005 15:30:01 PAGE 4
172 2 {
173 3 udp_out(10,f_addr,curr_conf.dst_ip,REMO_PORT);
174 3 tcp_abort();
175 3 for(temp=0;temp<4;temp++)
176 3 {
177 4 writebyte(addr[temp+7],temp+29);
178 4 }
179 3 init_card();
180 3 curr_conf.length=0;
181 3 tcp_listen(LOCAL_PORT);
182 3 rxok=FALSE;
183 3 return;
184 3 }
185 2 /*設置ip*/
186 2 if(memcmp (setsip, addr, 7)==0)
187 2 {
188 3 udp_out(10,f_addr,curr_conf.dst_ip,REMO_PORT);
189 3 tcp_abort();
190 3 for(temp=0;temp<4;temp++)
191 3 {
192 4 writebyte(addr[temp+7],temp+5);
193 4 }
194 3 init_card();
195 3 curr_conf.length=0;
196 3 tcp_listen(LOCAL_PORT);
197 3 rxok=FALSE;
198 3 return;
199 3 }
200 2 /*設置網關*/
201 2 if(memcmp (setsgt, addr, 7)==0)
202 2 {
203 3 udp_out(10,f_addr,curr_conf.dst_ip,REMO_PORT);
204 3 tcp_abort();
205 3 for(temp=0;temp<4;temp++)
206 3 {
207 4 writebyte(addr[temp+7],temp+9);
208 4 }
209 3 init_card();
210 3 curr_conf.length=0;
211 3 tcp_listen(LOCAL_PORT);
212 3 rxok=FALSE;
213 3 return;
214 3 }
215 2 /*設置端口*/
216 2 if(memcmp (setspt, addr, 7)==0)
217 2 {
218 3 udp_out(10,f_addr,curr_conf.dst_ip,REMO_PORT);
219 3 tcp_abort();
220 3 for(temp=0;temp<4;temp++)
221 3 {
222 4 writebyte(addr[temp+7],temp+19);
223 4 }
224 3 init_card();
225 3 curr_conf.length=0;
226 3 tcp_listen(LOCAL_PORT);
227 3 rxok=FALSE;
228 3 return;
229 3 }
230 2 /*設置波特率*/
231 2 if(memcmp (setsbd, addr, 7)==0)
232 2 {
233 3 udp_out(10,f_addr,curr_conf.dst_ip,REMO_PORT);
C51 COMPILER V7.00 TCPAPP 07/28/2005 15:30:01 PAGE 5
234 3 tcp_abort();
235 3 writebyte(addr[7],23);
236 3 writebyte(addr[8],24);
237 3 // init_card();
238 3 curr_conf.length=0;
239 3 baudrate = addr[7]*0x100+addr[8];
*** ERROR C193 IN LINE 239 OF D:\工作目錄\采集器~1\FORMAL\TCPAPP.C: '*': bad operand type
240 3 com_init();
241 3 // tcp_listen(LOCAL_PORT);
242 3 rxok=FALSE;
243 3 return;
244 3 }
245 2 /*設置物理地址*/
246 2 if(memcmp (setsma, addr , 7)==0)
247 2 {
248 3 udp_out(10,f_addr,curr_conf.dst_ip,REMO_PORT);
249 3 tcp_abort();
250 3 for(temp=0;temp<6;temp++)
251 3 {
252 4 writebyte(addr[temp+7],temp+13);
253 4 }
254 3 curr_conf.length=0;
255 3 rxok=FALSE;
256 3 init_card();
257 3 init_8019();
258 3 tcp_listen(LOCAL_PORT);
259 3 return;
260 3 }
261 2 }
262 1 totalnum=curr_conf.length;
263 1 sendnum=0;
264 1 SBUF=addr[0];
265 1 rxok=TRUE;
266 1 while(rxok);
267 1 }
268
269
270 void cope_serial(void)//see type of serial datas
271 {
272 1 ulong xdata dst_ip;
273 1 uint bufnum;
274 1 ES = 0;
275 1 bufnum = recenum;
276 1 recenum = 0;
277 1 if(seriend>0x4800)seriend = SERI_RECE_ADDR;/*早變換早安全*/
278 1 ES = 1;
279 1 ser_recving=FALSE;
280 1 if(bufnum>0x1800)/*數據量不可能超過6K*/
281 1 {
282 2 seriend =SERI_RECE_ADDR;
283 2 seristart = SERI_RECE_ADDR;
284 2 bufnum = 0;
285 2 return;
286 2 }
287 1
288 1 /*將tcp_conf 和udp_conf一段去掉了*/
289 1
290 1 if(!data_send(seristart,bufnum,LOCAL_PORT,curr_conf.dst_ip,REMO_PORT))
291 1 {
292 2 // memcpy(f_addr,err,5);
293 2 // totalnum=5;
294 2 // sendnum=0;
C51 COMPILER V7.00 TCPAPP 07/28/2005 15:30:01 PAGE 6
295 2 // SBUF=f_addr[0];
296 2 }
297 1 seristart = seristart + bufnum;
298 1 if(seristart>0x4800)seristart = SERI_RECE_ADDR; /*到了末尾,重新開始*/
299 1 bufnum=0;
300 1 txok=FALSE;
301 1 }
302
303
304 void serial(void) interrupt 4
305 {
306 1 uchar xdata *addr;
307 1 if(RI==1)
308 1 {
309 2 // if(txok)
310 2 // {
311 2 //
312 2 // RI=0;return;
313 2 // }
314 2 RI = 0;
315 2 ser_recving=1;
316 2 *(seriend++)=SBUF;
317 2 recenum++;
318 2 if(seriend>=SOCKET_ADDR)seriend = SERI_RECE_ADDR;/*這種現象最好不要出現,*/
319 2 if(recenum>1500)txok = 1;
320 2 }
321 1 if(TI==1)
322 1 {
323 2 addr=SERI_SEND_ADDR;
324 2 TI=0;
325 2 sendnum++;
326 2 if(sendnum>=totalnum)
327 2 {
328 3 s->sending=FALSE;
329 3 curr_conf.length=0;
330 3 rxok=FALSE;
331 3 }
332 2 else SBUF=addr[sendnum];
333 2 }
334 1 }
335
336
C51 COMPILATION COMPLETE. 7 WARNING(S), 2 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -