car_sim300.c
上传用户:sdbljx
上传日期:2016-10-27
资源大小:26k
文件大小:140k
- /**************************************************************
- Copyright (C), 2002-2030, HuerXun Tech. Co., Ltd.
- 文件名 : AnyData.c
- 作 者 : 华 猛 版本:V1.00.00 完成日期:2007-01-27
- 描 述 :
- 函数列表:
- 修改记录1:
- 日 期 :
- 修改人 :
- 修改说明:
- 修改记录2:
- 日 期 :
- 修改人 :
- 修改说明:
- ***************************************************************/
- #include <stm32f10x_lib.h> /* STM32F10x Library Definitions */
- #include<string.h>
- #include <stdio.h>
- #ifndef NULL
- #define NULL ((void *) 0L)
- #endif
- #ifndef OK
- #define OK 1
- #endif
- #ifndef NOT_OK
- #define NOT_OK 0
- #endif
- #define DELAY_TIME_START_VALUE 1
- #define WDT_TIME 0x00
- #define CHECK_WORD1 'm'
- #define CHECK_WORD2 'h'
- #define PASSWORD_STAR_ADDR 0x0000
- #define MONT_PHONE_STAR_ADDR 0x0010
- #define SEVER_IP_STAR_ADDR 0x0050
- #define CHECK_WORD_STAR_ADDR 0x0070
- #define LCT_TIME_IN_STAR_ADDR 0x0080
- #define DEVICE_PHONE_STAR_ADDR 0x0090
- #define SIM_CCID_STAR_ADDR 0x00a0
- #define CENTER_MODEM_STAR_ADDR 0x00b0
- #define LCT_TIME_INTV_ADDR 0x00c0
- #define OVER_SPEED_IN_STAR_ADDR 0x00d0
- #define OVER_SPEED_INTV_ADDR 0x00e0
- #define PHONE_LOCATION_MODE 0x00f0
- #define GPRS_APN_STAR_ADDR 0x0500//保存gprs接入点首地址
- /*--------------------标准数据类型重定义-----------------------*/
- typedef unsigned char BYTE; //无符号字符型(或者字节型)
- typedef signed char SBYTE; //有符号字节型(或者字节型)
- typedef unsigned short WORD; //无符号整型(或者字型)
- typedef signed short SWORD; //有无符号整型(或者字型)
- typedef unsigned long DWORDS; //无符号长整型(或者双字型)
- typedef signed long SDWORD; //有符号长整型(或者双字型)
- /*---------------------------------------------------------------*/
- /***************************time***************************************/
- #define AT_CMD_WAITING_TIMER 0//等待AT命令发送超时定时器
- #define LED_FLASHING_TIMER 1//LED灯闪定时器
- #define GPS_CHECK_WAITING_TIMER 2//GPS数据检测定时器
- #define SWAP_GPS_LCT_TIMER 3//定时请求交换数据到用户手机
- #define TCP_CCNT_START_TIMER 4//TCP已经连接,等待数据交换超时定时器
- #define MAX_LED_FLASH_TIME 20//<256
- #define MAX_LED_FLASH_TIME1 20//<256
- #define MAX_CHECK_SPEED_CNT 10
- #define MAX_CHECK_OVER_SPEED_CNT 5
- typedef struct{
- BYTE bStartFb; //1-启动定时器 ,0-关闭定时器
- WORD wOverValue; //定时器溢出值
- void (*pfTimerFunction)(void); //定时器溢出时间函数指针
- }recTIMER_A;//A型定时器结构:单定时触发
- #define MAX_A_SOFT_TIMERS 5 //系统最大A类软定时器数目
- #define MIN_TIME_PERIOD 100 //最小定时周期单位1s
- recTIMER_A REC_A_SoftTimers[MAX_A_SOFT_TIMERS];//A类软件定时器组
- WORD volatile W_TimeCount=0;//定时器基数循环变量//volatile
- BYTE B_CheckKeyTimer[4];
- WORD W_CheckConts[4];
- BYTE FB_Led=0,FB_Led1=0;
- BYTE volatile B_LedTimer=0,B_LedTimer1=0;//LED灯闪定时器
- BYTE GPS_V_F=0,GPS_CCNT_F=0;
- BYTE volatile B_GpsVFTimer = 0;
- /**********************************************************************/
- /****************************serial*******************************************/
- #define MAX_SERIAL_LEN 280 //定义最大串口1接收缓冲数
- #define MAX_SERIAL_LEN2 140 //100定义最大串口2接收缓冲数
- #define MAX_TCP_SERIAL_LEN 210 //定义最大tcp数据接收缓冲数
- BYTE B_SerialQueue[MAX_SERIAL_LEN];//串口接收队列
- WORD W_InSerial=0,W_OutSerial=0;//读写B_SerialQueue时进/出队列位置
- BYTE B_SerialQueue2[MAX_SERIAL_LEN2];//串口接收队列
- WORD W_InSerial2=0,W_OutSerial2=0;//读写B_SerialQueue时进/出队列位置
- BYTE B_TcpSerialQueue[MAX_TCP_SERIAL_LEN];//串口接收队列
- WORD W_TcpInSerial=0,W_TcpOutSerial=0;//读写B_TcpSerialQueue时进/出队列位置
- /*****************************************************************************/
- #define MAX_RECV_SMS_NUM 76
- BYTE B_SMSExist[MAX_RECV_SMS_NUM];//SIM卡上可存储76条SMS =0表示没有对应的短消息,=1表示有短消息要读,=2表示此条短消息已读
- BYTE FB_NextGsmMsg=0;//指示短消息已经读出来了
- BYTE FB_NextCCID=0;//指示SIM卡的标示号读出来了
- BYTE FB_CSCASet=0;//指示是查询还是设置短消息中心号码
- BYTE IpdFlag=0;
- BYTE FB_AtdReg=0;
- BYTE FB_AtdDelayStart=0;
- BYTE B_AtdDelayTimer=0;
- BYTE Call_Rdy=0;//模块允许呼叫标志
- BYTE Call_Modem=0;//呼叫中心MODEM标志
- BYTE FB_RestPro=0;//重启程序标志
- BYTE B_EnCodeSms[140];//PDU BIT7位编码数据内容
- BYTE B_EnCodeLen; //PDU BIT7位编码长度
- BYTE B_OnOff_FLAG=0;//开关机标志
- WORD W_PowerSwitchTimer=0;//sim508重启计时
- BYTE B_NoCsqTimer=0;//无信号强度计时
- BYTE B_NetValue_1_Cnt=0;//网络标志值为'1'的时长
- /*********************************************AT Commands**************************************************/
- /***********************************************************************************************************
- CIPSTATUS CIPHEAD CIPSPRT CNMI SIDET ECHO CLVL CMIC CHFA CSCA CSTA CSCS CMGF CLIP CREG ATE0
- 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
- 0 1 0 1 , 1 1 1 1 , 1 0 0 0 , 0 1 1 1
- ************************************************************************************************************
- ************************************************************************************************************
- CMGS CLCC CONT CSTT CIPSEND CIPSTART ATH CSQ VTS ATD ATA CIPSHUT CIPCLOSE CMGL CMGD CMGR
- 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
- 0 0 0 0 , 0 0 0 1 , 0 0 0 0 , 0 0 0 0
- *************************************************************************************************************/
- #define MAC_ATE0_ITEM 0
- #define MAC_CREG_ITEM 1
- #define MAC_CLIP_ITEM 2
- #define MAC_CMGF_ITEM 3
- #define MAC_CSCS_ITEM 4
- #define MAC_CSTA_ITEM 5
- #define MAC_CSCA_ITEM 6
- #define MAC_CHFA_ITEM 7
- #define MAC_CMIC_ITEM 8
- #define MAC_CLVL_ITEM 9
- #define MAC_ECHO_ITE M 10
- #define MAC_SIDET_ITEM 11
- #define MAC_CNMI_ITEM 12
- #define MAC_CIPSPRT_ITEM 13
- #define MAC_CIPHEAD_ITEM 14
- #define MAC_CIPSTATUS_ITEM 15
- #define MAC_CMGR_ITEM 16
- #define MAC_CMGD_ITEM 17
- #define MAC_CMGL_ITEM 18
- #define MAC_CIPCLOSE_ITEM 19
- #define MAC_CIPSHUT_ITEM 20
- #define MAC_ATA_ITEM 21
- #define MAC_ATD_ITEM 22
- #define MAC_VTS_ITEM 23
- #define MAC_CSQ_ITEM 24
- #define MAC_ATH_ITEM 25
- #define MAC_CIPSTART_ITEM 26
- #define MAC_CIPSEND_ITEM 27
- #define MAC_CSTT_ITEM 28
- #define MAC_CONT_ITEM 29
- #define MAC_CLCC_ITEM 30
- #define MAC_CMGS_ITEM 31
- #define MAC_SET_AT_CMD 0x01007fa7
- typedef enum {
- NO_COMMAND_WAIT,
- WAIT_ATE0,WAIT_CREG,WAIT_CLIP,WAIT_CMGF,
- WAIT_CSCS,WAIT_CSTA,WAIT_CSCA,WAIT_CHFA,
- WAIT_CMIC,WAIT_CLVL,WAIT_ECHO,WAIT_SIDET,
- WAIT_CNMI,WAIT_CIPSPRT,WAIT_CIPHEAD,WAIT_CIPSTATUS,
- WAIT_CMGR,WAIT_CMGD,WAIT_CMGL,WAIT_CIPCLOSE,
- WAIT_CIPSHUT,WAIT_ATA,WAIT_ATD ,WAIT_VTS,
- WAIT_CSQ,WAIT_ATH,WAIT_CIPSTART,WAIT_CIPSEND,
- WAIT_CSTT,WAIT_CONT,WAIT_CLCC, WAIT_CMGS,
- WAIT_SEND_MSG
- } enEchoWait;
- typedef struct {
- enEchoWait eAtCmdStatus;//AT命令标签
- BYTE bAtCommand[45];//AT命令字符串
- }recAtCmd;
- /**********定义收到的字符串及响应的确认函数结构**************/
- struct FunctionTable
- {
- BYTE *pbCmdStr;
- void (*pfCmdFun)(void);
- };
- enEchoWait EN_CommandStatus=NO_COMMAND_WAIT; //发送AT命令后的等待状态
- BYTE B_AtCommandItem=0xff; //当前已发送的AT命令的索引
- BYTE B_AtCmdTimes=0; //同一个AT命令重复发送的次数
- WORD W_InternalLctTimer; //定时定位时间间隔,单位分钟
- WORD W_OverSpeedValue; //超速速度,单位km/h
- DWORDS DW_MapTbl[ ]={ 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020, 0x00000040, 0x00000080,
- 0x00000100, 0x00000200, 0x00000400, 0x00000800, 0x00001000, 0x00002000, 0x00004000, 0x00008000,
- 0x00010000, 0x00020000, 0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000,
- 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000,
- 0x00000000
- };//定义检测需发送AT命令的参考标量
- DWORDS DW_SetAtCmdFlag = MAC_SET_AT_CMD;//0x01007fa7//是否发该AT命令的标志,1-发送,0-不发送0x01447fe7
- /***********************************************************************************************************
- CIPSTATUS CIPHEAD CIPSPRT CNMI SIDET ECHO CLVL CMIC CHFA CSCA CSTA CSCS CMGF CLIP CREG ATE0
- 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
- 0 1 1 1 , 1 1 1 1 , 1 0 1 0 , 0 1 1 1
- ************************************************************************************************************
- ************************************************************************************************************
- CMGS CLCC CONT CSTT CIPSEND CIPSTART ATH CSQ VTS ATD ATA CIPSHUT CIPCLOSE CMGL CMGD CMGR
- 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
- 0 0 0 0 , 0 0 0 1 , 0 0 0 0 , 0 0 0 0
- *************************************************************************************************************/
- //AT+CSTA=145
- recAtCmd REC_AtCommands[32]={
- WAIT_ATE0,"ATE1", WAIT_CREG,"AT+CREG=1", WAIT_CLIP,"AT+CLIP=1", WAIT_CMGF,"AT+CMGF=0",
- WAIT_CSCS,"AT+CSCS="GSM"", WAIT_CSTA,"AT+CCID", WAIT_CSCA,"AT+CSCA", WAIT_CHFA,"AT+CHFA=1",
- WAIT_CMIC,"AT+CMIC=1,6", WAIT_CLVL,"AT+CLVL=73", WAIT_ECHO,"AT+ECHO=0,0,0,1", WAIT_SIDET,"AT+SIDET=4096",
- WAIT_CNMI,"AT+CNMI?", WAIT_CIPSPRT,"AT+CIPSPRT=0", WAIT_CIPHEAD,"AT+CIPHEAD=1", WAIT_CIPSTATUS,"AT+CIPSTATUS",
- WAIT_CMGR,"AT+CMGR=", WAIT_CMGD,"AT+CMGD=", WAIT_CMGL,"AT+CMGL=4", WAIT_CIPCLOSE,"AT+CIPCLOSE",
- WAIT_CIPSHUT,"AT+CIPSHUT", WAIT_ATA, "ATA", WAIT_ATD, "ATD", WAIT_VTS, "AT+VTS=",
- WAIT_CSQ, "AT+CSQ", WAIT_ATH, "ATH", WAIT_CIPSTART,"AT+CIPSTART="TCP",",WAIT_CIPSEND,"AT+CIPSEND=",
- WAIT_CSTT,"AT+CSTT=", WAIT_CONT,"AT+CIPSCONT", WAIT_CLCC,"AT+CLCC", WAIT_CMGS,"AT+CMGS="
- };//220.194.62.247:1238//202.96.155.118//220.205.139.106
- /********************************CDMA 数据处理*************************************/
- #define IDILE 0 //空闲
- #define DIALING 1 //拨号
- #define RING 2 //来电
- #define CCNT 3 //接通
- #define MAX_CDMA_FRM_LEN 255 //CDMA输出一帧数据最大字符数
- #define MAX_GPS_FRM_LEN 100 //GPS输出一帧数据最大字符数
- #define MAX_TCP_CDMA_FRM_LEN 255 //CDMA_TCP输出一帧数据最大字符数
- #define MAX_SEND_SMS_LEN 140 //发送一条短消息的最大字符数
- #define MAX_PHONE_NUM 16 //电话号码的最大长度
- #define MAX_AT_CMD_ERRORS 3 //AT命令最大出错次数
- BYTE B_CdmaFrmBuf[MAX_CDMA_FRM_LEN];//用来存放被正确读取的一帧CDMA数据:AT+CSQ....0x0d,0x0a
- WORD W_CdmaFrmBufLen=0;//CDMA帧数据长度
- BYTE B_GpsFrmBuf[MAX_GPS_FRM_LEN];//用来存放被正确读取的一帧GPS数据:$GPRMC,....0x0d,0x0a
- WORD W_GpsFrmBufLen=0;//GPS帧数据长度
- BYTE B_TcpCdmaFrmBuf[MAX_TCP_CDMA_FRM_LEN];//用来存放被正确读取的一帧CDMA TCP数据
- BYTE B_SmsSendItem[MAX_SEND_SMS_LEN];//一条短消息的内容
- BYTE B_SmsSendLen=0;//需要发送短消息内容的长度
- BYTE B_TalkStatus=IDILE;//电话状态
- BYTE B_NetStatus=0;//网络状态
- BYTE B_AlarmFlag[4];
- BYTE B_UserNum[MAX_PHONE_NUM]; //用户电话号码
- BYTE B_DeviceNum[MAX_PHONE_NUM];//设备标识号码
- BYTE B_ScaPhone[MAX_PHONE_NUM];//短消息中心号码
- BYTE FB_RelayStart=0;
- BYTE B_RelayTime=0,B_DelayTimeValue=0;
- BYTE B_Screen=0;
- BYTE B_SpeedEnableCnt=0,B_SpeedOverCnt=0,B_StarORStop=0,B_OverORNormal=0;
- BYTE B_OverBeepStart=0;
- BYTE volatile B_OverBeepTimer=0;//超速报警执行
-
- BYTE B_PwdSetRet1[14] = {0x5b,0xc6,0x78,0x01,0x66,0xf4,0x65,0xb0,0x62,0x10,0x52,0x9f,0x00,0x21}; //密码更新成功!
- BYTE B_PwdSetRet0[14] = {0x5b,0xc6,0x78,0x01,0x66,0xf4,0x65,0xb0,0x59,0x31,0x8d,0x25,0x00,0x21}; //密码更新失败!
- BYTE B_PhoneSetRet1[18]={0x76,0xd1,0x63,0xa7,0x53,0xf7,0x78,0x01,0x8b,0xbe,0x7f,0x6e,0x62,0x10,0x52,0x9f,0x00,0x21}; //监控号码设置成功!
- BYTE B_PhoneSetRet0[28]={0x76,0xd1,0x63,0xa7,0x53,0xf7,0x78,0x01,0x8b,0xbe,0x7f,0x6e,0x59,0x31,0x8d,0x25,0x00,0x2c,0x5b,0xc6,0x78,0x01,0x67,0x09,0x8b,0xef,0x00,0x21}; //监控号码设置失败,密码有误!
- //BYTE B_LcntFailRet[26]= {0x8b,0xf7,0x6c,0x42,0x5b,0x9a,0x4f,0x4d,0x59,0x31,0x8d,0x25,0x00,0x2c,0x8b,0xf7,0x7a,0x0d,0x54,0x0e,0x51,0x8d,0x8b,0xd5,0x00,0x21}; //请求定位失败,请稍后再试!
- //BYTE B_TcpFailRet[22]= {0x7f,0x51,0x7e,0xdc,0x7E,0x41,0x5F,0xD9,0x00,0x2c,0x8b,0xf7,0x7a,0x0d,0x54,0x0e,0x51,0x8d,0x8b,0xd5,0x00,0x21}; //网络繁忙,请稍后再试!
- BYTE B_TcpFailRet[94] = { 0x79,0xFB,0x52,0xA8,0x51,0x6C,0x53,0xF8,0x00,0x47,
- 0x00,0x50,0x00,0x52,0x00,0x53,0x7F,0x51,0x7E,0xDC,
- 0x4E,0x0D,0x7A,0x33,0x5B,0x9A,0xFF,0x0C,0x89,0xE3,
- 0x67,0x90,0x4E,0x0D,0x62,0x10,0x52,0x9F,0x67,0x1B,
- 0x8C,0x05,0x89,0xE3,0xFF,0x01,0x4E,0xBA,0x5D,0xE5,
- 0x67,0xE5,0x8B,0xE2,0x75,0x35,0x8B,0xDD,0x00,0x30,
- 0x00,0x37,0x00,0x35,0x00,0x35,0x00,0x2D,0x00,0x32,
- 0x00,0x35,0x00,0x39,0x00,0x32,0x00,0x33,0x00,0x38,
- 0x00,0x34,0x00,0x35,0xFF,0x0C,0x7E,0xCF,0x7E,0xAC,
- 0x5E,0xA6,0xFF,0x1A};//移动公司GPRS网络不稳定,解析不成功望谅解!人工查询电话0755-25923845,经纬度:
- BYTE B_AlarmRet[4][98]= { 0x7D, 0x27, 0x60, 0x25, 0x62, 0xA5, 0x8B, 0x66, 0x62, 0x16,
- 0x6C, 0x42, 0x52, 0xA9, 0xFF, 0x01, 0x56, 0xDE, 0x59, 0x0D,
- 0x00, 0x47, 0x52, 0xa0, 0x5b, 0xc6, 0x78, 0x01, 0x53, 0xEF,
- 0x53, 0xD1, 0x8D, 0x77, 0x5B, 0x9A, 0x4F, 0x4D, 0xFF, 0x0C,
- 0x56, 0xDE, 0x62, 0xE8, 0x75, 0x35, 0x8B, 0xDD, 0x53, 0xEF,
- 0x76, 0xD1, 0x54, 0x2C, 0x8F, 0x66, 0x51, 0x85, 0x60, 0xC5,
- 0x51, 0xB5, 0xFF, 0x01, 0x55, 0x2E, 0x54, 0x0E, 0x70, 0xED,
- 0x7E, 0xBF, 0x00, 0x30, 0x00, 0x37, 0x00, 0x35, 0x00, 0x35,
- 0x00, 0x2D, 0x00, 0x32, 0x00, 0x35, 0x00, 0x39, 0x00, 0x32,
- 0x00, 0x33, 0x00, 0x38, 0x00, 0x34, 0x00, 0x35,
-
- 0x59, 0x82, 0x67, 0x65, 0x4E, 0x4B, 0x66, 0x1F, 0x63, 0xD0,
- 0x91, 0x92, 0xFF, 0x1A, 0x8B, 0xBE, 0x59, 0x07, 0x4E, 0x3B,
- 0x75, 0x35, 0x6E, 0x90, 0x67, 0x09, 0x65, 0x45, 0x96, 0x9C,
- 0xFF, 0x0C, 0x8B, 0xF7, 0x53, 0xCA, 0x65, 0xF6, 0x59, 0x04,
- 0x74, 0x06, 0xFF, 0x01, 0x00, 0x20, 0x00, 0x20, 0x20, 0x00,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
-
- 0x59, 0x82, 0x67, 0x65, 0x4E, 0x4B, 0x66, 0x1F, 0x63, 0xD0,
- 0x91, 0x92, 0xFF, 0x1A, 0x8F, 0x66, 0x8F, 0x86, 0x67, 0x09,
- 0x63, 0x2F, 0x52, 0xA8, 0xFF, 0x0C, 0x8B, 0xF7, 0x6C, 0xE8,
- 0x61, 0x0F, 0x8F, 0x66, 0x8F, 0x86, 0x5B, 0x89, 0x51, 0x68,
- 0xFF, 0x01, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
-
- 0x59, 0x82, 0x67, 0x65, 0x4E, 0x4B, 0x66, 0x1F, 0x63, 0xD0,
- 0x91, 0x92, 0xFF, 0x1A, 0x8F, 0x66, 0x8F, 0x86, 0x67, 0x09,
- 0x63, 0x2F, 0x52, 0xA8, 0xFF, 0x0C, 0x8B, 0xF7, 0x6C, 0xE8,
- 0x61, 0x0F, 0x8F, 0x66, 0x8F, 0x86, 0x5B, 0x89, 0x51, 0x68,
- 0xFF, 0x01, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
- 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20};
-
- BYTE B_DeviceNumRet1[18] = {0x62, 0x4B, 0x67, 0x3A, 0x53, 0xf7, 0x78, 0x01, 0x8B, 0xBE, 0x7F, 0x6E, 0x62, 0x10, 0x52, 0x9F, 0x00, 0x21};
- BYTE B_DeviceNumRet0[18] = {0x62, 0x4B, 0x67, 0x3A, 0x53, 0xf7, 0x78, 0x01, 0x8B, 0xBE, 0x7F, 0x6E, 0x59, 0x31, 0x8d, 0x25, 0x00, 0x21};
- BYTE B_ModemNumRet1[20] = {0x4E, 0x2D, 0x5F, 0xC3, 0x73, 0x2B, 0x53, 0xf7, 0x78, 0x01, 0x8B, 0xBE, 0x7F, 0x6E, 0x62, 0x10, 0x52, 0x9F, 0x00, 0x21};
- BYTE B_ModemNumRet0[20] = {0x4E, 0x2D, 0x5F, 0xC3, 0x73, 0x2B, 0x53, 0xf7, 0x78, 0x01, 0x8B, 0xBE, 0x7F, 0x6E, 0x59, 0x31, 0x8d, 0x25, 0x00, 0x21};
- BYTE B_GPSLctRet[20]= {0x5B, 0xC6, 0x78, 0x01, 0x95, 0x19, 0x8B, 0xEF, 0x00, 0x2C,
- 0x65, 0xE0, 0x67, 0x43, 0x5B, 0x9A, 0x4F, 0x4D, 0x00, 0x21};
-
- //BYTE B_LctInTimeNotice[26] = {0x52,0x06,0x94,0x9F,0x95,0xF4,0x96,0x94,0x76,0x84,0x5B,0x9A,0x65,0xF6,0x8F,0xFD,0x8E,0x2A,0x5D,0xF2,0x54,0x2F,0x52,0xA8,0x00,0x21};
- BYTE B_LctInTimeNotice[24] = {0x79,0xd2,0x95,0xF4,0x96,0x94,0x76,0x84,0x5B,0x9A,0x65,0xF6,0x8F,0xFD,0x8E,0x2A,0x5D,0xF2,0x54,0x2F,0x52,0xA8,0x00,0x21};
- BYTE B_OverSpeedSetNotice[30] = {0x00,0x4b, 0x00,0x6d, 0x00,0x2f, 0x00,0x68, 0x8D,0x85, 0x90,0x1F, 0x62,0xA5, 0x8B,0x66, 0x90,0x1F, 0x5E,0xA6, 0x8B,0xBE, 0x7F,0x6E, 0x62,0x10, 0x52,0x9F, 0x00,0x21,};//超速报警速度设置成功
- //BYTE B_N1234Notice[8] = {0x00,0x23,0x00,0x24,0x00,0x25,0x00,0x26};
- BYTE B_X_Ret[58]={ 0x5B,0xC6,0x78,0x01,0x95,0x01,0x8F,0x66,0x5D,0xF2,
- 0x54,0x2F,0x52,0xA8,0xFF,0x0C,0x56,0xDE,0x59,0x0D,
- 0x00,0x4B,0x52,0xA0,0x5B,0xC6,0x78,0x01,0x89,0xE3,
- 0x96,0x64,0x30,0x02,0x8B,0x66,0x54,0x4A,0xFF,0x0C,
- 0x8B,0xE5,0x52,0x9F,0x80,0xFD,0x88,0x4C,0x9A,0x76,
- 0x4E,0x2D,0x52,0xFF,0x75,0x28,0xFF,0x01};
-
- BYTE B_K_Ret[16]={ 0x5B,0xC6,0x78,0x01,0x95,0x01,0x8F,0x66,0x5D,0xF2,
- 0x89,0xE3,0x96,0x64,0xFF,0x01};
-
- BYTE B_Phone_Lct_Mode[22] = {0x75,0x35,0x8B,0xDD,0x5B,0x9A,0x4F,0x4D,
- 0x6A,0x21,0x5F,0x0F,0x8B,0xBE,0x7F,0x6E,0x62,0x10,0x52,0x9F,0x00,0x21};
- /********************************定义GPS初始化值************************************************/
- /*
- BYTE bGPSIinitTable[32] = {0xA0,0xA2,0x00,0x18, //----------------------//head
- 0x81,0x02, //message id
- 0x00,0x01, // GGA output interval , has CheckSum?(1/0) (6,7)
- 0x00,0x01, // GLL (8,9)
- 0x00,0x01, //GSA (10,11)
- 0x00,0x01, //GSV
- 0x01,0x01, //RMC
- 0x00,0x01, //VTG
- 0x00,0x01, //MSS
- 0x00,0x01, //not defined
- 0x00,0x01, //ZDA
- 0x00,0x01, //not defined
- 0x12,0xC0, // bitrate ----------- //payload
- 0x01,0x60, //checksum
- 0xB0,0xB3 // end sequence
- };
- */
- BYTE bGpsSet[6][25]={"$PSRF103,00,00,00,01*24","$PSRF103,01,00,00,01*25","$PSRF103,02,00,00,01*26",
- "$PSRF103,03,00,00,01*27","$PSRF103,04,00,01,01*21","$PSRF103,05,00,00,01*21"};
-
- BYTE B_SuperPassWord[]="159753";//超级密码
- BYTE B_DefaultPassWord[]="1234";//默认密码
- //BYTE B_DefaultMont[]="13392836733";
- BYTE B_DefaultMont[]="13924662814";
- BYTE B_DefaultModem[]="13925296854";
- //BYTE B_DefaultIP[]="202.96.155.118";//默认IP地址
- BYTE B_DefaultIP[]="58.61.160.72";//默认IP地址
- typedef struct {
- BYTE bLatitude[12];//纬度
- BYTE bLongitude[12];//经度
- BYTE bCurDate[12];//当前日期
- BYTE bCurTime[12];//当前时间
- BYTE bSpeed[12];//速度
- BYTE bDirection[12];//方向
- }recGpsLct;
- recGpsLct REC_GPSLCTINFO;
- BYTE B_SwapDataCount=0;//重复连接交换数据次数
- BYTE B_SmsSendCnt=0;//短消息重复发送次数
- static unsigned char led = 0x00;
- static unsigned char relay = 0x00,beep = 0x00;
- BYTE B_DisCnctRelayTime;
- //BYTE KEY;
- //BYTE RELAY;
- /**********************************************************************************/
-
- /**************************定义函数列表*************************/
- void vSmsPutInBuf(BYTE bSmsLen,BYTE bSmsBuf[]);
- void vRelayOut(void),vKeyCheck(void),vLedFlashing(void),vAtCmdOverTime(void);
- void vSendSmsData(void);
- void vSMSSendSucc(void);
- void vGpsCheckOver(void);
- void vIinitGps(void);
- void vStartAtCommand(BYTE bCommandItem);
- void vStopSoftTimer_A(WORD wIndex);
- void vSwapGpsLctTime(void);
- void vConfirmOK(void),vConfirmERROR(void),vConfirmRING(void),vConfirmCLIP(void),vConfirmCSQ(void),
- vConfirmNOCARIR(void),vConfirmCMGS(void),vConfirmCMS_ERROR(void),vConfirmCCNT_OK(void),
- vConfirmCLOSED(void),vConfirmCMGL(void),vConfirmCMTI(void),vConfirmCMGR(void),vConfirmCCID(void),
- vConfirmCSCA(void),vConfirmIPD(void),vConfirmCallRdy(void),vConfirmCCNTFAIL(void),vSwapGpsStart(BYTE *bPhone,BYTE fbDataMode);
-
- #define MAX_CONFIRM_FUNC_NUM 26
- struct FunctionTable REC_ConfirmFunTable[ MAX_CONFIRM_FUNC_NUM ] =
- {
- {
- "OK",
- vConfirmOK//1
- },
- {
- "SHUT OK",
- vConfirmOK//2
- },
-
- {
- "SEND OK",
- vConfirmOK//3
- },
-
- {
- "ERROR",
- vConfirmERROR//4
- },
- {
- "+CME ERROR:",
- vConfirmERROR//5
- },
-
- {
- "+CMS ERROR:",
- vConfirmCMS_ERROR//6
- },
- {
- "SEND FAIL:",
- vConfirmERROR//7
- },
- {
- "RING",
- vConfirmRING//8
- },
-
- {
- "+CLIP:",
- vConfirmCLIP//9
- },
- {
- "+CMGS:",
- vConfirmCMGS//10
- },
- {
- "CONNECT OK",
- vConfirmCCNT_OK//11
- },
-
- {
- "CLOSED",
- vConfirmCLOSED//12
- },
- {
- "NO CARRIER",
- vConfirmNOCARIR//13
- },
-
- {
- "NO ANSWER",
- vConfirmNOCARIR//14
- },
-
- {
- "BUSY",
- vConfirmNOCARIR//15
- },
- {
- "+CMGL:",
- vConfirmCMGL//16
- },
-
- {
- "+CMTI:",
- vConfirmCMTI//17
- },
-
- {
- "+CMGR:",
- vConfirmCMGR//18
- },
-
- {
- "+CSCA:",
- vConfirmCSCA//19
- },
-
- {
- "+IPD",
- vConfirmIPD//20
- },
-
- {
- "Call Ready",
- vConfirmCallRdy//21
- },
-
- {
- "CONNECT FAIL",
- vConfirmCCNTFAIL//22
- },
-
- {
- "AT+CCID",
- vConfirmCCID//23
- },
- {
- "NO DIALTONE",
- vConfirmNOCARIR//24//NO DIALTONE
- },
- {
- "+CSQ:",
- vConfirmCSQ//25
- }
- };
- /*setupclock function*/
- void SetupClock(void)
- {
- RCC_DeInit (); /* RCC system reset(for debug purpose)*/
- RCC_HSEConfig (RCC_HSE_ON); /* Enable HSE */
- /* Wait till HSE is ready */
- while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
- RCC_HCLKConfig (RCC_SYSCLK_Div1); /* HCLK = SYSCLK */
- RCC_PCLK2Config (RCC_HCLK_Div1); /* PCLK2 = HCLK */
- RCC_PCLK1Config (RCC_HCLK_Div2); /* PCLK1 = HCLK/2 */
- RCC_ADCCLKConfig (RCC_PCLK2_Div4); /* ADCCLK = PCLK2/4 */
- *(vu32 *)0x40022000 = 0x01; /* Flash 2 wait state */
- /* PLLCLK = 8MHz * 9 = 72 MHz */
- RCC_PLLConfig (RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
- RCC_PLLCmd (ENABLE); /* Enable PLL */
- /* Wait till PLL is ready */
- while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
- /* Select PLL as system clock source */
- RCC_SYSCLKConfig (RCC_SYSCLKSource_PLLCLK);
- /* Wait till PLL is used as system clock source */
- while (RCC_GetSYSCLKSource() != 0x08);
- /* Enable USART1 and GPIOA clock */
- RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
- /* Enable GPIOB clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- /* Enable USART2 */
- RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2, ENABLE);
- /* I2C1 Periph clock enable */
- //RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
- /* Check if the system has resumed from IWDG reset -------------------------*/
- if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
- { /* IWDGRST flag set */
- /* Clear reset flags */
- RCC_ClearFlag();
- }
- /* Enable LSI */
- RCC_LSICmd(ENABLE);
-
- /* Enable write access to IWDG_PR and IWDG_RLR registers */
- IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
- /* IWDG counter clock: 32KHz(LSI) / 32 = 1KHz */
- IWDG_SetPrescaler(IWDG_Prescaler_32);
- /* Set counter reload value to 349 */
- IWDG_SetReload(349);
- /* Reload IWDG counter */
- IWDG_ReloadCounter();
- /* SysTick event each 10 ms with input clock equal to 9MHz (HCLK/8) */
- SysTick_SetReload(90000);
- SysTick_ITConfig(ENABLE); /* Enable SysTick interrupt */
- }
- /*******************************************************************************
- * Function Name : NVIC_Configuration
- * Description : Configures the nested vectored interrupt controller.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- #ifdef VECT_TAB_RAM
- /* Set the Vector Table base location at 0x20000000 */
- NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
- #else /* VECT_TAB_FLASH */
- /* Set the Vector Table base location at 0x08000000 */
- NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
- #endif
- /* Enable the USART1 Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- /* Enable the USART2 Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- }
- void SetupUART (void) {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
-
- /* Configure USART1 Rx (PA10) as input floating */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* Configure USART1 Tx (PA9) as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- /* Configure USART2 Rx (PA3) as input floating */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* Configure USART2 Tx (PA2) as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* USART1,2 configured as follow:
- - BaudRate = 115200 baud
- - Word Length = 8 Bits
- - One Stop Bit
- - No parity
- - Hardware flow control disabled (RTS and CTS signals)
- - Receive and transmit enabled
- - USART Clock disabled
- - USART CPOL: Clock is active low
- - USART CPHA: Data is captured on the middle
- - USART LastBit: The clock pulse of the last data bit is not output to
- the SCLK pin
- */
- USART_InitStructure.USART_BaudRate = 4800;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No ;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- USART_InitStructure.USART_Clock = USART_Clock_Disable;
- USART_InitStructure.USART_CPOL = USART_CPOL_Low;
- USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;
- USART_InitStructure.USART_LastBit = USART_LastBit_Disable;
-
- USART_Init(USART2, &USART_InitStructure);
- USART_InitStructure.USART_BaudRate = 4800;
- USART_Init(USART1, &USART_InitStructure);
-
- /* Enable the USART Transmoit interrupt: this interrupt is generated when the
- USART1 transmit data register is empty */
- // USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
- /* Enable the USART Receive interrupt: this interrupt is generated when the
- USART1 receive data register is not empty */
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
- /* Enable the USART Transmoit interrupt: this interrupt is generated when the
- USART2 transmit data register is empty */
- // USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
- /* Enable the USART Receive interrupt: this interrupt is generated when the
- USART1 receive data register is not empty */
- USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
-
- USART_Cmd(USART1, ENABLE);
- USART_Cmd(USART2, ENABLE);
- }
- void SetRELAYOut(void) {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- }
- void SetSCLOut (void) {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure I2C1 pins: SCL */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- void SetSDAOut(void) {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure I2C1 pins: SDA */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- void SetSDAIn(void) {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure I2C1 pins: SDA */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- void SetKEYIn(void) {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure P15 pins: KEY */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- void SetACCIn(void) {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure P4 pins: ACC */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- }
- void SetZHDIn(void) {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure P9 pins: ZHD */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- void SetPWRCHKIn(void) {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure P14 pins: PWRCHK */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- }
- void SetupLED (void) {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* Configure PA7 as outputs push-pull, max speed 50 MHz */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* Configure PB0 as outputs push-pull, max speed 50 MHz */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* Configure PB1 as outputs push-pull, max speed 50 MHz */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
- //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* Configure PB12 as outputs push-pull, max speed 50 MHz */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* Enable the SysTick Counter */
- SysTick_CounterCmd(SysTick_Counter_Enable);
- }
- /* Implementation of putchar (also used by printf function to output data) */
- int SendChar1 (int ch) { /* Write character to Serial Port */
- USART_SendData(USART1, (unsigned char) ch);
- while (!(USART1->SR & USART_FLAG_TXE));
- return (ch);
- }
- /* Implementation of putchar (also used by printf function to output data) */
- int SendChar2 (int ch) { /* Write character to Serial Port */
- USART_SendData(USART2, (unsigned char) ch);
- while (!(USART2->SR & USART_FLAG_TXE));
- return (ch);
- }
- void ClrRELAY()
- {
- // RELAY=0;//.13
- GPIOB->ODR &= 0xFFFFDFFF;
- relay = 0x00;
- }
- void SetRELAY()
- {
- // RELAY=1;//.13
- GPIOB->ODR |= 0x00002000;
- relay = 0xff;
- }
- void ClrBeep()
- {
- // BEEP=0;//.11
- GPIOA->ODR &= 0xFFFFF7FF;
- beep = 0x00;
-
- }
- void SetBeep()
- {
- // BEEP=1;//.11
- GPIOA->ODR |= 0x00000800;
- beep = 0xff;
- }
- void ClrLED()
- {
- // LED=0;//.7
- GPIOA->ODR &= 0xFFFFFF7F;
- led = 0x00;
- }
- void SetLED()
- {
- // LED=1;//.7
- GPIOA->ODR |= 0x00000080;
- led = 0xff;
- }
- void ClrSCL(void)
- {
- // SCL=0;//.6
- GPIOB->ODR &= 0xFFFFFFBF;
- }
- void SetSCL(void)
- {
- // SCL=1;//.6
- GPIOB->ODR |= 0x00000040;
- }
- void ClrSDA(void)
- {
- // SDA=0;//.7
- GPIOB->ODR &= 0xFFFFFF7F;
- }
- void SetSDA(void)
- {
- // SDA=1;//.7
- GPIOB->ODR |= 0x00000080;
- }
- u16 GetSDA(void)
- {
- return (GPIOB->IDR);
- }
- u16 GetAcc(void)
- {
- return (GPIOA->IDR);
- }
- void SomeNOP()
- {
- u16 dly_time;
- for(dly_time=0;dly_time<60;dly_time++);
- }
- void Delay_lms(void)
- {
- u16 dly_time;
- for(dly_time=0;dly_time<600;dly_time++);
- }
- void Delay_l0ms(void)
- {
- u8 dly_time;
- for(dly_time=0;dly_time<50;dly_time++)Delay_lms();
- IWDG_ReloadCounter();//喂狗
- }
- /**--------------------------------------------------------------------------------
- 调用方式:void I2CStart(void)
- 函数说明:私有函数,I2C专用
- ---------------------------------------------------------------------------------*/
- //发启始条件:时钟线为高时数据线发生下降沿跳变
- void I2CStart(void)
- {
- //// EA=0;
- // SCL=0;//.6
- ClrSCL();
-
- SomeNOP();
- // SDA=1;//.7
- SetSDA();
-
- SomeNOP();
- // SCL=1;
- SetSCL();
-
- SomeNOP();
- // SDA=0;
- ClrSDA();
- SomeNOP();
- }
- /**--------------------------------------------------------------------------------
- 调用方式:void I2CStop(void)
- 函数说明:私有函数,I2C专用
- ---------------------------------------------------------------------------------*/
- // 发结束条件:时钟线为高时数据线发生上升沿跳变
- void I2CStop(void)
- {
- // SCL=0;
- ClrSCL();
-
- SomeNOP();
- // SDA=0;
- ClrSDA();
-
- SomeNOP();
- // SCL=1;
- SetSCL();
-
- SomeNOP();
- // SDA=1;
- SetSDA();
-
- SomeNOP();
-
- //// EA=1;
- }
- /**--------------------------------------------------------------------------------
- 调用方式:void I2CSend(BYTE ch)
- 函数说明:私有函数,I2C专用
- ---------------------------------------------------------------------------------*/
- void I2CSendByte(u8 ch)
- {
- u8 i=8;
- // u8 time_1=255;
- while (i--)
- {
- // SCL=0;
- ClrSCL();
-
- SomeNOP();
-
- if((ch&0x80)==0x00)ClrSDA();
- else SetSDA();
-
- ch<<=1;
- SomeNOP();
- // SCL=1;
- SetSCL();
-
- SomeNOP();
- }
- // SCL=0; //SCL的下降沿发送最后一位
- ClrSCL();
-
- SomeNOP();
-
- // SDA=1;
- SetSDA();
-
- SomeNOP();
- // SCL=1;
- SetSCL();
-
- SomeNOP();
-
- SetSDAIn();
-
- //while(SDA)
- while( ((GetSDA())& 0x0080) == 0x0080)
- {
- // if(--time_1==0)
- // break;
- }
-
- SetSDAOut();
- }
- /**--------------------------------------------------------------------------------
- 调用方式:BYTE I2CReceive_ACK(void)
- 函数说明:私有函数,I2C专用
- ---------------------------------------------------------------------------------*/
- u8 I2CReceiveByte_ACK(void)//读取中间一个字节
- {
- u8 i=8;
- u8 ddata=0;
- SetSDAIn();
- while (i--)
- {
- ddata<<=1;
- // SCL=0;
- ClrSCL();
- SomeNOP();
- // SCL=1;
- SetSCL();
-
- SomeNOP();
- // ddata|=SDA;
- if( ((GetSDA())& 0x0080) == 0x0080)ddata|=0x01;
- else ddata&=0xfe;
- }
- SetSDAOut();
-
- // SCL=0;
- ClrSCL();
-
- SomeNOP();
- // SDA=0;
- ClrSDA();
- SomeNOP();
- // SCL=1;
- SetSCL();
-
- SomeNOP();
- return ddata;
- }
- /**--------------------------------------------------------------------------------
- 调用方式:BYTE I2CReceive(void)
- 函数说明:私有函数,I2C专用
- ---------------------------------------------------------------------------------*/
- u8 I2CReceiveByte(void)//读取最后一个字节
- {
- u8 i=8;
- u8 ddata=0;
- SetSDAIn();
- while (i--)
- {
- ddata<<=1;
- // SCL=0;
- ClrSCL();
-
- SomeNOP();
- // SCL=1;
- SetSCL();
-
- SomeNOP();
- // ddata|=SDA;//SCL上升沿锁定一个数据
- if( ((GetSDA())& 0x0080) == 0x0080)ddata|=0x01;
- else ddata&=0xfe;
- }
- SetSDAOut();
-
- // SCL=0;
- ClrSCL();
-
- SomeNOP();
- // SDA=1;
- SetSDA();
- SomeNOP();
- // SCL=1;
- SetSCL();
-
- SomeNOP();
- return ddata;
- }
- u8 bISP_IAP_ByteRead(u16 wAddr)
- {
- u8 bTemp;
- u16 wTemp;
-
- wTemp = wAddr;
- wTemp >>= 8;
- I2CStart();
- I2CSendByte(0xa0);
- I2CSendByte((u8)wTemp);
- I2CSendByte((u8)wAddr);
- SomeNOP();
-
- I2CStart();
- I2CSendByte(0xa1);
- bTemp = I2CReceiveByte();
- I2CStop();
- return bTemp;
- }
- void vISP_IAP_ByteProgram(u8 bTemp,u16 wAddr)
- {
- u16 wTemp;
-
- wTemp = wAddr;
- wTemp >>= 8;
- I2CStart();
- I2CSendByte(0xa0);
- I2CSendByte((u8)wTemp);
- I2CSendByte((u8)wAddr);
- I2CSendByte(bTemp);
- I2CStop();
- Delay_l0ms();
- }
- //==============================================================================
- u16 wTimer0Ccount(void)
- {
- u16 wT;
- wT = W_TimeCount;
- return(wT);
- }
- void vDelayTime(u16 wCount)
- {
- u16 wStartCount;
- wStartCount = wTimer0Ccount(); /* get the start count */
- while ((wTimer0Ccount() - wStartCount) <= wCount) /* wait for count "ticks" */
- {
- IWDG_ReloadCounter();//喂狗
- }
- }
- /********************************************************************************************
- **函数名: vTurnOnGsm
- **功能简介: 硬件控制SIM508开机
- **参数说明: 无
- **调用函数: 无
- **全局变量: 无
- **函数返回: 无
- **最后修改时间:2007-02-09
- **********************************************************************************************/
- void vTurnOnGsm(void)
- {
- GPIOB->ODR &= 0xfffffffd;
- vDelayTime(250);
- GPIOB->ODR |= 0x00000002;
- vDelayTime(300);
- }
- void vRestGPS(void)
- {
- GPIOB->ODR &= 0xfffffffe;//低电平
- vDelayTime(50);
- GPIOB->ODR |= 0x00000001;//高电平
- vDelayTime(50);
- GPIOB->ODR &= 0xfffffffe;//低电平
- vDelayTime(300);
- vIinitGps();
- vIinitGps();
-
- }
- /********************************************************************************************
- **函数名: vTurnOffGsm
- **功能简介: 硬件控制SIM508关机
- **参数说明: 无
- **调用函数: 无
- **全局变量: 无
- **函数返回: 无
- **最后修改时间:2007-02-09
- **********************************************************************************************/
- void vTurnOffGsm(void)
- {
- GPIOB->ODR &= 0xfffffffd;
- vDelayTime(70);
- GPIOB->ODR |= 0x00000002;
- }
- /******************************************************************************
- **函 数 名 : vMcuTimer0Intr
- **功能简介 : 定时器0中断服务函数
- **参数说明 : 无
- **调用函数 : 无
- **被调用函数: 无
- **全局变量 : W_TimeCount
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- /* SysTick interrupt happens every 10 ms */
- void SysTick_Handler (void)
- {
- W_TimeCount++;
- if(GPS_V_F)B_GpsVFTimer++;
- if(B_OverBeepStart)B_OverBeepTimer++;
-
- }
- /*******************************************************************************
- * Function Name : USART1_IRQHandler
- * Description : This function handles USART1 global interrupt request.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void USART1_IRQHandler(void)
- {
- BYTE bTByte2;
- WORD wTPsn2;
- if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
- {
- /* Read one byte from the receive data register */
- bTByte2 = (USART_ReceiveData(USART1));
- wTPsn2 = W_InSerial2;
- if(++wTPsn2 == MAX_SERIAL_LEN2) wTPsn2 = 0;//修改指针边界
- if(wTPsn2 != W_OutSerial2)//队列没有满的情况下
- {
- B_SerialQueue2[W_InSerial2] = bTByte2;
- W_InSerial2 = wTPsn2;
- }
- /* Clear the USART1 Receive interrupt */
- USART_ClearITPendingBit(USART1, USART_IT_RXNE);
- }
- }
- /*******************************************************************************
- * Function Name : USART2_IRQHandler
- * Description : This function handles USART2 global interrupt request.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void USART2_IRQHandler(void)
- {
- BYTE bTByte;
- WORD wTPsn;
- if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
- {
- /* Read one byte from the receive data register */
- bTByte = (USART_ReceiveData(USART2));
- wTPsn = W_InSerial;
- if(++wTPsn == MAX_SERIAL_LEN) wTPsn = 0;//修改指针边界
- if(wTPsn != W_OutSerial)//队列没有满的情况下
- {
- B_SerialQueue[W_InSerial] = bTByte;
- W_InSerial = wTPsn;
- }
- /* Clear the USART1 Receive interrupt */
- USART_ClearITPendingBit(USART2, USART_IT_RXNE);
- }
- }
- /******************************************************************************
- **函 数 名 : vInitSoftTimer
- **功能简介 : 软定时器初始化
- **参数说明 : 无
- **调用函数 : 无
- **被调用函数: main
- **全局变量 : REC_A_SoftTimers
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- void vInitSoftTimer(void)
- {
- WORD wI;
-
- //初始化A类软定时器
- for(wI = 0; wI < MAX_A_SOFT_TIMERS; wI++)
- {
- REC_A_SoftTimers[wI].bStartFb = 0;
- REC_A_SoftTimers[wI].wOverValue = 0;
- REC_A_SoftTimers[wI].pfTimerFunction = NULL;
- }
- }
- /******************************************************************************
- **函 数 名 : vSoftTimerSum
- **功能简介 : 用于查询软定时器计时
- **参数说明 : 无
- **调用函数 : 无
- **被调用函数: main
- **全局变量 : W_TimeCount,REC_A_SoftTimers
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- void vSoftTimerSum(void)
- {
- WORD wI;
-
- if(B_GpsVFTimer>2)//gps状态灯指示
- {
- B_GpsVFTimer = 0;
- //LED = 0;
- ClrLED();
- }
-
- if(B_OverBeepTimer > 10)
- {
- B_OverBeepTimer = 0;
- //驱动封鸣器
- if(beep)ClrBeep();
- else SetBeep();
- }
-
- if(W_TimeCount<MIN_TIME_PERIOD)return;
- W_TimeCount = 0; //一秒钟时间到
-
- for(wI = 0; wI < MAX_A_SOFT_TIMERS; wI++)//检测A类定时器
- {
- if(REC_A_SoftTimers[wI].bStartFb == 1)//只有启动了的定时器才作检测
- {
- if(REC_A_SoftTimers[wI].wOverValue>0)
- {
- if(--REC_A_SoftTimers[wI].wOverValue == 0)
- {
- REC_A_SoftTimers[wI].bStartFb = 0;
- REC_A_SoftTimers[wI].pfTimerFunction();//溢出处理
- }
- }
-
- }
- }
-
- if(++B_NoCsqTimer > 120)
- {
- B_NoCsqTimer = 0;
- GPIOB->ODR &= 0xffffefff;//power//低电平
- vDelayTime(500);
- GPIOB->ODR |= 0x00001000;//power//高电平
- vDelayTime(500);
- vTurnOnGsm();//开GSM508时序
- EN_CommandStatus = NO_COMMAND_WAIT;
- DW_SetAtCmdFlag = MAC_SET_AT_CMD;
- vStopSoftTimer_A(AT_CMD_WAITING_TIMER); //停止AT命令超时等待定时器
- B_AtCmdTimes = 0;
- B_AtCommandItem = 0xff;//最后赋值成无意义值
- W_InSerial = 0;
- W_OutSerial = 0;
- }
-
- if(++W_PowerSwitchTimer > 28800)//8个小时
- {
- W_PowerSwitchTimer = 0;
- GPIOB->ODR &= 0xffffefff;//power//低电平
- vDelayTime(500);
- GPIOB->ODR |= 0x00001000;//power//高电平
- vDelayTime(500);
- vTurnOnGsm();//开GSM508时序
- EN_CommandStatus = NO_COMMAND_WAIT;
- DW_SetAtCmdFlag = MAC_SET_AT_CMD;
- vStopSoftTimer_A(AT_CMD_WAITING_TIMER); //停止AT命令超时等待定时器
- B_AtCmdTimes = 0;
- B_AtCommandItem = 0xff;//最后赋值成无意义值
- W_InSerial = 0;
- W_OutSerial = 0;
- }
-
-
- if(FB_AtdDelayStart)//ATD电话拨打延时准备
- {
- if(++B_AtdDelayTimer >= 30)//延时到
- {
- FB_AtdDelayStart = 0;
- B_AtdDelayTimer = 0;
- vStartAtCommand(MAC_ATD_ITEM);//拨打电话
- FB_AtdReg = 1;
- }
- }
-
- vRelayOut();
- vKeyCheck();//按键检测,一秒钟检测一次
-
- if(B_NetStatus == 1)//网络标志值为'1'不许时间太长
- {
- if(++B_NetValue_1_Cnt > 60)
- {
- B_NetValue_1_Cnt = 0;
- vStartAtCommand(MAC_CIPSHUT_ITEM);//关断IP连接
- }
- }
- else B_NetValue_1_Cnt = 0;
-
- }
- /******************************************************************************
- **函 数 名 : vStartSoftTimer_A
- **功能简介 : 启动一软定时器A
- **参数说明 : wIndex--为定时器索引,范围0至MAX_A_SOFT_TIMERS-1,
- wDelay--定时时间,pfTimerFun--时间到后执行的函数
- **调用函数 : 无
- **被调用函数: 暂无
- **全局变量 : REC_A_SoftTimers[MAX_A_SOFT_TIMERS]
- **函数返回 : 无
- **修改时间 : 2007-01-27
- ******************************************************************************/
- void vStartSoftTimer_A(WORD wIndex,WORD wDelay,void(*pfTimerFun)(void))
- {
- if(wIndex>=MAX_A_SOFT_TIMERS)return;//没有这个定时器
- REC_A_SoftTimers[wIndex].wOverValue = wDelay;
- REC_A_SoftTimers[wIndex].bStartFb = 1;
- REC_A_SoftTimers[wIndex].pfTimerFunction = pfTimerFun;
- }
- /******************************************************************************
- **函 数 名 : vStopSoftTimer_A
- **功能简介 : 停止一软定时器A
- **参数说明 : wIndex--为定时器索引,范围0至MAX_A_SOFT_TIMERS-1,
- **调用函数 : 无
- **被调用函数: 暂无
- **全局变量 : REC_A_SoftTimers[MAX_A_SOFT_TIMERS]
- **函数返回 : 无
- **修改时间 : 2006-04-11
- ******************************************************************************/
- void vStopSoftTimer_A(WORD wIndex)
- {
- if(wIndex>=MAX_A_SOFT_TIMERS)return;//没有这个定时器
- REC_A_SoftTimers[wIndex].wOverValue = 0;
- REC_A_SoftTimers[wIndex].bStartFb = 0;
- REC_A_SoftTimers[wIndex].pfTimerFunction = NULL;
- }
- /******************************************************************************
- **函 数 名 : vMcuSerialIntr
- **功能简介 : MCU串口1中断服务函数
- **参数说明 : 无
- **调用函数 : 无
- **被调用函数: 无
- **全局变量 : W_InSerial, W_OutSerial
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- /*
- void vMcuSerialIntr(void) interrupt SERIAL_INT_NUM //4
- {
- BYTE bTByte;
- WORD wTPsn;
-
- if(RI) //接收中断服务函数
- {
-
- RI = 0;
- bTByte = SBUF;//最好先读一下
- wTPsn = W_InSerial;
- if(++wTPsn == MAX_SERIAL_LEN) wTPsn = 0;//修改指针边界
- if(wTPsn != W_OutSerial)//队列没有满的情况下
- {
- B_SerialQueue[W_InSerial] = bTByte;
- W_InSerial = wTPsn;
- }
- }
- }
- */
- /******************************************************************************
- **函 数 名 : wReadSerial
- **功能简介 : 读MCU串口1缓冲中的一个字节
- **参数说明 : 无
- **调用函数 : vCloseINTR(),vOpenINT()
- **被调用函数: 暂无
- **全局变量 : W_InSerial, W_OutSerial
- **返 回 值 : WORD类型,为读出一字节内容
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- WORD wReadSerial(void)
- {
- BYTE bTByte;
-
- //vCloseINTR();//关中断
- if(W_InSerial == W_OutSerial)//没有字节内容可读取
- {
- //vOpenINTR();//开中断
- return 0x0100;//返回无意义的值(凡是高子节不为零的数都是无意义的值
- }
- bTByte = B_SerialQueue[W_OutSerial];
- if(++W_OutSerial == MAX_SERIAL_LEN) W_OutSerial = 0; //修改指针边界
- //vOpenINTR();//开中断
- return ((WORD)bTByte);
- }
- /******************************************************************************
- **函 数 名 : wGetSerialUnReadBytes
- **功能简介 : 获取MCU串口1缓冲中当前未读的字节数目
- **参数说明 : 无
- **调用函数 : vCloseINTR(),vOpenINT()
- **被调用函数: 暂无
- **全局变量 : W_InSerial, W_OutSerial
- **返 回 值 : WORD类型,为未读出的字节数
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- WORD wGetSerialUnReadBytes(void)
- {
- WORD wTemp,wTemp1,wTemp2;
-
- //vCloseINTR();//关中断
- wTemp1 = W_InSerial;
- wTemp2 = W_OutSerial;
- //vOpenINTR();
- if(wTemp1 >= wTemp2)wTemp = wTemp1 - wTemp2;
- else wTemp = wTemp1 + MAX_SERIAL_LEN - wTemp2;
- return (wTemp);
- }
- /******************************************************************************
- **函 数 名 : vSendSerialByte
- **功能简介 : 从MCU串口1发送一字符
- **参数说明 : bParaCh-待发送的字节
- **调用函数 : 无
- **被调用函数: vSendSerialString,vSendSerialChars
- **全局变量 : 无
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- void vSendSerialByte(BYTE bParaCh)
- {
- /*
- SBUF = bParaCh;
- while(!TI){ }
- TI = 0;
- */
- SendChar2(bParaCh);
-
- }
- /******************************************************************************
- **函 数 名 : vSendSerialString
- **功能简介 : 从MCU串口1发送一字符串
- **参数说明 : *pstrPara-指向待发送的字符串
- **调用函数 : vSendSerialByte
- **被调用函数: 暂无
- **全局变量 : 无
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- void vSendSerialString(BYTE *pstrPara)
- {
- BYTE *pstrTemp;
- pstrTemp = pstrPara;
- while( (*pstrTemp != 0x00) && (*pstrTemp != 0x0d) )
- {
- vSendSerialByte(*pstrTemp++);
- }
- vSendSerialByte(0x0d);
- }
- //=================================================================================================
- /******************************************************************************
- **函 数 名 : vSendNULLString
- **功能简介 : 从MCU串口1发送一字符串
- **参数说明 : *pstrPara-指向待发送的字符串
- **调用函数 : vSendSerialByte
- **被调用函数: 暂无
- **全局变量 : 无
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- void vSendNULLString(BYTE *pstrPara, WORD wStrLen)
- {
- BYTE *pstrTemp;
- WORD wI;
-
- pstrTemp = pstrPara;
- for(wI=0;wI<wStrLen;wI++)
- {
- vSendSerialByte(*pstrTemp++);
- }
-
- }
- //=================================================================================================
- ///////////////////////////
- //modify
- /******************************************************************************
- **函 数 名 : vMcuSerialIntr2
- **功能简介 : MCU串口1中断服务函数
- **参数说明 : 无
- **调用函数 : 无
- **被调用函数: 无
- **全局变量 : W_InSerial, W_OutSerial
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- /*
- void vMcuSerialIntr2(void) interrupt SERIAL2_INT_NUM //9
- {
- BYTE bTByte2;
- WORD wTPsn2;
-
- if( (SCON2 & 0x01) == 0x01) //接收中断服务函数
- {
- SCON2 &= 0xfe; //位清零
- bTByte2 = SBUF2;//最好先读一下
- wTPsn2 = W_InSerial2;
- if(++wTPsn2 == MAX_SERIAL_LEN2) wTPsn2 = 0;//修改指针边界
- if(wTPsn2 != W_OutSerial2)//队列没有满的情况下
- {
- B_SerialQueue2[W_InSerial2] = bTByte2;
- W_InSerial2 = wTPsn2;
- }
- }
- }
- */
- /******************************************************************************
- **函 数 名 : wReadSerial2
- **功能简介 : 读MCU串口1缓冲中的一个字节
- **参数说明 : 无
- **调用函数 : vCloseINTR(),vOpenINT()
- **被调用函数: 暂无
- **全局变量 : W_InSerial2, W_OutSerial2
- **返 回 值 : WORD类型,为读出一字节内容
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- WORD wReadSerial2(void)
- {
- BYTE bTByte2;
-
- //vCloseINTR();//关中断
- if(W_InSerial2 == W_OutSerial2)//没有字节内容可读取
- {
- //vOpenINTR();//开中断
- return 0x0100;//返回无意义的值(凡是高子节不为零的数都是无意义的值
- }
- bTByte2 = B_SerialQueue2[W_OutSerial2];
- if(++W_OutSerial2 == MAX_SERIAL_LEN2) W_OutSerial2 = 0; //修改指针边界
- //vOpenINTR();//开中断
- return ((WORD)bTByte2);
- }
- /******************************************************************************
- **函 数 名 : wGetSerialUnReadBytes2
- **功能简介 : 获取MCU串口1缓冲中当前未读的字节数目
- **参数说明 : 无
- **调用函数 : vCloseINTR(),vOpenINT()
- **被调用函数: 暂无
- **全局变量 : W_InSerial2, W_OutSerial2
- **返 回 值 : WORD类型,为未读出的字节数
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- WORD wGetSerialUnReadBytes2(void)
- {
- WORD wTemp2,wTemp3,wTemp4;
-
- //vCloseINTR();//关中断
- wTemp3 = W_InSerial2;
- wTemp4 = W_OutSerial2;
- //vOpenINTR();
- if(wTemp3 >= wTemp4)wTemp2 = wTemp3 - wTemp4;
- else wTemp2 = wTemp3 + MAX_SERIAL_LEN2 - wTemp4;
- return (wTemp2);
- }
- /******************************************************************************
- **函 数 名 : vSendSerialByte2
- **功能简介 : 从MCU串口2发送一字符
- **参数说明 : bParaCh-待发送的字节
- **调用函数 : 无
- **被调用函数: vSendSerialString2,vSendSerialChars2
- **全局变量 : 无
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- void vSendSerialByte2(BYTE bParaCh2)
- {
- /*
- SBUF2 = bParaCh2;
- while( (SCON2 & 0x02) != 0x02 ){ }
- SCON2 &= 0xfd;//清零
- */
-
- SendChar1(bParaCh2);
-
- }
- /******************************************************************************
- **函 数 名 : vSendSerialString2
- **功能简介 : 从MCU串口2发送一字符串
- **参数说明 : *pstrPara2-指向待发送的字符串
- **调用函数 : vSendSerialByte2
- **被调用函数: 暂无
- **全局变量 : 无
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- void vSendSerialString2(BYTE *pstrPara2)
- {
- BYTE *pstrTemp2;
- pstrTemp2 = pstrPara2;
- while( (*pstrTemp2 != 0x00) && (*pstrTemp2 != 0x0d) )
- {
- vSendSerialByte2(*pstrTemp2++);
- }
- vSendSerialByte2(0x0d);
- vSendSerialByte2(0x0a);
- }
- //=================================================================================================
- /******************************************************************************
- **函 数 名 : vSendNULLString2
- **功能简介 : 从MCU串口2发送一字符串
- **参数说明 : *pstrPara2-指向待发送的字符串
- **调用函数 : vSendSerialByte2
- **被调用函数: 暂无
- **全局变量 : 无
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- void vSendNULLString2(BYTE *pstrPara2, WORD wStrLen2)
- {
- BYTE *pstrTemp2;
- WORD wI2;
-
- pstrTemp2 = pstrPara2;
- for(wI2=0;wI2<wStrLen2;wI2++)
- {
- if((wI2%50)==0)IWDG_ReloadCounter();//喂狗
- vSendSerialByte2(*pstrTemp2++);
- }
-
- }
- //=================================================================================================
- /*
- void vIinitGps(void)//初始化GPS
- {
- WORD wI;
- for(wI = 0;wI < 32; wI++)
- vSendSerialByte2(bGPSIinitTable[wI]);
-
- }
- */
- void vIinitGps(void)//初始化GPS
- {
- BYTE bI;
-
- for(bI = 0; bI < 6; bI++)
- {
- IWDG_ReloadCounter();//喂狗
- vSendSerialString2(bGpsSet[bI]);
- }
- W_InSerial2 = 0;
- W_OutSerial2 = 0;
- }
- /******************************************************************************
- **函 数 名 : wReadTcpSerial
- **功能简介 : 读MCU串口1缓冲中的一个字节
- **参数说明 : 无
- **调用函数 : vCloseINTR(),vOpenINT()
- **被调用函数: 暂无
- **全局变量 : W_InSerial, W_OutSerial
- **返 回 值 : WORD类型,为读出一字节内容
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- WORD wReadTcpSerial(void)
- {
- BYTE bTByte;
-
- if(W_TcpInSerial == W_TcpOutSerial)//没有字节内容可读取
- {
- return 0x0100;//返回无意义的值(凡是高子节不为零的数都是无意义的值
- }
- bTByte = B_TcpSerialQueue[W_TcpOutSerial];
- if(++W_TcpOutSerial == MAX_TCP_SERIAL_LEN) W_TcpOutSerial = 0; //修改指针边界
- return ((WORD)bTByte);
- }
- /******************************************************************************
- **函 数 名 : wGetTcpSerialUnReadBytes
- **功能简介 : 获取MCU串口1缓冲中当前未读的字节数目
- **参数说明 : 无
- **调用函数 : vCloseINTR(),vOpenINT()
- **被调用函数: 暂无
- **全局变量 : W_InSerial, W_OutSerial
- **返 回 值 : WORD类型,为未读出的字节数
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-27
- ******************************************************************************/
- WORD wGetTcpSerialUnReadBytes(void)
- {
- WORD wTemp,wTemp1,wTemp2;
-
- wTemp1 = W_TcpInSerial;
- wTemp2 = W_TcpOutSerial;
- if(wTemp1 >= wTemp2)wTemp = wTemp1 - wTemp2;
- else wTemp = wTemp1 + MAX_TCP_SERIAL_LEN - wTemp2;
- return (wTemp);
- }
- //=================================================================================================
- /******************************************************************************
- **函 数 名 : vInitEepromPara
- **功能简介 : 写密码为默认值
- **参数说明 : 无
- **调用函数 : bISP_IAP_ByteRead,vISP_IAP_ByteProgram
- **被调用函数: 暂无
- **全局变量 : 无
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-02-05
- ******************************************************************************/
- void vInitEepromPara(void)
- {
- BYTE bI,bJ;
-
- if((bISP_IAP_ByteRead(CHECK_WORD_STAR_ADDR))!=CHECK_WORD1||(bISP_IAP_ByteRead(CHECK_WORD_STAR_ADDR + 1))!=CHECK_WORD2)
- {
-
-
- vISP_IAP_ByteProgram(CHECK_WORD1, CHECK_WORD_STAR_ADDR);
- vISP_IAP_ByteProgram(CHECK_WORD2, CHECK_WORD_STAR_ADDR + 1);
- for(bI = 0; bI < MAX_PHONE_NUM; bI++)//使用默认密码
- {
- vISP_IAP_ByteProgram(B_DefaultPassWord[bI], PASSWORD_STAR_ADDR + bI);
- if(B_DefaultPassWord[bI] == 0x0)break;
- }
-
- for(bI = 0; bI < MAX_PHONE_NUM; bI++)//使用默认服务器IP地址
- {
- vISP_IAP_ByteProgram(B_DefaultIP[bI], SEVER_IP_STAR_ADDR + bI);
- if(B_DefaultIP[bI] == 0x0)break;
- }
-
- for(bI = 0; bI < MAX_PHONE_NUM; bI++)//使用默认监控电话号码作为设备号
- {
- vISP_IAP_ByteProgram(B_DefaultMont[bI], DEVICE_PHONE_STAR_ADDR + bI);
- if(B_DefaultMont[bI] == 0x0)break;
- }
-
- for(bI = 0; bI < MAX_PHONE_NUM; bI++)//使用默认监控电话号码
- {
- vISP_IAP_ByteProgram(B_DefaultMont[bI], MONT_PHONE_STAR_ADDR + bI);
- if(B_DefaultMont[bI] == 0x0)
- {
- vISP_IAP_ByteProgram('#', MONT_PHONE_STAR_ADDR + bI + 1);
- break;
- }
- }
-
-
- for(bI = 0; bI < MAX_PHONE_NUM; bI++)//使用默认中心MODEM号码
- {
- vISP_IAP_ByteProgram(B_DefaultModem[bI], CENTER_MODEM_STAR_ADDR + bI);
- if(B_DefaultModem[bI] == 0x0)break;
- }
-
- W_InternalLctTimer = 0;
- vISP_IAP_ByteProgram( (BYTE)(W_InternalLctTimer >> 8),LCT_TIME_INTV_ADDR);
- vISP_IAP_ByteProgram( (BYTE) W_InternalLctTimer, LCT_TIME_INTV_ADDR + 1);
-
- W_OverSpeedValue = 110;
- vISP_IAP_ByteProgram( (BYTE)(W_OverSpeedValue >> 8),OVER_SPEED_INTV_ADDR);
- vISP_IAP_ByteProgram( (BYTE) W_OverSpeedValue, OVER_SPEED_INTV_ADDR + 1);
-
- vISP_IAP_ByteProgram('0', PHONE_LOCATION_MODE);//电话定位模式默认为'0'
- }
-
- for(bI=0;bI<MAX_PHONE_NUM-1;bI++)//读取中心MODEM号码
- {
- B_UserNum[bI] = bISP_IAP_ByteRead(CENTER_MODEM_STAR_ADDR + bI);
- if(B_UserNum[bI] == 0x0)break;
- }
- B_UserNum[bI] = 0x0;
-
- bI = bISP_IAP_ByteRead(LCT_TIME_INTV_ADDR);
- bJ = bISP_IAP_ByteRead(LCT_TIME_INTV_ADDR + 1);
- W_InternalLctTimer = bI * 256 + bJ;
-
- bI = bISP_IAP_ByteRead(OVER_SPEED_INTV_ADDR);
- bJ = bISP_IAP_ByteRead(OVER_SPEED_INTV_ADDR + 1);
- W_OverSpeedValue = bI * 256 + bJ;
-
- strcpy(B_ScaPhone,"8613800755500");
- }
- //=================================================================================================
- //=================================================================================================
- /******************************************************************************
- **函 数 名 : bSchearAtCommand
- **功能简介 : 查找处于要发送并且优先级最高的AT命令
- **参数说明 : 无
- **调用函数 : 无
- **被调用函数: vProduceAtCommand
- **全局变量 : DW_SetAtCmdFlag
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-29
- ******************************************************************************/
- BYTE bSchearAtCommand(void)
- {
- BYTE bI;
- DWORDS dwTemp;
-
- dwTemp = DW_SetAtCmdFlag;
- for(bI=0; bI<32; bI++)
- {
- if( (dwTemp&0x00000001) == 1 )break;
- dwTemp >>= 1;
- }
- return (bI);
- }
- /******************************************************************************
- **函 数 名 : vStopAtCommand
- **功能简介 : 不再发送该AT命令
- **参数说明 : bCommandItem-要发送的AT命令在REC_AtCommands中的索引
- **调用函数 : 无
- **被调用函数: vAtCmdOverTime
- **全局变量 : DW_SetAtCmdFlag,DW_MapTbl
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-29
- ******************************************************************************/
- void vStopAtCommand(BYTE bCommandItem)
- {
- if(bCommandItem < 32)DW_SetAtCmdFlag &= ~DW_MapTbl[bCommandItem];
- }
- /******************************************************************************
- **函 数 名 : vStartAtCommand
- **功能简介 : 使该AT命令可以发送
- **参数说明 : bCommandItem-要发送的AT命令在REC_AtCommands中的索引
- **调用函数 : 无
- **被调用函数: 暂无
- **全局变量 : DW_SetAtCmdFlag,DW_MapTbl
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-29
- ******************************************************************************/
- void vStartAtCommand(BYTE bCommandItem)
- {
- if(bCommandItem < 32)DW_SetAtCmdFlag |= DW_MapTbl[bCommandItem];
- }
- /******************************************************************************
- **函 数 名 : vSmsPutInBuf
- **功能简介 : 短消息进发送缓冲
- **参数说明 : bSmsLen-消息长度,bSmsBuf[]消息内容
- **调用函数 : 无
- **被调用函数:
- **全局变量 : B_SmsSendLen,B_SmsSendItem
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-02-05
- ******************************************************************************/
- void vSmsPutInBuf(BYTE bSmsLen,BYTE bSmsBuf[])
- {
- BYTE bI;
- B_SmsSendLen = bSmsLen;
- for(bI = 0; bI < bSmsLen; bI++)
- B_SmsSendItem[bI] = bSmsBuf[bI];
- }
- /******************************************************************************
- **函 数 名 : vReportLctInfo-二进制编码
- **功能简介 : 返回位置信息
- **参数说明 : 无
- **调用函数 :
- **被调用函数:
- **全局变量 :
- **返 回 值 : 无
- **函数版本 : V2.00.00
- **修改时间 : 2008-07-27
- ******************************************************************************/
- void vReportLctInfo(void)
- {
- BYTE bI,bJ,bTemp,bStr[15]="#[GPLUS GB012]";
- DWORDS dwLctInfo;
-
-
- bJ = 0;
- //-------------------起始---------------------------------
- for(bI=0;bI<14;bI++)
- {
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = bStr[bI];
- }
-
-
- //------------------经度值计算----------------------------
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = '[';
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = REC_GPSLCTINFO.bLongitude[0];
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = REC_GPSLCTINFO.bLongitude[1];
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = REC_GPSLCTINFO.bLongitude[2];
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = '.';
- dwLctInfo = 0;
- for(bI=0;bI<7;bI++)
- {
- bTemp = REC_GPSLCTINFO.bLongitude[3 + bI];
- if(bTemp == '.')continue;
- if(bTemp == 0x0)bTemp = 0x30;
- dwLctInfo = dwLctInfo * 10 + bTemp - 0x30;
- }
- dwLctInfo = dwLctInfo/60;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = dwLctInfo/1000 + 0x30;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = (dwLctInfo%1000)/100 + 0x30;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = ((dwLctInfo%1000)%100)/10 + 0x30;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = dwLctInfo%10 + 0x30;
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = ']';
- //------------------经度值计算----------------------------
-
-
-
- //------------------纬度值计算----------------------------
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = '[';
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = REC_GPSLCTINFO.bLatitude[0];
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = REC_GPSLCTINFO.bLatitude[1];
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = '.';
-
- dwLctInfo = 0;
- for(bI=0;bI<7;bI++)
- {
- bTemp = REC_GPSLCTINFO.bLatitude[2 + bI];
- if(bTemp == '.')continue;
- if(bTemp == 0x0)bTemp = 0x30;
- dwLctInfo = dwLctInfo * 10 + bTemp - 0x30;
- }
- dwLctInfo = dwLctInfo/60;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = dwLctInfo/1000 + 0x30;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = (dwLctInfo%1000)/100 + 0x30;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = ((dwLctInfo%1000)%100)/10 + 0x30;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = dwLctInfo%10 + 0x30;
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = ']';
- //------------------纬度值计算----------------------------
-
- //------------------速度值计算----------------------------
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = '[';
-
- dwLctInfo = (DWORDS)( 100 * (atof(REC_GPSLCTINFO.bSpeed)) );
-
- dwLctInfo = (185 * dwLctInfo)/100;
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = dwLctInfo/1000 + 0x30;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = (dwLctInfo%1000)/100 + 0x30;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = '.';
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = ((dwLctInfo%1000)%100)/10 + 0x30;
-
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = dwLctInfo%10 + 0x30;
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = ']';
- //------------------速度值计算----------------------------
-
-
- //-------------------结束---------------------------------
- for(bI=0;bI<14;bI++)
- {
- B_SmsSendItem[bJ++] = 0x0;
- B_SmsSendItem[bJ++] = bStr[bI];
- }
-
- B_SmsSendLen = bJ;
- }
- /********************************************************************************************
- **函数名: vDisConnectTcp
- **功能简介: 关闭IP连接
- **参数说明: 无
- **调用函数: 无
- **全局变量: 无
- **函数返回: 无
- **最后修改时间:2007-02-09
- **********************************************************************************************/
- void vDisConnectTcp(void)
- {
- BYTE bI,bK,bLen,bLonLat[24];
-
- B_NetStatus = 0;
- vStartAtCommand(MAC_CIPSHUT_ITEM);//关断IP连接
- vStopAtCommand(MAC_CIPSEND_ITEM);//停止该命令再次发送
- if(++B_SwapDataCount == 3)
- {
- B_SwapDataCount = 0;
- vSmsPutInBuf(94,B_TcpFailRet);
-
- strcpy(bLonLat,REC_GPSLCTINFO.bLongitude);
- strcat(bLonLat,",");
- strcat(bLonLat,REC_GPSLCTINFO.bLatitude);
- bLen = strlen(bLonLat);
-
- B_SmsSendLen = 2*bLen + 94;
-
- bK = 94;
- for(bI=0;bI<bLen;bI++)
- {
- B_SmsSendItem[bK++] = 0x00;
- B_SmsSendItem[bK++] = bLonLat[bI];
- if(bLonLat[bI] == 0x0)break;
- if(bK == MAX_SEND_SMS_LEN)break;
- }
-
-
- }
- else
- vSwapGpsStart(B_UserNum,0);//放入需要交换的数据到vSmsPutInBuf
-
- }
- /******************************************************************************
- **函 数 名 : vAtCmdOverTime
- **功能简介 : AT命令超时处理
- **参数说明 : 无
- **调用函数 : vStopAtCommand
- **被调用函数: vStartSoftTimer_A
- **全局变量 : REC_AtCommands[32],EN_CommandStatus,B_AtCommandItem
- **返 回 值 : 无
- **函数版本 : V1.00.00
- **修改时间 : 2007-01-29
- ******************************************************************************/
- void vAtCmdOverTime(void)
- {
- EN_CommandStatus = NO_COMMAND_WAIT;
-
- if(B_AtCommandItem == MAC_CIPSEND_ITEM)
- {
- vStopAtCommand(B_AtCommandItem);//禁止该AT命令发送,等待下一次该命令被激活
- vSendSerialByte2(B_AtCommandItem/10 + 0x30);
- vSendSerialByte2(B_AtCommandItem%10 + 0x30);
- B_SmsSendLen = 0;//没有消息可发送
- B_NetStatus = 0;//强制断开网络
- vStartAtCommand(MAC_CIPSHUT_ITEM);//关断IP连接
- B_AtCmdTimes = 0;
- }
-
- if(++B_AtCmdTimes >= MAX_AT_CMD_ERRORS)//无回应时,最多发送MAX_AT_CMD_ERRORS次
- {
- B_AtCmdTimes = 0;
- vStopAtCommand(B_AtCommandItem);//禁止该AT命令发送,等待下一次该命令被激活
- if(B_AtCommandItem == MAC_CMGS_ITEM || B_AtCommandItem == MAC_CIPSEND_ITEM || B_AtCommandItem == MAC_CIPSTART_ITEM)
- {
- B_SmsSendLen = 0;//没有消息可发送
- vStartAtCommand(MAC_CIPSHUT_ITEM);//关断IP连接
- }
- else
- {
-
- // vSendSerialByte2(B_AtCommandItem/10 + 0x30);
- // vSendSerialByte2(B_AtCommandItem%10 + 0x30);
- if(!B_OnOff_FLAG)
- {
- vTurnOnGsm();//开GSM508时序
- // vSendSerialByte2('O');
- // vSendSerialByte2('N');
- }
- else
- {
- vTurnOffGsm();//关GSM508时序
- B_OnOff_FLAG = 0;
- // vSendSerialByte2('O');
- // vSendSerialByte2('F');
- }
- DW_SetAtCmdFlag = MAC_SET_AT_CMD;
- }
- // for(;;);//使看门狗溢出
- }
- B_AtCommandItem = 0xff;//最后赋值成无意义值
- }
- /******************************************************************************
- **函 数 名 : vProduceAtCommand
- **功能简介 : 产生一条AT命令并发送
- **参数说明 : 无
- **调用函数 : vStartSoftTimer_A