1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467 |
- #include "includes.h"
- #define LEARN_HTTP_URL "test.rtpoc.com"
- #define LEARN_PORT 8000
- #define PAGE_SIZE 5
- #define LEARN_LIST "learnLists"
- #define LEARN_LIST_TMP "learnListsTmp"
- #define LEARN_RANK "learnRank"
- #define LEARN_CLASS "learnClass"
- #define LEARN_NOTICE "learnNotice"
- #define LEARN_UPDATE_MAX 10
- #define SHOW_TABLE_MAX_BYTES 40
- #define OBJECT_LIST "list"
- #define OBJECT_TID "tid"
- #define OBJECT_VER "ver"
- #define OBJECT_TITLE "t"
- #define OBJECT_SCORE "s"
- #define OBJECT_CONTENT "c"
- #define OBJECT_FINISH "f"
- #define OBJECT_UID "uid"
- #define OBJECT_GID "gid"
- #define OBJECT_GNAME "groupName"
- #define OBJECT_NNAME "nickname"
- #define OBJECT_TYPE "type"
- #define OBJECT_TOKEN "token"
- #define OBJECT_CONTENT_DETAIL "content"
- #define OBJECT_SPEED_PARAM "scoreSpeedParam"
- #define OBJECT_VOLUME_PARAM "scoreVolumeParam"
- static void httpCallBack(char *msg, int len);
- typedef enum{
- LEARN_DB_GET_INFO,
- LEARN_DB_WAIT_INFO,
- LEARN_GET_LIST,
- LEARN_WAIT_LIST,
- LEARN_DB_SYNC,
- LEARN_DB_SYNC_DEL,
- LEARN_DB_SYNC_ADD,
- LEARN_DB_SYNC_ADD_PAGE_WAIT,
- LEARN_DB_SYNC_ADD_SOME_WAIT,
- LEARN_DB_SYNC_DONE,
- LEARN_DB_SYNC_FAILED,
- LEARN_READ_TASK_INFO,
- LEARN_READ_FAILED,
- LEARN_SHOW_MENU,
- LEARN_WAIT_RESPONSE,
- LEARN_RECORD_UPLOAD,
- LEARN_RELEASE_DB,
- LEARN_END,
-
-
- LEARN_RANK_GET_DETAIL,
- LEARN_CLASS_GET_DETAIL,
- LEARN_NOTICE_GET_DETAIL,
- LEARN_NOTICE_GET_DETAIL_SHOW,
- LEARN_GET_PARAM,
- }LEARN_STATUS;
- static unsigned char charaNum;
- static unsigned int taskID[LEARN_UPDATE_MAX];
- static unsigned int taskNum=0;
- static unsigned char learnAddNum;
- static LEARN_STATUS learnStatus;
- static unsigned short learnPage;
- static unsigned int learnTick;
- static int learnTaskNum;
- static int learnPageNum;
- static bool learnDetailEnd;
- unsigned char rankType;
- static void pocAudioCtl(bool status){
- if(status==false){
- msgAtSend("AT+POC=0C0000\r\n");
- msgAtSend("AT+HTTS=0\r\n");
- sutApp.skipTTS=1;
- msgAtSend("AT+POC=060000\r\n");
- nwy_sleep(50);
- }else{
- sutApp.skipTTS=0;
- msgAtSend("AT+POC=070000\r\n");
- }
- }
- bool isLearnBusy(void){
- static bool pocIsEnable=true;
- if(sutUIstatus.Status==UIS_MENU_TASK_QUERY){
- if(true==pocIsEnable){
- pocIsEnable=false;
- pocAudioCtl(pocIsEnable);
- MSG_INFO(1, "Disable poc ctl");
- }
- return true;
- }else{
- if(false==pocIsEnable){
- pocIsEnable=true;
- pocAudioCtl(pocIsEnable);
- MSG_INFO(1, "Enable poc ctl");
- }
- return false;
- }
- }
- static char *getLearnFileJson(const char *fname);
- void sdCardCtl(bool status){
- if(status==true){
- CTL_SD_PWR(1);
- if(true!=nwy_sdk_sdcard_mount()){
- MSG_ERR(1, "SD card mount failed");
- CTL_SD_PWR(0);
- }else MSG_INFO(1, "SD card mount ok");
- }else{
- nwy_sdk_sdcard_unmount();
- CTL_SD_PWR(0);
- MSG_INFO(1, "SD card unmount");
- }
- }
- static void learnUpdateStatus(LEARN_STATUS newStatus){
- learnStatus=newStatus;
- }
- static LEARN_STATUS getLearnStatus(void){
- return learnStatus;
- }
- void showInfoBox(const char *info,int dly){
- guiShowMessageBox(info);
- uTimerStart(&learnTick, dly);
- }
- void releaseBuf(unsigned char **pointer){
- if(*pointer==NULL) return;
- free(*pointer);
- MSG_INFO(1, "[mem free]%x",*pointer);
- *pointer=NULL;
- }
- void releaseJson(cJSON** json){
- if(*json==NULL) return;
- cJSON_Delete(*json);
- MSG_INFO(1, "[json del]%x",*json);
- *json=NULL;
- }
- void *createBuf(unsigned int size){
- void *buf;
- buf=malloc(size);
- if(buf != NULL) MSG_INFO(1, "[mem malloc]%x", buf);
- return buf;
- }
- cJSON* createJson(char *msg){
- cJSON* tmp;
- tmp=cJSON_Parse(msg);
- if(tmp != NULL) MSG_INFO(1, "[json add]%x", tmp);
- return tmp;
- }
- static char *learnJsonGetItem(cJSON* json, const char *objString){
- if(NULL==json) return NULL;
- cJSON* t=cJSON_GetObjectItem(json, objString);
- if(NULL==t) return NULL;
- else return t->valuestring;
- }
- void learnUpdateListFile(void){
- char oldFile[50],newFile[50];
-
- snprintf(oldFile, sizeof(oldFile), "%s/%s",SD_TOKEN, LEARN_LIST);
- snprintf(newFile, sizeof(newFile), "%s/%s",SD_TOKEN, LEARN_LIST_TMP);
-
- if(true==nwy_sdk_fexist(oldFile)) nwy_sdk_file_unlink(oldFile);
-
- if(true==nwy_sdk_fexist(newFile)){
- nwy_sdk_frename(newFile, oldFile);
- MSG_INFO(1, "Learn Rename file:%s->%s",LEARN_LIST_TMP,LEARN_LIST);
- }
- }
- void learnGetNextPage(short direction){
- if(direction==0) learnPage=0;
- else if(direction>0){
- if(++learnPage>=learnPageNum) learnPage=0;
- }else{
- if(learnPage==0) learnPage=learnPageNum-1;
- else learnPage--;
- }
-
- }
- typedef struct{
- bool paramReady;
- double scoreSpeedParam;
- double scoreVolumeParam;
- bool ready;
- unsigned char type;
- unsigned int uid;
- unsigned int gid;
- char gname[30];
- char nname[30];
- char token[20];
- }USER_INFO;
- USER_INFO usr={false,1,1,false,0xff};
- unsigned int getLearnUid(void){return usr.uid;}
- unsigned int getLearnGid(void){return usr.gid;}
- char *getLearnGName(void){return usr.gname;}
- char *getLearnToken(void){return usr.token;}
- double getLearnSpeedParam(void){return usr.scoreSpeedParam;}
- bool isUserInfoReady(void){return usr.ready;}
- bool isUserStudent(void){
- if(usr.type==0) return false;
- else return true;
- }
- void learnUserInfoClear(void){usr.ready=false;}
- bool cJSONProcessUinfo(char *msg){
- cJSON* json,*item;
- json=createJson(msg);
- memset((unsigned char *)&usr, 0, sizeof(USER_INFO));
- if(json==NULL){
- MSG_WARN(1, "cJSONProcessUinfo json null");
- return false;
- }
-
- item=cJSON_GetObjectItem(json, OBJECT_UID);
- if(NULL!=item) usr.uid=atoi(item->valuestring);
-
- item=cJSON_GetObjectItem(json, OBJECT_GID);
- if(NULL!=item) usr.gid=atoi(item->valuestring);
-
- item=cJSON_GetObjectItem(json, OBJECT_TYPE);
- if(NULL!=item) usr.type=atoi(item->valuestring);
-
- item=cJSON_GetObjectItem(json, OBJECT_GNAME);
- if(NULL!=item) snprintf(usr.gname, sizeof(usr.gname), "%s",item->valuestring);
-
- item=cJSON_GetObjectItem(json, OBJECT_NNAME);
- if(NULL!=item) snprintf(usr.nname, sizeof(usr.nname), "%s",item->valuestring);
-
- item=cJSON_GetObjectItem(json, OBJECT_TOKEN);
- if(NULL!=item) snprintf(usr.token, sizeof(usr.token), "%s",item->valuestring);
- releaseJson(&json);
- MSG_INFO(1, "usr:%d,%s,%d,%s,%s", usr.uid, usr.gname, usr.gid, usr.nname, usr.token);
- usr.ready=true;
- return true;
- }
- bool learnTaskUpdate(LEARN_STATUS type, void *para1, void *para2, bool needShow){
- char url[200],tmp[10];
- unsigned char *msg=NULL;
- unsigned int len=0,i;
- UHTTP_ENUM httpType;
-
- if(sutApp.pocPpp==0 || sutPocStatus.logined==0){
- if(true==needShow) showInfoBox("无网络/未登录",2000);
- learnUpdateStatus(LEARN_END);
- return false;
- }
- if(type==LEARN_DB_GET_INFO){
- httpType=UHTTP_FILE_GET;
- snprintf(url, sizeof(url), "%s/api/cai/UserInfo?account=%d&password=%s", LEARN_HTTP_URL, sutApp.account.psn, sutApp.account.password);
- MSG_INFO(1, "Learn get user info");
- }else if(type==LEARN_GET_LIST){
- httpType=UHTTP_FILE_GET;
- snprintf(url, sizeof(url), "%s/api/cai/BriefTask?gid=%d&uid=%d&token=%s", LEARN_HTTP_URL, getLearnGid(),getLearnUid(),getLearnToken());
- MSG_INFO(1, "Learn get total list");
- }else if(type==LEARN_DB_SYNC_ADD_PAGE_WAIT){
- int *page=(int *)para1;
- int *size=(int *)para2;
- httpType=UHTTP_FILE_GET;
- snprintf(url, sizeof(url), "%s/api/cai/DetailedTask?gid=%d&uid=%d&page=%d&size=%d&token=%s", LEARN_HTTP_URL, getLearnGid(),getLearnUid(),*page,*size,getLearnToken());
- MSG_INFO(1, "Learn get detail,page:%d,size:%d", *page,*size);
- }else if(type==LEARN_DB_SYNC_ADD_SOME_WAIT){
- unsigned int *tids=(unsigned int *)para1;
- unsigned char *num=(unsigned char *)para2;
- httpType=UHTTP_FILE_GET;
- snprintf(url, sizeof(url), "%s/api/cai/DetailedTask?gid=%d&uid=%d&token=%s&tids=[%d", LEARN_HTTP_URL,getLearnGid(),getLearnUid(),getLearnToken(),tids[0]);
- for(i=1;i<*num;i++){
- snprintf(tmp, sizeof(tmp),",%d", tids[i]);
- strcat(url, tmp);
- }
- strcat(url, "]");
- MSG_INFO(1, "Learn get detail,tid num:%d", *num);
- }else if(type==LEARN_RECORD_UPLOAD){
- msg=(unsigned char *)para1;
- len=*((unsigned int *)para2);
- httpType=UHTTP_POST;
- snprintf(url, sizeof(url), "%s/api/cai/HandIn",LEARN_HTTP_URL);
- MSG_INFO(1, "Learn upload audio:%d bytes", len);
- }else if(type==LEARN_RANK_GET_DETAIL){
- httpType=UHTTP_FILE_GET;
- unsigned char *rankType=(unsigned char *)para1;
- snprintf(url, sizeof(url), "%s/api/cai/%slyRanking?uid=%d&gid=%d&token=%s", LEARN_HTTP_URL,(*rankType==0)?"Month":"Week" ,getLearnUid(),getLearnGid(),getLearnToken());
- MSG_INFO(1, "Learn get %s rank", (*rankType==0)?"month":"week");
- }else if(type==LEARN_CLASS_GET_DETAIL){
- httpType=UHTTP_FILE_GET;
- snprintf(url, sizeof(url), "%s/api/cai/Timetable?uid=%d&gid=%d&token=%s", LEARN_HTTP_URL, getLearnUid(), getLearnGid(), getLearnToken());
- MSG_INFO(1, "Learn get class detail");
- }else if(type==LEARN_NOTICE_GET_DETAIL){
- httpType=UHTTP_FILE_GET;
- snprintf(url, sizeof(url), "%s/api/cai/NotificationBrief?uid=%d&gid=%d&token=%s", LEARN_HTTP_URL, getLearnUid(), getLearnGid(), getLearnToken());
- MSG_INFO(1, "Learn get notice detail");
- }else if(type==LEARN_NOTICE_GET_DETAIL_SHOW){
- int *id=(int *)para1;
- httpType=UHTTP_FILE_GET;
- snprintf(url, sizeof(url), "%s/api/cai/NotificationContent?uid=%d&id=%d&token=%s", LEARN_HTTP_URL, getLearnUid(), *id, getLearnToken());
- MSG_INFO(1, "Learn get notice detail show");
- }else if(type==LEARN_GET_PARAM){
- httpType=UHTTP_FILE_GET;
- snprintf(url, sizeof(url), "%s/api/cai/Config?uid=%d&token=%s", LEARN_HTTP_URL, getLearnUid(), getLearnToken());
- MSG_INFO(1, "Learn get param");
- }
- if(true==needShow) showInfoBox("请稍候",5000);
- learnHttpStart(httpType,url, LEARN_PORT, httpCallBack,msg, len);
- return true;
- }
- static void LearnTaskProcess(void);
- static void sutJsonInit(void);
- static unsigned char needUpdate=1;
- void uiShowLearnTask(char update){
- if(update){
- sutJsonInit();
- guiClearAll(guiGetBackColor());
- guiShowCaption(30,"学习任务",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- uiMenuShowBottomLine();
- guiShowMessageBox("请稍候");
- uiMenuShowBottomIndacitor("查看", "返回");
- sdMount();
- #if 1
- if(isUserInfoReady()==false){
- if(true==learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,true)) learnUpdateStatus(LEARN_DB_WAIT_INFO);
- }else{
- if(needUpdate!=0){
- MSG_INFO(1, "learn task need sync");
- if(true==learnTaskUpdate(LEARN_GET_LIST,NULL, NULL,true)) learnUpdateStatus(LEARN_WAIT_LIST);
- }else learnUpdateStatus(LEARN_DB_SYNC_DONE);
- }
- needUpdate=0;
- #else
- if(needUpdate!=0){
- MSG_INFO(1, "learn task need sync");
- if(true==learnTaskUpdate(LEARN_GET_LIST,NULL, NULL,true)) learnUpdateStatus(LEARN_WAIT_LIST);
- }else learnUpdateStatus(LEARN_DB_SYNC_DONE);
- #endif
- }
-
- LearnTaskProcess();
- }
- static void learnTaskDel(const char *delFileName);
- typedef struct{
- bool initStatus;
- unsigned char direction;
- unsigned char lastDirection;
- unsigned short index;
- unsigned short selIndex;
- unsigned char validNum;
- unsigned short totalNum;
- cJSON* jsonList;
- char *bufList;
- cJSON* jsonTask[PAGE_SIZE];
- char *bufTask[PAGE_SIZE];
- char showTable[PAGE_SIZE][SHOW_TABLE_MAX_BYTES];
- char finishedFlag[PAGE_SIZE];
- }LEARN_SHOW_DEF;
- LEARN_SHOW_DEF sutJson={false};
- static void sutJsonInit(void){
- if(sutJson.initStatus==true) return;
- MSG_INFO(1, "sutJson init");
- memset((unsigned char *)&sutJson, 0, sizeof(LEARN_SHOW_DEF));
- sutJson.initStatus=true;
- }
- static unsigned char learnGetNextPageInfo(LEARN_SHOW_DEF *learn){
- cJSON* item, * element, * t;
- cJSON* tmpJson,*sele;
- char *tmpBuf;
- char file[50];
- int i;
-
- MSG_INFO(1, "GET PAGE INFO START");
- item=cJSON_GetObjectItem(learn->jsonList, OBJECT_LIST);
- if(NULL==item) return 1;
- int num=cJSON_GetArraySize(item);
- if(num<=0) return 0;
- learn->totalNum=num;
- int index=learn->index;
- if(learn->direction==1 && learn->lastDirection==2 && num<=PAGE_SIZE){
- index += learn->validNum;
- if(index>=num) index=0;
- }else if(learn->direction==2 && learn->lastDirection==1 && num<=PAGE_SIZE){
- index -= learn->validNum;
- if(index>0 && index<5) index=0;
- else if(index<=0){
- if(num==PAGE_SIZE) index=0;
- else index=num-num%PAGE_SIZE;
- }else index -= PAGE_SIZE;
- }else if(learn->direction==0){
- learn->direction=1;
- }
-
- for(i=0;i<PAGE_SIZE;i++){
- releaseBuf(&learn->bufTask[learn->validNum]);
- releaseJson(&learn->jsonTask[learn->validNum]);
- }
- learn->validNum=0;
- for(;;){
- element=cJSON_GetArrayItem(item, index);
- if(NULL==element){
- if(index==num){
- learn->selIndex=index-learn->validNum;
- learn->index=0;
- goto P_END;
- }else return 2;
- }else{
-
- t=cJSON_GetObjectItem(element, OBJECT_TID);
- if(NULL==t) goto P_CONTINUE;
- if(t->valuestring==NULL) goto P_CONTINUE;
-
- snprintf(file, sizeof(file), "%s.task", t->valuestring);
- tmpBuf=getLearnFileJson(file);
- if(NULL==tmpBuf) goto P_CONTINUE;
- tmpJson=createJson(tmpBuf);
- if(NULL==tmpJson){
- releaseBuf(&tmpBuf);
- goto P_CONTINUE;
- }
-
- sele=cJSON_GetObjectItem(tmpJson, OBJECT_FINISH);
- if(NULL==sele){
- releaseBuf(&tmpBuf);
- releaseJson(&tmpJson);
- goto P_CONTINUE;
- }
- if(sele->valuestring==NULL) goto P_CONTINUE;
- i=atoi(sele->valuestring);
- if(i==0) learn->finishedFlag[learn->validNum]=0;
- else learn->finishedFlag[learn->validNum]=1;
-
- sele=cJSON_GetObjectItem(tmpJson, OBJECT_TITLE);
- if(NULL==sele){
- releaseBuf(&tmpBuf);
- releaseJson(&tmpJson);
- goto P_CONTINUE;
- }
- if(sele->valuestring==NULL) goto P_CONTINUE;
-
- snprintf(learn->showTable[learn->validNum], SHOW_TABLE_MAX_BYTES, "%s", sele->valuestring);
- learn->jsonTask[learn->validNum]=tmpJson;
- learn->bufTask[learn->validNum]=tmpBuf;
- if(++learn->validNum>=PAGE_SIZE){
-
- index++;
- learn->selIndex=index-learn->validNum;
- if(index>=num) index=0;
- learn->index=index;
-
- goto P_END;
- }
- }
- P_CONTINUE:
- index++;
- }
-
- P_END:
- learn->lastDirection=learn->direction;
- return 0;
- }
- static void learnUIShowIndexAndTotal(unsigned int index, unsigned int total){
- char info[20];
- int i;
- snprintf(info, sizeof(info), "%d/%d", index, total);
- i=guiGetStrXLen(info,FONT_MODE_12X12);
- guiClearRect(GLCD_WIDTH-8*8, UI_STATUS_ITEM_Y, GLCD_WIDTH-1, UI_STATUS_ITEM_Y+UI_STATUS_ITEM_HEIGH-1, guiGetForeColor());
- guiShowStr(GLCD_WIDTH-i, UI_STATUS_ITEM_Y+1, info, FONT_MODE_12X12, REVERSED_NO, guiGetBackColor(), guiGetForeColor());
- }
- void LearnTaskSelResponse(void){
- unsigned short key;
- if(LEARN_WAIT_RESPONSE==getLearnStatus()){
- key=getKeyValue();
- if(sutJson.validNum!=0){
- if(sutListBox.handle==0 && MKEY_VALUE_UP==key){
- sutJson.direction=2;
- learnUpdateStatus(LEARN_READ_TASK_INFO);
- }else if(((sutListBox.handle+1) == sutListBox.itemnum) && MKEY_VALUE_DOWN==key){
- sutJson.direction=1;
- learnUpdateStatus(LEARN_READ_TASK_INFO);
- }
- key=ListBoxResponse(&sutListBox);
- if(MKEY_VALUE_ESC==key) learnUpdateStatus(LEARN_RELEASE_DB);
- else if(MKEY_VALUE_MENU==key){
- uiPushStack(sutListBox.handle);
- uISetNextStatus(UIS_MENU_TASK_QUERY);
-
- }else if(MKEY_VALUE_UP || MKEY_VALUE_DOWN){
- learnUIShowIndexAndTotal(sutJson.selIndex+sutListBox.handle+1,sutJson.totalNum);
- }
- }else if(MKEY_VALUE_ESC==key) learnUpdateStatus(LEARN_RELEASE_DB);
- }
- }
- static void LearnTaskProcess(void){
- unsigned char ret;
- static char *simpleList=NULL;
- static char *simpleListTmp=NULL;
- static cJSON* json=NULL,*item;
- cJSON* element,*subEle;
- static cJSON* jsonTmp=NULL,*itemTmp;
- cJSON* elementTmp,*subEleTmp;
- static int index;
- char tid[10],ver[10];
- static bool updateAll;
- int i,j,page,size;
- cJSON* readJson=NULL;
- static char *readBuf=NULL;
- static unsigned int tidTable[LEARN_UPDATE_MAX];
- static const char *learnIcon[]={
- "TASK1.bmp",
- "TASK2.bmp",
- ""
- };
- static char *menuTable[PAGE_SIZE+1];
- switch(getLearnStatus()){
- case LEARN_DB_WAIT_INFO:
- ret=getHttpLearnStatus();
- if(uTimerExpired(&learnTick) || ret!=1){
- MSG_INFO(1, "LEARN_DB_WAIT_INFO:%d",ret);
- switch(ret){
- case 0:
- if(true==learnTaskUpdate(LEARN_GET_LIST,NULL, NULL,true)) learnUpdateStatus(LEARN_WAIT_LIST);
- else{
- showInfoBox("更新失败",2000);
- learnUpdateStatus(LEARN_END);
- }
- break;
- case 2:
- showInfoBox("更新失败",2000);
- learnUpdateStatus(LEARN_END);
- break;
- default:
- hearnHttpOverTime();
- showInfoBox("更新超时",2000);
- learnUpdateStatus(LEARN_END);
- break;
- }
- }
- break;
- case LEARN_WAIT_LIST:
- ret=getHttpLearnStatus();
- if(uTimerExpired(&learnTick) || ret!=1){
- MSG_INFO(1, "LEARN_WAIT_LIST:%d",ret);
- switch(ret){
- case 0:
- learnUpdateStatus(LEARN_DB_SYNC);
- break;
- case 2:
- showInfoBox("更新失败",2000);
- learnUpdateStatus(LEARN_END);
- break;
- default:
- hearnHttpOverTime();
- showInfoBox("更新超时",2000);
- learnUpdateStatus(LEARN_END);
- break;
- }
- }
- break;
- case LEARN_DB_SYNC:
-
- simpleListTmp=getLearnFileJson(LEARN_LIST_TMP);
- if(NULL==simpleListTmp){
- learnUpdateStatus(LEARN_DB_SYNC_FAILED);
- break;
- }
-
- jsonTmp=createJson(simpleListTmp);
- if(NULL==jsonTmp){
- learnUpdateStatus(LEARN_DB_SYNC_FAILED);
- break;
- }
- itemTmp=cJSON_GetObjectItem(jsonTmp, OBJECT_LIST);
- if(NULL==itemTmp){
- learnUpdateStatus(LEARN_DB_SYNC_FAILED);
- break;
- }
- index=0;
-
- learnUpdateStatus(LEARN_DB_SYNC_ADD);
-
- simpleList=getLearnFileJson(LEARN_LIST);
- if(NULL==simpleList){
- updateAll=true;
- break;
- }
-
- json=createJson(simpleList);
- if(NULL==json){
- updateAll=true;
- break;
- }
- item=cJSON_GetObjectItem(json, OBJECT_LIST);
- if(NULL==item){
- updateAll=true;
- break;
- }
- MSG_INFO(1, "LEARN_DB_SYNC_DEL");
- learnUpdateStatus(LEARN_DB_SYNC_DEL);
- updateAll=false;
-
- break;
- case LEARN_DB_SYNC_DEL:
-
- i=0;
- MSG_INFO(1, "LEARN_DB_SYNC_DEL Start");
- for(;;){
- element=cJSON_GetArrayItem(item, i);
- if(element!=NULL){
- subEle=cJSON_GetObjectItem(element, OBJECT_TID);
- if(subEle!=NULL){
- if(subEle->valuestring==NULL) goto C_NEXT;
- j=0;
- for(;;){
- elementTmp=cJSON_GetArrayItem(itemTmp, j);
- if(elementTmp!=NULL){
- subEleTmp=cJSON_GetObjectItem(elementTmp, OBJECT_TID);
- if(subEleTmp!=NULL){
- if(subEleTmp->valuestring==NULL) break;
- if(0==strcmp(subEleTmp->valuestring, subEle->valuestring)) goto C_NEXT;
- }
- }else break;
- j++;
- }
-
- learnTaskDel(subEle->valuestring);
- }
- }else break;
- C_NEXT:
- i++;
- }
- if(updateAll==true){
- releaseBuf(&simpleList);
- releaseBuf(&simpleListTmp);
- releaseJson(&json);
- releaseJson(&jsonTmp);
- MSG_INFO(1, "Free resorce");
- }else{}
- MSG_INFO(1, "LEARN_DB_SYNC_DEL end");
- learnUpdateStatus(LEARN_DB_SYNC_ADD);
- break;
- case LEARN_DB_SYNC_ADD:
- if(true==updateAll){
- page=index/LEARN_UPDATE_MAX;
- size=LEARN_UPDATE_MAX;
- learnAddNum=0;
- learnUpdateStatus(LEARN_DB_SYNC_ADD_PAGE_WAIT);
- learnDetailEnd=false;
- learnTaskUpdate(LEARN_DB_SYNC_ADD_PAGE_WAIT,(void *)&page, (void *)&size,true);
- uTimerStart(&learnTick, 2000);
- }else{
- for(i=0;i<LEARN_UPDATE_MAX;i++) tidTable[i]=0;
- learnAddNum=0;
- for(;;){
- elementTmp=cJSON_GetArrayItem(itemTmp, index++);
- if(NULL==elementTmp){
- break;
- }
- subEleTmp=cJSON_GetObjectItem(elementTmp, OBJECT_TID);
- if(NULL==subEleTmp){
- continue;
- }
- if(subEleTmp->valuestring==NULL) continue;
-
- int w=0;
- bool taskExist=false;
- for(;;){
- element=cJSON_GetArrayItem(item,w++);
- if(NULL==element) break;
- subEle=cJSON_GetObjectItem(element, OBJECT_TID);
- if(NULL==subEle) continue;
- if(subEle->valuestring==NULL) continue;
- if(strcmp(subEle->valuestring, subEleTmp->valuestring)==0){
-
- cJSON* tver, *tverTmp;
- tver=cJSON_GetObjectItem(element, OBJECT_VER);
- tverTmp=cJSON_GetObjectItem(elementTmp, OBJECT_VER);
- if(tver==NULL || tverTmp==NULL) break;
- if(strcmp(tver->valuestring, tverTmp->valuestring)!=0) break;
- taskExist=true;
- break;
- }
- }
- if(taskExist==false){
- tidTable[learnAddNum++]=atoi(subEleTmp->valuestring);
- if(learnAddNum>=LEARN_UPDATE_MAX) break;
- }
- }
- if(learnAddNum==0){
- MSG_INFO(1, "LEARN_DB_SYNC_ADD_SOME_WAIT done");
- releaseBuf(&simpleList);
- releaseBuf(&simpleListTmp);
- releaseJson(&json);
- releaseJson(&jsonTmp);
- learnUpdateListFile();
- learnUpdateStatus(LEARN_DB_SYNC_DONE);
- break;
- }
-
-
- learnUpdateStatus(LEARN_DB_SYNC_ADD_SOME_WAIT);
- learnTaskUpdate(LEARN_DB_SYNC_ADD_SOME_WAIT,(void *)tidTable, (void *)&learnAddNum,true);
- MSG_ERR(1, "update tids:%d", learnAddNum);
- }
- break;
- case LEARN_DB_SYNC_ADD_PAGE_WAIT:
- case LEARN_DB_SYNC_ADD_SOME_WAIT:
- ret=getHttpLearnStatus();
- if(uTimerExpired(&learnTick) || ret!=1){
- MSG_INFO(1, "LEARN_DB_SYNC_ADD_PAGE/SOME_WAIT:%d,%d",getLearnStatus(),ret);
- switch(ret){
- case 0:
- if(getLearnStatus()==LEARN_DB_SYNC_ADD_PAGE_WAIT){
- if(learnDetailEnd==false){
- index += learnAddNum;
- learnUpdateStatus(LEARN_DB_SYNC_ADD);
- }else{
- releaseBuf(&simpleList);
- releaseBuf(&simpleListTmp);
- releaseJson(&json);
- releaseJson(&jsonTmp);
-
- learnUpdateListFile();
- learnUpdateStatus(LEARN_DB_SYNC_DONE);
- }
- }else learnUpdateStatus(LEARN_DB_SYNC_ADD);
- break;
- case 2:
- learnUpdateStatus(LEARN_DB_SYNC_FAILED);
- break;
- default:
- hearnHttpOverTime();
- learnUpdateStatus(LEARN_DB_SYNC_FAILED);
- break;
- }
- }
- break;
- case LEARN_DB_SYNC_DONE:
- MSG_INFO(1, "LEARN_DB_SYNC_DONE");
-
- releaseJson(&json);
- releaseJson(&jsonTmp);
- releaseBuf(&sutJson.bufList);
- releaseJson(&sutJson.jsonList);
- for(i=0;i<PAGE_SIZE;i++){
- releaseBuf(&sutJson.bufTask[i]);
- releaseJson(&sutJson.jsonTask[i]);
- }
- sutJson.direction=0;
- sutJson.lastDirection=0;
- sutJson.index=0;
-
- sutJson.bufList=getLearnFileJson(LEARN_LIST);
- if(NULL==sutJson.bufList){
- learnUpdateStatus(LEARN_READ_FAILED);
- break;
- }
- sutJson.jsonList=createJson(sutJson.bufList);
- if(NULL==sutJson.jsonList){
- learnUpdateStatus(LEARN_READ_FAILED);
- break;
- }
- learnUpdateStatus(LEARN_READ_TASK_INFO);
- break;
- case LEARN_READ_FAILED:
- showInfoBox("数据读取失败",2000);
- releaseBuf(&sutJson.bufList);
- releaseJson(&sutJson.jsonList);
- for(i=0;i<PAGE_SIZE;i++){
- releaseBuf(&sutJson.bufTask[i]);
- releaseJson(&sutJson.jsonTask[i]);
- }
- learnUpdateStatus(LEARN_END);
- break;
- case LEARN_DB_SYNC_FAILED:
- releaseBuf(&simpleList);
- releaseBuf(&simpleListTmp);
- releaseJson(&json);
- releaseJson(&jsonTmp);
- showInfoBox("数据同步失败",2000);
- learnUpdateStatus(LEARN_END);
- break;
- case LEARN_READ_TASK_INFO:
- sutJson.validNum=0;
- ret=learnGetNextPageInfo(&sutJson);
- MSG_INFO(1, "learnGetNextPageInfo:%d", ret);
- if(ret!=0) learnUpdateStatus(LEARN_READ_FAILED);
- else learnUpdateStatus(LEARN_SHOW_MENU);
- break;
- case LEARN_SHOW_MENU:
- MSG_INFO(1, "Task valid num:%d", sutJson.validNum);
- guiClearRect(0,(GLCD_HEIGHT/2)-20,GLCD_WIDTH-1,(GLCD_HEIGHT/2)+20,guiGetBackColor());
- if(sutJson.validNum==0){
- guiShowMessageBox("无数据");
- }else{
- for(i=0;i<sutJson.validNum;i++) menuTable[i]=&sutJson.showTable[i];
- menuTable[sutJson.validNum]=learnIcon[2];
- ListBoxInit(&sutListBox, menuTable,0,learnIcon, sutJson.finishedFlag);
- learnUIShowIndexAndTotal(sutJson.selIndex+sutListBox.handle+1,sutJson.totalNum);
- }
- learnUpdateStatus(LEARN_WAIT_RESPONSE);
- break;
- case LEARN_WAIT_RESPONSE:
- break;
- case LEARN_RELEASE_DB:
- MSG_INFO(1, "Release DB");
- releaseBuf(&simpleList);
- releaseBuf(&simpleListTmp);
- releaseBuf(&sutJson.bufList);
- releaseJson(&sutJson.jsonList);
- for(i=0;i<PAGE_SIZE;i++){
- releaseBuf(&sutJson.bufTask[i]);
- releaseJson(&sutJson.jsonTask[i]);
- }
- sdUnmount();
- if(getStackStruct()->FastUiChange)uISetNextStatus(UIS_STANDBY);
- else uISetNextStatus(UIS_MENU_MAIN);
- needUpdate=1;
- break;
- case LEARN_END:
- if(uTimerExpired(&learnTick)){
- sdUnmount();
- uISetNextStatus(UIS_MENU_MAIN);
- needUpdate=1;
- }
- break;
- }
- }
- static void cJSONSaveTaskFile(const char *jsonMsg);
- static void learnSaveTaskFile(const char *fname, const char *msg);
- void cJSONSaveFile(const char *fname, char *msg, int len){
-
- char file[50];
- snprintf(file, sizeof(file), "%s/%s",SD_TOKEN, fname);
- int fd = nwy_sdk_fopen(file, NWY_CREAT | NWY_RDWR|NWY_TRUNC);
- if(fd<0){
- MSG_WARN(1, "fopen failed,%s", fname);
- return;
- }
- #ifdef USE_TEST_TASK
- const char *testmsg="{\"uid\":\"12345\",\"list\":[{\"ver\":\"1\",\"tid\":\"5126\"},{\"ver\":\"2\",\"tid\":\"5127\"},{\"ver\":\"3\",\"tid\":\"8867\"},{\"ver\":\"2\",\"tid\":\"8868\"},{\"ver\":\"5\",\"tid\":\"1221\"},{\"ver\":\"1\",\"tid\":\"2546\"}]}";
- nwy_sdk_fwrite(fd, testmsg, strlen(testmsg));
- #else
- nwy_sdk_fwrite(fd, msg, len);
- #endif
- nwy_sdk_fclose(fd);
- MSG_INFO(1, "%s save done:%d", fname, len);
- }
- static void getRankShowMessage(unsigned char ranktype);
- static void httpCallBack(char *msg, int len){
-
- int outLen;
- unsigned char ret;
-
- MSG_INFO(1, "httpCallBack UTF8:%d", len);
- if(0!=Utf8ToGbkOrUnicode(msg, len, msg, &outLen,0)){
- MSG_ERR(1, "UTF8 to GBK failed");
- }
- ret=getLearnStatus();
- MSG_INFO(1, "httpCallBack GBK:%d,%d", outLen,ret);
- msg[outLen]=0;
- if(ret==LEARN_DB_WAIT_INFO){
-
- cJSONProcessUinfo(msg);
- }else if(ret==LEARN_WAIT_LIST){
-
- cJSONSaveFile(LEARN_LIST_TMP, msg,outLen);
- }else if(ret==LEARN_DB_SYNC_ADD_PAGE_WAIT || ret==LEARN_DB_SYNC_ADD_SOME_WAIT){
-
- cJSONSaveTaskFile(msg);
- }else if(ret==LEARN_RANK_GET_DETAIL){
- cJSONSaveFile(LEARN_RANK, msg,outLen);
- }else if(ret==LEARN_CLASS_GET_DETAIL){
- cJSONSaveFile(LEARN_CLASS, msg, outLen);
- }else if(ret==LEARN_NOTICE_GET_DETAIL){
- cJSONSaveFile(LEARN_NOTICE, msg, outLen);
- }else if(ret==LEARN_NOTICE_GET_DETAIL_SHOW){
- cJSONTakeContent(msg, outLen);
- }else if(ret==LEARN_GET_PARAM){
- cJSONTakeParam(msg, outLen);
- }
- MSG_INFO(1, "httpCallBack end");
- }
- static char *getLearnFileJson(const char *fname){
- char *buf=NULL,file[50];
- int fd;
-
-
- snprintf(file, sizeof(file), "%s/%s",SD_TOKEN, fname);
- fd=nwy_sdk_fopen(file, NWY_RDONLY);
- if(fd<0) goto L_END;
-
- long size=nwy_sdk_fsize_fd(fd);
- if(size<=0) goto L_END;
-
- buf=(char *)createBuf(size);
-
- if(NULL==buf) goto L_END;
- nwy_sdk_fread(fd, buf, size);
- L_END:
- if(fd>0) nwy_sdk_fclose(fd);
- return buf;
- }
- static void learnTaskDel(const char *delFileName){
- char file[50];
-
-
- snprintf(file, sizeof(file), "%s/%s.task", SD_TOKEN, delFileName);
- if(true==nwy_sdk_fexist(file)){
- nwy_sdk_file_unlink(file);
- MSG_INFO(1, "Del %s.task", delFileName);
- }
-
-
- snprintf(file, sizeof(file), "%s/%s.rec", SD_TOKEN, delFileName);
- if(true==nwy_sdk_fexist(file)){
- nwy_sdk_file_unlink(file);
- MSG_INFO(1, "Del %s.rec", delFileName);
- }
-
- MSG_INFO(1, "Del tid %s end", delFileName);
- }
- void printfJsonValue(cJSON* json){
- if(NULL==json) return;
- char *buf=cJSON_Print(json);
- if(NULL==buf) return;
- MSG_INFO(1, "json:%s",buf);
- free(buf);
- }
- static void cJSONSaveTaskFile(const char *jsonMsg){
- int i,fd;
- cJSON* json,*item,*element,*t;
- char *buf;
- #ifdef USE_TEST_TASK
- static char nextFlag=0;
- const *testBuf1="{\"uid\":\"12348\",\"list\":[{\"s\":\"4\",\"c\":\"What is your name?0123一二三四567890123一二三四567890123一二三四567890123一二三四567890123一二三四567890123一二三四567890123一二三四567890123一二三四567890123一二三四56789\",\"t\":\"学习任务1\",\"f\":\"1\",\"tid\":\"5126\"}, \
- {\"s\":\"3\",\"c\":\"Where are you?\",\"t\":\"学习任务2\",\"f\":\"1\",\"tid\":\"5127\"}, \
- {\"s\":\"5\",\"c\":\"How do you do!\",\"t\":\"学习任务3\",\"f\":\"1\",\"tid\":\"8867\"}, \
- {\"s\":\"3\",\"c\":\"Good morning!\",\"t\":\"学习任务4\",\"f\":\"1\",\"tid\":\"8868\"}, \
- {\"s\":\"0\",\"c\":\"How old are you?\",\"t\":\"学习任务5\",\"f\":\"0\",\"tid\":\"1221\"}, \
- {\"s\":\"0\",\"c\":\"I am come from Shenzhen, China\",\"t\":\"学习任务6\",\"f\":\"0\",\"tid\":\"2546\"} \
- ]}";
- const *testBuf2="{\"uid\":\"12348\",\"list\":[]}";
- char *ptr;
- if(nextFlag==0){
- ptr=testBuf1;
- nextFlag=1;
- }else if(nextFlag==1){
- ptr=testBuf2;
- nextFlag=0;
- }
- json=createJson(ptr);
- #else
- json=createJson(jsonMsg);
- #endif
- if(json==NULL){
- MSG_WARN(1, "cJSONSaveTaskFile json null");
- return;
- }
- item=cJSON_GetObjectItem(json, OBJECT_LIST);
- if(NULL==item){
- MSG_WARN(1, "cJSONSaveTaskFile item null");
- goto S_END;
- }
-
- int num=cJSON_GetArraySize(item);
- MSG_INFO(1, "Num:%d", num);
- if(0==num){
- learnDetailEnd=true;
- MSG_INFO(1, "cJSONSaveTaskFile done");
- }else{
-
- i=0;
- for(;;){
- element=cJSON_GetArrayItem(item, i);
- if(NULL==element){
- MSG_INFO(1, "json array end");
- break;
- }
- t=cJSON_GetObjectItem(element, OBJECT_TID);
- if(NULL != t){
-
- buf=cJSON_Print(element);
- if(NULL==buf){
- MSG_ERR(1, "cJSONSaveTaskFile cJSON_Print null");
- break;
- }
- learnSaveTaskFile(t->valuestring, buf);
- releaseBuf(&buf);
-
-
- learnAddNum++;
- MSG_INFO(1, "Save one task:%s.task", t->valuestring);
- }else MSG_WARN(1, "No find tid");
- i++;
- }
- }
- S_END:
- releaseJson(&json);
-
- }
- static void learnSaveTaskFile(const char *fname, const char *msg){
- int fd;
- char file[50];
-
- if(fname==NULL) return;
- snprintf(file, sizeof(file), "%s/%s.task", SD_TOKEN, fname);
- fd = nwy_sdk_fopen(file, NWY_CREAT | NWY_RDWR|NWY_TRUNC);
- if(fd<0){
- MSG_WARN(1, "learnSaveTaskFile fopen failed,%s", fname);
- return;
- }
- nwy_sdk_fwrite(fd, msg, strlen(msg));
- nwy_sdk_fclose(fd);
- MSG_INFO(1, "Save task %s", fname);
- }
- unsigned char haveNextPage;
- unsigned char taskIndex;
- char tidString[20];
- char *learnGetTid(void){return tidString;}
- static void calWordNum(char *msg){
- int i,len=strlen(msg);
- unsigned char num=0;
- unsigned char lashChara=0;
- MSG_INFO(1, "content:%s",msg);
- for(i=0;i<len;i++){
- if(msg[i]==',' || msg[i]=='.' || msg[i]==' ' || msg[i]=='?' || msg[i]=='!'){
- if(lashChara!=0){
- num++;
- lashChara=0;
- }
- }else if(lashChara==0) lashChara=msg[i];
- }
- if(lashChara!=0) num++;
- charaNum=num;
- MSG_INFO(1, "Chara Num:%d", num);
- }
- void readTaskToShow(void){
- char isDetailValid=0;
- char info[50];
- static cJSON* eleScore ,* eleContent;
-
- tidString[0]=0;
- eleScore=cJSON_GetObjectItem(sutJson.jsonTask[taskIndex], OBJECT_TID);
- if(NULL != eleScore) snprintf(tidString, sizeof(tidString), "%s", eleScore->valuestring);
- eleScore=cJSON_GetObjectItem(sutJson.jsonTask[taskIndex], OBJECT_SCORE);
- eleContent=cJSON_GetObjectItem(sutJson.jsonTask[taskIndex], OBJECT_CONTENT);
-
- if(NULL==eleScore){
- snprintf(info, sizeof(info), "分数:--");
- }else if(eleScore->valuestring==NULL){
- snprintf(info, sizeof(info), "分数:--");
- }else snprintf(info, sizeof(info), "分数:%s", eleScore->valuestring);
-
- if(NULL!=eleContent && eleContent->valuestring!=NULL){
- isDetailValid=1;
- calWordNum(eleContent->valuestring);
- }
- if(0!=newMessageInit(FONT_MODE_12X12, info, eleContent->valuestring, NULL)){
- MSG_WARN(1, "learn task show get error");
- }
- }
- unsigned char recoderVolume=0;
- LEARN_REC_STATUS learnRecordStatus;
- void learnRecSetStatus(LEARN_REC_STATUS newStatus){
- learnRecordStatus=newStatus;
- }
- void learnRecSetVol(unsigned char newVol){
- recoderVolume=newVol;
- }
- static void learnShowResult(void);
- static void learnShowStartScreen(void){
-
- if(isUserStudent()==true) uiMenuShowBottomIndacitor("[OK]重听", "[PTT]录音");
- else uiMenuShowBottomIndacitor(NULL, "返回");
- }
- void learnRetrunStatus(void){
- if(0==learnGetAudioType()){
- learnRecSetStatus(LEARN_REC_DONE);
- uiMenuShowBottomIndacitor("[OK]播放","[F1]提交");
- learnShowResult();
- }else{
- learnRecSetStatus(LEARN_REC_IDLE);
- learnShowStartScreen();
- }
- }
- static void learnRecordDoneProcess(void);
- static void learnDetailBackToTaskListMenu(void){
- uISetNextStatus(UIS_MENU_TASK_SEL);
- }
- void uiShowLearnTaskDetail(char update){
- unsigned char ret;
- if(update){
- guiClearAll(guiGetBackColor());
- guiShowCaption(0,"任务详情",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- uiMenuShowBottomLine();
- taskIndex=sutListBox.handle;
- learnRecSetStatus(LEARN_REC_IDLE);
- readTaskToShow();
- learnShowStartScreen();
- learnTick=0;
- }
-
- switch(learnRecordStatus){
- case LEARN_REC_BUSY:
- learnRecordVolShow(recoderVolume);
- break;
- if(uTimerExpired(&learnTick)){
- uTimerStart(&learnTick, 500);
- learnRecordVolShow(recoderVolume);
- }
- break;
- case LEARN_REC_OT:
- learnRecordDoneProcess();
- #ifdef SAVE_PCM_SD
- pcmFileClose();
- #endif
- break;
- case LEARN_REC_PLY:
- switch(learnPlyGetResult()){
- case LEARN_PLY_PRE_ERR:
- guiShowMessageBox("播放失败");
- nwy_sleep(1500);
- learnDetailBackToTaskListMenu();
- break;
- case LEARN_PLY_FAILED:
- guiShowMessageBox("播放异常");
- nwy_sleep(1500);
- learnDetailBackToTaskListMenu();
- break;
- case LEARN_PLY_DONE:
- learnRetrunStatus();
- break;
- }
- break;
- case LEARN_RECORD_UPLOAD:
- ret=getHttpLearnStatus();
- if(uTimerExpired(&learnTick) || ret!=1){
- MSG_INFO(1, "LEARN_RECORD_UPLOAD:%d",ret);
- switch(ret){
- case 0:
- guiShowMessageBox("上传完成");
- recordSaveTmpToLocal(tidString);
- break;
- case 2:
- guiShowMessageBox("上传失败");
- break;
- default:
- hearnHttpOverTime();
- guiShowMessageBox("上传超时");
- break;
- }
- nwy_sleep(1500);
-
- learnRecordBufRelease();
- learnShowStartScreen();
- newMessageShow(SHOW_HEAD);
- learnRecSetStatus(LEARN_REC_IDLE);
- }
- break;
- }
- }
- void learnRecordVolShow(unsigned char volLev){
- unsigned char vol=volLev;
- unsigned short y1,y2,x,i;
- unsigned int colorID;
- static unsigned char lashVel=99;
- unsigned char width=8;
- unsigned char tx=1;
- unsigned char sx=0;
- if(lashVel == volLev) return;
- lashVel=volLev;
-
- for(i=0;i<LEV_NUM;i++){
- if(i<vol) colorID=COLOR_BLUE;
- else colorID=guiGetBackColor();
- y2=GLCD_HEIGHT-2;
- y1=y2-i-3;if(y1<=UI_BOTTOM_LINE_Y) y1=UI_BOTTOM_LINE_Y+1;
- x=sx+i*(width+tx);
- guiDrawVLine(y1, y2, x, width, colorID);
- }
- }
- void httpPostResetUserTimer(unsigned int persent){
- char info[30];
- snprintf(info,sizeof(info), "正在上传:%d%%",persent);
- guiShowMessageBox(info);
- uTimerStart(&learnTick, 5000);
- }
- void uiShowLearnTaskDetailResponse(void){
- unsigned char *pcm;
- unsigned int plen;
- unsigned short key=getKeyValue();
- if(isUserStudent()==false){
-
- switch(key){
- case MKEY_VALUE_ESC:
- case MKEY_VALUE_UP:
- case MKEY_VALUE_DOWN:
- break;
- default: return;
- }
- }
- if(MKEY_VALUE_ESC==key){
- switch(learnRecordStatus){
- case LEARN_REC_IDLE:
- learnRecordBufRelease();
- learnDetailBackToTaskListMenu();
- break;
- case LEARN_REC_DONE:
- learnRecordBufRelease();
- learnShowStartScreen();
- newMessageShow(SHOW_HEAD);
- learnRecSetStatus(LEARN_REC_IDLE);
- break;
- case LEARN_REC_PLY:
- learnStopPlaying();
- learnRetrunStatus();
- break;
- case LEARN_UPLOAD_CONFIRM:
- learnRetrunStatus();
- break;
- }
- }else if(MKEY_VALUE_PTT==key){
- switch(learnRecordStatus){
- case LEARN_REC_IDLE:
- if(isUserStudent()==false){
- MSG_WARN(1, "Only student have rec feature!");
- break;
- }
- if(false==learnStartRecord(charaNum)){
- MSG_ERR(1, "try recoder failed");
- guiShowMessageBox("录音失败");
- nwy_sleep(1500);
- learnRecordBufRelease();
- learnDetailBackToTaskListMenu();
- break;
- }
- #ifdef SAVE_PCM_SD
- pcmFileOpen();
- #endif
- uiMenuShowBottomIndacitor(NULL, "[PTT]停止");
- learnRecSetStatus(LEARN_REC_BUSY);
- break;
- case LEARN_REC_BUSY:
- learnRecordDoneProcess();
- #ifdef SAVE_PCM_SD
- pcmFileClose();
- #endif
- break;
- }
- }else if(MKEY_VALUE_MENU==key){
- switch(learnRecordStatus){
- case LEARN_REC_IDLE:
- learnPlayAudio(1, tidString);
- learnRecSetStatus(LEARN_REC_PLY);
- uiMenuShowBottomIndacitor(NULL, "停止");
- break;
- case LEARN_REC_DONE:
- learnPlayAudio(0, NULL);
- learnRecSetStatus(LEARN_REC_PLY);
- uiMenuShowBottomIndacitor(NULL, "停止");
- break;
- case LEARN_UPLOAD_CONFIRM:
-
- httpPostResetUserTimer(0);
- uiMenuShowBottomIndacitor(NULL, "取消");
- pcm=learnGetTmpAudioBuf();
- plen=learnGetTmpAudioLength();
- learnRecSetStatus(LEARN_RECORD_UPLOAD);
- learnTaskUpdate(LEARN_RECORD_UPLOAD,(void *)pcm, (void *)&plen,true);
- break;
- }
- }else if(MKEY_VALUE_DOWN==key){
- switch(learnRecordStatus){
- case LEARN_REC_IDLE:
- case LEARN_REC_BUSY:
- newMessageShow(SHOW_DOWN);
- break;
- }
- }else if(MKEY_VALUE_UP==key){
- switch(learnRecordStatus){
- case LEARN_REC_IDLE:
- case LEARN_REC_BUSY:
- newMessageShow(SHOW_UP);
- break;
- }
- }else if(MKEY_VALUE_P1==key){
- switch(learnRecordStatus){
- case LEARN_REC_DONE:
- learnRecSetStatus(LEARN_UPLOAD_CONFIRM);
- guiShowMessageBox("确定提交?");
- uiMenuShowBottomIndacitor("[ok]确定", "取消");
- break;
- }
- }
- }
- static void learnShowResult(void){
- float devscore;
- float speedscore=learnGetRecordRecSpeed();
- float volumescore;
- char info[30];
- unsigned int y=UI_CONTENT_SHOW_Y+5;
- volumescore=usr.scoreVolumeParam*learnGetRecordMaxVolume();
- devscore=speedscore+volumescore;
- guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,GLCD_HEIGHT-16-1,guiGetBackColor());
- snprintf(info, sizeof(info), "设备评分:%.1f", devscore);
- guiShowStr(5, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+= 18;
- snprintf(info, sizeof(info), "速度评分:%.1f", speedscore);
- guiShowStr(5, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+= 18;
- snprintf(info, sizeof(info), "音量评分:%.1f", volumescore);
- guiShowStr(5, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+= 18;
- }
- static void learnRecordDoneProcess(void){
-
- learnRecordFree();
- learnStopRecord();
- learnRecSetStatus(LEARN_REC_DONE);
- uiMenuShowBottomIndacitor("[OK]播放","[F1]提交");
- learnShowResult();
- }
- void uiShowLearnRank(char update){
- static char machine=0;
- static unsigned int timer;
- static const char *rankMode[]={
- "月排名",
- "周排名",
- ""
- };
- static const char *learnIcon[]={
- "RANK-M.bmp",
- "RANK-W.bmp",
- ""
- };
- char Freatrue[2]={0,1};
- if(update){
- machine==0;
- if(isUserStudent()==true) sdMount();
- guiClearAll(guiGetBackColor());
- guiShowCaption(0,"学习排名",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- uiMenuShowBottomLine();
- uiMenuShowBottomIndacitor("查看", "返回");
- if(isUserStudent()==true) ListBoxInit(&sutListBox, rankMode, 0, learnIcon, Freatrue);
- else{
- machine=1;
- guiShowMessageBox("老师不支持排名");
- uTimerStart(&timer, 1000);
- }
- }
- if(machine==1){
- if(uTimerExpired(&timer)){
- uISetNextStatus(UIS_MENU_MAIN);
- }
- }
- }
- void LearnRankSelResponse(void){
- unsigned short key=ListBoxResponse(&sutListBox);
- if(isUserStudent()==false) return;
- if(MKEY_VALUE_ESC==key){
- sdUnmount();
- uISetNextStatus(UIS_MENU_MAIN);
- }else if(MKEY_VALUE_MENU==key){
- if(sutListBox.handle==0){
- rankType=0;
- uiPushStack(sutListBox.handle);
- uISetNextStatus(UIS_MENU_RANK_DETAIL);
- }else if(sutListBox.handle==1){
- rankType=1;
- uiPushStack(sutListBox.handle);
- uISetNextStatus(UIS_MENU_RANK_DETAIL);
- }
- }
- }
- typedef struct{
- char type;
- int typeIndex;
- int avg;
- int score;
- int ranking;
- int num;
- }RANK_DEF;
- typedef struct{
- unsigned int item;
- unsigned int num;
- RANK_DEF **rankResult;
- }RANK_RESULT_DEF;
- RANK_RESULT_DEF ranks={0,0,0,NULL};
- bool rankShowReady;
- static void rankInfoDetailShow(unsigned char direction){
- static int tIndex=0;
-
- if(ranks.item==0){
- guiShowMessageBox("无数据");
- return;
- }else if(ranks.item==1) tIndex=0;
- else{
- if(direction==0) tIndex=0;
- else if(direction==1){
- if(++tIndex>=ranks.item) tIndex=0;
- }else if(direction==2){
- if(tIndex==0) tIndex=ranks.item-1;
- else tIndex--;
- }
- }
- guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,UI_BOTTOM_SHOW_Y-2,guiGetBackColor());
-
- if(ranks.rankResult==NULL){
- MSG_WARN(1, "rank no data");
- return;
- }
- char info[50];
- int x=1,y=UI_CONTENT_SHOW_Y;
-
- if(0==ranks.rankResult[tIndex]->type) snprintf(info, sizeof(info), "month:%d", ranks.rankResult[tIndex]->typeIndex);
- else snprintf(info, sizeof(info), "week:%d", ranks.rankResult[tIndex]->typeIndex);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+=17;
-
- snprintf(info, sizeof(info), "avg:%d", ranks.rankResult[tIndex]->avg);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+=17;
-
- snprintf(info, sizeof(info), "score:%d", ranks.rankResult[tIndex]->score);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+=17;
-
- snprintf(info, sizeof(info), "ranking:%d", ranks.rankResult[tIndex]->ranking);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+=17;
-
- snprintf(info, sizeof(info), "num:%d", ranks.rankResult[tIndex]->num);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- }
- void uiShowLearnRankDetail(char update){
- int ret;
- static bool needGetUinfo=false;
- if(update){
- guiClearAll(guiGetBackColor());
- if(rankType==0)
- guiShowCaption(0,"月排名",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- else
- guiShowCaption(0,"周排名",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- uiMenuShowBottomLine();
- uiMenuShowBottomIndacitor(NULL, "返回");
- if(sutApp.pocPpp==0){
- guiShowMessageBox("无网络");
- nwy_sleep(1500);
- uISetNextStatus(UIS_MENU_RANK_SEL);
- return;
- }
- rankShowReady=false;
- showInfoBox("请稍候",3000);
- if(isUserInfoReady()==false){
- needGetUinfo=true;
- learnUpdateStatus(LEARN_DB_WAIT_INFO);
- learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,true);
- }else{
- needGetUinfo=false;
- learnUpdateStatus(LEARN_RANK_GET_DETAIL);
- learnTaskUpdate(LEARN_RANK_GET_DETAIL,(void*)&rankType, NULL,true);
- MSG_ERR(1, "update rank detail %s", (rankType==0)?"month":"week");
- }
- }
- if(false==rankShowReady){
- ret=getHttpLearnStatus();
- if(uTimerExpired(&learnTick) || ret!=1){
- MSG_INFO(1, "WAIT %s RESULT:%d",(rankType==0)?"MONTH":"WEEK",ret);
- switch(ret){
- case 0:
- if(needGetUinfo==true){
- needGetUinfo=false;
- learnUpdateStatus(LEARN_RANK_GET_DETAIL);
- learnTaskUpdate(LEARN_RANK_GET_DETAIL,(void*)&rankType, NULL,true);
- MSG_ERR(1, "update rank detail %s", (rankType==0)?"month":"week");
- }else{
- rankShowReady=true;
- getRankShowMessage(rankType);
- rankInfoDetailShow(0);
- }
- return;
- case 2:
- guiShowMessageBox("获取失败");
- break;
- default:
- hearnHttpOverTime();
- guiShowMessageBox("获取超时");
- break;
- }
- nwy_sleep(1500);
- getStackStruct()->ok_back=1;
- uISetNextStatus(UIS_MENU_RANK_SEL);
- }
- }
- }
- static void learnRankReleaseDB(void);
- void LearnRankDetailSelResponse(void){
- if(rankShowReady==true){
- switch(getKeyValue()){
- case MKEY_VALUE_ESC:
- learnRankReleaseDB();
- uISetNextStatus(UIS_MENU_RANK_SEL);
- break;
- case MKEY_VALUE_DOWN:rankInfoDetailShow(1);break;
- case MKEY_VALUE_UP:rankInfoDetailShow(2);break;
- }
- }
- }
- typedef struct{
- int week;
- char time[15];
- char subject[30*2];
- }CLASS_DEF;
- typedef struct{
- unsigned int item;
- unsigned int num;
- CLASS_DEF **classResult;
- }CLASS_RESULT_DEF;
- CLASS_RESULT_DEF classes={0,0,0,NULL};
- bool classShowReady;
- static void classInfoDetailShow(unsigned char direction){
- static int tIndex=0;
-
- if(classes.item==0){
- guiShowMessageBox("无数据");
- return;
- }else if(classes.item==1) tIndex=0;
- else{
- if(direction==0) tIndex=0;
- else if(direction==1){
- if(++tIndex>=classes.item) tIndex=0;
- }else if(direction==2){
- if(tIndex==0) tIndex=classes.item-1;
- else tIndex--;
- }
- }
- guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,UI_BOTTOM_SHOW_Y-2,guiGetBackColor());
-
- if(classes.classResult==NULL){
- MSG_WARN(1, "class no data");
- return;
- }
- #if 0
- char info[50];
- int x=1,y=UI_CONTENT_SHOW_Y;
-
- snprintf(info, sizeof(info), "week:%d", classes.classResult[tIndex]->week);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+=17;
-
- snprintf(info, sizeof(info), "time:%s", classes.classResult[tIndex]->time);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+=17;
-
- snprintf(info, sizeof(info), "subject:%s", classes.classResult[tIndex]->subject);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- #else
- const char *weekTable[]={
- "天","一","二","三","四","五","六",""
- };
- char info1[50],info2[100];
- unsigned char index;
-
- learnUIShowIndexAndTotal(tIndex+1,classes.item);
-
- index=classes.classResult[tIndex]->week;
- if(index>6) index=7;
- snprintf(info1, sizeof(info1), "星期%s%c时间:%s", weekTable[index],0x0a,classes.classResult[tIndex]->time);
- snprintf(info2, sizeof(info2), "课程:%s", classes.classResult[tIndex]->subject);
- newMessageInit(FONT_MODE_16X16,info1, info2, NULL);
- #endif
- }
- static void getClassShowMessage(void);
- void uiShowLearnClassDetail(char update){
- int ret;
- static bool needGetUinfo=false;
- if(update){
- guiClearAll(guiGetBackColor());
- guiShowCaption(30,"课程表",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- uiMenuShowBottomLine();
- uiMenuShowBottomIndacitor(NULL, "返回");
- if(sutApp.pocPpp==0){
- guiShowMessageBox("无网络");
- nwy_sleep(1500);
- uISetNextStatus(UIS_MENU_LOCATION_SEL);
- return;
- }
- classShowReady=false;
- showInfoBox("请稍候",3000);
- sdMount();
- if(isUserInfoReady()==false){
- needGetUinfo=true;
- learnUpdateStatus(LEARN_DB_WAIT_INFO);
- learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,true);
- }else{
- needGetUinfo=false;
- learnUpdateStatus(LEARN_CLASS_GET_DETAIL);
- learnTaskUpdate(LEARN_CLASS_GET_DETAIL,NULL, NULL,true);
- MSG_ERR(1, "update class detail");
- }
- }
- if(false==classShowReady){
- ret=getHttpLearnStatus();
- if(uTimerExpired(&learnTick) || ret!=1){
- MSG_INFO(1, "WAIT CLASS:%d",ret);
- switch(ret){
- case 0:
- if(needGetUinfo==true){
- needGetUinfo=false;
- learnUpdateStatus(LEARN_CLASS_GET_DETAIL);
- learnTaskUpdate(LEARN_CLASS_GET_DETAIL,NULL, NULL,true);
- MSG_ERR(1, "update class detail");
- }else{
- MSG_INFO(1, "class info get ok");
- classShowReady=true;
- getClassShowMessage();
- classInfoDetailShow(0);
- }
- return;
- case 2:
- guiShowMessageBox("获取失败");
- break;
- default:
- hearnHttpOverTime();
- guiShowMessageBox("获取超时");
- break;
- }
- nwy_sleep(1500);
- getStackStruct()->ok_back=1;
- uISetNextStatus(UIS_MENU_LOCATION_SEL);
- }
- }
- }
- static void learnClassReleaseDB(void);
- void LearnClassDetailResponse(void){
- if(classShowReady==true){
- switch(getKeyValue()){
- case MKEY_VALUE_ESC:
- learnClassReleaseDB();
- uISetNextStatus(UIS_MENU_LOCATION_SEL);
- break;
- case MKEY_VALUE_DOWN:classInfoDetailShow(1);break;
- case MKEY_VALUE_UP:classInfoDetailShow(2);break;
- }
- }
- }
- typedef struct{
- int id;
- char time[15];
- char title[60];
- }NOTICE_DEF;
- typedef struct{
- unsigned int item;
- unsigned int num;
- NOTICE_DEF **noticeResult;
- }NOTICE_RESULT_DEF;
- NOTICE_RESULT_DEF notices={0,0,0,NULL};
- bool noticeShowReady;
- static int noticetIndex=0;
- static void noticeInfoDetailShow(unsigned char direction){
- char time[35];
- char title[100];
- if(notices.item==0){
- guiShowMessageBox("无数据");
- return;
- }else if(notices.item==1) noticetIndex=0;
- else{
- if(direction==0) noticetIndex=0;
- else if(direction==1){
- if(++noticetIndex>=notices.item) noticetIndex=0;
- }else if(direction==2){
- if(noticetIndex==0) noticetIndex=notices.item-1;
- else noticetIndex--;
- }
- }
- guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,UI_BOTTOM_SHOW_Y-2,guiGetBackColor());
-
- if(notices.noticeResult==NULL){
- MSG_WARN(1, "notice no data");
- return;
- }
- #if 0
- char info[50];
- int x=1,y=UI_CONTENT_SHOW_Y;
-
- snprintf(info, sizeof(info), "title:%s", notices.noticeResult[noticetIndex]->title);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- y+=17;
-
- snprintf(info, sizeof(info), "time:%s", notices.noticeResult[noticetIndex]->time);
- guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
- #else
- snprintf(time, sizeof(time), "时间:%s", notices.noticeResult[noticetIndex]->time);
- snprintf(title, sizeof(title), "标题:%s", notices.noticeResult[noticetIndex]->title);
- learnUIShowIndexAndTotal(noticetIndex+1,notices.item);
- newMessageInit(FONT_MODE_16X16, time, title, NULL);
- #endif
- }
- static void getNoticeShowMessage(void);
- void uiShowLearnNoticeDetail(char update){
- int ret;
- static bool needGetUinfo=false;
- if(update){
- guiClearAll(guiGetBackColor());
- guiShowCaption(30,"消息通知",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- uiMenuShowBottomLine();
- uiMenuShowBottomIndacitor("阅读", "返回");
- if(sutApp.pocPpp==0){
- guiShowMessageBox("无网络");
- nwy_sleep(1500);
- uISetNextStatus(UIS_MENU_LOCATION_SEL);
- return;
- }
- if(noticeShowReady==false){
- showInfoBox("请稍候",3000);
- sdMount();
- if(isUserInfoReady()==false){
- needGetUinfo=true;
- learnUpdateStatus(LEARN_DB_WAIT_INFO);
- learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,true);
- }else{
- needGetUinfo=false;
- learnUpdateStatus(LEARN_NOTICE_GET_DETAIL);
- learnTaskUpdate(LEARN_NOTICE_GET_DETAIL,NULL, NULL,true);
- MSG_ERR(1, "update notice detail");
- }
- }
- }
- if(false==noticeShowReady){
- ret=getHttpLearnStatus();
- if(uTimerExpired(&learnTick) || ret!=1){
- MSG_INFO(1, "WAIT NOTICE:%d",ret);
- switch(ret){
- case 0:
- if(needGetUinfo==true){
- needGetUinfo=false;
- learnUpdateStatus(LEARN_NOTICE_GET_DETAIL);
- learnTaskUpdate(LEARN_NOTICE_GET_DETAIL,NULL, NULL,true);
- MSG_ERR(1, "update notice detail");
- }else{
- MSG_INFO(1, "notice info get ok");
- noticeShowReady=true;
- getNoticeShowMessage();
- noticeInfoDetailShow(0);
- }
- return;
- case 2:
- guiShowMessageBox("获取失败");
- break;
- default:
- hearnHttpOverTime();
- guiShowMessageBox("获取超时");
- break;
- }
- nwy_sleep(1500);
- getStackStruct()->ok_back=1;
- uISetNextStatus(UIS_MENU_LOCATION_SEL);
- }
- }
- }
- static void learnNoticeReleaseDB(void);
- unsigned char noticeHandle;
- void LearnNoticeResponse(void){
- if(noticeShowReady==true){
- switch(getKeyValue()){
- case MKEY_VALUE_ESC:
- learnNoticeReleaseDB();
- noticeShowReady=false;
- uISetNextStatus(UIS_MENU_LOCATION_SEL);
- break;
- case MKEY_VALUE_DOWN:noticeInfoDetailShow(1);break;
- case MKEY_VALUE_UP:noticeInfoDetailShow(2);break;
- case MKEY_VALUE_MENU:
- uISetNextStatus(UIS_MENU_LOCATION_NOTICE_DETAIL);
- break;
- }
- }
- }
- bool noticeDetailReady=false;
- void uiShowLearnNoticeDetailShow(char update){
- int ret;
- if(update){
- guiClearAll(guiGetBackColor());
- guiShowCaption(0,notices.noticeResult[noticetIndex]->time,UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- uiMenuShowBottomLine();
- uiMenuShowBottomIndacitor(NULL, "返回");
- if(sutApp.pocPpp==0){
- guiShowMessageBox("无网络");
- nwy_sleep(1500);
- uISetNextStatus(UIS_MENU_LOCATION_SEL);
- return;
- }
- showInfoBox("请稍候",3000);
- sdMount();
- noticeDetailReady=false;
- learnUpdateStatus(LEARN_NOTICE_GET_DETAIL_SHOW);
- learnTaskUpdate(LEARN_NOTICE_GET_DETAIL_SHOW,(void *)¬ices.noticeResult[noticetIndex]->id, NULL,true);
- MSG_ERR(1, "update notice detail show");
- }
- if(false==noticeDetailReady){
- ret=getHttpLearnStatus();
- if(uTimerExpired(&learnTick) || ret!=1){
- MSG_INFO(1, "WAIT NOTICE SHOW:%d",ret);
- switch(ret){
- case 0:
-
- noticeDetailReady=true;
- MSG_INFO(1, "notice info get ok");
- noticeInfoDetailShowContent(0);
- return;
- case 2:
- guiShowMessageBox("获取失败");
- break;
- default:
- hearnHttpOverTime();
- guiShowMessageBox("获取超时");
- break;
- }
- nwy_sleep(1500);
- noticeShowReady=false;
- getStackStruct()->ok_back=1;
- uISetNextStatus(UIS_MENU_LOCATION_SEL);
- }
- }
- }
- void LearnNoticeDetailResponse(void){
- if(noticeDetailReady==true){
- switch(getKeyValue()){
- case MKEY_VALUE_ESC:
- noticeShowReady=false;
- uISetNextStatus(UIS_MENU_LOCATION_NOTICE);
- break;
- case MKEY_VALUE_DOWN:noticeInfoDetailShowContent(1);break;
- case MKEY_VALUE_UP:noticeInfoDetailShowContent(2);break;
- }
- }
- }
- #define OBJECT_AVG_NAME "avg"
- #define OBJECT_SCORE_NAME "score"
- #define OBJECT_RANKING_NAME "ranking"
- #define OBJECT_NUM_NAME "num"
- static char *rankBuffer=NULL;
- cJSON* rankJson=NULL;
- static void learnRankReleaseDB(void){
- int i;
- releaseBuf(&rankBuffer);
- if(NULL!=ranks.rankResult){
- for(i=0;i<ranks.num;i++){
- if(ranks.rankResult[i]!=NULL) releaseBuf(&ranks.rankResult[i]);
- }
- releaseBuf(&ranks.rankResult);
- }
- releaseJson(&rankJson);
- }
- static void getRankShowMessage(unsigned char ranktype){
-
- RANK_DEF **rankPtr=NULL;
- int fd=-1,i=0;
- char info[50];
-
- ranks.item=0;
- snprintf(info, sizeof(info), "%s/%s", SD_TOKEN,LEARN_RANK);
- fd=nwy_sdk_fopen(info, NWY_RDONLY);
- if(fd<0){
- MSG_WARN(1, "Rank file open failed");
- goto R_EXIT;
- }
- long size=nwy_sdk_fsize_fd(fd);
- if(size<=0){
- MSG_WARN(1, "Rank file data error");
- goto R_EXIT;
- }
- releaseBuf(&rankBuffer);
- rankBuffer=(char *)createBuf(size);
-
- if(NULL == rankBuffer){
- MSG_ERR(1, "rank buffer malloc error");
- goto R_EXIT;
- }
-
- memset(rankBuffer, 0, size);
- nwy_sdk_fread(fd, rankBuffer, size);
- nwy_sdk_fclose(fd);
- fd=-1;
-
- MSG_INFO(1, "Rank data analyse len:%d, type:%d",size, ranktype);
- if(NULL!=ranks.rankResult){
- for(i=0;i<ranks.num;i++){
- if(ranks.rankResult[i]!=NULL) releaseBuf(&ranks.rankResult[i]);
- }
- releaseBuf(&ranks.rankResult);
- }
- ranks.num=0;
- if(0==ranktype) snprintf(info, sizeof(info), "month");
- else snprintf(info, sizeof(info), "week");
- rankJson = createJson(rankBuffer);
-
- if(NULL==rankJson){
- MSG_WARN(1, "rank json null");
- goto R_EXIT;
- }
-
- cJSON* item = cJSON_GetObjectItem(rankJson, OBJECT_LIST);
- if(NULL==item){
- MSG_ERR(1, "rank json failed");
- goto R_EXIT;
- }
- int num=cJSON_GetArraySize(item);
- if(num<=0){
- MSG_WARN(1, "rank array num:%d",num);
- goto R_EXIT;
- }
- MSG_INFO(1, "rank num:%d",num);
- rankPtr=(RANK_DEF **)createBuf(sizeof(RANK_DEF *)*num);
-
- if(NULL==rankPtr){
- MSG_ERR(1,"rank malloc failed");
- goto R_EXIT;
- }
-
- ranks.num=num;
- for(i=0;i<num;i++) rankPtr[i]=NULL;
- for(i=0;i<num;i++){
- rankPtr[i]=(RANK_DEF *)createBuf(sizeof(RANK_DEF));
-
- if(NULL==rankPtr[i]){
- MSG_ERR(1, "rank[%d] malloc failed", i);
- goto R_EXIT;
- }
-
- }
- cJSON* element,*t;
- i=0;
- for(;;){
- element=cJSON_GetArrayItem(item,i);
- if(NULL==element) break;
-
- rankPtr[i]->type=ranktype;
- t=cJSON_GetObjectItem(element, info);
- if(NULL==t) rankPtr[i]->typeIndex=-1;
- else rankPtr[i]->typeIndex=atoi(t->valuestring);
-
- t=cJSON_GetObjectItem(element, OBJECT_AVG_NAME);
- if(NULL==t) rankPtr[i]->avg=-1;
- else rankPtr[i]->avg=atoi(t->valuestring);
-
- t=cJSON_GetObjectItem(element, OBJECT_SCORE_NAME);
- if(NULL==t) rankPtr[i]->score=-1;
- else rankPtr[i]->score=atoi(t->valuestring);
-
- t=cJSON_GetObjectItem(element, OBJECT_RANKING_NAME);
- if(NULL==t) rankPtr[i]->ranking=-1;
- else rankPtr[i]->ranking=atoi(t->valuestring);
-
- t=cJSON_GetObjectItem(element, OBJECT_NUM_NAME);
- if(NULL==t) rankPtr[i]->num=-1;
- else rankPtr[i]->num=atoi(t->valuestring);
- i++;
- }
- ranks.item=i;
- ranks.rankResult=rankPtr;
- MSG_INFO(1, "rank valid num:%d",i);
- return;
-
- R_EXIT:
- releaseJson(&rankJson);
- releaseBuf(&rankBuffer);
- if(fd>0) nwy_sdk_fclose(fd);
- if(rankPtr != NULL){
- for(i=0;i<num;i++) releaseBuf(&rankPtr[i]);
- releaseBuf(&rankPtr);
- }
- }
- #define OBJECT_WEEK_NAME "week"
- #define OBJECT_TIME_NAME "time"
- #define OBJECT_SUBJECT_NAME "subject"
- static char *classBuffer=NULL;
- cJSON* classJson=NULL;
- static void learnClassReleaseDB(void){
- int i;
- releaseBuf(&classBuffer);
- if(NULL!=classes.classResult){
- for(i=0;i<classes.num;i++){
- if(classes.classResult[i]!=NULL) releaseBuf(&classes.classResult[i]);
- }
- releaseBuf(&classes.classResult);
- }
- releaseJson(&classJson);
- }
- static void getClassShowMessage(void){
-
- CLASS_DEF **classPtr=NULL;
- int fd=-1,i=0;
- char info[50];
-
- ranks.item=0;
- snprintf(info, sizeof(info), "%s/%s", SD_TOKEN,LEARN_CLASS);
- fd=nwy_sdk_fopen(info, NWY_RDONLY);
- if(fd<0){
- MSG_WARN(1, "Class file open failed");
- goto R_EXIT;
- }
- long size=nwy_sdk_fsize_fd(fd);
- if(size<=0){
- MSG_WARN(1, "Class file data error");
- goto R_EXIT;
- }
- releaseBuf(&classBuffer);
- classBuffer=(char *)createBuf(size);
-
- if(NULL == classBuffer){
- MSG_ERR(1, "class buffer malloc error");
- goto R_EXIT;
- }
-
- memset(classBuffer, 0, size);
- nwy_sdk_fread(fd, classBuffer, size);
- nwy_sdk_fclose(fd);
- fd=-1;
-
- MSG_INFO(1, "Class data analyse len:%d",size);
- if(NULL!=classes.classResult){
- for(i=0;i<classes.num;i++){
- if(classes.classResult[i]!=NULL) releaseBuf(&classes.classResult[i]);
- }
- releaseBuf(&classes.classResult);
- }
- classes.num=0;
- classJson = createJson(classBuffer);
-
- if(NULL==classJson){
- MSG_WARN(1, "class json null");
- goto R_EXIT;
- }
-
- cJSON* item = cJSON_GetObjectItem(classJson, OBJECT_LIST);
- if(NULL==item){
- MSG_ERR(1, "class json failed");
- goto R_EXIT;
- }
- int num=cJSON_GetArraySize(item);
- if(num<=0){
- MSG_WARN(1, "class array num:%d",num);
- goto R_EXIT;
- }
- MSG_INFO(1, "class num:%d",num);
- classPtr=(CLASS_DEF **)createBuf(sizeof(CLASS_DEF *)*num);
-
- if(NULL==classPtr){
- MSG_ERR(1,"class malloc failed");
- goto R_EXIT;
- }
-
- classes.num=num;
- for(i=0;i<num;i++) classPtr[i]=NULL;
- for(i=0;i<num;i++){
- classPtr[i]=(CLASS_DEF *)createBuf(sizeof(CLASS_DEF));
-
- if(NULL==classPtr[i]){
- MSG_ERR(1, "class[%d] malloc failed", i);
- goto R_EXIT;
- }
-
- }
- cJSON* element,*t;
- i=0;
- for(;;){
- element=cJSON_GetArrayItem(item,i);
- if(NULL==element) break;
-
- t=cJSON_GetObjectItem(element, OBJECT_WEEK_NAME);
- if(NULL==t) classPtr[i]->week=-1;
- else classPtr[i]->week=atoi(t->valuestring);
-
- t=cJSON_GetObjectItem(element, OBJECT_TIME_NAME);
- if(NULL==t) classPtr[i]->time[0]='\0';
- else snprintf(classPtr[i]->time, sizeof(classPtr[i]->time), "%s", t->valuestring);
-
- t=cJSON_GetObjectItem(element, OBJECT_SUBJECT_NAME);
- if(NULL==t) classPtr[i]->subject[0]='\0';
- else snprintf(classPtr[i]->subject, sizeof(classPtr[i]->subject), "%s", t->valuestring);
- i++;
- }
- classes.item=i;
- classes.classResult=classPtr;
- MSG_INFO(1, "class valid num:%d",i);
- return;
-
- R_EXIT:
- releaseJson(&classJson);
- releaseBuf(&classBuffer);
- if(fd>0) nwy_sdk_fclose(fd);
- if(classPtr != NULL){
- for(i=0;i<num;i++) releaseBuf(&classPtr[i]);
- releaseBuf(&classPtr);
- }
- }
- #define OBJECT_ID_NAME "id"
- #define OBJECT_TITLE_NAME "title"
- static char *noticeBuffer=NULL;
- cJSON* noticeJson=NULL;
- static void learnNoticeReleaseDB(void){
- int i;
- releaseBuf(¬iceBuffer);
- if(NULL!=notices.noticeResult){
- for(i=0;i<notices.num;i++){
- if(notices.noticeResult[i]!=NULL) releaseBuf(¬ices.noticeResult[i]);
- }
- releaseBuf(¬ices.noticeResult);
- }
- releaseJson(¬iceJson);
- }
- static void getNoticeShowMessage(void){
-
- NOTICE_DEF **noticePtr=NULL;
- int fd=-1,i=0;
- char info[50];
-
- notices.item=0;
- snprintf(info, sizeof(info), "%s/%s", SD_TOKEN,LEARN_NOTICE);
- fd=nwy_sdk_fopen(info, NWY_RDONLY);
- if(fd<0){
- MSG_WARN(1, "Notice file open failed");
- goto R_EXIT;
- }
- long size=nwy_sdk_fsize_fd(fd);
- if(size<=0){
- MSG_WARN(1, "Notice file data error");
- goto R_EXIT;
- }
- releaseBuf(¬iceBuffer);
- noticeBuffer=(char *)createBuf(size);
-
- if(NULL == noticeBuffer){
- MSG_ERR(1, "notice buffer malloc error");
- goto R_EXIT;
- }
-
- memset(noticeBuffer, 0, size);
- nwy_sdk_fread(fd, noticeBuffer, size);
- nwy_sdk_fclose(fd);
- fd=-1;
-
- MSG_INFO(1, "Notice data analyse len:%d",size);
- if(NULL!=notices.noticeResult){
- for(i=0;i<notices.num;i++){
- if(notices.noticeResult[i]!=NULL) releaseBuf(¬ices.noticeResult[i]);
- }
- releaseBuf(¬ices.noticeResult);
- }
- notices.num=0;
- noticeJson = createJson(noticeBuffer);
-
- if(NULL==noticeJson){
- MSG_WARN(1, "notice json null");
- goto R_EXIT;
- }
-
- cJSON* item = cJSON_GetObjectItem(noticeJson, OBJECT_LIST);
- if(NULL==item){
- MSG_ERR(1, "notice json failed");
- goto R_EXIT;
- }
- int num=cJSON_GetArraySize(item);
- if(num<=0){
- MSG_WARN(1, "notice array num:%d",num);
- goto R_EXIT;
- }
- MSG_INFO(1, "notice num:%d",num);
- noticePtr=(NOTICE_DEF **)createBuf(sizeof(NOTICE_DEF *)*num);
-
- if(NULL==noticePtr){
- MSG_ERR(1,"notice malloc failed");
- goto R_EXIT;
- }
-
- notices.num=num;
- for(i=0;i<num;i++) noticePtr[i]=NULL;
- for(i=0;i<num;i++){
- noticePtr[i]=(NOTICE_DEF *)createBuf(sizeof(NOTICE_DEF));
-
- if(NULL==noticePtr[i]){
- MSG_ERR(1, "notice[%d] malloc failed", i);
- goto R_EXIT;
- }
-
- }
- cJSON* element,*t;
- i=0;
- for(;;){
- element=cJSON_GetArrayItem(item,i);
- if(NULL==element) break;
-
- t=cJSON_GetObjectItem(element, OBJECT_ID_NAME);
- if(NULL==t) noticePtr[i]->id=-1;
- else noticePtr[i]->id=atoi(t->valuestring);
-
- t=cJSON_GetObjectItem(element, OBJECT_TIME_NAME);
- if(NULL==t) noticePtr[i]->time[0]='\0';
- else snprintf(noticePtr[i]->time, sizeof(noticePtr[i]->time), "%s", t->valuestring);
-
- t=cJSON_GetObjectItem(element, OBJECT_TITLE_NAME);
- if(NULL==t) noticePtr[i]->title[0]='\0';
- else snprintf(noticePtr[i]->title, sizeof(noticePtr[i]->title), "%s", t->valuestring);
- i++;
- }
- notices.item=i;
- notices.noticeResult=noticePtr;
- MSG_INFO(1, "notice valid num:%d",i);
- return;
-
- R_EXIT:
- releaseJson(¬iceJson);
- releaseBuf(¬iceBuffer);
- if(fd>0) nwy_sdk_fclose(fd);
- if(noticePtr != NULL){
- for(i=0;i<num;i++) releaseBuf(¬icePtr[i]);
- releaseBuf(¬icePtr);
- }
- }
- char *noticeDetailContent=NULL;
- void noticeInfoDetailShowContent(char direction){
- #if 0
- int x=1,y=UI_CONTENT_SHOW_Y;
- char *ptr=noticeDetailContent;
- static int showlen,showIndex,len;
- if(direction==0){
- showlen=strlen(ptr);
- showIndex=0;
- }
- guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,UI_BOTTOM_SHOW_Y-2,guiGetBackColor());
- MessageEditInit(&sutMEdit, x, y+2 , ptr, FONT_MODE_16X16);
- len=MessageEditShow(&sutMEdit,ptr+showIndex);
- if(len !=0) showIndex+=len;
- else showIndex=0;
- #else
- if(direction==0) newMessageInit(FONT_MODE_16X16, noticeDetailContent, NULL, NULL);
- else if(direction==1) newMessageShow(SHOW_DOWN);
- else if(direction==2) newMessageShow(SHOW_UP);
- #endif
- }
- void cJSONTakeContent(char *msg, int len){
-
-
- releaseBuf(¬iceDetailContent);
- cJSON* nJson=NULL;
- nJson = createJson(msg);
- if(NULL==nJson){
- MSG_WARN(1, "notice detail show json null");
- goto R_EXIT;
- }
- cJSON* item = cJSON_GetObjectItem(nJson, OBJECT_CONTENT_DETAIL);
- if(NULL==item){
- MSG_ERR(1, "notice detail show json failed");
- goto R_EXIT;
- }
- int length=strlen(item->valuestring)+1;
- char *ptr=(char *)createBuf(len*sizeof(char));
- if(ptr==NULL){
- MSG_ERR(1, "notice detail show malloc err");
- goto R_EXIT;
- }
- memcpy(ptr, item->valuestring, len);
- ptr[len]=0;
- noticeDetailContent=ptr;
- R_EXIT:
- releaseJson(&nJson);
- }
- void cJSONTakeParam(char *msg, int len){
-
- bool sparamOk=false;
- bool vparamOk=false;
- cJSON* nJson=NULL;
- nJson = createJson(msg);
- if(NULL==nJson){
- MSG_WARN(1, "param detail json null");
- goto R_EXIT;
- }
- cJSON* item = cJSON_GetObjectItem(nJson, OBJECT_SPEED_PARAM);
-
- if(NULL==item) MSG_ERR(1, "param speed json failed");
- else{
- usr.scoreSpeedParam=atof(item->valuestring);
- sparamOk=true;
- }
-
- item = cJSON_GetObjectItem(nJson, OBJECT_VOLUME_PARAM);
-
- if(NULL==item) MSG_ERR(1, "param volume json failed");
- else{
- usr.scoreVolumeParam=atof(item->valuestring);
- vparamOk=true;
- }
- if(sparamOk==true && vparamOk==true){
- MSG_INFO(1, "sparam:%f, vparam:%f", usr.scoreSpeedParam, usr.scoreVolumeParam);
- usr.paramReady=true;
- }
- R_EXIT:
- releaseJson(&nJson);
- }
- void LearnUsrInfoCheck(unsigned int interval){
- static char step=0;
- static unsigned int waitTimer;
- unsigned char ret;
- if(sutPocStatus.logined==0) return;
- if(true==isUserInfoReady() && true==usr.paramReady){
- if(step!=0) step=0;
- return;
- }
- switch(step){
- case 0:
- step=1;
- learnUpdateStatus(LEARN_DB_WAIT_INFO);
- learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,false);
- uTimerStart(&waitTimer, 5000);
- break;
- case 1:
- ret=getHttpLearnStatus();
- if(uTimerExpired(&waitTimer) || ret !=1){
- MSG_INFO(1, "Wait user account:%d", ret);
- if(ret==0) step=2;
- else step=0;
- }
- break;
- case 2:
- step=3;
- learnUpdateStatus(LEARN_GET_PARAM);
- learnTaskUpdate(LEARN_GET_PARAM,NULL, NULL,false);
- uTimerStart(&waitTimer, 5000);
- break;
- case 3:
- ret=getHttpLearnStatus();
- if(uTimerExpired(&waitTimer) || ret !=1){
- MSG_INFO(1, "Wait param:%d", ret);
- if(ret==0) step=4;
- else step=2;
- }
- break;
- case 4:
- break;
- }
- }
- void uiShowLearnGroup(char type){
- static unsigned int gid=0xffffffff;
- if(false==isUserInfoReady()) return;
- if(type) goto S_NOW;
- if(gid == getLearnGid()) return;
- gid=getLearnGid();
- S_NOW:
- uiShowLearnGName(getLearnGName());
- }
- static bool sdMountStatus=false;
- void sdUnmount(void){
- sdCardCtl(false);
- sdMountStatus=false;
- }
- void sdMount(void){
- if(sdMountStatus==false){
- sdCardCtl(true);
- sdMountStatus=true;
- }
- }
- bool sdCardTest(void){
- const char *table="sdTest.txt";
- char file[50];
- int fd=NULL;
- bool ret=false;
- sdCardCtl(true);
- snprintf(file, sizeof(file), "%s/%s",SD_TOKEN,table);
- fd = nwy_sdk_fopen(file, NWY_CREAT | NWY_RDWR|NWY_TRUNC);
- if(fd<0){
- MSG_WARN(1, "fopen to write failed:%s",table);
- goto SD_END;
- }
- nwy_sdk_fwrite(fd, table, strlen(table));
- nwy_sdk_fclose(fd);
-
- fd = nwy_sdk_fopen(file, NWY_RDONLY);
- if(fd < 0){
- MSG_WARN(1, "fopen to read failed:%s",table);
- goto SD_END;
- }
- memset(file, 0, sizeof(file));
- nwy_sdk_fread(fd, file, strlen(table));
- if(0==memcmp(file, table, strlen(file))) ret=true;
- SD_END:
- if(fd != NULL) nwy_sdk_fclose(fd);
- sdCardCtl(false);
- return ret;
- }
|