📄 at.lst
字号:
213 #define AT_CMD_CONNECT "+CIPSTART" //创建连接
214 #define AT_CMD_IPSENDDATA "+CIPSEND=" //发送数据
215 #define AT_CMD_CONFIGDNS "+CDNSCFG" //配置DNS
216 #define AT_CMD_DISCONNECT "+CIPCLOSE" //关闭连接
217 #define AT_CMD_SHUTDOWN "+CIPSHUT" //关闭移动场景
218 #define AT_CMD_SMSCENTERNO "+CSCA" //短消息中心号
219 #define AT_CMD_SENDSMS "+CMGS=" //发送短信
220 #define AT_CMD_DIAL "D" //拨号
221 #define AT_CMD_SENDDTMF "+VTS=" //双音频拨号
222 #define AT_CMD_PLAYDTMF "+CLDTMF=" //播放双音频
223 #define AT_CMD_ANSWER "A" //应答电话
224 #define AT_CMD_HANGUP "H" //挂断电话
225 #define AT_CMD_SWITCHAUDIO "+CHFA=" //切换音频通道
226 #define AT_CMD_VOLUME "+CLVL=" //音量控制
227 #define AT_CMD_MIC "+CMIC=" //MIC增益控制
228 //回应字定义
229 #define AT_ACK_OK 0x80
230 #define AT_ACK_ERROR 0xA0
231 //缓冲区定义
C51 COMPILER V7.20 AT 11/03/2007 17:08:50 PAGE 5
232 uchar xdata at_receive_buffer[AT_RECEIVE_BUF_SIZE];//接收缓冲区
233 static uint xdata at_buf_point=0;//接收缓冲区指针
234 static uchar xdata at_ack=0;//回应字
235 static uchar xdata sms_coding=0;//短信息编码类型
236 static uchar xdata sms_no[16];//短信对方号码
237 static uchar xdata sms_datetime[18]="00/00/00,00:00:00";//短信日期时间
238 static uchar xdata clip_no[21]="???????????";//来电显示号码
239 //状态位定义
240 static bit at_reset=1;//需要复位 第一次需要复位
241 static bit simok=0;//sim卡准备好
242 static bit loginok=0;//登陆网络标志
243 static bit smsin=0;//收到短消息
244 static bit ring=0;//来电话
245 static bit calling=0;//是否通话状态
246
247
248
249 //********************************************************************************************************
-***************
250 //函数作用:接收消息
251 //参数说明:
252 //注意事项:
253 //返回说明:如果接受到了完整包 返回1
254 //********************************************************************************************************
-***************
255 static uchar at_get_msg(void)
256 {
257 1 uchar temp;
258 1
259 1 //接收直到没有数据
260 1 while(AT_RECEIVE_CHAR(&temp))
261 1 {
262 2 dog();
263 2 if(temp=='\r')//判断结束符号
264 2 {
265 3 //如果缓冲区有内容
266 3 if(at_buf_point)
267 3 {
268 4 at_receive_buffer[at_buf_point]=0;//添加结束符
269 4 at_buf_point=0;//清缓冲区指针
270 4 return 1;
271 4 }
272 3 }
273 2 else if(temp=='\n')//过滤垃圾字符
274 2 {
275 3
276 3 }
277 2 else //正常字符
278 2 {
279 3 at_receive_buffer[at_buf_point++]=temp;//向缓存送数据
280 3 if(at_buf_point>=AT_RECEIVE_BUF_SIZE-1)at_buf_point=0;//判断是否超长
281 3 }
282 2 }
283 1 return 0;
284 1 }
285
286 //********************************************************************************************************
-***************
287 //函数作用:等待数据包---用于接收短消息内容
288 //参数说明:
289 //注意事项:
290 //返回说明:如果接受到了完整包 返回1
C51 COMPILER V7.20 AT 11/03/2007 17:08:50 PAGE 6
291 //********************************************************************************************************
-***************
292 static uchar at_wait_packet(void)
293 {
294 1 uchar over_flag=0;
295 1 uchar temp;
296 1 uint wait_time=30000;//超时3s
297 1
298 1 while(wait_time--)
299 1 {
300 2 dog();
301 2
302 2 //接收数据
303 2 if(AT_RECEIVE_CHAR(&temp))
304 2 {
305 3 if(temp=='\r')//判断结束符号
306 3 {
307 4 //如果缓冲区有内容
308 4 if(at_buf_point)
309 4 {
310 5 at_receive_buffer[at_buf_point]=0;//添加结束符
311 5 at_buf_point=0;//清缓冲区指针
312 5 if(over_flag)return 0;
313 5 return 1;
314 5 }
315 4 }
316 3 else if(temp=='\n')//过滤垃圾字符
317 3 {
318 4
319 4 }
320 3 else //正常字符
321 3 {
322 4 at_receive_buffer[at_buf_point++]=temp;//向缓存送数据
323 4 if(at_buf_point>=AT_RECEIVE_BUF_SIZE-1)
324 4 {
325 5 at_buf_point=0;//判断是否超长
326 5 over_flag=1;
327 5 }
328 4 }
329 3 }
330 2 }
331 1 at_buf_point=0;//清缓冲区指针
332 1 return 0;
333 1 }
334
335
336
337
338 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&消息列表处理函数&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
339
340
341
342 //函数作用:收到OK
343 static void receive_ok(void)
344 {
345 1 at_ack=AT_ACK_OK;
346 1 }
347 //函数作用:收到ERROR
348 static void receive_error(void)
349 {
350 1 at_ack=AT_ACK_ERROR;
351 1 }
C51 COMPILER V7.20 AT 11/03/2007 17:08:50 PAGE 7
352 //函数作用:收到SEND OK
353 static void receive_sendok(void)
354 {
355 1 at_ack=AT_ACK_OK;
356 1 }
357 //函数作用:收到短信息到达提示
358 static void receive_smsreceive(void)
359 {
360 1 if(!at_wait_packet())return;//读取数据
361 1 sms_coding=dispose_PDU(at_receive_buffer,sms_no,sms_datetime);//解析PDU
362 1 smsin=1;//送标志
363 1 //if(at_debug==1)//调试信息
364 1 //{
365 1 // print_line(sms_no);
366 1 // print_line(at_receive_buffer);
367 1 //}
368 1 }
369 //函数作用:收到来电提示
370 static void receive_ring(void)
371 {
372 1 ring=1;
373 1 calling=1;
374 1 }
375 //函数作用:收到来电显示
376 static void receive_clip(void)
377 {
378 1 //送标志
379 1 ring=1;
380 1 calling=1;
381 1 //纪录来电号码
382 1 if(at_receive_buffer[7]!='\"')return;//判断是否开通了来电显示
383 1 if(at_receive_buffer[8]=='\"')return;//判断是否开通了来电显示
384 1 str_char_copy(clip_no,&at_receive_buffer[8],'\"');
385 1 }
386 //函数作用:收到对方挂机的信息
387 static void receive_nocarr(void)
388 {
389 1 //送标志
390 1 ring=0;
391 1 calling=0;//通话标志
392 1 //清号码
393 1 str_copy(clip_no,"???????????");
394 1 }
395 //函数作用:收到CSQ
396 static void receive_signal(void)
397 {
398 1 at_ack=AT_ACK_OK;
399 1 }
400 //函数作用:收到注册网络成功的提示
401 static void receive_loginok(void)
402 {
403 1 if(at_receive_buffer[7]=='1' || at_receive_buffer[7]=='5')loginok=1;//送标志
404 1 else if(at_receive_buffer[7]=='0')if(loginok)at_reset=1;//中途脱网 送复位标志
405 1 }
406 //函数作用:收到SIM卡准备好
407 static void receive_smsok(void)
408 {
409 1 if(simok)at_reset=1;
410 1 simok=1;
411 1 }
412
413
C51 COMPILER V7.20 AT 11/03/2007 17:08:50 PAGE 8
414 //命令列表
415 typedef struct
416 {
417 uchar *cmdstr;
418 void (*callback)(void);
419 }at_msglist_t;//消息列表数据结构
420 static at_msglist_t code at_msglist[]=
421 {
422
423 {AT_MSG_OK,receive_ok},
424 {AT_MSG_ERROR,receive_error},
425 {AT_MSG_SENDOK,receive_sendok},
426 {AT_MSG_SMSRECEIVE,receive_smsreceive},
427 {AT_MSG_RING,receive_ring},
428 {AT_MSG_CLIP,receive_clip},
429 {AT_MSG_NOCARR,receive_nocarr},
430 {AT_MSG_SIGNAL,receive_signal},
431 {AT_MSG_LOGINOK,receive_loginok},
432 {AT_MSG_SIMOK,receive_smsok},
433
434 {NULL,NULL},
435 };
436
437 //********************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -