#include "includes.h" SUT_SMS_DEFINE sutSms; SUT_MESSAGE_EDIT sutMEdit; static void SmsScan(unsigned char ret); void ShowMessageFlag(uint8_t show) { static uint8_t smsUnReadBackup; uint8_t showFlag; showFlag=0; if(show) { if(sutSms.haveUnRead) showFlag=1; }else { if(smsUnReadBackup == sutSms.haveUnRead) return; smsUnReadBackup = sutSms.haveUnRead; if(sutSms.haveUnRead) showFlag=1; } switch(showFlag) { case 0:GuiShowStr(106,1," ",0x01,0);break; case 1:GuiShowBmp(106,1,"Mail1.bmp");break; //case 2:GuiShowStr(60,3," ",0x01,0);break; default:break; } } //读取所有信息的前15字节内容 //返回消息总数目 uint8_t GetPagePreMessage(struct SUT_LIST_BOX *p,uint8_t firstRead, char up_down) { uint8_t i,*ptr,buf[16],ptrTem[8]; uint32_t readAddr; uint16_t totalnum,retNum; struct SUT_SMS_INFO_HEADER info; uint8_t downFindFirst;//向下查找时第一次找到消息-此时要记录向上查找记录upToBeRead uint8_t upFindFirst; uint8_t reCtPerTime; //以下用于交换用 struct SUT_LIST_BOX_SMS_INFO boxinfo; uint8_t temp,*Cptr1,*Cptr2; // char buf1[30]; //1从最新消息,即sutSms.newestAddr开始读出最多5项 if(sutSms.smsTotalNum >= LIST_ROW) reCtPerTime=LIST_ROW; else reCtPerTime = sutSms.smsTotalNum; downFindFirst=0; upFindFirst=0; totalnum = SMS_TOTAL_NUM; ptr=(uint8_t *)&info; if(firstRead == 1) { //SmsScan(1); sutSms.downToBeRead = sutSms.newestAddr; sFlash_Read(ptr, sutSms.newestAddr, sizeof(struct SUT_SMS_INFO_HEADER)); sutSms.upToBeRead = info.upperAddr; firstRead=0; } i=0; if(up_down == 'd') {//向下读 while(1) { readAddr = sutSms.downToBeRead; //1.1读出年月日(16/06/01 = 8字节)+内容7字节 sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER)); sFlash_Read(ptrTem, readAddr+SMS_INFO_DETAIL_OFFSET, 8);//8字节内容 if(1==info.flag) { if(!downFindFirst) { downFindFirst++; sutSms.upToBeRead = info.upperAddr; } sprintf(p->boxinfo[i].item,"%02d/%02d/%02d ", (info.recTime>>26)&0x3F,(info.recTime>>22)&0x0F,(info.recTime>>17)&0x1F); strcat(p->boxinfo[i].item, (char *)ptrTem); if(1==info.read) p->boxinfo[i].features = 0; else p->boxinfo[i].features = 1; sutSms.downToBeRead = info.nextAddr; sutSms.ReadAddr[i] = readAddr; i++; if(i>=reCtPerTime) { retNum=i; break; } }else {//读完了,转到一开始 sutSms.downToBeRead = sutSms.newestAddr; //sutSms.downToBeRead = info.nextAddr; continue; } totalnum--; if(!totalnum) { //error SlwTrace(INF, "[SMS]err1",1); retNum=i; break; } } p->handle=0; }else {//向上读 while(1) { readAddr = sutSms.upToBeRead; //1.1读出年月日(16/06/01 = 8字节)+内容7字节 sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER)); sFlash_Read(ptrTem, readAddr+SMS_INFO_DETAIL_OFFSET, 8);//8字节内容 if(1==info.flag) { if(!upFindFirst) { upFindFirst++; sutSms.downToBeRead = info.nextAddr; } sprintf(p->boxinfo[i].item,"%d/%d/%d ", (info.recTime>>26)&0x3F,(info.recTime>>22)&0x0F,(info.recTime>>17)&0x1F); strcat(p->boxinfo[i].item, (char *)ptrTem); if(1==info.read) p->boxinfo[i].features = 0; else p->boxinfo[i].features = 1; sutSms.upToBeRead = info.upperAddr; sutSms.ReadAddr[i] = readAddr; i++; if(i>=reCtPerTime) { retNum=i; break; } }else {//读完了,转到最后一条 //sutSms.upToBeRead = sutSms.newestAddr+(sutSms.smsTotalNum-1)*SMS_SIZE_PER; //sutSms.upToBeRead = SMS_START_ADDRESS+(sutSms.smsTotalNum-1)*SMS_SIZE_PER; sutSms.upToBeRead = info.upperAddr; continue; } totalnum--; if(!totalnum) { //error SlwTrace(INF, "[SMS]err2",1); retNum=i; break; } } //switch ptr=(uint8_t *)&boxinfo;//copy temp = retNum/2; for(i=0;iboxinfo[i]; Cptr2=(uint8_t *)&p->boxinfo[retNum-1-i]; memcpy(ptr, Cptr1, LIST_ITEM_TEXT_LEN_MAX+1); memcpy(Cptr1, Cptr2, LIST_ITEM_TEXT_LEN_MAX+1); memcpy(Cptr2, ptr, LIST_ITEM_TEXT_LEN_MAX+1); readAddr=sutSms.ReadAddr[i]; sutSms.ReadAddr[i] = sutSms.ReadAddr[retNum-1-i]; sutSms.ReadAddr[retNum-1-i] = readAddr; } p->handle=reCtPerTime-1; } p->itemnum=retNum; p->pageChange=0; ListBoxItemNumShowSMS(p->notehandle,p->totalnum); ListBoxShowSMS(p); } void SetGotNewMessage(void) { unsigned char type,encode,def1,def2; type = sutMess.GBKMess1[0]; encode=sutMess.GBKMess1[1]; def1 = sutMess.GBKMess1[2]; def2 = sutMess.GBKMess1[3]; //处理分析消息类型 if(type == 0x30 && encode == 0x30 && def1 == 0x32 && def2 == 0x30) {//一键报警 sutMess.len -= 4; sutMess.Update=1;//收到一条消息标记 sutMess.startCntFlag=1; sutMess.skipCnt=0;//从此时开始计数 sutMess.forcePullGroupOn=0; SlwTrace(INF,"AlarmStart",1); sutMess.codeType=2;//unicode //sutSms.smsUpdate=1;//need to store }else if(type == 0x01 && encode == 0x02) {//纯TTS播报 sutMess.len -= 4; sutMess.Update=2; sutMess.codeType=2;//unicode sutSms.smsUpdate=1;//need to store SlwTrace(INF,"Pure TTS",1); }else if(type == 0x20 && encode == 0x20 && def1 == 0x20 && def2 == 0x20) {//全文本 sutMess.len -= 4; sutMess.Update=0; sutMess.codeType=1;//gb2312 sutSms.smsUpdate=1;//need to store SlwTrace(INF,"Pure TXT",1); } sutFeed.result=0; sutFeed.feedBackStart=1; } //扫描消息 ret值: //0、重置过的 //1、获得消息总数以及未读数目 //2、往上查找当前最新消息位置上一条空地址 static void SmsScan(unsigned char ret) { uint8_t *ptr; uint16_t i; struct SUT_SMS_INFO_HEADER smsinfo,*info; uint32_t readAddr; if(ret > 2) return;//出错不扫描 if(0 == ret) {//已reset过 }else if(1 == ret) {//查找消息总数和未读数 sutSms.smsTotalNum=0; sutSms.smsUnReadNum=0; ptr = (unsigned char *)&smsinfo; readAddr = sutSms.newestAddr; info=&smsinfo; i=SMS_TOTAL_NUM; while(1) { sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER)); if(1==smsinfo.flag) { sutSms.smsTotalNum ++; if(1==smsinfo.read) { sutSms.smsUnReadNum ++; sutSms.haveUnRead = 1; } } i--; if(!i) break; readAddr = info->nextAddr; } }else if(2 == ret) {//向上查找空地址 ptr = (unsigned char *)&smsinfo; readAddr = sutSms.newestAddr; info=&smsinfo; i=SMS_TOTAL_NUM; while(1) { sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER)); if(0==smsinfo.flag) {//找到 sutSms.emptyAddr = readAddr; break; } i--; if(!i) { sutSms.poolFull = 1; SlwTrace(INF, "[SMS]Full",1); SpeakerEnable(); ModemSendAt("AT+LSHTTS=1,\"CFFBCFA2D2D1C2FA\"\r\n"); break; } readAddr = smsinfo.upperAddr; } } } /////////////////////////////////////////////////////////// //uint8_t defaultSMS[] = "0我们都是好朋友"; //重置设置 //返回值0到2用实际用处 unsigned char ResetSMSConfi(void) { int endAddress,temp1,i; unsigned char *ptr,process=0; struct SUT_SMS_INFO_HEADER smsinfo; // struct SUT_SMS_CONF_HEADER conf; unsigned short sectorNum,startSector,k; unsigned int totalBytes; #if 0 //1,得到HGS.sms文件内容 g_iMessageFileIndex=GetFileIndex("HGS.sms"); if(g_iMessageFileIndex == -1) { sutSms.smsEnable = 0; SlwTrace(INF, "[SMS]RErr1",1); return 3; } temp1=GetFileLen(g_iMessageFileIndex); if(!temp1) { sutSms.smsEnable = 0; SlwTrace(INF, "[SMS]RErr2",1); return 4; } ptr=(uint8_t *)&conf; ReadFileData(g_iMessageFileIndex,0,5,ptr); #else #endif switch(newPara.messageResetFlag) { case 'N'://不用重置 sutSms.smsEnable = 1; //读出最新消息地址 sutSms.newestAddr = newPara.messageNewAddr; return 1; break; case 'R'://重置 SlwTrace(INF, "[SMS]Reset",1); break; default://文件内容错误 SlwTrace(INF, "[SMS]RErr3",1); sutSms.smsEnable = 0; return 5; break; } //2,根据短信格式初始化消息内存 GuiShowStr(26,13,"消息内存配置1/2",0x01,0); GuiDrawRect(29,50+50,128,66+50,1); //还是得将1M的消息空间擦除掉 //扇区大小4K //算出扇区地址 //SMS_START_ADDRESS一定要设置成整4K的 startSector = SMS_START_ADDRESS/4096;//消息位置的开始sector数 totalBytes = SMS_TOTAL_NUM*SMS_SIZE_PER; sectorNum = totalBytes/4096; if(totalBytes%4096) sectorNum ++; for(k=0;k=1) ListBoxInitSMS(&sutListBox,sutSms.smsTotalNum,accIconFileName,0); else ListBoxItemNumShowSMS(0,0); GuiShowStr(0,SUBSCRIPT_LOCATION,"[P1]查阅 [P2]选项",0x01,0); GuiDrawHLine(0,159,110,1); } } void DeleteSpecificSMS(void) { struct SUT_SMS_INFO_HEADER smsinfo,smsinfoTem,*info; uint8_t *ptr,*ptrTem,temp; uint32_t curAddr; ptr=(uint8_t *)&smsinfo; info=&smsinfo; //curAddr=SMS_START_ADDRESS+index*SMS_SIZE_PER;//要删除的消息地址 curAddr=sutSms.ReadAddr[sutListBox.handle]; sFlash_Read(ptr, curAddr, sizeof(struct SUT_SMS_INFO_HEADER)); //0 更新数目 if(1==smsinfo.read) { if(sutSms.smsUnReadNum) { sutSms.smsUnReadNum --; if(0==sutSms.smsUnReadNum) sutSms.haveUnRead =0; } } if(sutSms.smsTotalNum) sutSms.smsTotalNum --; if(sutSms.poolFull) sutSms.poolFull--; if(curAddr != sutSms.newestAddr){ //1将当前要删除的消息的上下消息接连起来 //1.1设置上一条消息的nextAddr ptrTem=(uint8_t *)&smsinfo.nextAddr; sFlash_Write(ptrTem, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, 4); //1.2设置下一条消息的upperAddr ptrTem=(uint8_t *)&smsinfo.upperAddr; sFlash_Write(ptrTem, smsinfo.nextAddr+SMS_INFO_REAL_LEN, 4); } //2设置要删除的消息的标志位 temp=0; sFlash_Write(&temp, curAddr, 1); if(curAddr != sutSms.newestAddr) { //3把空的消息插到最新的那条消息的上面去,它的下面都会是连续的新消息,不要往下插 sFlash_Read(ptr, sutSms.newestAddr, sizeof(struct SUT_SMS_INFO_HEADER)); //3.1设置最新的消息的upperAddr sFlash_Write((uint8_t *)&curAddr, sutSms.newestAddr+SMS_INFO_REAL_LEN, 4); //3.2设置最新消息原来的上一条消息的nextAddr sFlash_Write((uint8_t *)&curAddr, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, 4); //4设置被删除的消息的upperAddr and nextAddr //4.1设置upperAddr sFlash_Write((uint8_t *)&smsinfo.upperAddr, curAddr+SMS_INFO_REAL_LEN, 4); //4.2设置nextAddr sFlash_Write((uint8_t *)&sutSms.newestAddr, curAddr+SMS_INFO_REAL_LEN+4, 4); }else { //如果是删除最新的那条消息,不用更改位置,只要将更改最新消息的地址即可 sutSms.newestAddr = smsinfo.nextAddr; } } void MessageDeletResponse(void) { if(KEY_PANEL_MENU==g_ulKeyValue) { if(sutSms.smsTotalNum>=1) DeleteSpecificSMS(); UISetNextStatus(UIS_MAIL_BOX); } if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_MAIL_BOX); //else if(KEY_PANEL_MENU==g_ulKeyValue)UISetNextStatus(UIS_MENU_MAIN); } void FormatSMS(void) { uint16_t i; uint8_t *ptr; struct SUT_SMS_INFO_HEADER info; uint32_t readAddr; uint8_t process; GuiClearRect(0,44,159,84); GuiDrawRect(29,50,128,66,1); process=0; readAddr = sutSms.newestAddr; ptr=(uint8_t *)&info; for(i=0;i cnt) // {//秒粗计数器 // cnt=os_time_get()+100; // if(++sutMess.skipCnt>20) // {//时间到了 // sutMess.startCntFlag=0; // SlwTrace(INF,"Timeout",1); // } // } } if(sutSms.smsUpdate !=0) return; //未存完不处理 if(sutMess.Update == 1 || sutMess.Update == 2) { printf("TTS_LEN:%d\r\n",sutMess.len); p = sutMess.GBKMess1+4; // for(i=0;i