123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877 |
- #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;i<temp;i++)
- {
- Cptr1=(uint8_t *)&p->boxinfo[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<sectorNum;k++)
- {
- sFlash_Erase_Sector(startSector+k);
- if(k%10) IWDG_ReloadCounter();
- process = k*100/sectorNum;
- GuiFillRect(29,50+51+1,29+process,66+49-1,COLOR_BLUE);
- }
- GuiShowStr(26,13,"消息内存配置2/2",0x01,0);
- GuiClearRect(30,50+51,127,66+49);
- ////////////////////////////////////////////////////
-
- ptr = (unsigned char *)&smsinfo;
- for(i=0;i<SMS_TOTAL_NUM;i++)
- {
- smsinfo.flag = 0;
- smsinfo.read = 0;
- smsinfo.len = 0;
- smsinfo.recTime = 0;
- if(0==i)
- {//第一条
- smsinfo.upperAddr = SMS_START_ADDRESS+(SMS_TOTAL_NUM-1)*SMS_SIZE_PER;//连接最后一条地址
- smsinfo.nextAddr = SMS_START_ADDRESS+SMS_SIZE_PER;//指向下一条地址
- sutSms.emptyAddr = smsinfo.upperAddr;//空地址为上一条
- //sFlash_Write(defaultSMS, SMS_START_ADDRESS+SMS_INFO_DETAIL_OFFSET, sizeof(defaultSMS));
- }else if(i == (SMS_TOTAL_NUM-1))
- {//最后一条
- smsinfo.upperAddr = SMS_START_ADDRESS+(SMS_TOTAL_NUM-2)*SMS_SIZE_PER;//倒数第二条地址
- smsinfo.nextAddr = SMS_START_ADDRESS;//第一条地址
- //sFlash_Write(defaultSMS, SMS_START_ADDRESS+i*SMS_SIZE_PER+SMS_INFO_DETAIL_OFFSET, sizeof(defaultSMS));
- }
- else
- {
- smsinfo.upperAddr = SMS_START_ADDRESS+(i-1)*SMS_SIZE_PER;
- smsinfo.nextAddr = SMS_START_ADDRESS+(i+1)*SMS_SIZE_PER;
- //sFlash_Write(defaultSMS, SMS_START_ADDRESS+i*SMS_SIZE_PER+SMS_INFO_DETAIL_OFFSET, sizeof(defaultSMS));
- }
-
- sFlash_Write(ptr, SMS_START_ADDRESS+i*SMS_SIZE_PER, sizeof(struct SUT_SMS_INFO_HEADER));
-
- if(i%20)
- IWDG_ReloadCounter();
-
- if(i%10==0)
- {
- process = i*100/SMS_TOTAL_NUM;
- GuiDrawVLine(52+50,64+50,29+process,1,COLOR_DEFAULT_BLUE);
- }
- }
-
- newPara.messageResetFlag = 'N';
- newPara.messageNewAddr = SMS_START_ADDRESS;
- //save sys
- ModifyConfigureFile(0);
- //3,初始化参数
- sutSms.newestAddr = SMS_START_ADDRESS;
- sutSms.smsTotalNum=0;
- sutSms.smsUnReadNum=0;
- sutSms.haveUnRead = 0;
- sutSms.smsUpdate = 0;
- sutSms.poolFull = 0;
- sutSms.smsEnable = 1;
- SmsScan(1);
- sFlash_Read(ptr, SMS_START_ADDRESS, sizeof(struct SUT_SMS_INFO_HEADER));
- return 0;
- }
- void SetMessageConfi(void)
- {
- SmsScan(ResetSMSConfi());
- SlwTrace(INF, "[SMS]Ok",1);
- }
- void MessageResponse(void)
- {
- if(sutSms.smsTotalNum)
- ListBoxResponseSMS(&sutListBox);
- switch(g_ulKeyValue)
- {
- case KEY_PANEL_EXIT:
- UISetNextStatus(UIS_MENU_MAIN);
- break;
- // case KEY_PANEL_MENU:
- // UISetNextStatus(UIS_MENU_MAIN);
- // break;
- case KEY_PANEL_MENU:
- if(sutSms.smsTotalNum)
- UISetNextStatus(UIS_MESSAGE_READ);
- break;
- case KEY_OPTION:
- UISetNextStatus(UIS_MESSAGE_OPTION);
- break;
- default:
- break;
- }
- }
- void MessageDeletShow(int update)
- {
- if(update)
- {
- GuiClearAll();//clear
- ShowCaption("消息删除",1);//0
- //GuiDrawHLine(0,159,20,1);
- ShowMessageBox("确定删除?");
- GuiDrawHLine(0,159,110,1);
- GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]取消",0x01,0);
- }
- }
- void MessageFormatShow(int update)
- {
- if(update)
- {
- GuiClearAll();//clear
- ShowCaption("消息格式化",1);//0
- //GuiDrawHLine(0,159,20,1);
- ShowMessageBox("确定删除所有?");
- GuiDrawHLine(0,159,110,1);
- GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]取消",0x01,0);
- }
- }
- const char *accIconFileName[]={
- "Mail1.bmp",
- "Mail2.bmp",
- ""
- };
- /******************************************************
- UIShowMailBox
- 信箱
- *******************************************************/
- void UIShowMailBox(int update)
- {
- uint8_t SmsNumTemp;
- if(update)
- {
- GuiClearAll();
- GuiShowStr(0,STATUS_BAR_HEIGH," 文本消息",0x01,0);
- //GuiDrawHLine(0,159,20,1);
- if(sutSms.smsTotalNum>=1)
- ListBoxInitSMS(&sutListBox,sutSms.smsTotalNum,accIconFileName,0);
- else
- ListBoxItemNumShowSMS(0,0);
-
- GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]查阅 [S]选项",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<SMS_TOTAL_NUM;i++)
- {
- sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER));
- if(info.flag == 1)
- {
- info.flag=0;
- sFlash_Write(ptr, readAddr, 1);
- }
- readAddr = info.nextAddr;
- if(i%10== 0)
- IWDG_ReloadCounter();
-
- if(i%10==0)
- {
- GuiDrawVLine(52,64,29+process,1,COLOR_DEFAULT_BLUE);
- process++;
- }
- }
-
-
-
-
- sutSms.smsTotalNum = 0;
- sutSms.smsUnReadNum = 0;
- sutSms.haveUnRead = 0;
- }
- void MessageFormatResponse(void)
- {
- if(KEY_PANEL_MENU==g_ulKeyValue)
- {
- FormatSMS();
- 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 MessageOptionResponse(void)
- {
- char buf[30];
- unsigned long key;
- key=MenuResponse(&sutMenuSysSetup);
- if(KEY_PANEL_MENU==key)
- {
- switch(sutMenuSysSetup.handle)
- {
- case 0:UISetNextStatus(UIS_MESSAGE_DELE);break;
- case 1:UISetNextStatus(UIS_MESSAGE_FORMAT);break;
- }
- }
- else if(KEY_PANEL_EXIT==g_ulKeyValue) UISetNextStatus(sutUIstatus.LastStatus);
- //else if(KEY_PANEL_MENU==g_ulKeyValue) UISetNextStatus(UIS_MENU_MAIN);
- }
- void MessageOptionShow(int update)
- {
- static const char *apcMenuSysSetup[]=
- {"删除","格式化",""};
- if(update)
- {
- GuiClearAll();
- ShowCaption("文本选项",1); //0
- //GuiDrawHLine(0,159,20,1);
- GuiDrawHLine(0,159,110,1);
- MenuInit(&sutMenuSysSetup,apcMenuSysSetup);
- GuiDrawHLine(0,159,110,1);
- GuiShowStr(0,SUBSCRIPT_LOCATION,"[M]确定 [EXIT]退出",0x01,0);
- }
- }
- //读取index短信全部内容到bufPt
- static void ReadSpecificSms(uint8_t *bufPt)
- {
- struct SUT_SMS_INFO_HEADER info;
- uint8_t *ptr;
-
- ptr=(uint8_t *)&info;
- sFlash_Read(bufPt, sutSms.ReadAddr[sutListBox.handle]+SMS_INFO_DETAIL_OFFSET, SMS_SIGNAL_LEN);
- sFlash_Read(ptr, sutSms.ReadAddr[sutListBox.handle],2);
- info.read = 0;
- sFlash_Write(ptr, sutSms.ReadAddr[sutListBox.handle], 2);
- if(sutSms.smsUnReadNum)
- {
- sutSms.smsUnReadNum--;
- if(sutSms.smsUnReadNum==0)
- sutSms.haveUnRead = 0;
- }
- }
- static uint16_t lastShowIndex=0;
- uint8_t smsDetail[SMS_SIGNAL_LEN];
- void MessageReadShow(int update)
- {
- if(update)
- {
- lastShowIndex=0;
- memset(smsDetail,0,sizeof(smsDetail));
- GuiClearAll();
- ShowCaption("消息阅读",1);
- //GuiDrawHLine(0,159,20,1);
- ReadSpecificSms(smsDetail);
- MessageEditInit(&sutMEdit,8,STATUS_ITEM_HEIGH, (char *)smsDetail);
- lastShowIndex=MessageEditShow(&sutMEdit,(char *)smsDetail+lastShowIndex);
- GuiDrawHLine(0,159,110,1);
- #ifdef REPORT_SMS_VOICE
- GuiShowStr(0,SUBSCRIPT_LOCATION,"[P1]播放 [EXIT]返回",0x01);
- #else
- GuiShowStr(0,SUBSCRIPT_LOCATION,"[下]翻页 [EXIT]返回",0x01,0);
- #endif
- return;
- }
- }
- void MessageReadResponse(void)
- {
- unsigned short len;
- if(KEY_PANEL_EXIT==g_ulKeyValue)UISetNextStatus(UIS_MAIL_BOX);
- else if(KEY_PANEL_MENU == g_ulKeyValue)
- {
- #ifdef REPORT_SMS_VOICE
- // ReadSpecificSms(smsDetail);
- // AnsiToStrUnicode(unicodeSms,sizeof(unicodeSms),(char *)smsDetail);
- // ModemSendAt("AT+ZTTS=1,\"");
- // ModemSendAt((char *)unicodeSms);
- // ModemSendAt("\"\r");
- #endif
- }else if(KEY_PANEL_DOWN==g_ulKeyValue)
- {
- //printf("len:%d,%d\r\n",lastShowIndex,strlen(smsDetail));
- if(lastShowIndex<strlen(smsDetail))
- {
- GuiClearRect(0,24,LCD_WIDTH-1,106);
- MessageEditInit(&sutMEdit,8,STATUS_ITEM_HEIGH, (char *)smsDetail);
- len=MessageEditShow(&sutMEdit,(char *)smsDetail+lastShowIndex);
- if(len !=0) lastShowIndex+=len;
- else lastShowIndex=0;
- }
- }
- }
- void SwitchSMS_ToGB2312(void)
- {
- uint8_t *ptr;
- unsigned char tempSMS[SMS_SIGNAL_LEN+1];
- ptr = sutMess.GBKMess1+4;
- //source data:sutMess.GBKMess1+4;
- //data len:sutMess.len
- switch(sutMess.codeType)
- {
- case 2://unicode to gb2312
- memcpy(tempSMS, ptr, SMS_SIGNAL_LEN+1-4);
- StrUnicodeToAnsi(ptr, sutMess.len, (const char *)tempSMS);//
- //len no change
- break;
- default:
- break;
- }
- }
- //向上存方式
- void IncomingSMS(void)
- {
- struct SUT_SMS_INFO_HEADER infosms;
- uint8_t *ptr,i;
- static uint8_t showCt;
- unsigned char *smsPtr;
- unsigned char tempyear;
- USER_RTC_DEF time;
- RTC_UserGetTime(&time);
-
- if(0 == sutSms.smsEnable)
- {
- if(showCt++ == 0)
- SlwTrace(INF, "[SMS]Invalid",1);
- return;
- }
- //if(0 != sutMess.Update) return;//消息播报处理完毕
-
- if(0 == sutSms.smsUpdate) return;//没有可存储处理
- //sutSms.smsUpdate = 0;
- SlwTrace(INF, "[SMS]Store SMS",1);
- SmsScan(2);
- if(sutSms.poolFull)
- return;
- SwitchSMS_ToGB2312();
- // SpeakerEnable();
- // ModemSendAt("AT+ZTTS=1,\"36653052B065886D6F60\"\r");
- //1.1
- ptr = (uint8_t*)&infosms;
- infosms.flag=1;
- infosms.read=1;
- tempyear=time.year%2000;
-
- infosms.recTime = (uint32_t)tempyear<<26 |
- (uint32_t)time.month<<22 |
- (uint32_t)time.day<<17 |
- (uint32_t)time.hour<<12 |
- (uint32_t)time.min<<6 |
- (uint32_t)time.second<<0;
- infosms.len = sutMess.len;
- //保存头信息
- sFlash_Write(ptr, sutSms.emptyAddr, SMS_INFO_REAL_LEN);
- //保存内容
- smsPtr = sutMess.GBKMess1+4;
- //sFlash_Write((uint8_t *)sutMess.GBKMess1, sutSms.emptyAddr+SMS_INFO_DETAIL_OFFSET, SMS_SIGNAL_LEN);
- sFlash_Write(smsPtr, sutSms.emptyAddr+SMS_INFO_DETAIL_OFFSET, SMS_SIGNAL_LEN);
- sutSms.haveUnRead=1;
- sutSms.smsTotalNum ++;
- sutSms.smsUnReadNum ++;
- sutSms.newestAddr = sutSms.emptyAddr;
- //保存
- newPara.messageNewAddr=sutSms.newestAddr;
- //save sys
- ModifyConfigureFile(0);
-
- sutSms.smsUpdate = 0;
- }
- void SMSHandle(void)
- {
- unsigned char temp1,temp2;
- unsigned short i;
- char buf[30];
- static unsigned int cnt=0;
- unsigned char *p;
-
- if(sutMess.startCntFlag)
- {
- // if(os_time_get() > 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<sutMess.len;i+=4)
- // {
- // temp1 = p[i+2];
- // temp2 = p[i+3];
- // p[i+2] = p[i];
- // p[i+3] = p[i+1];
- // p[i] = temp1;
- // p[i+1]=temp2;
- // }
- // p[sutMess.len]=0;
- //MeSpeak(ENCODE_UNICODEBigend, (char *)p);
- MeSpeak(ENCODE_ASCII, (char *)p);
- sutMess.Update=0;
- }
- }
|