📄 posbusmodem.lst
字号:
C51 COMPILER V6.23a POSBUSMODEM 08/23/2004 13:22:31 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE POSBUSMODEM
OBJECT MODULE PLACED IN POSBusModem.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE POSBusModem.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 // This modul has the following functin:
2 // fuctionno=0: for protocol :NULL
3 // fuctionno=2: Link...(devno,StationNo) :devno[LL],devno[HH],StationNo[LL],StationNo[HH]
4 // fuctionno=4: Login (user name,password,OpSnr)
5 // :user name[10],password[10],OpSnr[4],SecurityStr[16]
6 // fuctionno=6: logout (down net) :NULL
7 // fuctionno=8: CheckTime send LocalTm,rec SeverTm) :loctm[6],svrtm[6](tm_format:YYMMDDhhmmss)
8 // fuctionno=10: Transfer Data () :data[...]
9 // fuctionno=12: Transfer End () :
10
11 #include "_POS.h"
12
13
14 #define MODEM_CP_LINK 02
15 #define MODEM_CP_LOGIN 04
16 #define MODEM_CP_LOGOUT 06
17 #define MODEM_CP_CHECKTIME 0X08
18 #define MODEM_CP_TDSTART 10 //packageno;;length_L;length_H;Sum_L;Sum_H;;
19 #define MODEM_CP_TDDATA 12 //data...
20 #define MODEM_CP_TDEND 14 //packageno;;length_L;length_H;Sum_L;Sum_H;;
21
22 #define CRC_POLYNOM 0x1021
23 #define CRC_PRESET 0xFFFF
24 #define CRC_CHKBYTES 2
25
26 #define MI_CRC_ZERO 0
27 #define MI_CRC_NOTZERO 1
28
29 //#define CRC16 0x00
30 //#define CRC8 0x80
31
32 char SecurityStr[16]; //all data_part all [addr]Xor SecurityStr[addr%16];
33 // fuctionno=1: Link...(devno,StationNo) :devno[LL],devno[HH],StationNo[LL],StationNo[HH]
34 // if OK;return MODEM_OK;else return NOK;
35
36 char ModemLink(char *dialnum,int devno,int StationNo);
37 char ModemLogin(char username[10],char password[10],char opsnr[4]);
38 char ModemTime();
39 char ModemTx(unsigned char *txbuf, int length,unsigned int sno ,unsigned char funno,int waittm); //length
-<240
40 char ModemTx5(unsigned char *txbuf, int length,unsigned int sno ,unsigned char funno,int waittm); //lengt
-h<240
41 int ModemRx(unsigned char *rbuf, int length,int dl);//return =0:NOK, 1~256 OK'
42 char ModemOnline();
43 void ModemOffline();
44 char ModemSend(uchar *tm,int length);
45
46
47 unsigned char ModemInit();
48 unsigned char modemdial(unsigned char*num);
49 void modemanswer();
50 int modem_retcode(int handle,char *buf,int len);
51 int modem_rec(int dltm,int recnum,uchar *buf);
52 int Calc_crc(uchar mode, uchar len, uchar *in, uchar *out);
53
C51 COMPILER V6.23a POSBUSMODEM 08/23/2004 13:22:31 PAGE 2
54
55 unsigned char modemhd;
56
57 #define ESC 0x1b
58
59 #define EM -150
60
61 //ret code state
62 #define Leading_CR 0
63 #define Leading_LF 1
64 #define Message 2
65 #define Trailing_CR 3
66 #define Trailing_LF 4
67
68 //return code
69 #define RE_NONE 0
70 #define RE_OK 1
71 #define RE_CONNECT 2
72 #define RE_RING 3
73 #define RE_NOCARRIER 4
74 #define RE_ERROR 5
75 #define RE_NODIALTONE 6
76 #define RE_BUSY 7
77 #define RE_NOANSWER 8
78 #define RE_CARRIER 9
79 #define RE_DATA 10
80 #define RE_FAX 11
81 #define RE_UNKNOWN 12
82 #define RE_TIMEOUT 13
83
84 #define MODEM_CP_REQDATA 15 //request data
85 #define MODEM_CP_RDSTART 16
86 #define MODEM_CP_RDSTDATA 18
87 #define MODEM_CP_RDEND 1a
88
89 #define MODEM_OK 1
90 #define MODEM_NOK 0
91
92
93 //modem command state
94 #define Idle 0
95 #define Dialing 1
96 #define Answer 2
97 #define Hangup 3
98 #define Online 4
99
100 #define PACKETSIZE 110
101 extern unsigned char devid;
102
103
104 static char xdata RetInfo[11][12] = {//
105 "OK",
106 "CONNECT",
107 "RING",
108 "NO CARRIER",
109 "ERROR",
110 "NO DIALTONE",
111 "BUSY",
112 "NO ANSWER",
113 "CARRIER",
114 "DATA",
115 "FAX"
C51 COMPILER V6.23a POSBUSMODEM 08/23/2004 13:22:31 PAGE 3
116 };
117
118 static unsigned int mspb=2;
119
120
121
122 //-------------------------------------------------------------------------------------------------
123 int modem_read(char dev_id,uint len,uchar *buf)
124 {
125 1 int last_r;
126 1 while(1)
127 1 {
128 2 last_r=_pRecBuf;
129 2 if(last_r==R232MEMMAX){ memcpy(buf,_R232Buf,len);_pRecBuf=0;return last_r;}
130 2 _delay_1ms(200);
131 2 if(last_r==_pRecBuf)
132 2 {
133 3 /*if(last_r>sizeof(buf))memcpy(buf,_R232Buf,sizeof(buf));
134 3 else */memcpy(buf,_R232Buf,last_r);
135 3 _pRecBuf=0;return last_r;
136 3 }
137 2 }
138 1 }
*** WARNING C280 IN LINE 123 OF POSBUSMODEM.C: 'dev_id': unreferenced local variable
139
140 int modem_write(char dev_id,uint len,uchar *buf)
141 {
142 1 _os232(buf,len);
143 1 }
*** WARNING C280 IN LINE 140 OF POSBUSMODEM.C: 'dev_id': unreferenced local variable
144
145 unsigned char modemdial(unsigned char *num)
146 {
147 1 uchar xdata phone[20]=" ";
148 1 uchar xdata cmd[40]="ATDT";
149 1 uchar xdata buf[40];
150 1 int i,len,ret;
151 1
152 1 if(strlen(num)<2)
153 1 {
154 2 _Clr(); _Display(0,1, "请输入电话号码:",15);
155 2 if(_GetStr(0,2,phone,16)==0) return MODEM_NOK;
156 2 strcat(cmd, phone);
157 2 strcat(cmd, "\r");
158 2 }
159 1 else
160 1 { strcat(cmd, num); strcat(cmd, "\r"); }
161 1 len = strlen(cmd);
162 1 // _display(LCD1,3,0,"请稍等.....");
163 1 _os232(cmd, len );
164 1 _delay_1ms(3000);_delay_1ms(3000);_delay_1ms(3000);
165 1 ret = modem_read(modemhd,len,(uchar *)buf);
166 1 if( ret<0 || ret!=len || strncmp(cmd, buf, len)!=0 )
167 1 {
168 2 return MODEM_NOK;
169 2 }
170 1 for(i=0;i<8;i++) {
171 2 ret = modem_retcode(modemhd, buf, 40);
172 2 if(ret==RE_NONE) {_delay_1ms(1500*mspb);continue;}
173 2 else if( ret==RE_CONNECT || ret==RE_CARRIER) {return MODEM_OK;}
174 2
175 2 }
C51 COMPILER V6.23a POSBUSMODEM 08/23/2004 13:22:31 PAGE 4
176 1 return MODEM_NOK;
177 1 }
178
179 static int modem_retcode(int modemhd, char *buf, int len)
180 {
181 1 int i, ret;
182 1 uchar xdata *p;
183 1 p = (uchar *)buf;
184 1 for(i=0;i<len;i++)
185 1 {
186 2 ret = modem_read((uchar)modemhd, 1, p);
187 2 if(ret<0) return ret;
188 2 else if(ret==0) {
189 3 _delay_1ms(mspb);
190 3 ret = modem_read((uchar)modemhd, 1, p);
191 3 if(ret<0) return ret;
192 3 else if(ret==0) return 0;
193 3 }
194 2 for(i=0;i<11;i++) {
195 3 if(strncmp(buf+2, RetInfo[i], strlen(RetInfo[i]))==0)
196 3 {return (i+1); }
197 3 }
198 2
199 2 }
200 1 return (-4);
201 1 }
202
203
204
205
206
207
208
209 /*void modem_test()
210 {
211 unsigned char retchar,rbuf[300],ss[6000];
212 unsigned char menu_head[15]="请选择测试项目";
213 unsigned char menu0[18]="Modem Link(8001)";
214 unsigned char menu1[18]="ModemTime ";
215 unsigned char menu2[18]="ChkModemOnline ";
216 // unsigned char menu3[18]="ModemTx ";
217 unsigned char menu3[18]="ModemRx";
218 unsigned char menu4[18]="modemOffline";
219 unsigned char menu5[18]="modemLogin ";
220 unsigned char menu6[18]="modemLogout ";
221 unsigned char menu7[18]="ModemTime ";
222 unsigned char menu8[18]="TxPacket ";
223 unsigned char menu9[18]="TxBegin-x-End ";
224 // unsigned char menu6[18]="ModemOnline ";
225 unsigned char * menu[12]={menu0,menu1,menu2,menu3,menu4,menu5,menu6,menu7,menu8,menu9,0,0},tmp[0x20];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -