123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889 |
- #include "includes.h"
- SUT_SMS_DEFINE sutSms;
- SUT_MESSAGE_EDIT sutMEdit;
- static void SmsScan(unsigned char ret);
- void ShowMessageFlag(unsigned char show){
- static unsigned char smsUnReadBackup;
- unsigned char 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:
- guiClearRect(SMS_ICON_X,0,SMS_ICON_X+SMS_ICON_WX,12,COLOR_STATUS_BAR);
- //guiShowStr(70,1," ",FONT_MODE_12X12, REVERSED_NO, guiGetForeColor(), COLOR_STATUS_BAR);
- break;
- case 1:guiShowBmp(SMS_ICON_X,1,"Mail1.bmp");break;
- //case 2:GuiShowStr(60,3," ",0x01,0);break;
- default:break;
- }
- }
- //读取所有信息的前15字节内容
- //返回消息总数目
- unsigned char GetPagePreMessage(SUT_LIST_BOX *p,unsigned char firstRead, char up_down){
- unsigned char i,*ptr,buf[16],ptrTem[8];
- uint32_t readAddr;
- uint16_t totalnum,retNum;
- SUT_SMS_INFO_HEADER info;
- unsigned char downFindFirst;//向下查找时第一次找到消息-此时要记录向上查找记录upToBeRead
- unsigned char upFindFirst;
- unsigned char reCtPerTime;
- int fd;
- //以下用于交换用
- SUT_LIST_BOX_SMS_INFO boxinfo;
- unsigned char temp,*Cptr1,*Cptr2;
- fd=nwy_sdk_fopen(SMS_FILE, NWY_RDONLY);
- if(fd<0){
- MSG_ERR(1,"%s GetPagePreMessage open failed", SMS_FILE);
- return;
- }
- //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=(unsigned char *)&info;
- if(firstRead == 1){
- //SmsScan(1);
- sutSms.downToBeRead = sutSms.newestAddr;
- nwy_sdk_fseek(fd, sutSms.newestAddr, NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptr,sizeof( SUT_SMS_INFO_HEADER));
- //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字节
- nwy_sdk_fseek(fd, readAddr, NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptr,sizeof( SUT_SMS_INFO_HEADER));
- nwy_sdk_fseek(fd, readAddr+SMS_INFO_DETAIL_OFFSET, NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptrTem,8);
- //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
- MSG_ERR(1, "[SMS]err1");
- retNum=i;
- break;
- }
- }
- p->handle=0;
- }else
- {//向上读
- while(1)
- {
- readAddr = sutSms.upToBeRead;
- //1.1读出年月日(16/06/01 = 8字节)+内容7字节
- nwy_sdk_fseek(fd, readAddr, NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptr,sizeof( SUT_SMS_INFO_HEADER));
- nwy_sdk_fseek(fd, readAddr+SMS_INFO_DETAIL_OFFSET, NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptrTem,8);
- //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
- MSG_ERR(1,"[SMS]err2");
- retNum=i;
- break;
- }
- }
- //switch
- ptr=(unsigned char *)&boxinfo;//copy
- temp = retNum/2;
- for(i=0;i<temp;i++)
- {
- Cptr1=(unsigned char *)&p->boxinfo[i];
- Cptr2=(unsigned char *)&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;
- }
- if(fd>0) nwy_sdk_fclose(fd);
- 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;
- MSG_WARN(1,"AlarmStart");
- 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
- MSG_WARN(1,"Pure TTS");
- }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
- MSG_WARN(1,"Pure TXT");
- }
- // sutFeed.result=0;
- // sutFeed.feedBackStart=1;
- }
- //扫描消息 ret值:
- //0、重置过的
- //1、获得消息总数以及未读数目
- //2、往上查找当前最新消息位置上一条空地址
- static void SmsScan(unsigned char ret)
- {
- unsigned char *ptr;
- unsigned short i;
- SUT_SMS_INFO_HEADER smsinfo,*info;
- unsigned int readAddr;
- int fd=-1;
- if(ret > 2) return;//出错不扫描
- if(0!=ret){
- fd=nwy_sdk_fopen(SMS_FILE, NWY_RDONLY);
- if(fd<0){
- MSG_ERR(1,"%s smsscan but open failed", SMS_FILE);
- 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)
- {
- nwy_sdk_fseek(fd, readAddr, NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptr, sizeof(SUT_SMS_INFO_HEADER));
- //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)
- {
- nwy_sdk_fseek(fd, readAddr, NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptr, sizeof(SUT_SMS_INFO_HEADER));
- //sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER));
- if(0==smsinfo.flag)
- {//找到
- sutSms.emptyAddr = readAddr;
- break;
- }
- i--;
- if(!i)
- {
- sutSms.poolFull = 1;
- MSG_WARN(1,"[SMS]Full");
- //SpeakerEnable();
- ttsPlay(ENCODE_USER_GBK,"CFFBCFA2D2D1C2FA");
- break;
- }
- readAddr = smsinfo.upperAddr;
- }
- }
- if(fd>0) nwy_sdk_fclose(fd);
- }
- ///////////////////////////////////////////////////////////
- //uint8_t defaultSMS[] = "0我们都是好朋友";
- //重置设置
- //返回值0到2用实际用处
- unsigned char ResetSMSConfi(void){
- int endAddress,temp1,i;
- unsigned char *ptr,process=0;
- SUT_SMS_INFO_HEADER smsinfo;
- unsigned short sectorNum,startSector,k,x,y,lx;
- unsigned int totalBytes;
- unsigned char tbuf[SMS_SIZE_PER];
- long ret;
-
- switch(newPara.messageResetFlag){
- case 'N'://不用重置
- sutSms.smsEnable = 1;
- //读出最新消息地址
- sutSms.newestAddr = newPara.messageNewAddr;
- MSG_WARN(1,"[SMS]IDLE");
- return 1;
- break;
- case 'R'://重置
- MSG_WARN(1,"[SMS]Reset");
- break;
- default://文件内容错误
- MSG_ERR(1,"[SMS]RErr3");
- sutSms.smsEnable = 0;
- return 5;
- break;
- }
- //2,根据短信格式初始化消息内存
- y=(GLCD_HEIGHT-24-4)/2;
- guiShowStr(26,y,"消息内存配置",FONT_MODE_12X12, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- x=29;y+=(12+4);lx=x;
- guiDrawRect(x,y,x+100,y+16,1,COLOR_BLACK);
- //guiDrawRect(29,50+50,128,66+50,1,COLOR_BLACK);
- //新建文件,如果存在则清空
- int fd;
- fd=nwy_sdk_fopen(SMS_FILE, NWY_RDWR|NWY_CREAT);
- if(fd<0){
- MSG_ERR(1,"[SMS]%s open err",SMS_FILE);
- sutSms.smsEnable = 0;
- return 5;
- }
- 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));
- }
- nwy_sdk_fseek(fd, SMS_START_ADDRESS+i*SMS_SIZE_PER, NWY_SEEK_SET);
- //nwy_sdk_fwrite(fd,ptr,sizeof(SUT_SMS_INFO_HEADER));
- memset(tbuf, 0, sizeof(tbuf));
- memcpy(tbuf, ptr, sizeof(SUT_SMS_INFO_HEADER));
- ret=nwy_sdk_fwrite(fd,tbuf,SMS_SIZE_PER);
- if(ret==-1) MSG_INFO(1, "sms init failed:%d",i);
-
- if(i%10==0){
- process = i*100/SMS_TOTAL_NUM;
- guiFillRect(lx,y+2,x+process,y+14,COLOR_BLACK);
- lx=x+process;
- }
- }
- guiFillRect(lx,y+2,x+100,y+14,COLOR_BLACK);
- nwy_sdk_fclose(fd);
- newPara.messageResetFlag = 'N';
- newPara.messageNewAddr = SMS_START_ADDRESS;
- //save sys
- sysIniSave();
- //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);
- fd=nwy_sdk_fopen(SMS_FILE, NWY_RDONLY);
- if(fd<0) MSG_WARN(1,"%s open to read but failed",SMS_FILE);
- else{
- nwy_sdk_fseek(fd, SMS_START_ADDRESS, NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptr, sizeof( SUT_SMS_INFO_HEADER));
- nwy_sdk_fclose(fd);
- }
- return 0;
- }
- void SetMessageConfi(void)
- {
- SmsScan(ResetSMSConfi());
- MSG_INFO(1,"[SMS]Ok");
- }
- void MessageResponse(void)
- {
- if(sutSms.smsTotalNum) ListBoxResponseSMS(&sutListBox);
- switch(getKeyValue()){
- case MKEY_VALUE_ESC:
- uISetNextStatus(UIS_MENU_MAIN);
- break;
- case MKEY_VALUE_MENU:
- if(sutSms.smsTotalNum)
- uISetNextStatus(UIS_MENU_MAIL_READ);
- break;
- case MKEY_VALUE_P1:
- uISetNextStatus(UIS_MENU_MAIL_OPTION);
- break;
- default:
- break;
- }
- }
- void MessageDeletShow(char update)
- {
- if(update)
- {
- guiClearAll(guiGetBackColor());//clear
- guiShowCaption(0,"消息删除",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- guiShowMessageBox("确定删除?");
- uiMenuShowBottomLine();
- uiMenuShowBottomIndacitor("确定", "取消");
- }
- }
- void MessageFormatShow(char update)
- {
- if(update)
- {
- guiClearAll(guiGetBackColor());//clear
- guiShowCaption(0,"消息格式化",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- guiShowMessageBox("确定删除所有?");
- uiMenuShowBottomLine();
- uiMenuShowBottomIndacitor("确定", "取消");
- }
- }
- const char *accIconFileName[]={
- "Mail1.bmp",
- "Mail2.bmp",
- ""
- };
- /******************************************************
- uiShowMailBox
- 信箱
- *******************************************************/
- void uiShowMailBox(char update){
- if(update){
- guiClearAll(guiGetBackColor());
- guiShowCaption(40,"文本消息",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- uiMenuShowBottomLine();
- if(sutSms.smsTotalNum>=1){
- ListBoxInitSMS(&sutListBox,sutSms.smsTotalNum,accIconFileName,0);
- uiMenuShowBottomIndacitor("查阅", "[P1]选项");
- }else{
- ListBoxItemNumShowSMS(0,0);
- uiMenuShowBottomIndacitor(NULL, "[P1]选项");
- }
- }
- }
- void DeleteSpecificSMS(void)
- {
- SUT_SMS_INFO_HEADER smsinfo,smsinfoTem,*info;
- unsigned char *ptr,*ptrTem,temp;
- unsigned int curAddr;
- int fd;
- fd=nwy_sdk_fopen(SMS_FILE, NWY_RDWR);
- if(fd<0){
- MSG_ERR(1,"%s del open but failed", SMS_FILE);
- return;
- }
- ptr=(unsigned char *)&smsinfo;
- info=&smsinfo;
- //curAddr=SMS_START_ADDRESS+index*SMS_SIZE_PER;//要删除的消息地址
- curAddr=sutSms.ReadAddr[sutListBox.handle];
-
- nwy_sdk_fseek(fd, curAddr,NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptr, sizeof( SUT_SMS_INFO_HEADER));
- //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=(unsigned char *)&smsinfo.nextAddr;
- nwy_sdk_fseek(fd,smsinfo.upperAddr+SMS_INFO_REAL_LEN+4,NWY_SEEK_SET );
- nwy_sdk_fwrite(fd, ptrTem, 4);
- //sFlash_Write(ptrTem, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, 4);
- //1.2设置下一条消息的upperAddr
- ptrTem=(unsigned char *)&smsinfo.upperAddr;
- nwy_sdk_fseek(fd,smsinfo.nextAddr+SMS_INFO_REAL_LEN,NWY_SEEK_SET );
- nwy_sdk_fwrite(fd, ptrTem, 4);
- //sFlash_Write(ptrTem, smsinfo.nextAddr+SMS_INFO_REAL_LEN, 4);
- }
- //2设置要删除的消息的标志位
- temp=0;
- nwy_sdk_fseek(fd,curAddr,NWY_SEEK_SET );
- nwy_sdk_fwrite(fd, &temp, 1);
- //sFlash_Write(&temp, curAddr, 1);
- if(curAddr != sutSms.newestAddr)
- {
- //3把空的消息插到最新的那条消息的上面去,它的下面都会是连续的新消息,不要往下插
- nwy_sdk_fseek(fd, sutSms.newestAddr, NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptr, sizeof( SUT_SMS_INFO_HEADER));
- //sFlash_Read(ptr, sutSms.newestAddr, sizeof(struct SUT_SMS_INFO_HEADER));
- //3.1设置最新的消息的upperAddr
- nwy_sdk_fseek(fd, sutSms.newestAddr+SMS_INFO_REAL_LEN, NWY_SEEK_SET);
- nwy_sdk_fwrite(fd, (unsigned char *)&curAddr, 4);
- //sFlash_Write((uint8_t *)&curAddr, sutSms.newestAddr+SMS_INFO_REAL_LEN, 4);
- //3.2设置最新消息原来的上一条消息的nextAddr
- nwy_sdk_fseek(fd, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, NWY_SEEK_SET);
- nwy_sdk_fwrite(fd, (unsigned char *)&curAddr, 4);
- //sFlash_Write((uint8_t *)&curAddr, smsinfo.upperAddr+SMS_INFO_REAL_LEN+4, 4);
- //4设置被删除的消息的upperAddr and nextAddr
- //4.1设置upperAddr
- nwy_sdk_fseek(fd, curAddr+SMS_INFO_REAL_LEN, NWY_SEEK_SET);
- nwy_sdk_fwrite(fd, (unsigned char *)&smsinfo.upperAddr, 4);
- //sFlash_Write((uint8_t *)&smsinfo.upperAddr, curAddr+SMS_INFO_REAL_LEN, 4);
- //4.2设置nextAddr
- nwy_sdk_fseek(fd, curAddr+SMS_INFO_REAL_LEN+4, NWY_SEEK_SET);
- nwy_sdk_fwrite(fd, (unsigned char *)&sutSms.newestAddr, 4);
- //sFlash_Write((uint8_t *)&sutSms.newestAddr, curAddr+SMS_INFO_REAL_LEN+4, 4);
- }else
- {
- //如果是删除最新的那条消息,不用更改位置,只要将更改最新消息的地址即可
- sutSms.newestAddr = smsinfo.nextAddr;
- }
- if(fd>0) nwy_sdk_fclose(fd);
- }
- void MessageDeletResponse(void)
- {
- unsigned short key=getKeyValue();
- if(MKEY_VALUE_MENU==key)
- {
- if(sutSms.smsTotalNum>=1)
- DeleteSpecificSMS();
- uISetNextStatus(UIS_MENU_MAIL_SEL);
- }
- if(MKEY_VALUE_ESC==key)uISetNextStatus(UIS_MENU_MAIL_SEL);
- }
- void FormatSMS(void)
- {
- unsigned short i;
- unsigned char *ptr;
- SUT_SMS_INFO_HEADER info;
- unsigned int readAddr;
- unsigned char process;
- int fd;
- fd=nwy_sdk_fopen(SMS_FILE, NWY_RDWR);
- if(fd<0){
- MSG_ERR(1,"%s format but open failed", SMS_FILE);
- return;
- }
- guiClearRect(0,44,GLCD_WIDTH,84,guiGetBackColor());
- guiDrawRect(29,50,128,66,1,guiGetForeColor());
- process=0;
- readAddr = sutSms.newestAddr;
- ptr=(unsigned char *)&info;
- for(i=0;i<SMS_TOTAL_NUM;i++)
- {
- nwy_sdk_fseek(fd, readAddr,NWY_SEEK_SET);
- nwy_sdk_fread(fd, ptr, sizeof(SUT_SMS_INFO_HEADER));
- //sFlash_Read(ptr, readAddr, sizeof(struct SUT_SMS_INFO_HEADER));
- if(info.flag == 1)
- {
- info.flag=0;
- nwy_sdk_fseek(fd, readAddr,NWY_SEEK_SET);
- nwy_sdk_fwrite(fd, ptr, 1);
- //sFlash_Write(ptr, readAddr, 1);
- }
- readAddr = info.nextAddr;
-
- if(i%10==0)
- {
- guiDrawVLine(52,64,29+process,1,guiGetForeColor());
- process++;
- }
- }
-
-
-
- if(fd>0) nwy_sdk_fclose(fd);
- sutSms.smsTotalNum = 0;
- sutSms.smsUnReadNum = 0;
- sutSms.haveUnRead = 0;
- }
- void MessageFormatResponse(void)
- {
- unsigned short key=getKeyValue();
- if(MKEY_VALUE_MENU==key)
- {
- FormatSMS();
- uISetNextStatus(UIS_MENU_MAIL_SEL);
- }
- if(MKEY_VALUE_ESC==key)uISetNextStatus(UIS_MENU_MAIL_SEL);
- }
- void MessageOptionResponse(void)
- {
- char buf[30];
- unsigned short key;
- key=uiMenuResponse(&sutMenuSysSetup);
- if(MKEY_VALUE_MENU==key)
- {
- switch(sutMenuSysSetup.handle)
- {
- case 0:uISetNextStatus(UIS_MENU_MAIL_DEL);break;
- case 1:uISetNextStatus(UIS_MENU_MAIL_FORMAT);break;
- }
- }
- else if(MKEY_VALUE_ESC==key) uISetNextStatus(sutUIstatus.LastStatus);
- }
- void MessageOptionShow(char update)
- {
- static const char *apcMenuSysSetup[]=
- {"删除","格式化",""};
- if(update)
- {
- guiClearAll(guiGetBackColor());
- guiShowCaption(0,"文本选项",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- uiMenuShowBottomLine();
- uiMenuInit(&sutMenuSysSetup,apcMenuSysSetup, FONT_MODE_12X12,true);
- uiMenuShowBottomIndacitor("确定", "返回");
- }
- }
- //读取index短信全部内容到bufPt
- static void ReadSpecificSms(unsigned char *bufPt)
- {
- SUT_SMS_INFO_HEADER info;
- unsigned char *ptr;
- int fd;
- fd=nwy_sdk_fopen(SMS_FILE, NWY_RDWR);
- if(fd<0){
- MSG_ERR(1,"%s read sms but open failed", SMS_FILE);
- return;
- }
- ptr=(unsigned char *)&info;
- nwy_sdk_fseek(fd, sutSms.ReadAddr[sutListBox.handle]+SMS_INFO_DETAIL_OFFSET, NWY_SEEK_SET);
- nwy_sdk_fread(fd,bufPt, SMS_SIGNAL_LEN);
- //sFlash_Read(bufPt, sutSms.ReadAddr[sutListBox.handle]+SMS_INFO_DETAIL_OFFSET, SMS_SIGNAL_LEN);
- nwy_sdk_fseek(fd, sutSms.ReadAddr[sutListBox.handle], NWY_SEEK_SET);
- nwy_sdk_fread(fd,ptr, 2);
- //sFlash_Read(ptr, sutSms.ReadAddr[sutListBox.handle],2);
- info.read = 0;
- nwy_sdk_fseek(fd, sutSms.ReadAddr[sutListBox.handle], NWY_SEEK_SET);
- nwy_sdk_fwrite(fd,ptr, 2);
- //sFlash_Write(ptr, sutSms.ReadAddr[sutListBox.handle], 2);
- if(sutSms.smsUnReadNum)
- {
- sutSms.smsUnReadNum--;
- if(sutSms.smsUnReadNum==0)
- sutSms.haveUnRead = 0;
- }
- if(fd>0) nwy_sdk_fclose(fd);
- }
- static unsigned short lastShowIndex=0;
- unsigned char smsDetail[SMS_SIGNAL_LEN];
- void MessageReadShow(char update)
- {
- if(update)
- {
- lastShowIndex=0;
- memset(smsDetail,0,sizeof(smsDetail));
- guiClearAll(guiGetBackColor());
- guiShowCaption(0,"消息阅读",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- ReadSpecificSms(smsDetail);
- MessageEditInit(&sutMEdit,8,UI_CONTENT_SHOW_Y+5, (char *)smsDetail,FONT_MODE_16X16);
- lastShowIndex=MessageEditShow(&sutMEdit,(char *)smsDetail+lastShowIndex);
- uiMenuShowBottomLine();
- #ifdef REPORT_SMS_VOICE
- uiMenuShowBottomIndacitor("播放", "返回");
- #else
- uiMenuShowBottomIndacitor(NULL, "返回");
- #endif
- return;
- }
- }
- void MessageReadResponse(void)
- {
- unsigned short len;
- unsigned short key=getKeyValue();
- if(MKEY_VALUE_ESC==getKeyValue())uISetNextStatus(UIS_MENU_MAIL_SEL);
- else if(MKEY_VALUE_MENU == key)
- {
- #ifdef REPORT_SMS_VOICE
- // ReadSpecificSms(smsDetail);
- // AnsiToStrUnicode(unicodeSms,sizeof(unicodeSms),(char *)smsDetail);
- // ModemSendAt("AT+ZTTS=1,\"");
- // ModemSendAt((char *)unicodeSms);
- // ModemSendAt("\"\r");
- #endif
- }else if(MKEY_VALUE_DOWN==key)
- {
- //printf("len:%d,%d\r\n",lastShowIndex,strlen(smsDetail));
- if(lastShowIndex<strlen(smsDetail))
- {
- guiClearRect(0,UI_CONTENT_SHOW_Y+5,GLCD_WIDTH-1,UI_BOTTOM_LINE_Y-2,guiGetBackColor());
- MessageEditInit(&sutMEdit,8,UI_CONTENT_SHOW_Y+5, (char *)smsDetail,FONT_MODE_16X16);
- len=MessageEditShow(&sutMEdit,(char *)smsDetail+lastShowIndex);
- if(len !=0) lastShowIndex+=len;
- else lastShowIndex=0;
- }
- }
- }
- void SwitchSMS_ToGB2312(void)
- {
- unsigned char *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);//
- unicodeToGbk(tempSMS, ptr, &sutMess.len);
- //len no change
- break;
- default:
- break;
- }
- }
- //向上存方式
- void IncomingSMS(void)
- {
- SUT_SMS_INFO_HEADER infosms;
- unsigned char *ptr,i;
- static unsigned short showCt;
- unsigned char *smsPtr;
- unsigned char tempyear;
- MY_CLOCK time;
- getMyClock(&time);
-
- if(0 == sutSms.smsEnable)
- {
- if(++showCt >= 500)
- MSG_ERR(1,"[SMS]Invalid");
- return;
- }
- if(0 != sutMess.Update) return;//消息播报处理完毕
- if(0 == sutSms.smsUpdate) return;//没有可存储处理
- sutSms.smsUpdate = 0;
- MSG_INFO(1,"[SMS]Store SMS");
- SmsScan(2);
- if(sutSms.poolFull)
- return;
- int fd;
- fd=nwy_sdk_fopen(SMS_FILE, NWY_RDWR);
- if(fd<0){
- MSG_ERR(1,"%s open to save but failed",SMS_FILE);
- return;
- }
- SwitchSMS_ToGB2312();
- // SpeakerEnable();
- // ModemSendAt("AT+ZTTS=1,\"36653052B065886D6F60\"\r");
- //1.1
- ptr = (unsigned char*)&infosms;
- infosms.flag=1;
- infosms.read=1;
- tempyear=time.year%2000;
-
- infosms.recTime = (unsigned int)tempyear<<26 |
- (unsigned int)time.month<<22 |
- (unsigned int)time.day<<17 |
- (unsigned int)time.hour<<12 |
- (unsigned int)time.min<<6 |
- (unsigned int)time.sec<<0;
- infosms.len = sutMess.len;
- //保存头信息
- nwy_sdk_fseek(fd, sutSms.emptyAddr, NWY_SEEK_SET);
- nwy_sdk_fwrite(fd, ptr, SMS_INFO_REAL_LEN);
- //保存内容
- smsPtr = sutMess.GBKMess1+4;
- nwy_sdk_fseek(fd, sutSms.emptyAddr+SMS_INFO_DETAIL_OFFSET,NWY_SEEK_SET);
- nwy_sdk_fwrite(fd, smsPtr, SMS_SIGNAL_LEN);
- nwy_sdk_fclose(fd);
- sutSms.haveUnRead=1;
- sutSms.smsTotalNum ++;
- sutSms.smsUnReadNum ++;
- sutSms.newestAddr = sutSms.emptyAddr;
- //保存
- newPara.messageNewAddr=sutSms.newestAddr;
- //save sys
- sysIniSave();
- }
- 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(sutMess.Update == 1 || sutMess.Update == 2)
- {
- MSG_INFO(1,"TTS_LEN:%d",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;
- ttsPlay(ENCODE_USER_UNICODE_BE, (char *)p);
- sutMess.Update=0;
- }
- }
|