//=========================================
//
//
//
// 文 件 名: GPRS.c
// 目标器件:
// 编写日期:
// 作 者:
//
//=========================================
#include "..\declare\define.h"
#include "..\declare\key.h"
#include "..\declare\globePara.h"
#include "..\declare\SHARPLCD.h"
#include "..\declare\timer.h"
#include "..\declare\ST16C554.h"
#include "..\declare\uart.h"
#include "..\declare\I2C.h"
#include "..\declare\crc.h"
#include "..\declare\SDcard.h"
#include "..\declare\ISP1161.h"
#include "..\declare\Fat.h"
#include "..\declare\diskmanange.h"
#include "..\declare\uart.h"
#include "..\declare\codeconversion.h"
#define AT_RECV
// - GSM模块参数
typedef struct GSMMODULE{
UINT8 csq; // 场强值
UINT8 net; // 网络状态
UINT8 copn[30]; // 动营商
UINT8 micGain; // MIC增溢
UINT8 speakerGain; // 喇叭增溢
UINT8 phoneSelf[20]; // 本机号码
UINT8 msgCtrCode[20];
}GSMMODULE;
// - GSM呼叫参数
typedef struct GSMCALLLIST{
UINT8 num; // 列表编号
UINT8 dir; // 呼入/呼出
UINT8 stat; // 状态,"接通/保持/呼叫/呼入/等待,等"
UINT8 mode; // 模式,"语音/数据/传真/未知"
UINT8 mpty; // 是否为电话会议
UINT8 phoneCode[20]; // 电话号码
}CALLLIST;
typedef struct GSMCALLPARA{
UINT8 callNum; // 呼叫个数
UINT8 callPhone[20];
CALLLIST currentList; // 当前通话列表
CALLLIST checkList[5]; // 查询通话列表
}GSMCALL;
// - GSM短消息参数
typedef struct GSMMSGPARA{
UINT8 msgRead;
UINT8 msgFormat; // 短信格式 0-PDU,1-文本
UINT8 msgPhone[20]; // 短信号码
UINT8 msgCtrCode[20]; // 短信中心号码
UINT8 msgPhoneCode[20];
UINT8 msgSendBuf[150]; // 短信发送缓冲区
UINT8 msgRecvBuf[512]; // 短信接收缓冲区
}GSMMSG;
// - GSM GPRS参数
typedef struct GSMGPRSPARA{
UINT8 gprsSta; // 0模块未附着,1,模块已附着GPRS网络
UINT8 gprsConnect; // 0,GPRS未连接,1,GPRS已连接到要应的IP地址上,
UINT8 APN[20];
UINT8 userName[20];
UINT8 password[20];
UINT8 sourcePort[6]; // 本机端口
UINT8 aimPort[6]; // 联接远程端口
UINT8 sourceProtocol[4];
UINT8 aimProtocol[4]; // 协议TCP/IP,UDP协议
UINT8 sourceIP[20]; // 本机IP地址
UINT8 aimIP[20]; // 联接远程IP地址
}GSMGPRS;
extern const UINT8 DISP_TEST_FRAME[107]; // extern from: wirelessTest.c
extern const UINT8 DISP_REQUERST_DATA[38] ;
extern const char FN_TYPE[301][6];
extern const UINT8 DISP_TYPE[20][17];
extern UINT8 LcdShowHex(UINT16 x0,UINT16 y0,UINT16 x1,UINT16 y1,UINT8 botton,UINT8 character,UINT8 *pBuf,UINT16 num,UINT8 *title,UINT8 page);
const UINT8 GPRS_BAR[12][10]={
"接 入 点:","用 户 名:","密 码:","目标IP号:","机 车 号:","车 次 号:",
"本机端口:","本机协议:","目标端口:","目标协议:","调令类型:","调令包号:"};
const GSMGPRS GPRS_CONST_STYLE={0,0,"","15800121","15800121","20001","20000","UDP","UDP","0.0.0.0","10.10.10.10"};
const UINT8 GSMCALLBAR[4][5]={"呼叫","接听","切换","挂断"};
const UINT8 CONST_MANUFACTURER[15][20]={
"未知厂家","希电公司","天津通广","思科泰","杭州创联",
"上海通信","泉州","兰新集团","深圳长龙","上海复旦",
"北京华铁","北京和利时","北京世纪东方","河南辉煌","未知厂家"};
//===============================================================================
//
// GSM模块基本函数
//
//===============================================================================
/*==============================================
函 数:
功 能:模块电源控制
参 数:
返 回:
================================================*/
void GsmModulePwr(UINT8 type)
{
IO1DIR |= GSMPWR;
if(type == 1)
{
IO1CLR = GSMPWR;
}
else
{
IO1SET = GSMPWR;
}
}
/*==============================================
函 数:
功 能:模块天关机
参 数:开/关机
返 回:
================================================*/
void GsmModuleOn(void)
{
IO1DIR |= GSMON;
IO1CLR = GSMON;
DelayMs(2000,0);
IO1SET = GSMON;
}
/*==============================================
函 数:
功 能:发送AT指令
参 数:
返 回:
================================================*/
void ATCmdSend(UINT8 *cpT)
{
UartBSend(cpT,strlen((const char *)cpT));
}
/*==============================================
函 数:
功 能:接收应答
参 数:
返 回:0: 未等到相应的数据
1: 等到相应的数据
2: 接收到GPRS发送允许标志">"
0xFF: 按键返回
================================================*/
UINT8 WaitForAnswer(UINT8 *pBuf,UINT16 time)
{
UINT8 key;
DelayMs(time,1);
while(system.bDelayMsOvr == 0)
{
SystemCycle();
key=GetChar(1);
if(key==KEY_RETURN) return(0xFF); // "返回"
if(uartExp[1].recv == 1)
{
uartExp[1].recv = 0;
#ifdef AT_RECV
Uart0Send(uartExp[1].RECV_BUF,uartExp[1].recvByte+2);
#endif
if(*pBuf == 0)
{
if(uartExp[1].recvByte > 2)
{
memcpy(pBuf,uartExp[1].RECV_BUF,uartExp[1].recvByte);
return(1);
}
}
else if(memcmp(uartExp[1].RECV_BUF,pBuf,strlen((const char *)pBuf)) == CMP_OK)
{
return(1);
}
else
{
uartExp[1].recv = 0;
}
}
else if(uartExp[1].recv == 2)
{
uartExp[1].recv = 0;
#ifdef AT_RECV
Uart0Send(">\r\n",3);
#endif
return(2);
}
}
return(0);
}
/*==============================================
函 数:
功 能:接收处理
参 数:
返 回:
================================================*/
UINT8 GprsRecvHandle(UINT8 *cPT,UINT16 *num)
{
if(uartExp[1].recv == 3)
{
uartExp[1].recv = 0;
if (CrcCheck(uartExp[1].RECV_BUF,uartExp[1].recvByte) == CRC_OK)
{
*num=uartExp[1].recvByte;
memcpy(cPT,uartExp[1].RECV_BUF,uartExp[1].recvByte);
return (1);
}
}
return (0);
}
/*==============================================
函 数:
功 能:
参 数:
返 回:
================================================*/
UINT8 GsmIni(GSMMODULE *Module)
{
UINT8 i;
UINT8 ret;
for(i=0;i<10;i++) // 模块未连接
{
ATCmdSend("ATE0\r");
ret= WaitForAnswer("OK",500);
if( ret== 1)
{
break;
}
else if(ret == 0xFF)
{
return(0xFF);
}
}
if(i == 10)
{
return(0);
}
WaitForAnswer("Call Ready",10000); // 等待模块注册上网络
for(i=0;i<20;i++) // 网络查询
{
ATCmdSend("AT+CREG?\r");
ret = WaitForAnswer("+CREG:",1000);
if(ret == 1)
{
if(uartExp[1].RECV_BUF[9] == '1')
{
break;
}
else
{
DelayMs(500,0);
}
}
else if(ret == 0xFF)
{
return (0xFF);
}
}
ATCmdSend("AT+CSQ\r"); // 场强查询
ret=WaitForAnswer("+CSQ:",2000);
if(ret == 1)
{
if(uartExp[1].RECV_BUF[7] != ',')// 注意:AT指令返回是ASCII码,0-9单字节表示,10用双字节表示
{
Module->csq = (uartExp[1].RECV_BUF[6]-0x30)*10+(uartExp[1].RECV_BUF[7]-0x30);
}
else
{
Module->csq = (uartExp[1].RECV_BUF[6]-0x30);
}
}
else if(ret==0xFF)
{
return(0xFF);
}
if(i == 20)
{
return(2);
}
else
{
return(1);
}
}
//===============================================================================
//
// GSM语音功能
//
//===============================================================================
/*==============================================
函 数:
功 能:初始化
参 数:
返 回:
================================================*/
void LcdShowCallTheme(GSMMODULE *Module,GSMCALL *call)
{
UINT8 i;
UINT8 buf[5];
// -- 框架
LcdDrawRectFrame(0,0,319,239,H_RED); // 画边框
LcdDrawRectBlock(1,1,318,42,H_YELLOW); // 相当于清屏功能
LcdDrawRectBlock(1,42,318,65,H_BLUE); // 相当于清屏功能
LcdDrawRectBlock(1,65,65,238,H_SYAN); // 相当于清屏功能
LcdDrawRect
GPRS_set.zip_setgprs
版权申诉
39 浏览量
2022-09-24
19:04:20
上传
评论
收藏 12KB ZIP 举报
刘良运
- 粉丝: 70
- 资源: 1万+
最新资源
- proteusntion-model-for-network-id开发笔记
- dockerntion-model-for-network-ids开发笔记
- 工程伦理e-MM-m开发笔记
- zlibrary-attention-model-for-network-i开发笔记
- matlab GUI仿真ntion-model-for-network-ids开发笔记
- 注意力机制t-JavaWeb-m开发笔记
- 雾霾分析的MATLAB GUI仿真程序
- 基于Matlab的超声场可视化研究及GUI仿真模拟
- DJ宏财-全外文FunkyHouse音乐总有一天你会出现在我身边必听精选专辑串烧.mp3
- kuzu 5.16(是2.18回锅饭).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈