123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- #include "includes.h"
- SUT_MODEM_AT_MSG sutAtm,sutAtmPro;
- unsigned char ModemVer[15];
- 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_2MHz;
- GPIO_InitStructure.GPIO_Pin = MODEM_RESET_PIN;
- GPIO_Init(MODEM_RESET_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = MODEM_PWREN_PIN;
- GPIO_Init(MODEM_PWREN_PORT, &GPIO_InitStructure);
-
-
- //MODEM DATE or UPDATE
- GPIO_InitStructure.GPIO_Pin = MODEM_UPDATE_PIN;
- GPIO_Init(MODEM_UPDATE_PORT, &GPIO_InitStructure);
-
- MODEM_UPDATE_LOW;
- MODEM_RESET_LOW;
-
- }
- void ModemSendAt(char *p){
- unsigned short len;
- len=strlen(p);
- Uart2Send((unsigned char *)p,len);
- }
- /************************************************************************************
- *
- *************************************************************************************/
- void ModemSendData(unsigned char *pData,unsigned short datalen)
- {
- Uart2Send(pData,datalen);
- }
- void ModemVersionGet(char *msg)
- {//InnerVersion: LLA0029_0016_1.0.57_L0901_EFS2.6
- char j,bufTemp[30],version[10],type,countFlag;
-
- if(0==ModemStrCmp(msg,"InnerVersion:")){
- countFlag=0;
- for(j=0;j<strlen(msg);j++){
- if(msg[j] == '_'){
- countFlag++;
- if(countFlag == 1){
- version[0] = msg[j+3];
- version[1] = msg[j+4];
- }else if(countFlag == 3){
- version[2] = msg[j+2];
- version[3] = msg[j+3];
- version[4] = msg[j+4];
- version[5] = msg[j+5];
- version[6] = 0;
- snprintf(bufTemp, sizeof(bufTemp), "ModemVer:%s",version);
- SlwTrace(INF, bufTemp, 1);
- g_iModemVer=atoi(version);
- }
- }
- }
- }
- }
- void SetDefaultSpkMic(void){
- char sendInfo[40];
-
- snprintf(sendInfo, sizeof(sendInfo), "at+syscmd=start_pcm volume ");
- if(1) strcat(sendInfo, "7 7\r\n");//这里1根据实际参数替换吧
- else strcat(sendInfo, "7 5\r\n");
- ModemSendAt(sendInfo);
- }
- char IMEI[18]={0};
- char *getIMEI(void){return IMEI;}
- void ModemGetIMEI(char *msg){
- //+LSHIMEI:862015039899963
- ReplaceStrWithN(msg);
- strncpy(IMEI, msg+9, sizeof(IMEI));
- printf("IMEI:%s\r\n",IMEI);
- }
- void ModemGetTime(char *msg)
- {
- USER_RTC_DEF tmpTime;
- //+CCLK: "20/07/03,09:18:32+32"
- ReplaceStrWithN(msg);
- tmpTime.year=atoi(&msg[8]);
- tmpTime.month=atoi(&msg[11]);
- tmpTime.day=atoi(&msg[14]);
- tmpTime.hour=atoi(&msg[17]);
- tmpTime.min=atoi(&msg[20]);
- tmpTime.second=atoi(&msg[23]);
- RTC_UserSetTime(tmpTime);
- printf("\r\nNewTime:%02d-%02d-%02d %02d:%02d:%02d\r\n",
- tmpTime.year,tmpTime.month,tmpTime.day,
- tmpTime.hour,tmpTime.min,tmpTime.second);
- }
- char CCID[21]={0};
- char *getICCID(void){return CCID;}
- void ModemGetICCID(char *msg){
- char bufTemp[3],info[20];
- //+CCID: 89860316452001903429
- memcpy(CCID, &msg[7], sizeof(CCID));
- CCID[20]=0;
- bufTemp[0] = CCID[4];
- bufTemp[1] = CCID[5];
- bufTemp[2] = 0;
- switch(atoi(bufTemp))
- {
- case 1:
- case 6:
- case 9:thisYunYingShang = CHINA_UNICOM;
- snprintf(info,sizeof(info), "CHINA_UNICOM]");
- break;
- case 0:
- case 2:
- case 4:
- case 7:thisYunYingShang = CHINA_MOBILE;
- snprintf(info,sizeof(info), "CHINA_MOBILE]");
- break;
- case 3:
- case 8:
- case 11:thisYunYingShang = CHINA_TELECOM;
- snprintf(info,sizeof(info), "CHINA_TELECOM]");
- break;
- default:snprintf(info,sizeof(info), "UNKNOW-ICCID]");
- break;
- }
- printf("ICCID:%s %s\r\n", CCID, info);
- }
- void ModemSetPocPara(char *msg,int len){
- //+POC:0200000069643D313030303031343031343B69703D3138332E3133312E31332E31303B7077643D3135303034343739303438383931343B646F6D61696E3D7777772E6869676F73706F632E636F6D3B
- //id=1000014014;ip=183.131.13.10;pwd=150044790488914;domain=www.higospoc.com;
- char buf[40];
- char buf1[100];
- char idFlag=0;
- char ipFlag=0;
- char pwdFlag=0;
- char domainFlag=0;
- char enableChangeIp=1;
-
- msg[len-3]=0;
- len=AsciiHexStringToHexBytes(&msg[13], msg);
- msg[len]=0;
- //找id
- len=GetParaFromStr(msg,"id",buf);
- snprintf(buf1, sizeof(buf1),"%lu",sutProductPara.PSN);
- if(0!=strcmp(buf1, buf)) idFlag=1;;
- // //找ip
- // len=GetParaFromStr(msg,"ip",buf);
- // snprintf(buf1, sizeof(buf1), "%s", getPIPAddr());
- // if(0!=strcmp(buf1, buf)) ipFlag=1;
- //找pwd
- len=GetParaFromStr(msg,"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(msg,"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(msg,"ip",buf);
- snprintf(buf1, sizeof(buf1), "%s", getPIPAddr());
- if(0!=strcmp(buf1, buf)) ipFlag=1;
- }
-
- if(idFlag == 0 && ipFlag==0 && pwdFlag==0&&domainFlag==0) {
- SlwTrace(INF,"POC still",1);
- return;
- }
- 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);
- }
- AscStrToHexStr(buf,buf1);
- ModemSendAt(buf1);
-
- ModemSendAt("\r\n");
- SlwTrace(INF,"Rst_POCPara",1);
- }
- void MeSpeak(ENCODE_DEF type, char *voice)
- {
- char buf[20];//
-
- SpeakerCtrl(1);//wjl
- snprintf(buf, sizeof(buf), "AT+LSHTTS=%d,\"",type);
- ModemSendAt(buf);
- ModemSendAt(voice);
- // if(ENCODE_UNICODEBigend==type)
- // else TTSdaxieguibi(voice);
- ModemSendAt("\"\r\n");
- sutPocStatus.TTS=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), "Accessp:");
- if(apnName[0] ==0 ||
- apnPass[0] ==0)
- {//名称或密码为空不配置,因为模块不支持
- strcat(buf, "unsupport-Empty");
- }else
- {
- snprintf(buf2, sizeof(buf2),"AT+CSTT=\"%s\",\"%s\",\"%s\"\r\n",newPara.apnList.APN_Name,apnName,apnPass);
- ModemSendAt(buf2);
- snprintf(buf2, sizeof(buf2), "%s,%s,%s",newPara.apnList.APN_Name,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");
- case AUTH_LOGIN_CHAP:strcat(buf, "CHAP");
- snprintf(buf2, sizeof(buf2),"AT+CGAUTH=1,%d,%s,%s\r\n",newPara.authType,apnName,apnPass);
- ModemSendAt(buf2);
- SlwTrace(INF,buf2,0);
- break;
-
- case AUTH_LOGIN_NONE:strcat(buf, "NONE");
- break;
- default:strcat(buf, " Do nothing");
- break;
- }
-
- SlwTrace(INF,buf, 1);
- // ModemSendAt(buf2);
- // SlwTrace(INF,buf2,0);
- __nop();__nop();
- SlwTrace(INF,"AuthLogin Done",1);
- }
-
- }
- //////////////////////////////////////////
- void getModemModule(char *msg){
- memcpy(ModemVer,msg,strlen(msg)-2);
- SlwTrace(INF, msg,0);
- }
- void getModemVersion(char *msg){
- short j;
- char countFlag,version[10];
-
- SlwTrace(INF, msg, 0);
- countFlag=0;
- for(j=0;j<strlen(msg);j++){
- if(msg[j] == '_'){
- countFlag++;
- if(countFlag == 1){
- version[0] = msg[j+3];
- version[1] = msg[j+4];
- }else if(countFlag == 3)
- {
- version[2] = msg[j+2];
- version[3] = msg[j+3];
- version[4] = msg[j+4];
- version[5] = msg[j+5];
- version[6] = 0;
- g_iModemVer=atoi(version);
- printf("ModemVer:%d\r\n",g_iModemVer);
- }
- }
- }
- }
- //AT+POC=version
- //+POC:BROAD-3.0.7-20200812-release
- void getPocVersion(char *msg,HGS_POC_DEF type){
- int i,j,len,ver;
- char bufTemp[40];
- len = strlen(msg);
- j=0;
- for(i=0;i<len;i++){
- if(msg[i] == '\r'){
- bufTemp[j]=0;
- strncpy(g_iPocVer,bufTemp,sizeof(g_iPocVer));
- //ver=atoi(bufTemp);
- snprintf(bufTemp, sizeof(bufTemp),"POCver:%s<->%s", bufTemp,msg);
- SlwTrace(INF, bufTemp,0);
- // g_iPocVer=ver;
- return;
- }else if(msg[i] >= '0' && msg[i] <= '9') bufTemp[j++]=msg[i];
- }
-
-
- }
- void CheckPocType(void)
- {
- hgs_poc_type=POC_OWN;//默认是西安的,然后通过POC版本号来判断是西安的还是自研的POC
- }
- void ModemOwnPocSet(void)
- {
- if(hgs_poc_type != POC_OWN) return;
- ModemSendAt("AT+POC=3000000100\r\n");//GBK
- __nop();__nop();
- ModemSendAt("AT+POC=030000\r\n");//启动登陆,POC默认打开的
- __nop();__nop();
- }
- void getPocCode(char *msg){
- if(msg[14]=='0') sutPocStatus.codeType=0;
- else sutPocStatus.codeType=1;
- printf("PocCode:%d\r\n", sutPocStatus.codeType);
- }
- //total 成员总数
- //一次获取个数最多5个,取决于显示条目个数
- //前提是要使用简短模式
- char SimpleUserInfoScan(uint8_t firstIn,uint8_t direction)
- {
- static char first=1;
- static unsigned char machine;
- static unsigned int timer;
-
- char buf[40];//30
- char ret =0;
- if(firstIn && first){
- sutPocStatus.handleIndex=0;//当前页
- machine=0;
- first=0;
- ret=0;
- }
- switch(machine){
- case 0:
- //ShowMessageBox("请稍候...");
-
- if(sutUIstatus.Status==UIS_MENU_GROUP_SEL){
- if(hgs_poc_type==POC_BND) snprintf(buf, sizeof(buf),"AT+POC=groupnum\r\n");//先更新总数
- else snprintf(buf, sizeof(buf),"AT+POC=3D0000\r\n");//先更新总数
- }
- else {
- if(hgs_poc_type==POC_BND)snprintf(buf, sizeof(buf),"AT+POC=membernum,%d\r\n",sutPocStatus.LocalGroup.ID);//先更新总数
- else snprintf(buf, sizeof(buf),"AT+POC=3E0000\r\n");//先更新总数
- }
- ModemSendAt(buf);
- SlwTrace(INF,buf,0);
- sutPocStatus.ListUpdate=0;
- sutPocStatus.ListFillIndex=0;
- uTimerStart(&timer, 500);//500
- machine=1;
- break;
- case 1:
- if(sutPocStatus.ListUpdate || uTimerExpired(&timer) ){
- if(sutPocStatus.ListCurOnlineNum<=0){
- sutPocStatus.ListFillIndex=0;
- printf("sutPocStatus.ListUpdate==%d,ListCurOnlineNum==%d\r\n",sutPocStatus.ListUpdate,sutPocStatus.ListCurOnlineNum);
- goto QUIT_FUNCTION;
- }
-
- machine=2;
- }
- break;
-
- case 2:
- /*
- 第一次进来不操作页数
- 后续判定sutPocStatus.handleIndex 页是否合法
- 注意处理临界值 5的倍数
- */
- if(firstIn!=1){
- if(direction==1){
- sutPocStatus.handleIndex ++;
- if(sutPocStatus.handleIndex>sutPocStatus.ListCurOnlineNum/5){
- sutPocStatus.handleIndex=0;
- }
- if(sutPocStatus.ListCurOnlineNum%5==0){
- if(sutPocStatus.handleIndex==sutPocStatus.ListCurOnlineNum/5)sutPocStatus.handleIndex=0;
- }
-
- }
- else {
- if(sutPocStatus.handleIndex>0)sutPocStatus.handleIndex--;
- else if(sutPocStatus.handleIndex==0){
- if(sutPocStatus.ListCurOnlineNum%5==0)sutPocStatus.handleIndex=(sutPocStatus.ListCurOnlineNum/5)-1;
- else sutPocStatus.handleIndex=sutPocStatus.ListCurOnlineNum/5;
- printf("sutPocStatus.ListCurOnlineNum===%d,sutPocStatus.handleIndex==%d\r\n",sutPocStatus.ListCurOnlineNum,sutPocStatus.handleIndex);
- }
- }
- }
- /*
- 下面操作只决定 预读值sutPocStatus.ExceptionReadNum
- */
- if((sutPocStatus.handleIndex+1)*5 >sutPocStatus.ListCurOnlineNum){ //超过 首页 +1
- snprintf(buf, sizeof(buf), "over:%d",sutPocStatus.handleIndex);
- SlwTrace(INF, buf, 1);
- if(sutPocStatus.ListCurOnlineNum%5==0)sutPocStatus.ExceptionReadNum=5;
- else sutPocStatus.ExceptionReadNum=sutPocStatus.ListCurOnlineNum%5;
- } else{
- sutPocStatus.ExceptionReadNum=5; //普通情况 5个
- }
- sutPocStatus.ListFillIndex=0;
- machine=3;
- break;
-
- case 3:
- sutPocStatus.ListGetOneFlag=0; //起始 //个数//5个
- if(sutUIstatus.Status==UIS_MENU_GROUP_SEL){
- if(hgs_poc_type==POC_BND) snprintf(buf, sizeof(buf),"AT+POC=groups,%d+1,5\r\n",sutPocStatus.handleIndex*5);//先更新总数
- else snprintf(buf, sizeof(buf), "AT+POC=1D0000%04x0005\r\n",sutPocStatus.handleIndex*5);
- }
- else {
- if(hgs_poc_type==POC_BND) snprintf(buf, sizeof(buf),"AT+POC=members,%d,%d+1,5\r\n",sutPocStatus.LocalGroup.ID,sutPocStatus.handleIndex*5);
- else snprintf(buf, sizeof(buf), "AT+POC=1E0000%04x0005\r\n",sutPocStatus.handleIndex*5);
- }
- ModemSendAt(buf);
- SlwTrace(INF, buf,0);
- uTimerStart(&timer, 200);
- machine=4;
- break;
-
- case 4:
- if(sutPocStatus.ListGetOneFlag){//获取成功
- machine=5;
- }
- if(uTimerExpired(&timer)){
- machine=5;//超时了,结束
- }
- break;
- case 5:
- //最终成功读了多少个回来,存在sutPocStatus.FillUserIndex中
- QUIT_FUNCTION:
- first=1;
- GuiClearRect(0, 40, LCD_WIDTH-1, LCD_HEIGHT-32);
- machine=0;//
- return 1;
- break;
- }
-
- return ret;
- }
|