12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298 |
- /**********************************************************************************
- * File Name: Modem.c
- * Function Describe:device for modem
- * Relate Module:
- * Explain: the modem must be using ZTE MC8332
- * Writer: ShiLiangWen
- * Date: 2015.1.20
- ***********************************************************************************/
- #define THIS_FILE_ID 2
- /* Includes ------------------------------------------------------------------*/
- #include "includes.h"
- //os_mbx_declare (PocMsgBox, 5); /* Declare an RTX mailbox */
- //_declare_box(PocMpool,sizeof(SUT_MODEM_POC_MSG),5);
- //SUT_SMS_PARA sutSMSpara;
- //os_mbx_declare (AtMsgBox, 7); /* Declare an RTX mailbox */
- //_declare_box(AtMpool,sizeof(SUT_MODEM_AT_MSG),7);
- SUT_MODEM_AT_MSG sutAtm,sutAtmPro;
- unsigned char g_ucModemSentTcpCt;//TCP 发送计数器
- unsigned char g_usModeMTime=0x00;
- unsigned char g_usModeSTime=0x00;
- unsigned char g_usModeHTime=0x00;
- unsigned char g_usModeYTime=0x00;//年
- unsigned char g_usModemTime=0x00;//月
- unsigned char g_usModeDTime=0x00;//日
- //MODEM_TYPE MODEM_TYPE;
- /************************************************************************************
- *
- *************************************************************************************/
- void ModemSendAT(char *p)
- {
- unsigned short len;
- len=strlen(p);
- RunMake(THIS_FILE_ID);
- #if UART2_TX_USE_DMA==0
- Uart2Send(p,len);
- #else
- USART2_Send(p,len);
- #endif
-
- }
- /************************************************************************************
- *
- *************************************************************************************/
- void ModemSendData(unsigned char *pData,unsigned short datalen)
- {
-
- #if UART2_TX_USE_DMA==0
- Uart2Send(pData,datalen);
- #else
- USART2_Send((char *)pData,datalen);
- #endif
- }
- /**********************************************************************************
- 等待模块启动完成
- 0:成功 -1:超时
- ***********************************************************************************/
- int WaitModemIsOpened(void)
- {
-
- int i;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- RunMake(THIS_FILE_ID);
- for(i=0;i<100;i++){
- SlwTrace(INF,"AT",1);
- ModemSendAT("AT\r\n");
- //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&pMsg,50)){
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData)))){
- if('O'==pMsg->MsgData[0] && 'K'==pMsg->MsgData[1]){
- return 0;
- }
- //free(pMsg);
- }else os_dly_wait(1);
- }
- return -1;
- }
- void ModemCtrlInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- MODEM_DTR_HIGH;
- MODEM_RING_HIGH;
- MODEM_DSR_HIGH;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Pin = MODEM_DTR_PIN;
- GPIO_Init(MODEM_DTR_PORT, &GPIO_InitStructure);
- MODEM_DTR_HIGH;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Pin = MODEM_RING_PIN;
- GPIO_Init(MODEM_RING_PORT, &GPIO_InitStructure);
- MODEM_RING_HIGH;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Pin = MODEM_DSR_PIN;
- GPIO_Init(MODEM_DSR_PORT, &GPIO_InitStructure);
- MODEM_DSR_HIGH;
- MODEM_DCD_HIGH;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_InitStructure.GPIO_Pin = MODEM_DCD_PIN;
- GPIO_Init(MODEM_DCD_PORT, &GPIO_InitStructure);
- }
- /*************************************************************************
- *ModemWaitAtReady
- **************************************************************************/
- int ModemWaitAtReady(void)
- {
- int i;
- SUT_MODEM_AT_MSG *pMsg;
- for(i=0;i<20;i++){
- if(ModemSendAT2WaitAckMsg("AT\r\n","OK",&pMsg,100)){
- //_free_box(AtMpool,pMsg);
- return 1;
- }
- }
- return 0;
- }
- /*************************************************************************
- ModemWaitOpen
- 等待模块开机
- 通过检查模块主动上报:
- **************************************************************************/
- int ModemWaitOpen(int timeout)
- {
- //char *pAck;
- //SUT_MODEM_AT_MSG **pMsg;
- SUT_MODEM_AT_MSG *Msg;
- SlwTrace(DEBUG,"ModemWaitOpen",1);
- while(timeout--){
- //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&Msg,1)){
- if((Msg->MsgLen = MsgQueueAccept(Msg->MsgData,sizeof(Msg->MsgData)))){
- SlwTrace(DEBUG,(char *)Msg->MsgData,0);
- // if(0==ModemStrCmp((char *)Msg->MsgData,pAck)){
- // *pMsg=Msg;
- // return 1;
- // }else{
- // _free_box(AtMpool,Msg);
- //}
- }else os_dly_wait(1);
- }
- return 1;
- }
- //模块的电源以及复位引脚的配置
- //这段配置要放要最开始
- //目的是一开机时确保模块是没有电源的
- //解决原来问题:当开机到模块播报“欢迎.....”时马上关机,看到屏幕灭后马上又开机,此次开机会失败
- void ModemPinConfig(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin = MODEM_RESET_PIN;
- GPIO_Init(MODEM_RESET_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = MODEM_PWRKEY_PIN;
- GPIO_Init(MODEM_PWRKEY_PORT, &GPIO_InitStructure);
-
- MODEM_RESET_HIGH;
- MODEM_PWRKEY_LOW;
- }
- /**********************************************************************************
- ModemInit
- 返回:1 初始化成功 0-失败
- ***********************************************************************************/
- int ModemInit(void)
- {
- RunMake(THIS_FILE_ID);
- MsgQueueSet();//初始化队列
- g_ucModemSentTcpCt=0;
- RunMake(THIS_FILE_ID);
-
- MODEM_RESET_HIGH;
- os_dly_wait(100);
- MODEM_RESET_LOW;
- MODEM_PWRKEY_HIGH;
- os_dly_wait(100);
- MODEM_PWRKEY_LOW;
- //等待模块开机并能接受AT命令
- if(WaitModemStart())return 0;
- return 1;
- //ModemGetIMEI();
- }
- char ModemLCCCheck(void)
- {
- int t,i;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- SlwTrace(INF, "check version type",1);
- for(i=0;i<100;i++)
- {
- t=50;
- ModemSendAT("AT+LSPOCPF?\r\n");
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if((0==ModemStrCmp((char *)pMsg->MsgData,"ERROR"))){
- SlwTrace(INF, "It is not 3 in 1 version quit this check",1);
- return 0;
- }else if(0==ModemStrCmp((char *)pMsg->MsgData,"+LSPOCPF:")){//+LSPOCPF:hgs(1)
- //这个模块支持三合一指令,即为三合一模块版本
- if(pMsg->MsgData[13] == '1'){
- SlwTrace(INF, "It is hgs version now",1);
- return 0;
- }else{
- SlwTrace(INF, "Reset to hgs version and reboot",1);
- ModemSendAT("AT+LSPOCPF=hgs\r\n");
- ShowMessageBox("切换海高思版本");
- t=0;
- while(++t<50){
- DelayMs(2);
- IWDG_ReloadCounter();
- }
- return 1;
- }
- }
- }else
- os_dly_wait(1);
- }
- }
- SlwTrace(INF, "TimeOut",1);
- return 0;
- }
- /**********************************************************************************
- CSQ2Num
- ***********************************************************************************/
- int CSQ2Num(char *str)
- {
- int csq;
- csq=atoi(str);
- if(csq<0 || csq>99)return 99;
- else return csq;
- }
- /**********************************************************************************
- ModemStrCmp
- ***********************************************************************************/
- int ModemStrCmp(char *msg,char *str)
- {
- char *p1=str;
- char *p2=msg;
- while(*p1!=0){
- if(*p1!=*p2)return 1;
- p1++;
- p2++;
- }
- return 0;
- }
- /**********************************************************************************
- ModemWaitAckMsg
- Input:
- pATCmd--AT Command string
- pAck --期待回的ACK,头相同即可
- pMsg --实际消息内容,可能比pAck长
- timeout --超时,10ms为单位
- Output:
- if timeout return 0
- else return 1 注意,处理完消息要调用_free_box释放消息
- ***********************************************************************************/
- int ModemSendAT2WaitAckMsg(char *pATCmd,char *pAck,SUT_MODEM_AT_MSG **pMsg,int timeout)
- {
- SUT_MODEM_AT_MSG *Msg=&sutAtmPro;
- ModemSendAT(pATCmd);
- while(timeout){
-
- //if(OS_R_TMO!=os_mbx_wait(AtMsgBox,(void **)&Msg,1)){
- if((Msg->MsgLen = MsgQueueAccept(Msg->MsgData,sizeof(Msg->MsgData)))){
- //SlwTrace(DEBUG,(char *)Msg->MsgData);
- if(0==ModemStrCmp((char *)Msg->MsgData,pAck)){
- *pMsg=Msg;
- return 1;
- }else{
- //_free_box(AtMpool,Msg);
- }
- }else {
- timeout--;
- os_dly_wait(1);
- }
-
- }
- return 0;
- }
- /********************************************
- *0x12 --> "12" --> 0x31 0x32
- **********************************************/
- void HexToAsc(unsigned char Hex,char *pAsc)
- {
- unsigned char h,l;
- l=Hex & 0x0f;
- h=Hex >> 4;
- if((l>=0)&&(l<=9))l += 0x30;
- else if((l>=10)&&(l<=15))l += ('A'-10);
-
- if((h>=0)&&(h<=9))h += 0x30;
- else if((h>=10)&&(h<=15))h += ('A'-10);
-
- pAsc[0]=h;
- pAsc[1]=l;
- }
- void HexToStr(unsigned char *HexStr,char *AscStr,unsigned short len)
- {
- int i,j=0;
- for(i=0;i<len;i++)
- {
- HexToAsc(HexStr[i],&AscStr[j]);
- j+=2;
- }
- }
- /***********************************************************************************
- *ModemSendUdpData WCDMA没有UDP指令
- ************************************************************************************/
- int ModemSendUdpData(unsigned char socket,unsigned char *pData,unsigned short len)
- {
- int i;
- char buf[142];
- char tmp[5];
- unsigned char temp=0;
- snprintf(buf, sizeof(buf),"AT+ZIPSENDU=%d,%d\r",socket,len);
- ModemSendAT(buf);
- ModemSendData(pData,len);
-
- snprintf(buf, sizeof(buf),"UdpSend[%d]",len);
- SlwTrace(INF,buf,1);
-
- #ifdef SLW_DEBUG
- if(len>45)len=45;
- buf[0]='>';buf[1]='>';buf[2]=0;
- for(i=0;i<len;i++){
- snprintf(tmp, sizeof(tmp),"%02x,",pData[i]);
- strcat(buf,tmp);
- }
- SlwTrace(DEBUG,buf,1);
- #endif
- return 0;
-
- }
- /***********************************************************************************
- *StrToNum
- ************************************************************************************/
- unsigned short StrToNum(char *str)
- {
- unsigned short num;
- if(str[0]>0x2f && str[0]<0x3a){
- if(str[1]>0x2f && str[1]<0x3a){
- if(str[2]>0x2f && str[2]<0x3a){
- if(str[3]>0x2f && str[3]<0x3a){
- num=1000*(str[0]-0x30);
- num+=100*(str[1]-0x30);
- num+=10*(str[2]-0x30);
- num+=(str[3]-0x30);
- }else{
- num=100*(str[0]-0x30);
- num+=10*(str[1]-0x30);
- num+=(str[2]-0x30);
- }
- }else{
- num=10*(str[0]-0x30);
- num+=(str[1]-0x30);
- }
- }else{
- num= str[0]-0x30;
- }
- }else{
- num=0;
- }
- return num;
- }
- /***********************************************************************************
- *ModemPoweroff
- ************************************************************************************/
- void ModemPoweroff(void)
- {
- ModemSendAT("AT+ZPWROFF\r\n");
- os_dly_wait(50);
- ModemSendAT("AT+ZPWROFF\r\n");
- IWDG_ReloadCounter();//喂狗
- os_dly_wait(100);
- IWDG_ReloadCounter();//喂狗
- os_dly_wait(100);
- IWDG_ReloadCounter();//喂狗
- os_dly_wait(50);
- IWDG_ReloadCounter();//喂狗
- MODEM_PWRKEY_LOW;
- MODEM_RESET_HIGH;
- os_dly_wait(10);
- MODEM_RESET_LOW;
- }
- /**********************************************************************************
- *ModemSetDTRLow
- ***********************************************************************************/
- void ModemSetDtrLow(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Pin = MODEM_DTR_PIN;
- GPIO_Init(MODEM_DTR_PORT, &GPIO_InitStructure);
- MODEM_DTR_LOW;
- }
- /**********************************************************************************
- *ModemSetRINGLow
- ***********************************************************************************/
- void ModemSetRingLow(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Pin = MODEM_RING_PIN;
- GPIO_Init(MODEM_RING_PORT, &GPIO_InitStructure);
- MODEM_RING_LOW;
- }
- unsigned char AsciiHexStringToHexBytes(char *src, unsigned char *des)
- {//"3031"-->0x30,0x31
- unsigned char temp[2];
- unsigned char i,k;
- int len;
-
- len=strlen(src);
- if(len % 2) return 0;//不能为单数
- for(i=0;i<len/2;i++){
- temp[0]=src[2*i];
- temp[1]=src[2*i+1];
- for(k=0;k<2;k++){
- if(temp[k] >= '0' && temp[k] <= '9') temp[k] -= 0x30;
- else if(temp[k] >= 'a' && temp[k] <= 'f') temp[k] -= 0x57;
- else if(temp[k] >= 'A' && temp[k] <= 'F') temp[k] -= 0x37;
- }
- des[i] = ((temp[0]<<4)&0xf0) | temp[1];
- }
- return i;
- }
- /*******************************************************************
- *ModemCheckPocParam
- return:
- 1--not same, Reset
- 0--same,no reset
- ********************************************************************/
- int ModemCheckPocParam(void)
- {
- int t,j;
- int i,len;
- char buf[40];
- char buf1[100];
- char idFlag=0;
- char ipFlag=0;
- char pwdFlag=0;
- char domainFlag=0;
- char enableChangeIp=1;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- // #error "也测试一下这个函数正常与否呗"
- for(i=0;i<5;i++)
- {
- ModemSendAT("AT+POC=020000\r\n");
- //+POC:0200000069643D313030303031343031343B69703D3138332E3133312E31332E31303B7077643D3135303034343739303438383931343B646F6D61696E3D7777772E6869676F73706F632E636F6D3B
- //id=1000014014;ip=183.131.13.10;pwd=150044790488914;domain=www.higospoc.com;
- t=50;
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:02"))
- {
- pMsg->MsgData[pMsg->MsgLen-3]=0;
- len=AsciiHexStringToHexBytes(&pMsg->MsgData[13], pMsg->MsgData);
- pMsg->MsgData[len]=0;
- //找id
- len=GetParaFromStr(pMsg->MsgData,"id",buf);
- snprintf(buf1, sizeof(buf1),"%lu",sutProductPara.PSN);
- if(0!=strcmp(buf1, buf)) idFlag=1;;
-
- //找pwd
- len=GetParaFromStr(pMsg->MsgData,"pwd",buf);
- snprintf(buf1, sizeof(buf1), "%s",DEV_HARDID);
- if(0!=strcmp(buf1, buf)) pwdFlag=1;
-
- //找domain
- switch(newPara.serList.defaultuse)
- {
- case SER_HZ:
- case SER_SD:
- case SER_US:
-
- break;
- case SER_IP:
- case SER_JIQUN:
- if(newPara.serList.defaultuse==SER_IP)snprintf(buf1, sizeof(buf1), "%s",newPara.serList.ipFenFa);
- else if(newPara.serList.defaultuse==SER_JIQUN)snprintf(buf1, sizeof(buf1), "%s",newPara.serList.jiqun);
- len=GetParaFromStr(pMsg->MsgData,"domain",buf); //domain
-
- if(0!=strcmp(buf1, buf)) domainFlag=1;
- //modify by wjl 0609
- //但使用集群或者IP分发的时候,保证不去更新ip即可
- enableChangeIp=0;
- break;
- }
-
- //找ip
- if(enableChangeIp!=0){//modify by wjl 0609
- len=GetParaFromStr(pMsg->MsgData,"ip",buf);
- snprintf(buf1, sizeof(buf1), "%s", getPIPAddr());
- if(0!=strcmp(buf1, buf)) ipFlag=1;
- }
-
- if(idFlag == 0 && ipFlag==0 && pwdFlag==0&&domainFlag==0) return 0;
- RESET_ALL:
- ModemSendAT("AT+POC=010000");
- //更新id
- //if(idFlag != 0){
- snprintf(buf, sizeof(buf),"id=%lu;",sutProductPara.PSN);
- AscStrToHexStr(buf,buf1);
- ModemSendAT(buf1);
- //}
- //更新ip
- if(enableChangeIp!=0){//modify by wjl 0609
- //if(ipFlag != 0){
- snprintf(buf, sizeof(buf), "ip=%s;", getPIPAddr());
- AscStrToHexStr(buf,buf1);
- ModemSendAT(buf1);
- //}
- }
- //更新pwd
- //if(pwdFlag != 0){
- snprintf(buf, sizeof(buf), "pwd=%s;",DEV_HARDID);
- AscStrToHexStr(buf,buf1);
- ModemSendAT(buf1);
- //}
- if(newPara.serList.defaultuse==SER_IP)snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.ipFenFa);
- else if(newPara.serList.defaultuse==SER_JIQUN)snprintf(buf, sizeof(buf), "domain=%s;",newPara.serList.jiqun);
- else{
- snprintf(buf, sizeof(buf), "domain=;");
- AscStrToHexStr(buf,buf1);
- // ModemSendAT(buf1);
- // //ModemSendAT("\r\n");
- // return 1;
- }
- AscStrToHexStr(buf,buf1);
- ModemSendAT(buf1);
- //}
- ModemSendAT("\r\n");
- return 1;
- }
- }else os_dly_wait(1);
- }
- }
- return 0;
- }
- char WaitModemStart(void)
- {
- int t,i;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- SlwTrace(INF, "WaitModemRun:",0);
- for(i=0;i<100;i++)
- {
- t=50;
- ModemSendAT("ATE0\r\n");
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,"OK") ||
- 0==ModemStrCmp((char *)pMsg->MsgData,"+POC:START"))
- {
- SlwTrace(INF, "Runing",1);
- return 0;
- }
- }else
- os_dly_wait(1);
- }
- }
- SlwTrace(INF, "TimeOut",1);
- return 1;
- }
- void ModemInfo(void)
- {
- int t;
- int i,len,ver,j;
- char bufTemp[30],version[10],type,countFlag;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- RunMake(THIS_FILE_ID);
- ver=0;
-
- SlwTrace(INF, "[03]ModemInfo:",1);
- type=1;
- for(i=0;i<10;i++)
- {
- if(type==0) ModemSendAT("ATI\r\n");//模块型号
- else ModemSendAT("AT+LCTSW\r\n");//版本信息
- t=50;
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(type==0)
- {//Manufacturer: LONGSUNG
- //Model: U9507C 全网通模块版本
- //Model: U9507C_SXNT 单电信模块版本
- //Model: U9507C_SXNM 移动联通模块版本
- //Model: U9507C V3 全网通版本
- if(0==ModemStrCmp((char *)pMsg->MsgData,"Manufacturer:")) SlwTrace(INF, pMsg->MsgData, 0);
- else if(0==ModemStrCmp((char *)pMsg->MsgData,"Model:"))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C V3")|| 0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C SXNT")){
- //单电信
- support_type=ONLY_Telecom;
- }else if(0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C_SXNM")|| 0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C SXNM")){
- //移动联通版
- support_type=Mobile_unicom;
-
- }else if(0==ModemStrCmp((char *)pMsg->MsgData,"Model: U9507C POCC") ){
-
- support_type=All_Netcom;
- //全网通
- }else {
- //未知
- support_type=Un_Known;
- }
-
- SlwTrace(INF, pMsg->MsgData, 0);
- type ++;
- break;
- }
- }else{
- //SoftwareVersion: LLA0029.1.2_M005
- //InnerVersion: LLA0029_0016_1.0.57_L0901_EFS2.6
- //AP: LLA0029_0016_0.0.57_L0901_M005
- if(0==ModemStrCmp((char *)pMsg->MsgData,"SoftwareVersion:")) SlwTrace(INF, pMsg->MsgData, 0);
- else if(0==ModemStrCmp((char *)pMsg->MsgData,"AP:"))
- {
- SlwTrace(INF, pMsg->MsgData, 0);
- return;
- }
- else if(0==ModemStrCmp((char *)pMsg->MsgData,"InnerVersion:"))
- {
- SlwTrace(INF, pMsg->MsgData, 0);
- countFlag=0;
- for(j=0;j<strlen(pMsg->MsgData);j++)
- {
- if(pMsg->MsgData[j] == '_')
- {
- countFlag++;
- if(countFlag == 1)
- {
- version[0] = pMsg->MsgData[j+3];
- version[1] = pMsg->MsgData[j+4];
- }else if(countFlag == 3)
- {
- version[2] = pMsg->MsgData[j+2];
- version[3] = pMsg->MsgData[j+3];
- version[4] = pMsg->MsgData[j+4];
- version[5] = pMsg->MsgData[j+5];
- version[6] = 0;
- snprintf(bufTemp, sizeof(bufTemp), "[03]ModemVer:%s",version);
- SlwTrace(INF, bufTemp, 1);
- g_iModemVer=atoi(version);
- }
- }
- }
- }
- }
- }else os_dly_wait(1);
- }
- }
- }
- int ModemGetIMEI(void)
- {
- int t,j;
- int i,len;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- for(i=0;i<50;i++){
- ModemSendAT("AT+GSN\r\n");//0x80DA219D
- //862015030301209 两种情况都会返回
- t=50;
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- len=strlen((char *)&(pMsg->MsgData));
- if(0==ModemStrCmp((char *)pMsg->MsgData,"0x"))
- {
- len -=4;
- memcpy(DEV_HARDID, &pMsg->MsgData[2], len);
- if(len < sizeof(DEV_HARDID))
- DEV_HARDID[len]=0;
- return 1;
- }else if(len == 17)
- {
- len -= 2;
- memcpy(DEV_HARDID, pMsg->MsgData, len);
- if(len < sizeof(DEV_HARDID))
- DEV_HARDID[len]=0;
- return 2;
- }
- }else
- os_dly_wait(1);
- }
- }
- return 0;
- }
- void CheckPocType(void)
- {
- //19001 19002 19003 自研POC版本号
- //1184 1191 西安POC版本号
- hgs_poc_type=POC_XIAN;//默认是西安的,然后通过POC版本号来判断是西安的还是自研的POC
-
- if(g_iPocVer > 19000){
- hgs_poc_type=POC_OWN;
- SlwTrace(INF, "poc-own",1);
- }else SlwTrace(INF, "poc-xian",1);
- }
- void ModemPocVersionCheck(void)
- {
- char bufTemp[40];
- short t,i,len,j;
- int ver;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
-
-
- for(i=0;i<5;i++)
- {
- t=50;
- ModemSendAT("AT+POC_VER?\r\n");
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC_VER:"))
- {
- len = strlen(pMsg->MsgData);
- j=0;
- for(i=0;i<len;i++)
- {
- if(pMsg->MsgData[i] == '\r')
- {
- bufTemp[j]=0;
- ver=atoi(bufTemp);
- snprintf(bufTemp, sizeof(bufTemp),"[04]POCver:%d<->%s", ver,pMsg->MsgData);
- SlwTrace(INF, bufTemp,0);
- g_iPocVer=ver;
- return;
- }else if(pMsg->MsgData[i] >= '0' && pMsg->MsgData[i] <= '9') bufTemp[j++]=pMsg->MsgData[i];
- }
- }
- }else
- os_dly_wait(1);
- }
- }
- snprintf(bufTemp, sizeof(bufTemp),"[04]PocVer=%d", ver);
- SlwTrace(INF, bufTemp, 1);
- }
- void ModemApnConfig(void)
- {
- char needAuthLogin=0;
- char buf[100];
- char buf2[80];
- char i,t;
- char ApnSetFlag=0;
- char *apnName=newPara.apnList.apnList[newPara.apnList.defaultuse].account;
- char *apnPass=newPara.apnList.apnList[newPara.apnList.defaultuse].pass;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
-
- snprintf(buf, sizeof(buf), "[11]Accessp:");
- if(newPara.apnList.APN_Name[0]==0)
- {//接入点为空时不配置,因为模块不支持
- strcat(buf, "unsupport-Empty");
- }else
- {
- snprintf(buf2, sizeof(buf2), "AT+MIPPROFILE=1,\"%s\"\r\n",newPara.apnList.APN_Name);
- ModemSendAT(buf2);
- snprintf(buf2, sizeof(buf2), "%s",newPara.apnList.APN_Name);
- strcat(buf,buf2);
- }
- SlwTrace(INF,buf,0);
-
- snprintf(buf, sizeof(buf), ",Name-Pass:");
- if(apnName[0] ==0 ||
- apnPass[0] ==0)
- {//名称或密码为空不配置,因为模块不支持
- strcat(buf, "unsupport-Empty");
- }else
- {
- snprintf(buf2, sizeof(buf2),"AT^PPPCFG=\"%s\",\"%s\"\r\n",apnName,apnPass);
- ModemSendAT(buf2);
- snprintf(buf2, sizeof(buf2), "%s,%s",apnName,apnPass);
- strcat(buf,buf2);
- needAuthLogin=1;
- }
- SlwTrace(INF, buf,1);
- if(needAuthLogin != 0){
- //认证
- snprintf(buf, sizeof(buf),"AUTH-LOGIN:");
- switch(newPara.authType){
- case AUTH_LOGIN_PAP:strcat(buf, "PAP");
- snprintf(buf2, sizeof(buf2),"AT$QCPDPP=1,%d,%s,%s\r\n",newPara.authType,apnPass,apnName);
- break;
- case AUTH_LOGIN_CHAP:strcat(buf, "CHAP");
- case AUTH_LOGIN_NONE:strcat(buf, "NONE");
- default:strcat(buf, " Do nothing");
- snprintf(buf2, sizeof(buf2),"AT$QCPDPP=1,%d\r\n",newPara.authType);
- break;
- }
- SlwTrace(INF,buf, 1);
- ModemSendAT(buf2);
- SlwTrace(INF,buf2,0);
- os_dly_wait(20);
-
- SlwTrace(INF,"AuthLogin Done",1);
- }
- }
- void M9507CSendTcpData(unsigned char socket, unsigned char *pData, unsigned short len)
- {
- char buf[20];
-
- snprintf(buf, sizeof(buf), "AT+TCPSEND=%d,%d,",socket, len);
- ModemSendAT(buf);
- ModemSendData(pData, len);
- ModemSendAT("\r\n");
- }
- void ModemSetSpeed(void)
- {
- char i,t;
- int Volume;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
-
- for(i=0;i<5;i++)
- {
- t=50;
- REGO:
- ModemSendAT("AT+LSHTTSSPEED?\r\n");
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,"+LSHTTSSPEED:"))
- {
- Volume=atoi(&pMsg->MsgData[13]);
- if(7000 != Volume)
- {
- ModemSendAT("AT+LSHTTSSPEED=-1,7000\r\n");
- os_dly_wait(1);
- goto REGO;
- }
- else
- {
- SlwTrace(INF, "[06]SetTTS Speed Ok",1);
- return;
- }
- }
- }else
- os_dly_wait(1);
- }
- }
- SlwTrace(INF, "[06]SetTTS Speed Failed",1);
- }
- void VolumeSet(void)
- {
- char i,t;
- int Volume;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- char sendBuf[40],readBuf[30];
- char target[5];
-
- snprintf(sendBuf, sizeof(sendBuf), "at+syscmd=start_pcm volume ");
- snprintf(readBuf, sizeof(readBuf), "at+syscmd=start_pcm volume\r\n");
- // if(newPara.SoundMode==0) snprintf(target, sizeof(target), "7 5");
- // else snprintf(target, sizeof(target), "7 7");
- snprintf(target, sizeof(target), "7 5");
- strcat(sendBuf, target);
- strcat(sendBuf, "\r\n");
-
- //先配置一次,再查,因为默认就查有可能是没有返回的
- ModemSendAT(sendBuf);//TTS 音量/ MIC 输入音量
- os_dly_wait(50);
- for(i=0;i<10;i++)
- {
- t=100;
- ModemSendAT(readBuf);
-
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,target))
- {
- SlwTrace(INF, "[07]Set Volume ok",1);
- return;
- }
- }else
- os_dly_wait(1);
- }
- }
- SlwTrace(INF, "[07]Set Volume failed",1);
- }
- void SpeakTTSVoice(void)
- {
- int len,timeout;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- unsigned char codeType=ENCODE_UNICODE;
-
- if(newPara.ttsMessage[0]==0) return;
- len=strlen(newPara.ttsMessage);
- len = len+(8-len%8);//8倍数
- timeout=len/8;//两个中文需要播报1秒算
- timeout *= 100;
- if(newPara.ttsCodeType==TTS_UNICODE) codeType=ENCODE_UNICODE;
- else if(newPara.ttsCodeType==TTS_GBK) codeType=ENCODE_GBK;
- MeSpeak(codeType, newPara.ttsMessage,0);
- // while(timeout--)
- // {
- // if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- // {
- // if(0==ModemStrCmp((char *)pMsg->MsgData,"+LSHTTS: END"))
- // {
- // SpeakerCtrl(0);
- // return;
- // }
- // }else os_dly_wait(1);
- // }
- // SpeakerCtrl(0);
- }
- void ServerTimeGet(void)
- {
- static unsigned short timeCnt=12000;
-
- if(++timeCnt < 12000) return;
- timeCnt=0;
- ModemSendAT("AT+CCLK?\r\n");
- }
- //total 成员总数
- //一次获取个数最多5个,取决于显示条目个数
- //前提是要使用简短模式
- void SimpleUserInfoScan(uint8_t firstIn,uint8_t direction)
- {
- uint16_t i;
- uint16_t timeout;
- char buf[30];
- uint16_t thisStartIndex;
- uint8_t readNum;
- static char flag;
- char trycnt=0;
- if(firstIn) sutPocStatus.handleIndex=0;
-
- ShowMessageBox("请稍候...");
- os_dly_wait(1);
- snprintf(buf, sizeof(buf),"AT+POC=0E0000%08x\r\n",sutPocStatus.LocalGroup.ID);//先更新总数
- ModemSendAT(buf);
- SlwTrace(INF,buf,0);
- timeout=1000;
- sutPocStatus.UserNum_Update=0;
- sutPocStatus.UserOnLineNum=0;
- while(timeout)
- {
- timeout--;
- OsDelayTime(1);
- if(sutPocStatus.UserNum_Update) break;
- if(timeout % 200 == 0)
- ModemSendAT(buf);
- }
- if(sutPocStatus.UserOnLineNum<=0) {
- sutPocStatus.FillUserIndex=0;
- goto QUIT_FUNCTION;
- }
-
- // if(sutPocStatus.handleIndex >= sutPocStatus.UserOnLineNum)
- // {
- // snprintf(buf, sizeof(buf), "over:%d",sutPocStatus.handleIndex);
- // SlwTrace(INF, buf, 1);
- // sutPocStatus.handleIndex=sutPocStatus.UserOnLineNum-1;
- // }
-
- if(sutPocStatus.UserOnLineNum%5==0)flag=5;
- else flag=sutPocStatus.UserOnLineNum%5;
-
- //然后根据最新总数来获取每个成员信息
- if(direction==1)//递增索引
- {
-
- thisStartIndex=sutPocStatus.handleIndex;
- if(sutPocStatus.UserOnLineNum-thisStartIndex>=5) readNum=5;
- else {
-
- readNum=sutPocStatus.UserOnLineNum-thisStartIndex;
- }
-
- }else{//递减索引
-
- thisStartIndex=sutPocStatus.handleIndex;
-
- if(sutPocStatus.handleIndex <5) //<
- {
- thisStartIndex=0;//0
- readNum=sutPocStatus.UserOnLineNum; //(sutPocStatus.UserOnLineNum%5)
- }
- else if(sutPocStatus.UserOnLineNum-thisStartIndex<=flag){
- if((sutPocStatus.UserOnLineNum%5)==0)readNum=5;
- else readNum=(sutPocStatus.UserOnLineNum%5); //Z
- //thisStartIndex=sutPocStatus.UserOnLineNum-readNum;
- }
- else
- {
- //thisStartIndex=sutPocStatus.handleIndex-5;
- readNum=5;
- }
-
- }
-
- if(readNum >= 5) readNum=5;
- sutPocStatus.FillUserIndex=0;
- for(i=thisStartIndex;i<(thisStartIndex+readNum);i++)
- {
- sutPocStatus.GetOneUserFlag=0;
- snprintf(buf, sizeof(buf), "AT+POC=10000021%04x\r\n",i);
- ModemSendAT(buf);
- SlwTrace(INF, buf,0);
- timeout=200;
- while(1)
- {
- OsDelayTime(1);
- if(sutPocStatus.GetOneUserFlag)
- {
- sutPocStatus.FillUserIndex++;
- break;
- }
- if(--timeout==0) break;
- }
- }
- if(firstIn)sutPocStatus.handleIndex=0;
- //最终成功读了多少个回来,存在sutPocStatus.FillUserIndex中
- QUIT_FUNCTION:
- GuiClearRect(0, 40, LCD_WIDTH-1, LCD_HEIGHT-32);
- }
- void SetModemPocSimpleMode(void)
- {//设置使用简短模式获取成员信息
- short t,i;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- for(i=0;i<5;i++)
- {
- t=50;
- ModemSendAT("AT+POC=10000020\r\n");
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:10000000"))
- {
- SlwTrace(INF, "[14]SimpleMode_Ok",1);
- return;
- }
- }else
- os_dly_wait(1);
- }
- }
- SlwTrace(INF, "[14]SimpleMode_Tout",1);
- }
- char GetUniStringByID(char *HardIDString)
- {//输出15个字节的字符串
- unsigned char id[12];
- unsigned char string[16];
-
- long long temp;
- short i;
- unsigned char seed;
- if(HardIDString == '\0') return 0;
- GetSTM32ID(id);
- printf("STM32 ID==");
- for(i=0;i<12;i++)printf("%02x",id[i]);
- printf("\r\n");
- for(i=5;i>=0;i--){
- temp <<=8;
- temp |= id[i];
- }
- temp &= 0xffffffffffff;
- printf("temp=%015llu\r\n",temp);
- snprintf(string,sizeof(string),"%015llu",temp);
- for(i=0;i<15;i++) HardIDString[i]=string[i];
- HardIDString[15]='\0';
- //snprintf(HardIDString,16,"%015llu",temp);
- return 1;
- }
- //检查并设置POC域名
- int ModemCheckFotaDomain(void)
- {
- #if 1
- return 0;
- #else
- int t,j;
- int i,len;
-
- char buf1[130];
- char buf2[40];
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- RunMake(THIS_FILE_ID);
-
- for(i=0;i<5;i++)
- {
- ModemSendAT("AT+POC=21000000\r\n");
-
- t=50;
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,"+POC:21000000"))
- {
-
- snprintf(buf2,sizeof(buf2),"%s",sutProductPara.fota_pocdomain);
- //strcat(buf,buf2);
- for(j=0;j<strlen(pMsg->MsgData);j++) if(pMsg->MsgData[j]== '\r') pMsg->MsgData[j] = 0;
- if(0!=strcasecmp((char *)&pMsg->MsgData[13],buf2))
- {
- snprintf(buf1,sizeof(buf1),"AT+POC=21000001%s",buf1);
- return 1;
- }else return 0;
- }
- }else os_dly_wait(1);
- }
- }
- return 0;
- #endif
- }
- int htoi(char s[])
- {
- int i = 0;
- int n = 0;
- if (s[0] == '0' && (s[1]=='x' || s[1]=='X'))
- {
- i = 2;
- }
- else
- {
- i = 0;
- }
- for (; (s[i] >= '0' && s[i] <= '9') || (s[i] >= 'a' && s[i] <= 'z') || (s[i] >='A' && s[i] <= 'Z');++i)
- {
- if (tolower(s[i]) > '9')
- {
- n = 16 * n + (10 + tolower(s[i]) - 'a');
- }
- else
- {
- n = 16 * n + (tolower(s[i]) - '0');
- }
- }
- return n;
- }
- int ModemSetCodec(unsigned char addr,unsigned short value)
- {
- int t,j;
- int i,len;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- char buf[50];
- for(i=0;i<10;i++){
- t=50;
- sprintf(buf,"AT+CODEC=3,%2x,%4x\r\n",addr,value);
- ModemSendAT(buf);
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- len=strlen((char *)&(pMsg->MsgData));
- if(0==ModemStrCmp((char *)pMsg->MsgData,"OK"))
- {
- //SlwTrace(INF,(char *)pMsg->MsgData,1);
- return 0;
- }
- }else os_dly_wait(1);
- }
- }
-
- return addr;
- }
- void VolumeSetSpk(void)
- {
- char i,t;
- int Volume;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
- char sendBuf[40],readBuf[30];
- char target[5];
- snprintf(sendBuf,sizeof(sendBuf),"AT+LVL=4,%d\r\n",newPara.Spklv);
- snprintf(readBuf,sizeof(readBuf),"+LVL:4,%d\r\n",newPara.Spklv);
- SlwTrace(INF,sendBuf,0);
- for(i=0;i<15;i++)
- {
- t=100; //100
- ModemSendAT(sendBuf);//TTS 音量/ MIC 输入音量
- os_dly_wait(100);
- ModemSendAT("AT+LVL?\r\n");
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,readBuf))
- {
- SlwTrace(INF, "[07-02]Set SPK ok",1);
- return;
- }
-
- }else
- os_dly_wait(1);
- }
- }
- SlwTrace(INF, "[07-02]Set Volume failed",1);
-
- }
- void VolumeSetMIC(void)
- {
- char i,t;
- char buf[40];
- char readbuf[20];
- int Volume;
- SUT_MODEM_AT_MSG *pMsg=&sutAtmPro;
-
-
- snprintf(buf,sizeof(buf),"AT+MIC=2,%d\r\n",newPara.Miclv);
- snprintf(readbuf,sizeof(readbuf),"+MIC:2,%d\r\n",newPara.Miclv);
-
- ModemSendAT(buf);//TTS 音量/ MIC 输入音量
- SlwTrace(INF,buf,0);
- SlwTrace(INF,readbuf,0);
- for(i=0;i<15;i++)
- {
- t=100; //100
- os_dly_wait(10);
- ModemSendAT("AT+MIC?\r\n");
- while(t--)
- {
- if((pMsg->MsgLen = MsgQueueAccept(pMsg->MsgData,sizeof(pMsg->MsgData))))
- {
- if(0==ModemStrCmp((char *)pMsg->MsgData,readbuf))
- {
- SlwTrace(INF, "[07-03]Set MIC ok",1);
- return;
- }else{
- if(t==0) ModemSendAT(buf);
- }
- }else
- os_dly_wait(1);
- }
- }
- SlwTrace(INF, "[07-03]Set MIC failed",1);
- }
- /***********************************************************************************/
|