?? m32.lst
字號:
247 7 putstring1("\r\n");
248 7 if(phone==1)return Number;
249 7 if(strncmp(Number,TPA,strlen(TPA))==0)
250 7 {
251 8 //is right number,go on next.
252 8 return Number;
253 8
254 8 }
255 7 return NULL;
256 7 }
257 6 }//for(i=0;i<16;i++)
258 5
259 5 }//if(strncpy(SCA,ptr,16) != NULL)
260 4
261 4 }//if((ptr=strstr(ptr,",\"")) != NULL)
262 3 else
263 3 return NULL;
264 3 }//if((ptr=strstr(ans,"+CPBF: ")) != NULL)
265 2 else
266 2 return NULL;
267 2 } //while(1)
268 1
269 1 }
270
271
272
273
274 #if 1
275 int gsmGetRightNumber(uchar* text)
276 {
277 1 uchar xdata* ptr;
278 1
279 1 if((ptr=gsmCheckRightNumber(text,1))==NULL) return 0;
280 1 strcpy(TPA,ptr);
281 1
282 1
283 1 putstring1("You have Right Name is:\r\n");
284 1 putstring1(text);
285 1 putstring1("\r\n");
286 1 putstring1("You have Right Number is:\r\n");
287 1 putstring1(TPA);
288 1 putstring1("\r\n");
289 1 return 1;
290 1
291 1 }
292 #endif
293
294
C51 COMPILER V7.50 M32 04/04/2007 15:01:44 PAGE 6
295
296
297
298 BOOL gsmSendMessage(void)
299 {
300 1 int xdata nPduLength; // PDU串長度
301 1 unsigned char xdata nSmscLength; // SMSC串長度
302 1 int xdata nLength; // 串口收到的數據長度
303 1 uchar xdata* ptr;
304 1
305 1 TPA[0]=SCA[0];
306 1 TPA[1]=SCA[1];
307 1
308 1
309 1 putstring1("Send Message Start:\r\n");
310 1 putstring1("SCA=:\r\n");
311 1 putstring1(SCA);
312 1 putstring1("\r\n");
313 1 putstring1("TPA=:\r\n");
314 1 putstring1(TPA);
315 1 putstring1("\r\n");
316 1
317 1
318 1 nPduLength = gsmEncodePdu(pdu); // 根據PDU參數,編碼PDU串
319 1 strcat(pdu, "\x01a"); // 以Ctrl-Z結束
320 1 gsmString2Bytes(pdu, &nSmscLength, 2); // 取PDU串中的SMSC信息長度
321 1 nSmscLength++; // 加上長度字節本身
322 1 // 命令中的長度,不包括SMSC信息長度,以數據字節計
323 1 sprintf(cmd, "AT+CMGS=%d\r", nPduLength/2 - nSmscLength); // 生成命令
324 1
325 1 while(1)
326 1 {
327 2 ATSend(cmd);
328 2 ReadSerail(ans, 128, &nLength,5);
*** WARNING C214 IN LINE 328 OF M32.C: 'Argument': conversion: pointer to non-pointer
329 2 if((ptr=strstr(ans,"\r\n> ")) != NULL)
330 2 {
331 3
332 3 ATSend(pdu); // 得到肯定回答,繼續輸出PDU串
333 3 ReadSerail(ans, 128, &nLength,5);
*** WARNING C214 IN LINE 333 OF M32.C: 'Argument': conversion: pointer to non-pointer
334 3 if((strstr(ans, "+CMGS: ")) == NULL)
335 3 {
336 4 putbyte('\r');
337 4 delay_ms(20);
338 4 putstring1("SMSC Send Ok!\r\n");
339 4
340 4 return 1;
341 4 }
342 3 else
343 3 {
344 4 putstring1("SMSC ANSWER:Err\r\n");
345 4 putstring1(ans);
346 4 putstring1("\r\n");
347 4
348 4
349 4 putbyte('\r');
350 4 delay_ms(20);
351 4 ATSend("AT\r\n");
352 4 delay_ms(200);
353 4
354 4
C51 COMPILER V7.50 M32 04/04/2007 15:01:44 PAGE 7
355 4 }
356 3 }
357 2 else
358 2 {
359 3 putstring1("NO ANSWER:\r\n");
360 3 putstring1(ans);
361 3 putstring1("\r\n");
362 3
363 3 if((strstr(ans,"RING")) != NULL) return FALSE;
364 3 putbyte('\r');
365 3 delay_ms(20);
366 3 ATSend("AT\r\n");
367 3 delay_ms(200);
368 3
369 3 }
370 2 }
371 1
372 1 }
373
374
375
376
377
378
379
380 //List all phonebook entries:
381 // AT+CPBF="DA"
382
383
384
385
386
387
388
389 /************************************************************************************************
390 * int gsmEncode7bit(const char* pSrc, unsigned char* pDst, int nSrcLength)
391 * 7-bit編碼
392 * pSrc: 源字符串指針
393 * pDst: 目標編碼串指針
394 * nSrcLength: 源字符串長度
395 * 返回: 目標編碼串長度
396 ***************************************************************************************/
397 int gsmEncode7bit(char xdata* pSrc, unsigned char xdata* pDst, int nSrcLength)
398 {
399 1 int xdata nSrc; // 源字符串的計數值
400 1 int xdata nDst; // 目標編碼串的計數值
401 1 int xdata nChar; // 當前正在處理的組內字符字節的序號,范圍是0-7
402 1 unsigned char xdata nLeft; // 上一字節殘余的數據
403 1 // 計數值初始化
404 1 nSrc = 0;
405 1 nDst = 0;
406 1
407 1 // 將源串每8個字節分為一組,壓縮成7個字節
408 1 // 循環該處理過程,直至源串被處理完
409 1 // 如果分組不到8字節,也能正確處理
410 1 while(nSrc<nSrcLength)
411 1 {
412 2 // 取源字符串的計數值的最低3位
413 2 nChar = nSrc & 7;
414 2
415 2 // 處理源串的每個字節
416 2 if(nChar == 0)
C51 COMPILER V7.50 M32 04/04/2007 15:01:44 PAGE 8
417 2 {
418 3 // 組內第一個字節,只是保存起來,待處理下一個字節時使用
419 3 nLeft = *pSrc;
420 3 }
421 2 else
422 2 {
423 3
424 3 // 組內其它字節,將其右邊部分與殘余數據相加,得到一個目標編碼字節
425 3 *pDst = (*pSrc << (8-nChar))| nLeft;
426 3 // 將該字節剩下的左邊部分,作為殘余數據保存起來
427 3 nLeft = *pSrc >> nChar;
428 3 // 修改目標串的指針和計數值
429 3 pDst++;
430 3 nDst++;
431 3 }
432 2
433 2
434 2 // 修改源串的指針和計數值
435 2 pSrc++;
436 2 nSrc++;
437 2 }
438 1
439 1 // 返回目標串長度
440 1 return nDst;
441 1 }
442
443
444 // 字節數據轉換為可打印字符串 // 如:{0xC8, 0x32, 0x9B, 0xFD, 0x0E, 0x01} --> "C8329BFD0E01"
445 // pSrc: 源數據指針
446 // pDst: 目標字符串指針
447 // nSrcLength: 源數據長度
448 // 返回: 目標字符串長度
449 int gsmBytes2String(uchar xdata * pSrc, char xdata* pDst, int nSrcLength)
450 {
451 1 code char tab[]="0123456789ABCDEF";
452 1
453 1 int i;
454 1 // 0x0-0xf的字符查找表
455 1 for(i=0; i<nSrcLength; i++)
456 1 {
457 2 // 輸出低4位
458 2 *pDst++ = tab[*pSrc >> 4];
459 2 // 輸出高4位
460 2 *pDst++ = tab[*pSrc & 0x0f];
461 2 pSrc++;
462 2 }
463 1 // 輸出字符串加個結束符
464 1 *pDst = '\0';
465 1 // 返回目標字符串長度
466 1 return nSrcLength * 2;
467 1 }
468
469 // 可打印字符串轉換為字節數據 // 如:"C8329BFD0E01" --> {0xC8, 0x32, 0x9B, 0xFD, 0x0E, 0x01}
470 // pSrc: 源字符串指針
471 // pDst: 目標數據指針
472 // nSrcLength: 源字符串長度
473 // 返回: 目標數據長度
474 //int gsmString2Bytes(const char* pSrc, unsigned char* pDst, int nSrcLength)
475 int gsmString2Bytes(uchar* pSrc, uchar* pDst, int nSrcLength)
476 {
477 1 int i;
478 1
C51 COMPILER V7.50 M32 04/04/2007 15:01:44 PAGE 9
479 1
480 1 for(i=0; i<nSrcLength; i+=2)
481 1 {
482 2 // 輸出高4位
483 2 if((*pSrc>='0') && (*pSrc<='9'))
484 2 {
485 3 *pDst = (*pSrc - '0') << 4;
486 3
487 3
488 3 }
489 2 else
490 2 {
491 3 *pDst = (*pSrc - 'A' + 10) << 4;
492 3 }
493 2
494 2
495 2 pSrc++;
496 2 // 輸出低4位
497 2 if(*pSrc>='0' && *pSrc<='9')
498 2 {
499 3 *pDst |= (*pSrc - '0');
500 3 }
501 2 else
502 2 {
503 3 *pDst |= (*pSrc - 'A' + 10);
504 3 }
505 2
506 2
507 2
508 2 pSrc++;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -