📄 gprs.lst
字号:
602 1
603 1 unsigned int tmp;
C51 COMPILER V7.09 GPRS 08/22/2008 14:26:33 PAGE 11
604 1
605 1 if( ipInfo.rxState )
606 1 return;
607 1
608 1 tmp = at_serial_receive(&gprsInfo.rxPtr);
609 1 if( tmp )
610 1 {
611 2 gprsInfo.rxBytes += tmp;
612 2 }
613 1 else
614 1 {
615 2 if( gprsInfo.rxBytes )
616 2 {/*收到数据*/
617 3 /*xhb_debug 0*/
618 3 // if (STATE_RECEIVE_PACKET_INIT == gprsInfo.state)
619 3 debugDump(0, gprsRcvBuffer, gprsInfo.rxBytes);
620 3
621 3 gprsRcvBuffer[gprsInfo.rxBytes] = 0;
622 3 explain_at_return();
623 3
624 3 gprsInfo.rxBytes = 0;
625 3 gprsInfo.rxPtr = gprsRcvBuffer;
626 3
627 3 }
628 2 }
629 1
630 1 }
631
632 void gprs_auto_reset(void)
633 {
634 1 static unsigned char count=0;
635 1
636 1 /*要1分钟内必须收到数据包,否则模块断电*/
637 1 count ++;
638 1 if( gprsInfo.state >= STATE_VOICE_RING )
639 1 {
640 2 ipInfo.rxTimer = 0;
641 2 }
642 1 else if( count >= 20 )
643 1 {
644 2 count = 0;
645 2 ipInfo.rxTimer ++;
646 2
647 2 if( (gprsInfo.state<STATE_IDLE) && (ipInfo.rxTimer>=60*1))
648 2 {
649 3 gprs_reset(3);
650 3 }
651 2 else if(ipInfo.rxTimer >= 60*2 )
652 2 {
653 3 gprs_reset(4);
654 3 }
655 2 }
656 1
657 1 }
658
659 /*每50ms调用一次*/
660 void gprs_process(void)
661 {
662 1 static unsigned int data lastRxCount=0;
663 1
664 1 /*add for debug*/
665 1 // gprs_debug();
C51 COMPILER V7.09 GPRS 08/22/2008 14:26:33 PAGE 12
666 1 /*end of add*/
667 1 gprs_transmit_process();
668 1 gprs_receive_process();
669 1
670 1 if( gprsInfo.indication )
671 1 {
672 2 voice_indication(gprsInfo.indication, gprsInfo.inCallNumber);
673 2 gprsInfo.indication = 0;
674 2 gprsInfo.inCallNumber[0] = 0;
675 2 }
676 1
677 1 if( gprsInfo.txTimer )
678 1 {
679 2 gprsInfo.txTimer --;
680 2
681 2 if( (!gprsInfo.txTimer) && (gprsInfo.state<STATE_VOICE_RING) )
682 2 // if( (!gprsInfo.txTimer) && (gprsInfo.state<=STATE_VOICE_RING) )
683 2 {
684 3 switch( gprsInfo.state )
685 3 {
686 4 case STATE_RECEIVE_PREINIT:
687 4 gprsInfo.state = STATE_SEND_PREINIT;
688 4 break;
689 4
690 4 case STATE_RECEIVE_INIT:
691 4 gprsInfo.state = STATE_SEND_INIT;
692 4 break;
693 4
694 4 case STATE_IDLE:
695 4 break;
696 4 case STATE_RECEIVE_PACKET_INIT:
697 4 gprsInfo.errorCount ++;
698 4 if( gprsInfo.errorCount >= 20 )
699 4 gprs_reset(5);
700 4 else
701 4 gprsInfo.state = STATE_SEND_PACKET_INIT;
702 4 break;
703 4
704 4 case STATE_WAIT_UDP_OK:
705 4 //准备在这个地方关闭IP连接
706 4 gprsInfo.state = STATE_IDLE;
707 4 // sprintf(debug_msg, "111:here\r\n");
708 4 // sioc_send(debug_msg, strlen(debug_msg));
709 4
710 4 break;
711 4 case STATE_WAIT_PROMPT:
712 4 gprsInfo.state = STATE_SEND_UDP_PACKET;
713 4 // sprintf(debug_msg, "222:here\r\n");
714 4 // sioc_send(debug_msg, strlen(debug_msg));
715 4 break;
716 4 default:
717 4 gprsInfo.state = STATE_SEND_PACKET_INIT;
718 4 break;
719 4
720 4 //gprs_reset();
721 4 break;
722 4 }
723 3 }
724 2 }
725 1
726 1 gprs_auto_reset();
727 1
C51 COMPILER V7.09 GPRS 08/22/2008 14:26:33 PAGE 13
728 1 if( lastRxCount != ipInfo.rxCount )
729 1 {
730 2 ipInfo.ipLinkTimer = 0;
731 2
732 2 ipInfo.state = 1;
733 2 lastRxCount = ipInfo.rxCount;
734 2 }
735 1 else
736 1 {
737 2 ipInfo.ipLinkTimer ++;
738 2
739 2 if( (ipInfo.ipLinkTimer>20*60) || (lastRxCount==0) )
740 2 ipInfo.state = 0;
741 2 else
742 2 ipInfo.state = 1;
743 2 }
744 1
745 1 }
746
747
748
749 /***********************************************
750 *
751 ************************************************/
752
753 static unsigned long data transIndex=300;
754
755 char udp_send2(char *ptr, unsigned char len)
756 {
757 1 return 0;
758 1 }
*** WARNING C280 IN LINE 755 OF GPRS\GPRS.C: 'ptr': unreferenced local variable
*** WARNING C280 IN LINE 755 OF GPRS\GPRS.C: 'len': unreferenced local variable
759
760 char udp_send(char *ptr, unsigned int len)
761 {
762 1
763 1 unsigned char *tmpPtr;
764 1 unsigned int i;
765 1 unsigned int checkSum;
766 1
767 1 if( gprsInfo.state != STATE_IDLE)
768 1 return -1;
769 1
770 1
771 1 gprsInfo.state = STATE_SEND_PACKET_INIT;
772 1
773 1 ipInfo.txTimer = 40;
774 1 ipInfo.txLength = len + 12 + 0; /*多发送一个字节*/
775 1 ptr[len+12] = 0;
776 1
777 1 tmpPtr = ptr + 12;
778 1 checkSum = 0;
779 1
780 1 for(i=0; i<len; i++)
781 1 {
782 2 checkSum += *tmpPtr;
783 2 tmpPtr ++;
784 2 }
785 1
786 1 tmpPtr = ptr + 8;
787 1 *tmpPtr++ = checkSum;
C51 COMPILER V7.09 GPRS 08/22/2008 14:26:33 PAGE 14
788 1 *tmpPtr++ = checkSum / 256;
789 1 *tmpPtr++ = LSB(len);
790 1 *tmpPtr++ = MSB(len);
791 1
792 1 memcpy(ipInfo.txBuffer, ptr, ipInfo.txLength);
793 1
794 1 return(0);
795 1
796 1 }
797
798 /***********************************************
799 *
800 ************************************************/
801 unsigned int udp_receive(char **ptr)
802 {
803 1
804 1 if( ipInfo.rxState )
805 1 {
806 2 *ptr = ipInfo.rxBuffer;
807 2
808 2 return(ipInfo.rxLength);
809 2 }
810 1
811 1 return(0);
812 1 }
813
814 void udp_start_receive(void)
815 {
816 1
817 1 ipInfo.rxState = 0;
818 1
819 1 }
820
821
822 unsigned char udpOnline[]={0x4E, 0x4A, 0x50, 0x54, 0x02, 0, 0x07, 0x20, 0, 0x0, 0, 0x0E,\
823 0, 0, 0, 0,\
824 0x31, 0x32, 0x33, \
825 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31,\
826 };
827
828 void test_online(void)
829 {
830 1
831 1 udpOnline[15] ++;
832 1 udp_send2(udpOnline, sizeof(udpOnline)-12);
833 1
834 1 }
835
836 void udp_test(void)
837 {
838 1 /* static unsigned char count;
839 1
840 1 count ++;
841 1 if( count == 10 )
842 1 {
843 1 test_online();
844 1 }
845 1 else if( count >= 20 )
846 1 {
847 1 count = 0;
848 1 udp_send2(udpDebug, sizeof(udpDebug)-12);
849 1 }*/
C51 COMPILER V7.09 GPRS 08/22/2008 14:26:33 PAGE 15
850 1
851 1
852 1 }
853
854 /*陈剑修改,07年3月16日*/
855 /*************************
856 **返回值:0 表示无法连通
857 ** 1 表示与中心连接
858 ** 2 表示正在语音通话
859 **************************/
860 unsigned char get_gprs_state(void)
861 {
862 1 if( gprsInfo.state >= STATE_VOICE_RING )
863 1 return PPP_VOICE;
864 1 else if( ipInfo.state )
865 1 return PPP_CONECTTOCENTER;
866 1 else
867 1 return PPP_CONECTTING;
868 1 }
869
870
871 /**********************************************************/
872 char voice_call(char *number)
873 {
874 1 strcpy(gprsInfo.outCallNumber, number);
875 1
876 1 return 0;
877 1 }
878
879 void voice_hold_on(void)
880 {
881 1 if( gprsInfo.state >= STATE_VOICE_RING )
882 1 gprsInfo.state = STATE_HOLD_ON;
883 1 }
884
885 void voice_hold_off(void)
886 {
887 1 if( gprsInfo.state >= STATE_VOICE_RING )
888 1 gprsInfo.state = STATE_HOLD_OFF;
889 1 }
890
891
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 3340 ----
CONSTANT SIZE = 492 ----
XDATA SIZE = 2137 53
PDATA SIZE = ---- ----
DATA SIZE = 6 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 6 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -