learnTask.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. #include "includes.h"
  2. #define LEARN_HTTP_URL "test.rtpoc.com"
  3. #define LEARN_PORT 8000
  4. #define PAGE_SIZE 5//一页能显示多少条
  5. #define LEARN_LIST "learnLists" //任务简表总表
  6. #define LEARN_LIST_TMP "learnListsTmp" //临时任务简表总表
  7. #define LEARN_RANK "learnRank" //排名临时表,不需要删除
  8. #define LEARN_CLASS "learnClass"
  9. #define LEARN_NOTICE "learnNotice"
  10. #define LEARN_UPDATE_MAX 10 //一次性最多拉取任务个数
  11. #define SHOW_TABLE_MAX_BYTES 40
  12. #define OBJECT_LIST "list"
  13. #define OBJECT_TID "tid"
  14. #define OBJECT_VER "ver"
  15. #define OBJECT_TITLE "t"
  16. #define OBJECT_SCORE "s"
  17. #define OBJECT_CONTENT "c"
  18. #define OBJECT_FINISH "f"
  19. #define OBJECT_UID "uid"
  20. #define OBJECT_GID "gid"
  21. #define OBJECT_GNAME "groupName"
  22. #define OBJECT_NNAME "nickname"
  23. #define OBJECT_TYPE "type"
  24. #define OBJECT_TOKEN "token"
  25. #define OBJECT_CONTENT_DETAIL "content"
  26. #define OBJECT_SPEED_PARAM "scoreSpeedParam"
  27. #define OBJECT_VOLUME_PARAM "scoreVolumeParam"
  28. static void httpCallBack(char *msg, int len);
  29. typedef enum{
  30. LEARN_DB_GET_INFO,//获取用户信息
  31. LEARN_DB_WAIT_INFO,//等待用户信息
  32. LEARN_GET_LIST,//获取任务列表
  33. LEARN_WAIT_LIST,//等待列表
  34. LEARN_DB_SYNC,//同步数据
  35. LEARN_DB_SYNC_DEL,//同步本地多了的任务(删除)
  36. LEARN_DB_SYNC_ADD,//同步本地没有的任务(获取)
  37. LEARN_DB_SYNC_ADD_PAGE_WAIT,//等待页任务获取
  38. LEARN_DB_SYNC_ADD_SOME_WAIT,//等待部分任务获取
  39. LEARN_DB_SYNC_DONE,//同步完成
  40. LEARN_DB_SYNC_FAILED,//同步失败
  41. LEARN_READ_TASK_INFO,//读取任务用于显示
  42. LEARN_READ_FAILED,//用于读取任务过程出现失败或错误时退出使用
  43. LEARN_SHOW_MENU,
  44. LEARN_WAIT_RESPONSE,//按键响应
  45. LEARN_RECORD_UPLOAD,
  46. LEARN_RELEASE_DB,
  47. LEARN_END,
  48. LEARN_RANK_GET_DETAIL,
  49. LEARN_CLASS_GET_DETAIL,
  50. LEARN_NOTICE_GET_DETAIL,
  51. LEARN_NOTICE_GET_DETAIL_SHOW,
  52. LEARN_GET_PARAM,
  53. }LEARN_STATUS;
  54. static unsigned char charaNum;//单词个数
  55. static unsigned int taskID[LEARN_UPDATE_MAX];
  56. static unsigned int taskNum=0;
  57. static unsigned char learnAddNum;//添加任务时,添加的个数
  58. static LEARN_STATUS learnStatus;
  59. static unsigned short learnPage;
  60. static unsigned int learnTick;
  61. static int learnTaskNum;
  62. static int learnPageNum;
  63. static bool learnDetailEnd;
  64. unsigned char rankType;//获取的排名类型 0 月排名 其它 周排名
  65. static void pocAudioCtl(bool status){
  66. if(status==false){
  67. msgAtSend("AT+POC=0C0000\r\n");//停止POC录音
  68. msgAtSend("AT+HTTS=0\r\n");//停止TTS,防止TTS播放还未完成时,就使用学习录音了
  69. sutApp.skipTTS=1;//本地也不能再使用TTS
  70. msgAtSend("AT+POC=060000\r\n");//强制停止POC使用对讲播放
  71. nwy_sleep(50);//给点时间POC完成切换
  72. }else{//恢复
  73. sutApp.skipTTS=0;
  74. msgAtSend("AT+POC=070000\r\n");
  75. }
  76. }
  77. bool isLearnBusy(void){
  78. static bool pocIsEnable=true;
  79. if(sutUIstatus.Status==UIS_MENU_TASK_QUERY){//需要禁止POC
  80. if(true==pocIsEnable){
  81. pocIsEnable=false;
  82. pocAudioCtl(pocIsEnable);
  83. MSG_INFO(1, "Disable poc ctl");
  84. }
  85. return true;
  86. }else{//需要开启POC
  87. if(false==pocIsEnable){
  88. pocIsEnable=true;
  89. pocAudioCtl(pocIsEnable);
  90. MSG_INFO(1, "Enable poc ctl");
  91. }
  92. return false;
  93. }
  94. }
  95. static char *getLearnFileJson(const char *fname);
  96. void sdCardCtl(bool status){
  97. if(status==true){
  98. CTL_SD_PWR(1);
  99. if(true!=nwy_sdk_sdcard_mount()){
  100. MSG_ERR(1, "SD card mount failed");
  101. CTL_SD_PWR(0);
  102. }else MSG_INFO(1, "SD card mount ok");
  103. }else{
  104. nwy_sdk_sdcard_unmount();
  105. CTL_SD_PWR(0);
  106. MSG_INFO(1, "SD card unmount");
  107. }
  108. }
  109. static void learnUpdateStatus(LEARN_STATUS newStatus){
  110. learnStatus=newStatus;
  111. }
  112. static LEARN_STATUS getLearnStatus(void){
  113. return learnStatus;
  114. }
  115. void showInfoBox(const char *info,int dly){
  116. guiShowMessageBox(info);
  117. uTimerStart(&learnTick, dly);
  118. }
  119. void releaseBuf(unsigned char **pointer){
  120. if(*pointer==NULL) return;
  121. free(*pointer);
  122. MSG_INFO(1, "[mem free]%x",*pointer);
  123. *pointer=NULL;
  124. }
  125. void releaseJson(cJSON** json){
  126. if(*json==NULL) return;
  127. cJSON_Delete(*json);
  128. MSG_INFO(1, "[json del]%x",*json);
  129. *json=NULL;
  130. }
  131. void *createBuf(unsigned int size){
  132. void *buf;
  133. buf=malloc(size);
  134. if(buf != NULL) MSG_INFO(1, "[mem malloc]%x", buf);
  135. return buf;
  136. }
  137. cJSON* createJson(char *msg){
  138. cJSON* tmp;
  139. tmp=cJSON_Parse(msg);
  140. if(tmp != NULL) MSG_INFO(1, "[json add]%x", tmp);
  141. return tmp;
  142. }
  143. //从json中获取objString的Value,只用于获取key:value格式
  144. static char *learnJsonGetItem(cJSON* json, const char *objString){
  145. if(NULL==json) return NULL;
  146. cJSON* t=cJSON_GetObjectItem(json, objString);
  147. if(NULL==t) return NULL;
  148. else return t->valuestring;
  149. }
  150. //删除simpleList,simpleListTmp重命名为simpleList
  151. void learnUpdateListFile(void){
  152. char oldFile[50],newFile[50];
  153. snprintf(oldFile, sizeof(oldFile), "%s/%s",SD_TOKEN, LEARN_LIST);
  154. snprintf(newFile, sizeof(newFile), "%s/%s",SD_TOKEN, LEARN_LIST_TMP);
  155. //删除文件
  156. if(true==nwy_sdk_fexist(oldFile)) nwy_sdk_file_unlink(oldFile);
  157. //重命名文件
  158. if(true==nwy_sdk_fexist(newFile)){
  159. nwy_sdk_frename(newFile, oldFile);
  160. MSG_INFO(1, "Learn Rename file:%s->%s",LEARN_LIST_TMP,LEARN_LIST);
  161. }
  162. }
  163. void learnGetNextPage(short direction){
  164. if(direction==0) learnPage=0;
  165. else if(direction>0){
  166. if(++learnPage>=learnPageNum) learnPage=0;
  167. }else{
  168. if(learnPage==0) learnPage=learnPageNum-1;
  169. else learnPage--;
  170. }
  171. //得到page后,先检测本地是否已存有任务
  172. }
  173. /*********************从文件中获取用户信息******************************/
  174. typedef struct{
  175. bool paramReady;
  176. double scoreSpeedParam;
  177. double scoreVolumeParam;
  178. bool ready;
  179. unsigned char type;
  180. unsigned int uid;
  181. unsigned int gid;
  182. char gname[30];
  183. char nname[30];
  184. char token[20];
  185. }USER_INFO;
  186. USER_INFO usr={false,1,1,false,0xff};
  187. unsigned int getLearnUid(void){return usr.uid;}
  188. unsigned int getLearnGid(void){return usr.gid;}
  189. char *getLearnGName(void){return usr.gname;}
  190. char *getLearnToken(void){return usr.token;}
  191. double getLearnSpeedParam(void){return usr.scoreSpeedParam;}
  192. bool isUserInfoReady(void){return usr.ready;}
  193. void learnUserInfoClear(void){usr.ready=false;}
  194. /*
  195. {"uid":"5028","groupName":"测试组3","gid":"21731","nickname":"用户30","type":"1","token":"120a1a7436"}
  196. */
  197. bool cJSONProcessUinfo(char *msg){
  198. cJSON* json,*item;
  199. json=createJson(msg);
  200. memset((unsigned char *)&usr, 0, sizeof(USER_INFO));
  201. if(json==NULL){
  202. MSG_WARN(1, "cJSONProcessUinfo json null");
  203. return false;
  204. }
  205. //uid
  206. item=cJSON_GetObjectItem(json, OBJECT_UID);
  207. if(NULL!=item) usr.uid=atoi(item->valuestring);
  208. //gid
  209. item=cJSON_GetObjectItem(json, OBJECT_GID);
  210. if(NULL!=item) usr.gid=atoi(item->valuestring);
  211. //type
  212. item=cJSON_GetObjectItem(json, OBJECT_TYPE);
  213. if(NULL!=item) usr.type=atoi(item->valuestring);
  214. //groupName
  215. item=cJSON_GetObjectItem(json, OBJECT_GNAME);
  216. if(NULL!=item) snprintf(usr.gname, sizeof(usr.gname), "%s",item->valuestring);
  217. //nickname
  218. item=cJSON_GetObjectItem(json, OBJECT_NNAME);
  219. if(NULL!=item) snprintf(usr.nname, sizeof(usr.nname), "%s",item->valuestring);
  220. //token
  221. item=cJSON_GetObjectItem(json, OBJECT_TOKEN);
  222. if(NULL!=item) snprintf(usr.token, sizeof(usr.token), "%s",item->valuestring);
  223. releaseJson(&json);
  224. MSG_INFO(1, "usr:%d,%s,%d,%s,%s", usr.uid, usr.gname, usr.gid, usr.nname, usr.token);
  225. usr.ready=true;
  226. return true;
  227. }
  228. /*************************从文件中获取用户信息******************************/
  229. bool learnTaskUpdate(LEARN_STATUS type, void *para1, void *para2, bool needShow){
  230. char url[200],tmp[10];
  231. unsigned char *msg=NULL;
  232. unsigned int len=0,i;
  233. UHTTP_ENUM httpType;
  234. //触发获取任务列表操作
  235. if(sutApp.pocPpp==0 || sutPocStatus.logined==0){
  236. if(true==needShow) showInfoBox("无网络/未登录",2000);
  237. learnUpdateStatus(LEARN_END);
  238. return false;
  239. }
  240. if(type==LEARN_DB_GET_INFO){//获取用户信息
  241. httpType=UHTTP_FILE_GET;
  242. snprintf(url, sizeof(url), "%s/api/cai/UserInfo?account=%d&password=%s", LEARN_HTTP_URL, sutApp.account.psn, sutApp.account.password);
  243. MSG_INFO(1, "Learn get user info");
  244. }else if(type==LEARN_GET_LIST){//获取任务列表
  245. httpType=UHTTP_FILE_GET;
  246. snprintf(url, sizeof(url), "%s/api/cai/BriefTask?gid=%d&uid=%d&token=%s", LEARN_HTTP_URL, getLearnGid(),getLearnUid(),getLearnToken());
  247. MSG_INFO(1, "Learn get total list");
  248. }else if(type==LEARN_DB_SYNC_ADD_PAGE_WAIT){//根据页获取详细表
  249. int *page=(int *)para1;
  250. int *size=(int *)para2;
  251. httpType=UHTTP_FILE_GET;
  252. 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());
  253. MSG_INFO(1, "Learn get detail,page:%d,size:%d", *page,*size);
  254. }else if(type==LEARN_DB_SYNC_ADD_SOME_WAIT){//根据tid获取详细表
  255. unsigned int *tids=(unsigned int *)para1;
  256. unsigned char *num=(unsigned char *)para2;
  257. httpType=UHTTP_FILE_GET;
  258. snprintf(url, sizeof(url), "%s/api/cai/DetailedTask?gid=%d&uid=%d&token=%s&tids=[%d", LEARN_HTTP_URL,getLearnGid(),getLearnUid(),getLearnToken(),tids[0]);
  259. for(i=1;i<*num;i++){
  260. snprintf(tmp, sizeof(tmp),",%d", tids[i]);
  261. strcat(url, tmp);
  262. }
  263. strcat(url, "]");
  264. MSG_INFO(1, "Learn get detail,tid num:%d", *num);
  265. }else if(type==LEARN_RECORD_UPLOAD){//上传语音数据到服务器
  266. msg=(unsigned char *)para1;
  267. len=*((unsigned int *)para2);
  268. httpType=UHTTP_POST;
  269. snprintf(url, sizeof(url), "%s/api/cai/HandIn",LEARN_HTTP_URL);
  270. MSG_INFO(1, "Learn upload audio:%d bytes", len);
  271. }else if(type==LEARN_RANK_GET_DETAIL){
  272. httpType=UHTTP_FILE_GET;
  273. unsigned char *rankType=(unsigned char *)para1;
  274. snprintf(url, sizeof(url), "%s/api/cai/%slyRanking?uid=%d&gid=%d&token=%s", LEARN_HTTP_URL,(*rankType==0)?"Month":"Week" ,getLearnUid(),getLearnGid(),getLearnToken());
  275. MSG_INFO(1, "Learn get %s rank", (*rankType==0)?"month":"week");
  276. }else if(type==LEARN_CLASS_GET_DETAIL){
  277. httpType=UHTTP_FILE_GET;
  278. snprintf(url, sizeof(url), "%s/api/cai/Timetable?uid=%d&gid=%d&token=%s", LEARN_HTTP_URL, getLearnUid(), getLearnGid(), getLearnToken());
  279. MSG_INFO(1, "Learn get class detail");
  280. }else if(type==LEARN_NOTICE_GET_DETAIL){
  281. httpType=UHTTP_FILE_GET;
  282. snprintf(url, sizeof(url), "%s/api/cai/NotificationBrief?uid=%d&gid=%d&token=%s", LEARN_HTTP_URL, getLearnUid(), getLearnGid(), getLearnToken());
  283. MSG_INFO(1, "Learn get notice detail");
  284. }else if(type==LEARN_NOTICE_GET_DETAIL_SHOW){
  285. int *id=(int *)para1;
  286. httpType=UHTTP_FILE_GET;
  287. snprintf(url, sizeof(url), "%s/api/cai/NotificationContent?uid=%d&id=%d&token=%s", LEARN_HTTP_URL, getLearnUid(), *id, getLearnToken());
  288. MSG_INFO(1, "Learn get notice detail show");
  289. }else if(type==LEARN_GET_PARAM){
  290. httpType=UHTTP_FILE_GET;
  291. snprintf(url, sizeof(url), "%s/api/cai/Config?uid=%d&token=%s", LEARN_HTTP_URL, getLearnUid(), getLearnToken());
  292. MSG_INFO(1, "Learn get param");
  293. }
  294. if(true==needShow) showInfoBox("请稍候",5000);
  295. learnHttpStart(httpType,url, LEARN_PORT, httpCallBack,msg, len);
  296. return true;
  297. }
  298. static void LearnTaskProcess(void);
  299. static void sutJsonInit(void);
  300. //学习任务菜单
  301. static unsigned char needUpdate=1;//是否需要更新,我们只从主菜单进此菜单时才同步,从里面的子菜单返回不同步
  302. void uiShowLearnTask(char update){
  303. if(update){
  304. sutJsonInit();
  305. guiClearAll(guiGetBackColor());
  306. guiShowCaption(30,"学习任务",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  307. uiMenuShowBottomLine();
  308. guiShowMessageBox("请稍候");
  309. uiMenuShowBottomIndacitor("查看", "返回");
  310. sdMount();
  311. #if 1
  312. if(isUserInfoReady()==false){
  313. if(true==learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,true)) learnUpdateStatus(LEARN_DB_WAIT_INFO);
  314. }else{
  315. if(needUpdate!=0){
  316. MSG_INFO(1, "learn task need sync");
  317. if(true==learnTaskUpdate(LEARN_GET_LIST,NULL, NULL,true)) learnUpdateStatus(LEARN_WAIT_LIST);
  318. }else learnUpdateStatus(LEARN_DB_SYNC_DONE);//子菜单返回时,直接读取显示,不去同步
  319. }
  320. needUpdate=0;
  321. #else
  322. if(needUpdate!=0){
  323. MSG_INFO(1, "learn task need sync");
  324. if(true==learnTaskUpdate(LEARN_GET_LIST,NULL, NULL,true)) learnUpdateStatus(LEARN_WAIT_LIST);
  325. }else learnUpdateStatus(LEARN_DB_SYNC_DONE);//子菜单返回时,直接读取显示,不去同步
  326. #endif
  327. }
  328. LearnTaskProcess();
  329. }
  330. static void learnTaskDel(const char *delFileName);
  331. typedef struct{//用于显示的时候使用的
  332. bool initStatus;
  333. unsigned char direction;//获取任务方向 0第一次获取,1向下,2向上
  334. unsigned char lastDirection;//上一次获取方向
  335. unsigned short index;//当前正查看询的索引
  336. unsigned short selIndex;//最后读出来的项目,未经处理后的项目索引值,用于显示第几条使用
  337. unsigned char validNum;//当前页有效项目数
  338. unsigned short totalNum;//总任务数
  339. cJSON* jsonList;//用于读取简表
  340. char *bufList;//用于读取简表文件时使用的内存
  341. cJSON* jsonTask[PAGE_SIZE];//用于读取每个任务详情
  342. char *bufTask[PAGE_SIZE];//用于读取每个任务文件使用的内存
  343. char showTable[PAGE_SIZE][SHOW_TABLE_MAX_BYTES];//用于菜单显示时使用
  344. int finishedFlag[PAGE_SIZE];//完成状态
  345. }LEARN_SHOW_DEF;
  346. LEARN_SHOW_DEF sutJson={false};
  347. static void sutJsonInit(void){
  348. if(sutJson.initStatus==true) return;
  349. MSG_INFO(1, "sutJson init");
  350. memset((unsigned char *)&sutJson, 0, sizeof(LEARN_SHOW_DEF));
  351. sutJson.initStatus=true;
  352. }
  353. static unsigned char learnGetNextPageInfo(LEARN_SHOW_DEF *learn){
  354. cJSON* item, * element, * t;
  355. cJSON* tmpJson,*sele;
  356. char *tmpBuf;
  357. char file[50];
  358. int i;
  359. MSG_INFO(1, "GET PAGE INFO START");
  360. item=cJSON_GetObjectItem(learn->jsonList, OBJECT_LIST);
  361. if(NULL==item) return 1;//没有找到有元素数组
  362. int num=cJSON_GetArraySize(item);
  363. if(num<=0) return 0;//没有任务,返回时会显示"无任务"
  364. learn->totalNum=num;
  365. int index=learn->index;//这里不处理learn->index
  366. if(learn->direction==1 && learn->lastDirection==2 && num<=PAGE_SIZE){//上次是向上,现在向下
  367. index += learn->validNum;
  368. if(index>=num) index=0;
  369. }else if(learn->direction==2 && learn->lastDirection==1 && num<=PAGE_SIZE){//上次是向下,现在是向上
  370. index -= learn->validNum;
  371. if(index>0 && index<5) index=0;
  372. else if(index<=0) index=num-num%PAGE_SIZE;
  373. else index -= PAGE_SIZE;
  374. }else if(learn->direction==0){
  375. learn->direction=1;
  376. }
  377. //需要先释放上次进来时使用过的资源
  378. for(i=0;i<PAGE_SIZE;i++){
  379. releaseBuf(&learn->bufTask[learn->validNum]);
  380. releaseJson(&learn->jsonTask[learn->validNum]);
  381. }
  382. learn->validNum=0;
  383. for(;;){
  384. element=cJSON_GetArrayItem(item, index);
  385. if(NULL==element){
  386. if(index==num){//读到结尾了
  387. learn->selIndex=index-learn->validNum;
  388. learn->index=0;//重置
  389. goto P_END;
  390. }else return 2;//出错了
  391. }else{
  392. //获取tid
  393. t=cJSON_GetObjectItem(element, OBJECT_TID);
  394. if(NULL==t) goto P_CONTINUE;
  395. if(t->valuestring==NULL) goto P_CONTINUE;//没有找到值
  396. //找到TID,根据TID获取文件内容出来/*{"s":4,"c":"What is your name?","t":"学习任务1","f":1,"tid":5126*/
  397. snprintf(file, sizeof(file), "%s.task", t->valuestring);
  398. tmpBuf=getLearnFileJson(file);
  399. if(NULL==tmpBuf) goto P_CONTINUE;
  400. tmpJson=createJson(tmpBuf);
  401. if(NULL==tmpJson){
  402. releaseBuf(&tmpBuf);
  403. goto P_CONTINUE;
  404. }
  405. //获取OBJECT_FINISH
  406. sele=cJSON_GetObjectItem(tmpJson, OBJECT_FINISH);
  407. if(NULL==sele){//获取finish失败
  408. releaseBuf(&tmpBuf);
  409. releaseJson(&tmpJson);
  410. goto P_CONTINUE;
  411. }
  412. if(sele->valuestring==NULL) goto P_CONTINUE;
  413. i=atoi(sele->valuestring);
  414. if(i==0) learn->finishedFlag[learn->validNum]=0;
  415. else learn->finishedFlag[learn->validNum]=1;
  416. //获取OBJECT_TITLE
  417. sele=cJSON_GetObjectItem(tmpJson, OBJECT_TITLE);
  418. if(NULL==sele){//获取TITLE失败
  419. releaseBuf(&tmpBuf);
  420. releaseJson(&tmpJson);
  421. goto P_CONTINUE;
  422. }
  423. if(sele->valuestring==NULL) goto P_CONTINUE;
  424. //格式化TITLE到显示Buff用于显示(看一下是否要转换编码格式)
  425. snprintf(learn->showTable[learn->validNum], SHOW_TABLE_MAX_BYTES, "%s", sele->valuestring);
  426. learn->jsonTask[learn->validNum]=tmpJson;
  427. learn->bufTask[learn->validNum]=tmpBuf;
  428. if(++learn->validNum>=PAGE_SIZE){
  429. //获取够了,暂时不需要去释放资源,因为如果按确定查看内容时,还需要读取任务详细内容
  430. index++;
  431. learn->selIndex=index-learn->validNum;
  432. if(index>=num) index=0;
  433. learn->index=index;
  434. goto P_END;
  435. }
  436. }
  437. P_CONTINUE:
  438. index++;
  439. }
  440. P_END:
  441. learn->lastDirection=learn->direction;
  442. return 0;
  443. }
  444. static void learnUIShowIndexAndTotal(void){
  445. char info[20];
  446. int i,total,index;
  447. total=sutJson.totalNum;
  448. index=sutJson.selIndex+sutListBox.handle+1;
  449. snprintf(info, sizeof(info), "%d/%d", index, total);
  450. i=guiGetStrXLen(info,FONT_MODE_12X12);
  451. guiClearRect(GLCD_WIDTH-8*8, UI_STATUS_ITEM_Y, GLCD_WIDTH-1, UI_STATUS_ITEM_Y+UI_STATUS_ITEM_HEIGH-1, guiGetForeColor());
  452. guiShowStr(GLCD_WIDTH-i, UI_STATUS_ITEM_Y+1, info, FONT_MODE_12X12, REVERSED_NO, guiGetBackColor(), guiGetForeColor());
  453. }
  454. void LearnTaskSelResponse(void){
  455. unsigned short key;
  456. if(LEARN_WAIT_RESPONSE==getLearnStatus()){
  457. key=getKeyValue();
  458. if(sutJson.validNum!=0){
  459. if(sutListBox.handle==0 && MKEY_VALUE_UP==key){
  460. sutJson.direction=2;
  461. learnUpdateStatus(LEARN_READ_TASK_INFO);
  462. }else if(((sutListBox.handle+1) == sutListBox.itemnum) && MKEY_VALUE_DOWN==key){
  463. sutJson.direction=1;
  464. learnUpdateStatus(LEARN_READ_TASK_INFO);
  465. }
  466. key=ListBoxResponse(&sutListBox);
  467. if(MKEY_VALUE_ESC==key) learnUpdateStatus(LEARN_RELEASE_DB);
  468. else if(MKEY_VALUE_MENU==key){
  469. uiPushStack(sutListBox.handle);
  470. uISetNextStatus(UIS_MENU_TASK_QUERY);
  471. //里面的菜单如果不返回本菜单,直接退出此任务操作,需要释放资源LEARN_RELEASE_DB
  472. }else if(MKEY_VALUE_UP || MKEY_VALUE_DOWN){
  473. learnUIShowIndexAndTotal();
  474. }
  475. }else if(MKEY_VALUE_ESC==key) learnUpdateStatus(LEARN_RELEASE_DB);
  476. }
  477. }
  478. static void LearnTaskProcess(void){
  479. unsigned char ret;
  480. static char *simpleList=NULL;
  481. static char *simpleListTmp=NULL;
  482. static cJSON* json=NULL,*item;
  483. cJSON* element,*subEle;
  484. static cJSON* jsonTmp=NULL,*itemTmp;
  485. cJSON* elementTmp,*subEleTmp;
  486. static int index;
  487. char tid[10],ver[10];
  488. static bool updateAll;
  489. int i,j,page,size;
  490. cJSON* readJson=NULL;
  491. static char *readBuf=NULL;
  492. static unsigned int tidTable[LEARN_UPDATE_MAX];
  493. static const char *learnIcon[]={
  494. "TASK1.bmp",
  495. "TASK2.bmp",
  496. ""
  497. };
  498. static char *menuTable[PAGE_SIZE+1];
  499. switch(getLearnStatus()){
  500. case LEARN_DB_WAIT_INFO:
  501. ret=getHttpLearnStatus();
  502. if(uTimerExpired(&learnTick) || ret!=1){
  503. MSG_INFO(1, "LEARN_DB_WAIT_INFO:%d",ret);
  504. switch(ret){
  505. case 0://获取用户信息成功,获取简表信息
  506. if(true==learnTaskUpdate(LEARN_GET_LIST,NULL, NULL,true)) learnUpdateStatus(LEARN_WAIT_LIST);
  507. else{
  508. showInfoBox("更新失败",2000);
  509. learnUpdateStatus(LEARN_END);
  510. }
  511. break;
  512. case 2://列表获取失败
  513. showInfoBox("更新失败",2000);
  514. learnUpdateStatus(LEARN_END);
  515. break;
  516. default://获取超时
  517. hearnHttpOverTime();
  518. showInfoBox("更新超时",2000);
  519. learnUpdateStatus(LEARN_END);
  520. break;
  521. }
  522. }
  523. break;
  524. case LEARN_WAIT_LIST:
  525. ret=getHttpLearnStatus();
  526. if(uTimerExpired(&learnTick) || ret!=1){
  527. MSG_INFO(1, "LEARN_WAIT_LIST:%d",ret);
  528. switch(ret){
  529. case 0://获取列表成功,同步数据
  530. learnUpdateStatus(LEARN_DB_SYNC);
  531. break;
  532. case 2://列表获取失败
  533. showInfoBox("更新失败",2000);
  534. learnUpdateStatus(LEARN_END);
  535. break;
  536. default://获取超时
  537. hearnHttpOverTime();
  538. showInfoBox("更新超时",2000);
  539. learnUpdateStatus(LEARN_END);
  540. break;
  541. }
  542. }
  543. break;
  544. case LEARN_DB_SYNC://根据LEARN_LIST表同步数据
  545. //读取LEARN_LIST_TMP数据用于同步
  546. simpleListTmp=getLearnFileJson(LEARN_LIST_TMP);
  547. if(NULL==simpleListTmp){
  548. learnUpdateStatus(LEARN_DB_SYNC_FAILED);
  549. break;
  550. }
  551. //加载到CJSON
  552. jsonTmp=createJson(simpleListTmp);
  553. if(NULL==jsonTmp){
  554. learnUpdateStatus(LEARN_DB_SYNC_FAILED);
  555. break;
  556. }
  557. itemTmp=cJSON_GetObjectItem(jsonTmp, OBJECT_LIST);
  558. if(NULL==itemTmp){
  559. learnUpdateStatus(LEARN_DB_SYNC_FAILED);
  560. break;
  561. }
  562. index=0;
  563. learnUpdateStatus(LEARN_DB_SYNC_ADD);//获取新任务
  564. //再检测LEARN_LIST
  565. simpleList=getLearnFileJson(LEARN_LIST);
  566. if(NULL==simpleList){//读取失败,则直接认为没有主简表,则直接全部更新
  567. updateAll=true;//全部拉取更新
  568. break;
  569. }
  570. //加载到CJSON
  571. json=createJson(simpleList);
  572. if(NULL==json){//加载失败,全部更新
  573. updateAll=true;//全部拉取更新
  574. break;
  575. }
  576. item=cJSON_GetObjectItem(json, OBJECT_LIST);
  577. if(NULL==item){//无OBJECT_LIST项目,全部更新
  578. updateAll=true;//全部拉取更新
  579. break;
  580. }
  581. MSG_INFO(1, "LEARN_DB_SYNC_DEL");
  582. learnUpdateStatus(LEARN_DB_SYNC_DEL);
  583. updateAll=false;
  584. //开始同步(先同步任务文件,最后更新任务简表总表)
  585. break;
  586. case LEARN_DB_SYNC_DEL://先删除多余的任务
  587. //读取主简表中有,但临时简表中没有的任务,然后删除之
  588. i=0;
  589. MSG_INFO(1, "LEARN_DB_SYNC_DEL Start");
  590. for(;;){
  591. element=cJSON_GetArrayItem(item, i);
  592. if(element!=NULL){
  593. subEle=cJSON_GetObjectItem(element, OBJECT_TID);
  594. if(subEle!=NULL){//找到了一个任务,检测在TMP任务中是否存在
  595. if(subEle->valuestring==NULL) goto C_NEXT;//tid值为空,忽视此项
  596. j=0;
  597. for(;;){
  598. elementTmp=cJSON_GetArrayItem(itemTmp, j);
  599. if(elementTmp!=NULL){
  600. subEleTmp=cJSON_GetObjectItem(elementTmp, OBJECT_TID);
  601. if(subEleTmp!=NULL){//比对
  602. if(subEleTmp->valuestring==NULL) break;//tid值为空,忽视此项,认为不存在
  603. if(0==strcmp(subEleTmp->valuestring, subEle->valuestring)) goto C_NEXT;//存在,不处理
  604. }
  605. }else break;//检查完了
  606. j++;
  607. }
  608. //在新(临时)任务简表总表中未找到此任务,即为多余任务,需要删除掉
  609. learnTaskDel(subEle->valuestring);
  610. }
  611. }else break;//检测完了
  612. C_NEXT:
  613. i++;
  614. }
  615. if(updateAll==true){//全部更新,就不需要再使用simpleList,simpleListTmp,json,jsonTmp
  616. releaseBuf(&simpleList);
  617. releaseBuf(&simpleListTmp);
  618. releaseJson(&json);
  619. releaseJson(&jsonTmp);
  620. MSG_INFO(1, "Free resorce");
  621. }else{/*不是全部更新时还是需要*/}
  622. MSG_INFO(1, "LEARN_DB_SYNC_DEL end");
  623. learnUpdateStatus(LEARN_DB_SYNC_ADD);//添加新任务了
  624. break;
  625. case LEARN_DB_SYNC_ADD:
  626. if(true==updateAll){//全部更新,同一次获取多个
  627. page=index/LEARN_UPDATE_MAX;
  628. size=LEARN_UPDATE_MAX;
  629. learnAddNum=0;
  630. learnUpdateStatus(LEARN_DB_SYNC_ADD_PAGE_WAIT);
  631. learnDetailEnd=false;//检测是否下载完毕使用
  632. learnTaskUpdate(LEARN_DB_SYNC_ADD_PAGE_WAIT,(void *)&page, (void *)&size,true);
  633. uTimerStart(&learnTick, 2000);
  634. }else{//根据两个简表,添加回LEARN_LIST中没有,但LEARN_LIST_TMP中有的任务
  635. for(i=0;i<LEARN_UPDATE_MAX;i++) tidTable[i]=0;
  636. learnAddNum=0;
  637. for(;;){
  638. elementTmp=cJSON_GetArrayItem(itemTmp, index++);
  639. if(NULL==elementTmp){//同步完了
  640. break;
  641. }
  642. subEleTmp=cJSON_GetObjectItem(elementTmp, OBJECT_TID);
  643. if(NULL==subEleTmp){//没有找到TID,忽视之
  644. continue;
  645. }
  646. if(subEleTmp->valuestring==NULL) continue;//tid值为空,忽视此项
  647. //找到任务ID subEleTmp->valuestring,遍历LEARN_LIST中是否不存在,是则需要获取
  648. int w=0;
  649. bool taskExist=false;
  650. for(;;){
  651. element=cJSON_GetArrayItem(item,w++);
  652. if(NULL==element) break;//遍历完了
  653. subEle=cJSON_GetObjectItem(element, OBJECT_TID);
  654. if(NULL==subEle) continue;
  655. if(subEle->valuestring==NULL) continue;//tid值为空,忽视此项
  656. if(strcmp(subEle->valuestring, subEleTmp->valuestring)==0){//任务存在
  657. //对比OBJECT_VER是否一样
  658. cJSON* tver, *tverTmp;
  659. tver=cJSON_GetObjectItem(element, OBJECT_VER);
  660. tverTmp=cJSON_GetObjectItem(elementTmp, OBJECT_VER);
  661. if(tver==NULL || tverTmp==NULL) break;//有找不到OBJECT_VER字段的,认为需要得新获取处理
  662. if(strcmp(tver->valuestring, tverTmp->valuestring)!=0) break;//OBJECT_VER变化了,需要获取处理
  663. taskExist=true;
  664. break;
  665. }
  666. }
  667. if(taskExist==false){//任务不存在添加到列表
  668. tidTable[learnAddNum++]=atoi(subEleTmp->valuestring);
  669. if(learnAddNum>=LEARN_UPDATE_MAX) break;//列表满了,需要先获取
  670. }
  671. }
  672. if(learnAddNum==0){//同步完成
  673. MSG_INFO(1, "LEARN_DB_SYNC_ADD_SOME_WAIT done");
  674. releaseBuf(&simpleList);
  675. releaseBuf(&simpleListTmp);
  676. releaseJson(&json);
  677. releaseJson(&jsonTmp);
  678. learnUpdateListFile();
  679. learnUpdateStatus(LEARN_DB_SYNC_DONE);
  680. break;
  681. }
  682. //发起新的文件获取(根据任务ID获取)
  683. //文件ID表在tidTable中,个数为learnAddNum个
  684. learnUpdateStatus(LEARN_DB_SYNC_ADD_SOME_WAIT);
  685. learnTaskUpdate(LEARN_DB_SYNC_ADD_SOME_WAIT,(void *)tidTable, (void *)&learnAddNum,true);
  686. MSG_ERR(1, "update tids:%d", learnAddNum);
  687. }
  688. break;
  689. case LEARN_DB_SYNC_ADD_PAGE_WAIT:
  690. case LEARN_DB_SYNC_ADD_SOME_WAIT:
  691. ret=getHttpLearnStatus();
  692. if(uTimerExpired(&learnTick) || ret!=1){
  693. MSG_INFO(1, "LEARN_DB_SYNC_ADD_PAGE/SOME_WAIT:%d,%d",getLearnStatus(),ret);
  694. switch(ret){
  695. case 0://获取任务详表成功
  696. if(getLearnStatus()==LEARN_DB_SYNC_ADD_PAGE_WAIT){
  697. if(learnDetailEnd==false){
  698. index += learnAddNum;
  699. learnUpdateStatus(LEARN_DB_SYNC_ADD);
  700. }else{//同步完成了
  701. releaseBuf(&simpleList);
  702. releaseBuf(&simpleListTmp);
  703. releaseJson(&json);
  704. releaseJson(&jsonTmp);
  705. //删除simpleList,simpleListTmp重命名为simpleList
  706. learnUpdateListFile();
  707. learnUpdateStatus(LEARN_DB_SYNC_DONE);
  708. }
  709. }else learnUpdateStatus(LEARN_DB_SYNC_ADD);//继续
  710. break;
  711. case 2://失败
  712. learnUpdateStatus(LEARN_DB_SYNC_FAILED);
  713. break;
  714. default://获取超时
  715. hearnHttpOverTime();
  716. learnUpdateStatus(LEARN_DB_SYNC_FAILED);
  717. break;
  718. }
  719. }
  720. break;
  721. case LEARN_DB_SYNC_DONE://同步完成,可以读取用于显示
  722. MSG_INFO(1, "LEARN_DB_SYNC_DONE");
  723. //释放
  724. releaseJson(&json);
  725. releaseJson(&jsonTmp);
  726. releaseBuf(&sutJson.bufList);
  727. releaseJson(&sutJson.jsonList);
  728. for(i=0;i<PAGE_SIZE;i++){
  729. releaseBuf(&sutJson.bufTask[i]);
  730. releaseJson(&sutJson.jsonTask[i]);
  731. }
  732. sutJson.direction=0;
  733. sutJson.lastDirection=0;
  734. sutJson.index=0;
  735. //先读取简表,得到任务ID列表,随着菜单选择,每次最多最取PAGE_SIZE个任务出来显示
  736. sutJson.bufList=getLearnFileJson(LEARN_LIST);
  737. if(NULL==sutJson.bufList){
  738. learnUpdateStatus(LEARN_READ_FAILED);
  739. break;
  740. }
  741. sutJson.jsonList=createJson(sutJson.bufList);
  742. if(NULL==sutJson.jsonList){
  743. learnUpdateStatus(LEARN_READ_FAILED);
  744. break;
  745. }
  746. learnUpdateStatus(LEARN_READ_TASK_INFO);
  747. break;
  748. case LEARN_READ_FAILED:
  749. showInfoBox("数据读取失败",2000);
  750. releaseBuf(&sutJson.bufList);
  751. releaseJson(&sutJson.jsonList);
  752. for(i=0;i<PAGE_SIZE;i++){
  753. releaseBuf(&sutJson.bufTask[i]);
  754. releaseJson(&sutJson.jsonTask[i]);
  755. }
  756. learnUpdateStatus(LEARN_END);
  757. break;
  758. case LEARN_DB_SYNC_FAILED:
  759. releaseBuf(&simpleList);
  760. releaseBuf(&simpleListTmp);
  761. releaseJson(&json);
  762. releaseJson(&jsonTmp);
  763. showInfoBox("数据同步失败",2000);
  764. learnUpdateStatus(LEARN_END);
  765. break;
  766. case LEARN_READ_TASK_INFO://根据方向,获取下/上page项目
  767. sutJson.validNum=0;
  768. ret=learnGetNextPageInfo(&sutJson);
  769. MSG_INFO(1, "learnGetNextPageInfo:%d", ret);
  770. if(ret!=0) learnUpdateStatus(LEARN_READ_FAILED);
  771. else learnUpdateStatus(LEARN_SHOW_MENU);
  772. break;
  773. case LEARN_SHOW_MENU://显示
  774. guiClearRect(0,(GLCD_HEIGHT/2)-20,GLCD_WIDTH-1,(GLCD_HEIGHT/2)+20,guiGetBackColor());//清除消息框
  775. if(sutJson.validNum==0){
  776. guiShowMessageBox("无数据");
  777. }else{
  778. for(i=0;i<sutJson.validNum;i++) menuTable[i]=&sutJson.showTable[i];
  779. sutJson.showTable[sutJson.validNum][0]=0;
  780. menuTable[sutJson.validNum]=learnIcon[2];
  781. ListBoxInit(&sutListBox, menuTable,0,learnIcon, sutJson.finishedFlag);
  782. learnUIShowIndexAndTotal();
  783. }
  784. learnUpdateStatus(LEARN_WAIT_RESPONSE);
  785. break;
  786. case LEARN_WAIT_RESPONSE:
  787. break;
  788. case LEARN_RELEASE_DB:
  789. MSG_INFO(1, "Release DB");
  790. releaseBuf(&simpleList);
  791. releaseBuf(&simpleListTmp);
  792. releaseBuf(&sutJson.bufList);
  793. releaseJson(&sutJson.jsonList);
  794. for(i=0;i<PAGE_SIZE;i++){
  795. releaseBuf(&sutJson.bufTask[i]);
  796. releaseJson(&sutJson.jsonTask[i]);
  797. }
  798. sdUnmount();
  799. uISetNextStatus(UIS_MENU_MAIN);
  800. needUpdate=1;
  801. break;
  802. case LEARN_END:
  803. if(uTimerExpired(&learnTick)){
  804. sdUnmount();
  805. uISetNextStatus(UIS_MENU_MAIN);
  806. needUpdate=1;
  807. }
  808. break;
  809. }
  810. }
  811. ////////////////////////http 获取文件数据处理///////////////////////
  812. //#define USE_TEST_TASK //使用自己定义的任务
  813. static void cJSONSaveTaskFile(const char *jsonMsg);
  814. static void learnSaveTaskFile(const char *fname, const char *msg);
  815. //使用cJSON格式保存成文件
  816. void cJSONSaveFile(const char *fname, char *msg, int len){
  817. //保存到SD卡中
  818. char file[50];
  819. snprintf(file, sizeof(file), "%s/%s",SD_TOKEN, fname);
  820. int fd = nwy_sdk_fopen(file, NWY_CREAT | NWY_RDWR|NWY_TRUNC);//清0式
  821. if(fd<0){
  822. MSG_WARN(1, "fopen failed,%s", fname);
  823. return;
  824. }
  825. #ifdef USE_TEST_TASK
  826. 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\"}]}";
  827. nwy_sdk_fwrite(fd, testmsg, strlen(testmsg));
  828. #else
  829. nwy_sdk_fwrite(fd, msg, len);
  830. #endif
  831. nwy_sdk_fclose(fd);
  832. MSG_INFO(1, "%s save done:%d", fname, len);
  833. }
  834. static void getRankShowMessage(unsigned char ranktype);
  835. static void httpCallBack(char *msg, int len){
  836. //将长为len的UTF8数据msg转换成GBK
  837. int outLen;
  838. unsigned char ret;
  839. MSG_INFO(1, "httpCallBack UTF8:%d", len);
  840. if(0!=Utf8ToGbkOrUnicode(msg, len, msg, &outLen,0)){
  841. MSG_ERR(1, "UTF8 to GBK failed");
  842. }
  843. ret=getLearnStatus();
  844. MSG_INFO(1, "httpCallBack GBK:%d,%d", outLen,ret);
  845. msg[outLen]=0;
  846. if(ret==LEARN_DB_WAIT_INFO){//获取到了用户信息
  847. //解析一下
  848. cJSONProcessUinfo(msg);
  849. }else if(ret==LEARN_WAIT_LIST){//获取到了列表简表
  850. //保存成功为文件,文件名为临时总表LEARN_LIST_TMP
  851. cJSONSaveFile(LEARN_LIST_TMP, msg,outLen);
  852. }else if(ret==LEARN_DB_SYNC_ADD_PAGE_WAIT || ret==LEARN_DB_SYNC_ADD_SOME_WAIT){//获取到了任务详表
  853. //每个任务保存成一个.task文件
  854. cJSONSaveTaskFile(msg);
  855. }else if(ret==LEARN_RANK_GET_DETAIL){
  856. cJSONSaveFile(LEARN_RANK, msg,outLen);
  857. }else if(ret==LEARN_CLASS_GET_DETAIL){
  858. cJSONSaveFile(LEARN_CLASS, msg, outLen);
  859. }else if(ret==LEARN_NOTICE_GET_DETAIL){
  860. cJSONSaveFile(LEARN_NOTICE, msg, outLen);
  861. }else if(ret==LEARN_NOTICE_GET_DETAIL_SHOW){
  862. cJSONTakeContent(msg, outLen);
  863. }else if(ret==LEARN_GET_PARAM){
  864. cJSONTakeParam(msg, outLen);
  865. }
  866. MSG_INFO(1, "httpCallBack end");
  867. }
  868. //读取指令文件内容到缓存中(注意释放内存)
  869. static char *getLearnFileJson(const char *fname){
  870. char *buf=NULL,file[50];
  871. int fd;
  872. //只读方式打开文件
  873. snprintf(file, sizeof(file), "%s/%s",SD_TOKEN, fname);
  874. fd=nwy_sdk_fopen(file, NWY_RDONLY);
  875. if(fd<0) goto L_END;
  876. //获取文件大小
  877. long size=nwy_sdk_fsize_fd(fd);
  878. if(size<=0) goto L_END;
  879. //分配内存空间
  880. buf=(char *)createBuf(size);
  881. //buf=(char *)malloc(size);
  882. if(NULL==buf) goto L_END;
  883. nwy_sdk_fread(fd, buf, size);
  884. L_END:
  885. if(fd>0) nwy_sdk_fclose(fd);
  886. return buf;
  887. }
  888. //delFileName:任务ID
  889. //删除以delFileName为名字的.task .rec文件
  890. static void learnTaskDel(const char *delFileName){
  891. char file[50];
  892. //删除.task文件
  893. snprintf(file, sizeof(file), "%s/%s.task", SD_TOKEN, delFileName);
  894. if(true==nwy_sdk_fexist(file)){
  895. nwy_sdk_file_unlink(file);
  896. MSG_INFO(1, "Del %s.task", delFileName);
  897. }
  898. //删除.rec文件
  899. snprintf(file, sizeof(file), "%s/%s.rec", SD_TOKEN, delFileName);
  900. if(true==nwy_sdk_fexist(file)){
  901. nwy_sdk_file_unlink(file);
  902. MSG_INFO(1, "Del %s.rec", delFileName);
  903. }
  904. MSG_INFO(1, "Del tid %s end", delFileName);
  905. }
  906. void printfJsonValue(cJSON* json){
  907. if(NULL==json) return;
  908. char *buf=cJSON_Print(json);
  909. if(NULL==buf) return;
  910. MSG_INFO(1, "json:%s",buf);
  911. free(buf);
  912. }
  913. //解析JSON得到tid作为文件名,同时将任务JCSON保存起来
  914. static void cJSONSaveTaskFile(const char *jsonMsg){
  915. int i,fd;
  916. cJSON* json,*item,*element,*t;
  917. char *buf;
  918. #ifdef USE_TEST_TASK
  919. static char nextFlag=0;
  920. 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\"}, \
  921. {\"s\":\"3\",\"c\":\"Where are you?\",\"t\":\"学习任务2\",\"f\":\"1\",\"tid\":\"5127\"}, \
  922. {\"s\":\"5\",\"c\":\"How do you do!\",\"t\":\"学习任务3\",\"f\":\"1\",\"tid\":\"8867\"}, \
  923. {\"s\":\"3\",\"c\":\"Good morning!\",\"t\":\"学习任务4\",\"f\":\"1\",\"tid\":\"8868\"}, \
  924. {\"s\":\"0\",\"c\":\"How old are you?\",\"t\":\"学习任务5\",\"f\":\"0\",\"tid\":\"1221\"}, \
  925. {\"s\":\"0\",\"c\":\"I am come from Shenzhen, China\",\"t\":\"学习任务6\",\"f\":\"0\",\"tid\":\"2546\"} \
  926. ]}";
  927. const *testBuf2="{\"uid\":\"12348\",\"list\":[]}";
  928. char *ptr;
  929. if(nextFlag==0){
  930. ptr=testBuf1;
  931. nextFlag=1;
  932. }else if(nextFlag==1){
  933. ptr=testBuf2;
  934. nextFlag=0;
  935. }
  936. json=createJson(ptr);
  937. #else
  938. json=createJson(jsonMsg);
  939. #endif
  940. if(json==NULL){
  941. MSG_WARN(1, "cJSONSaveTaskFile json null");
  942. return;
  943. }
  944. item=cJSON_GetObjectItem(json, OBJECT_LIST);
  945. if(NULL==item){
  946. MSG_WARN(1, "cJSONSaveTaskFile item null");
  947. goto S_END;
  948. }
  949. //获取OBJECT_LIST元素个数
  950. int num=cJSON_GetArraySize(item);
  951. MSG_INFO(1, "Num:%d", num);
  952. if(0==num){//获取完成了
  953. learnDetailEnd=true;
  954. MSG_INFO(1, "cJSONSaveTaskFile done");
  955. }else{
  956. //解析每个任务的任务ID
  957. i=0;
  958. for(;;){
  959. element=cJSON_GetArrayItem(item, i);
  960. if(NULL==element){
  961. MSG_INFO(1, "json array end");
  962. break;
  963. }
  964. t=cJSON_GetObjectItem(element, OBJECT_TID);
  965. if(NULL != t){
  966. //得到一个任务ID,内容为cJSON_Print(element),保存起来
  967. buf=cJSON_Print(element);
  968. if(NULL==buf){
  969. MSG_ERR(1, "cJSONSaveTaskFile cJSON_Print null");
  970. break;
  971. }
  972. learnSaveTaskFile(t->valuestring, buf);
  973. releaseBuf(&buf);
  974. //MSG_INFO(1, "[mem free]%x",buf);
  975. //free(buf);
  976. learnAddNum++;//已添加一个文件(任务)
  977. MSG_INFO(1, "Save one task:%s.task", t->valuestring);
  978. }else MSG_WARN(1, "No find tid");
  979. i++;
  980. }
  981. }
  982. S_END:
  983. releaseJson(&json);
  984. //cJSON_Delete(json);
  985. }
  986. static void learnSaveTaskFile(const char *fname, const char *msg){
  987. int fd;
  988. char file[50];
  989. if(fname==NULL) return;
  990. snprintf(file, sizeof(file), "%s/%s.task", SD_TOKEN, fname);
  991. fd = nwy_sdk_fopen(file, NWY_CREAT | NWY_RDWR|NWY_TRUNC);//清0式
  992. if(fd<0){
  993. MSG_WARN(1, "learnSaveTaskFile fopen failed,%s", fname);
  994. return;
  995. }
  996. nwy_sdk_fwrite(fd, msg, strlen(msg));
  997. nwy_sdk_fclose(fd);
  998. MSG_INFO(1, "Save task %s", fname);
  999. }
  1000. bool showFirstFlag;
  1001. unsigned char haveNextPage;
  1002. unsigned char taskIndex;
  1003. unsigned short showIndex;//内容显示的索引
  1004. char tidString[20];//保存正在查看的任务的tid串
  1005. char *learnGetTid(void){return tidString;}
  1006. /*
  1007. 统计有多少个单词
  1008. 原理:单词间用标点(, .)或空格分开
  1009. */
  1010. static void calWordNum(char *msg){
  1011. int i,len=strlen(msg);
  1012. unsigned char num=0;
  1013. unsigned char lashChara=0;
  1014. MSG_INFO(1, "content:%s",msg);
  1015. for(i=0;i<len;i++){
  1016. if(msg[i]==',' || msg[i]=='.' || msg[i]==' ' || msg[i]=='?' || msg[i]=='!'){
  1017. if(lashChara!=0){//记录为一个单词出现
  1018. num++;
  1019. lashChara=0;
  1020. }
  1021. }else if(lashChara==0) lashChara=msg[i];//有单词出现
  1022. }
  1023. if(lashChara!=0) num++;//没有标点结尾时
  1024. charaNum=num;
  1025. MSG_INFO(1, "Chara Num:%d", num);
  1026. }
  1027. void readTaskAndShow(void){
  1028. char info[50];
  1029. int y=UI_LOGIN_SHOW_Y;
  1030. static cJSON* eleScore ,* eleContent;
  1031. unsigned short len;
  1032. char *ptr;
  1033. guiClearRect(0,y, GLCD_WIDTH-1, UI_BOTTOM_LINE_Y-1, guiGetBackColor());
  1034. if(showFirstFlag==true){
  1035. showFirstFlag=false;
  1036. showIndex=0;
  1037. //读取当前任务的uid保存起来先
  1038. tidString[0]=0;
  1039. eleScore=cJSON_GetObjectItem(sutJson.jsonTask[taskIndex], OBJECT_TID);
  1040. if(NULL != eleScore) snprintf(tidString, sizeof(tidString), "%s", eleScore->valuestring);
  1041. eleScore=cJSON_GetObjectItem(sutJson.jsonTask[taskIndex], OBJECT_SCORE);
  1042. eleContent=cJSON_GetObjectItem(sutJson.jsonTask[taskIndex], OBJECT_CONTENT);
  1043. }
  1044. if(showIndex==0){
  1045. //显示分数
  1046. if(NULL==eleScore){//没有找到分数字段,显示'--'
  1047. snprintf(info, sizeof(info), "分数:--");
  1048. }else if(eleScore->valuestring==NULL){
  1049. snprintf(info, sizeof(info), "分数:--");
  1050. }else snprintf(info, sizeof(info), "分数:%s", eleScore->valuestring);
  1051. guiShowStr(1, y+1, info, FONT_MODE_16X16,REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1052. y += 18;
  1053. }
  1054. //显示内容
  1055. if(NULL==eleContent) return;
  1056. if(eleContent->valuestring==NULL) return;
  1057. //计算单词个数
  1058. calWordNum(eleContent->valuestring);
  1059. ptr=eleContent->valuestring;
  1060. MessageEditInit(&sutMEdit, 1, y , ptr, FONT_MODE_16X16);
  1061. len=MessageEditShow(&sutMEdit,ptr+showIndex);
  1062. if(len !=0) showIndex+=len;
  1063. else showIndex=0;
  1064. }
  1065. unsigned char recoderVolume=0;
  1066. LEARN_REC_STATUS learnRecordStatus;
  1067. void learnRecSetStatus(LEARN_REC_STATUS newStatus){
  1068. learnRecordStatus=newStatus;
  1069. }
  1070. void learnRecSetVol(unsigned char newVol){
  1071. recoderVolume=newVol;
  1072. }
  1073. static void learnShowResult(void);
  1074. static void learnShowStartScreen(void){
  1075. const char *repeatListen="[PTT]录音";
  1076. if(usr.type==1) uiMenuShowBottomIndacitor("[OK]重听", repeatListen);
  1077. else uiMenuShowBottomIndacitor(NULL, repeatListen);
  1078. }
  1079. /*播放录音中止/完成后,返回原定界面及操作*/
  1080. void learnRetrunStatus(void){
  1081. if(0==learnGetAudioType()){//返回原定界面及操作
  1082. learnRecSetStatus(LEARN_REC_DONE);
  1083. uiMenuShowBottomIndacitor("[OK]播放","[F1]提交");//选择提交还是播放
  1084. learnShowResult();
  1085. }else{//返回原定界面及操作
  1086. learnRecSetStatus(LEARN_REC_IDLE);
  1087. learnShowStartScreen();
  1088. }
  1089. }
  1090. static void learnRecordDoneProcess(void);
  1091. static void learnDetailBackToTaskListMenu(void){
  1092. uISetNextStatus(UIS_MENU_TASK_SEL);//返回上层菜单
  1093. }
  1094. /*任务查看*/
  1095. void uiShowLearnTaskDetail(char update){
  1096. unsigned char ret;
  1097. if(update){
  1098. guiClearAll(guiGetBackColor());
  1099. guiShowCaption(0,"任务详情",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  1100. uiMenuShowBottomLine();
  1101. showFirstFlag=true;
  1102. taskIndex=sutListBox.handle;
  1103. learnRecSetStatus(LEARN_REC_IDLE);
  1104. readTaskAndShow();
  1105. learnShowStartScreen();
  1106. learnTick=0;
  1107. }
  1108. switch(learnRecordStatus){
  1109. case LEARN_REC_BUSY://动态显示正在录音效果
  1110. learnRecordVolShow(recoderVolume);
  1111. break;
  1112. if(uTimerExpired(&learnTick)){
  1113. uTimerStart(&learnTick, 500);
  1114. learnRecordVolShow(recoderVolume);
  1115. }
  1116. break;
  1117. case LEARN_REC_OT://录音已超过最大时间,停止录音
  1118. learnRecordDoneProcess();
  1119. #ifdef SAVE_PCM_SD
  1120. pcmFileClose();
  1121. #endif
  1122. break;
  1123. case LEARN_REC_PLY://正在播放
  1124. switch(learnPlyGetResult()){
  1125. case LEARN_PLY_PRE_ERR://播放失败
  1126. guiShowMessageBox("播放失败");
  1127. nwy_sleep(1500);
  1128. learnDetailBackToTaskListMenu();
  1129. break;
  1130. case LEARN_PLY_FAILED://播放异常
  1131. guiShowMessageBox("播放异常");//返回上层菜单
  1132. nwy_sleep(1500);
  1133. learnDetailBackToTaskListMenu();
  1134. break;
  1135. case LEARN_PLY_DONE://播放成功,结束
  1136. learnRetrunStatus();
  1137. break;
  1138. }
  1139. break;
  1140. case LEARN_RECORD_UPLOAD://等待上传结果
  1141. ret=getHttpLearnStatus();
  1142. if(uTimerExpired(&learnTick) || ret!=1){
  1143. MSG_INFO(1, "LEARN_RECORD_UPLOAD:%d",ret);
  1144. switch(ret){
  1145. case 0://上传完成
  1146. guiShowMessageBox("上传完成");
  1147. recordSaveTmpToLocal(tidString);
  1148. break;
  1149. case 2://上传失败
  1150. guiShowMessageBox("上传失败");
  1151. break;
  1152. default://上传超时
  1153. hearnHttpOverTime();
  1154. guiShowMessageBox("上传超时");
  1155. break;
  1156. }
  1157. nwy_sleep(1500);
  1158. //返回任务详情内容页面,录音临时信息及资源回收
  1159. learnRecordBufRelease();
  1160. learnShowStartScreen();
  1161. readTaskAndShow();
  1162. learnRecSetStatus(LEARN_REC_IDLE);
  1163. }
  1164. break;
  1165. }
  1166. }
  1167. //根据录制的语音内容算出平均值用于显示
  1168. //volLev:经过计算后得出的0~10等级数值
  1169. void learnRecordVolShow(unsigned char volLev){
  1170. unsigned char vol=volLev;
  1171. unsigned short y1,y2,x,i;
  1172. unsigned int colorID;
  1173. static unsigned char lashVel=99;
  1174. unsigned char width=8;//一格音量宽度
  1175. unsigned char tx=1;//音量柱间隔
  1176. unsigned char sx=0;//音量柱开始坐标
  1177. if(lashVel == volLev) return;
  1178. lashVel=volLev;
  1179. //然后使用绿色显示实际音量
  1180. for(i=0;i<LEV_NUM;i++){
  1181. if(i<vol) colorID=COLOR_BLUE;
  1182. else colorID=guiGetBackColor();//COLOR_GRAY;
  1183. y2=GLCD_HEIGHT-2;
  1184. y1=y2-i-3;if(y1<=UI_BOTTOM_LINE_Y) y1=UI_BOTTOM_LINE_Y+1;
  1185. x=sx+i*(width+tx);
  1186. guiDrawVLine(y1, y2, x, width, colorID);
  1187. }
  1188. }
  1189. /*复位用户超时定时器*/
  1190. void httpPostResetUserTimer(unsigned int persent){
  1191. char info[30];
  1192. snprintf(info,sizeof(info), "正在上传:%d%%",persent);
  1193. guiShowMessageBox(info);
  1194. uTimerStart(&learnTick, 5000);
  1195. }
  1196. void uiShowLearnTaskDetailResponse(void){
  1197. unsigned char *pcm;
  1198. unsigned int plen;
  1199. unsigned short key=getKeyValue();
  1200. if(MKEY_VALUE_ESC==key){
  1201. switch(learnRecordStatus){
  1202. case LEARN_REC_IDLE://未录音,退出
  1203. learnRecordBufRelease();
  1204. learnDetailBackToTaskListMenu();
  1205. break;
  1206. case LEARN_REC_DONE://刚录音完成,选择放弃而返回到任务详情
  1207. learnRecordBufRelease();
  1208. learnShowStartScreen();
  1209. readTaskAndShow();
  1210. learnRecSetStatus(LEARN_REC_IDLE);
  1211. break;
  1212. case LEARN_REC_PLY://停止正在播放的操作
  1213. learnStopPlaying();
  1214. learnRetrunStatus();
  1215. break;
  1216. case LEARN_UPLOAD_CONFIRM://取消提交
  1217. learnRetrunStatus();
  1218. break;
  1219. }
  1220. }else if(MKEY_VALUE_PTT==key){
  1221. switch(learnRecordStatus){
  1222. case LEARN_REC_IDLE://选择了录音做作业
  1223. if(usr.type != 1){
  1224. MSG_WARN(1, "Only student have rec feature!");
  1225. break;
  1226. }
  1227. if(false==learnStartRecord(charaNum)){
  1228. MSG_ERR(1, "try recoder failed");
  1229. guiShowMessageBox("录音失败");
  1230. nwy_sleep(1500);
  1231. learnRecordBufRelease();
  1232. learnDetailBackToTaskListMenu();
  1233. break;
  1234. }
  1235. #ifdef SAVE_PCM_SD
  1236. pcmFileOpen();
  1237. #endif
  1238. uiMenuShowBottomIndacitor(NULL, "[PTT]停止");
  1239. learnRecSetStatus(LEARN_REC_BUSY);
  1240. break;
  1241. case LEARN_REC_BUSY://正在录音,选择停止
  1242. learnRecordDoneProcess();
  1243. #ifdef SAVE_PCM_SD
  1244. pcmFileClose();
  1245. #endif
  1246. break;
  1247. }
  1248. }else if(MKEY_VALUE_MENU==key){
  1249. switch(learnRecordStatus){
  1250. case LEARN_REC_IDLE://选择回放已提交的录音
  1251. learnPlayAudio(1, tidString);
  1252. learnRecSetStatus(LEARN_REC_PLY);
  1253. uiMenuShowBottomIndacitor(NULL, "停止");
  1254. break;
  1255. case LEARN_REC_DONE://选择播放录音(临时)
  1256. learnPlayAudio(0, NULL);
  1257. learnRecSetStatus(LEARN_REC_PLY);
  1258. uiMenuShowBottomIndacitor(NULL, "停止");
  1259. break;
  1260. case LEARN_UPLOAD_CONFIRM://确定提交
  1261. //暂时不做上传操作,将临时录音保存为.rec文件
  1262. httpPostResetUserTimer(0);
  1263. uiMenuShowBottomIndacitor(NULL, "取消");
  1264. pcm=learnGetTmpAudioBuf();
  1265. plen=learnGetTmpAudioLength();
  1266. learnRecSetStatus(LEARN_RECORD_UPLOAD);
  1267. learnTaskUpdate(LEARN_RECORD_UPLOAD,(void *)pcm, (void *)&plen,true);
  1268. break;
  1269. }
  1270. }else if(MKEY_VALUE_DOWN==key){
  1271. switch(learnRecordStatus){
  1272. case LEARN_REC_IDLE:
  1273. case LEARN_REC_BUSY:
  1274. readTaskAndShow();//显示任务其它内容
  1275. break;
  1276. }
  1277. }else if(MKEY_VALUE_P1==key){
  1278. switch(learnRecordStatus){
  1279. case LEARN_REC_DONE://选择提交录音(临时)
  1280. learnRecSetStatus(LEARN_UPLOAD_CONFIRM);
  1281. guiShowMessageBox("确定提交?");
  1282. uiMenuShowBottomIndacitor("[ok]确定", "取消");
  1283. break;
  1284. }
  1285. }
  1286. }
  1287. static void learnShowResult(void){
  1288. float devscore;
  1289. float speedscore=learnGetRecordRecSpeed();
  1290. float volumescore;
  1291. char info[30];
  1292. unsigned int y=UI_CONTENT_SHOW_Y+5;
  1293. volumescore=usr.scoreVolumeParam*learnGetRecordMaxVolume();
  1294. devscore=speedscore+volumescore;
  1295. guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,GLCD_HEIGHT-16-1,guiGetBackColor());
  1296. snprintf(info, sizeof(info), "设备评分:%.1f", devscore);
  1297. guiShowStr(5, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1298. y+= 18;
  1299. snprintf(info, sizeof(info), "速度评分:%.1f", speedscore);
  1300. guiShowStr(5, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1301. y+= 18;
  1302. snprintf(info, sizeof(info), "音量评分:%.1f", volumescore);
  1303. guiShowStr(5, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1304. y+= 18;
  1305. }
  1306. static void learnRecordDoneProcess(void){
  1307. learnRecordFree();
  1308. learnStopRecord();
  1309. learnRecSetStatus(LEARN_REC_DONE);
  1310. uiMenuShowBottomIndacitor("[OK]播放","[F1]提交");//选择提交还是播放
  1311. learnShowResult();
  1312. }
  1313. //学习排名菜单
  1314. void uiShowLearnRank(char update){
  1315. static const char *rankMode[]={
  1316. "月排名",
  1317. "周排名",
  1318. ""
  1319. };
  1320. static const char *learnIcon[]={
  1321. "RANK-M.bmp",
  1322. "RANK-W.bmp",
  1323. ""
  1324. };
  1325. char Freatrue[2]={0,1};
  1326. if(update){
  1327. sdMount();
  1328. guiClearAll(guiGetBackColor());
  1329. guiShowCaption(0,"学习排名",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  1330. uiMenuShowBottomLine();
  1331. ListBoxInit(&sutListBox, rankMode, 0, learnIcon, Freatrue);
  1332. uiMenuShowBottomIndacitor("查看", "返回");
  1333. }
  1334. }
  1335. void LearnRankSelResponse(void){
  1336. unsigned short key=ListBoxResponse(&sutListBox);
  1337. if(MKEY_VALUE_ESC==key){
  1338. sdUnmount();
  1339. uISetNextStatus(UIS_MENU_MAIN);
  1340. }else if(MKEY_VALUE_MENU==key){
  1341. if(sutListBox.handle==0){
  1342. rankType=0;
  1343. uiPushStack(sutListBox.handle);
  1344. uISetNextStatus(UIS_MENU_RANK_DETAIL);
  1345. }else if(sutListBox.handle==1){
  1346. rankType=1;
  1347. uiPushStack(sutListBox.handle);
  1348. uISetNextStatus(UIS_MENU_RANK_DETAIL);
  1349. }
  1350. }
  1351. }
  1352. typedef struct{
  1353. char type;//表示是month还是week
  1354. int typeIndex;//type的值
  1355. int avg;
  1356. int score;
  1357. int ranking;
  1358. int num;
  1359. }RANK_DEF;
  1360. typedef struct{
  1361. unsigned int item;//rankResult实际使用的个数
  1362. unsigned int num;//rankResult分配的个数(释放时使用)
  1363. RANK_DEF **rankResult;
  1364. }RANK_RESULT_DEF;
  1365. RANK_RESULT_DEF ranks={0,0,0,NULL};
  1366. bool rankShowReady;
  1367. static void rankInfoDetailShow(unsigned char direction){
  1368. static int tIndex=0;
  1369. if(ranks.item==0){
  1370. guiShowMessageBox("无数据");
  1371. return;
  1372. }else if(ranks.item==1) tIndex=0;
  1373. else{
  1374. if(direction==0) tIndex=0;
  1375. else if(direction==1){
  1376. if(++tIndex>=ranks.item) tIndex=0;
  1377. }else if(direction==2){
  1378. if(tIndex==0) tIndex=ranks.item-1;
  1379. else tIndex--;
  1380. }
  1381. }
  1382. guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,UI_BOTTOM_SHOW_Y-2,guiGetBackColor());
  1383. //显示
  1384. if(ranks.rankResult==NULL){
  1385. MSG_WARN(1, "rank no data");
  1386. return;
  1387. }
  1388. char info[50];
  1389. int x=1,y=UI_CONTENT_SHOW_Y;
  1390. //显示排名类型
  1391. if(0==ranks.rankResult[tIndex]->type) snprintf(info, sizeof(info), "month:%d", ranks.rankResult[tIndex]->typeIndex);
  1392. else snprintf(info, sizeof(info), "week:%d", ranks.rankResult[tIndex]->typeIndex);
  1393. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1394. y+=17;
  1395. //显示avg
  1396. snprintf(info, sizeof(info), "avg:%d", ranks.rankResult[tIndex]->avg);
  1397. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1398. y+=17;
  1399. //显示score
  1400. snprintf(info, sizeof(info), "score:%d", ranks.rankResult[tIndex]->score);
  1401. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1402. y+=17;
  1403. //显示ranking
  1404. snprintf(info, sizeof(info), "ranking:%d", ranks.rankResult[tIndex]->ranking);
  1405. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1406. y+=17;
  1407. //显示num
  1408. snprintf(info, sizeof(info), "num:%d", ranks.rankResult[tIndex]->num);
  1409. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1410. }
  1411. void uiShowLearnRankDetail(char update){
  1412. int ret;
  1413. static bool needGetUinfo=false;
  1414. if(update){
  1415. guiClearAll(guiGetBackColor());
  1416. if(rankType==0)
  1417. guiShowCaption(0,"月排名",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  1418. else
  1419. guiShowCaption(0,"周排名",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  1420. uiMenuShowBottomLine();
  1421. uiMenuShowBottomIndacitor(NULL, "返回");
  1422. if(sutApp.pocPpp==0){
  1423. guiShowMessageBox("无网络");
  1424. nwy_sleep(1500);
  1425. uISetNextStatus(UIS_MENU_RANK_SEL);
  1426. return;
  1427. }
  1428. rankShowReady=false;
  1429. showInfoBox("请稍候",3000);
  1430. if(isUserInfoReady()==false){//如果未获取用户信息,先获取用户信息
  1431. needGetUinfo=true;
  1432. learnUpdateStatus(LEARN_DB_WAIT_INFO);
  1433. learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,true);
  1434. }else{//否则可以直接获取排名
  1435. needGetUinfo=false;
  1436. learnUpdateStatus(LEARN_RANK_GET_DETAIL);
  1437. learnTaskUpdate(LEARN_RANK_GET_DETAIL,(void*)&rankType, NULL,true);
  1438. MSG_ERR(1, "update rank detail %s", (rankType==0)?"month":"week");
  1439. }
  1440. }
  1441. if(false==rankShowReady){
  1442. ret=getHttpLearnStatus();
  1443. if(uTimerExpired(&learnTick) || ret!=1){
  1444. MSG_INFO(1, "WAIT %s RESULT:%d",(rankType==0)?"MONTH":"WEEK",ret);
  1445. switch(ret){
  1446. case 0://功获取到了信息
  1447. if(needGetUinfo==true){
  1448. needGetUinfo=false;
  1449. learnUpdateStatus(LEARN_RANK_GET_DETAIL);
  1450. learnTaskUpdate(LEARN_RANK_GET_DETAIL,(void*)&rankType, NULL,true);
  1451. MSG_ERR(1, "update rank detail %s", (rankType==0)?"month":"week");
  1452. }else{
  1453. rankShowReady=true;
  1454. getRankShowMessage(rankType);
  1455. rankInfoDetailShow(0);
  1456. }
  1457. return;
  1458. case 2://获取失败
  1459. guiShowMessageBox("获取失败");
  1460. break;
  1461. default://获取超时
  1462. hearnHttpOverTime();
  1463. guiShowMessageBox("获取超时");
  1464. break;
  1465. }
  1466. nwy_sleep(1500);
  1467. getStackStruct()->ok_back=1;
  1468. uISetNextStatus(UIS_MENU_RANK_SEL);
  1469. }
  1470. }
  1471. }
  1472. static void learnRankReleaseDB(void);
  1473. void LearnRankDetailSelResponse(void){
  1474. if(rankShowReady==true){
  1475. switch(getKeyValue()){
  1476. case MKEY_VALUE_ESC:
  1477. learnRankReleaseDB();
  1478. uISetNextStatus(UIS_MENU_RANK_SEL);
  1479. break;
  1480. case MKEY_VALUE_DOWN:rankInfoDetailShow(1);break;
  1481. case MKEY_VALUE_UP:rankInfoDetailShow(2);break;
  1482. }
  1483. }
  1484. }
  1485. typedef struct{
  1486. int week;
  1487. char time[15];
  1488. char subject[30*2];
  1489. }CLASS_DEF;
  1490. typedef struct{
  1491. unsigned int item;//rankResult实际使用的个数
  1492. unsigned int num;//rankResult分配的个数(释放时使用)
  1493. CLASS_DEF **classResult;
  1494. }CLASS_RESULT_DEF;
  1495. CLASS_RESULT_DEF classes={0,0,0,NULL};
  1496. bool classShowReady;
  1497. static void classInfoDetailShow(unsigned char direction){
  1498. static int tIndex=0;
  1499. if(classes.item==0){
  1500. guiShowMessageBox("无数据");
  1501. return;
  1502. }else if(classes.item==1) tIndex=0;
  1503. else{
  1504. if(direction==0) tIndex=0;
  1505. else if(direction==1){
  1506. if(++tIndex>=classes.item) tIndex=0;
  1507. }else if(direction==2){
  1508. if(tIndex==0) tIndex=classes.item-1;
  1509. else tIndex--;
  1510. }
  1511. }
  1512. guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,UI_BOTTOM_SHOW_Y-2,guiGetBackColor());
  1513. //显示
  1514. if(classes.classResult==NULL){
  1515. MSG_WARN(1, "class no data");
  1516. return;
  1517. }
  1518. char info[50];
  1519. int x=1,y=UI_CONTENT_SHOW_Y;
  1520. //显示week
  1521. snprintf(info, sizeof(info), "week:%d", classes.classResult[tIndex]->week);
  1522. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1523. y+=17;
  1524. //显示time
  1525. snprintf(info, sizeof(info), "time:%s", classes.classResult[tIndex]->time);
  1526. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1527. y+=17;
  1528. //显示subject
  1529. snprintf(info, sizeof(info), "subject:%s", classes.classResult[tIndex]->subject);
  1530. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1531. }
  1532. static void getClassShowMessage(void);
  1533. /*课程表*/
  1534. void uiShowLearnClassDetail(char update){
  1535. int ret;
  1536. static bool needGetUinfo=false;
  1537. if(update){
  1538. guiClearAll(guiGetBackColor());
  1539. guiShowCaption(0,"课程表",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  1540. uiMenuShowBottomLine();
  1541. uiMenuShowBottomIndacitor(NULL, "返回");
  1542. if(sutApp.pocPpp==0){
  1543. guiShowMessageBox("无网络");
  1544. nwy_sleep(1500);
  1545. uISetNextStatus(UIS_MENU_LOCATION_SEL);
  1546. return;
  1547. }
  1548. classShowReady=false;
  1549. showInfoBox("请稍候",3000);
  1550. sdMount();
  1551. if(isUserInfoReady()==false){//如果未获取用户信息,先获取用户信息
  1552. needGetUinfo=true;
  1553. learnUpdateStatus(LEARN_DB_WAIT_INFO);
  1554. learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,true);
  1555. }else{//否则可以直接获取课程表
  1556. needGetUinfo=false;
  1557. learnUpdateStatus(LEARN_CLASS_GET_DETAIL);
  1558. learnTaskUpdate(LEARN_CLASS_GET_DETAIL,NULL, NULL,true);
  1559. MSG_ERR(1, "update class detail");
  1560. }
  1561. }
  1562. if(false==classShowReady){
  1563. ret=getHttpLearnStatus();
  1564. if(uTimerExpired(&learnTick) || ret!=1){
  1565. MSG_INFO(1, "WAIT CLASS:%d",ret);
  1566. switch(ret){
  1567. case 0://功获取到了信息
  1568. if(needGetUinfo==true){
  1569. needGetUinfo=false;
  1570. learnUpdateStatus(LEARN_CLASS_GET_DETAIL);
  1571. learnTaskUpdate(LEARN_CLASS_GET_DETAIL,NULL, NULL,true);
  1572. MSG_ERR(1, "update class detail");
  1573. }else{//处理
  1574. MSG_INFO(1, "class info get ok");
  1575. classShowReady=true;
  1576. getClassShowMessage();
  1577. classInfoDetailShow(0);
  1578. }
  1579. return;
  1580. case 2://获取失败
  1581. guiShowMessageBox("获取失败");
  1582. break;
  1583. default://获取超时
  1584. hearnHttpOverTime();
  1585. guiShowMessageBox("获取超时");
  1586. break;
  1587. }
  1588. nwy_sleep(1500);
  1589. getStackStruct()->ok_back=1;
  1590. uISetNextStatus(UIS_MENU_LOCATION_SEL);
  1591. }
  1592. }
  1593. }
  1594. static void learnClassReleaseDB(void);
  1595. void LearnClassDetailResponse(void){
  1596. if(classShowReady==true){
  1597. switch(getKeyValue()){
  1598. case MKEY_VALUE_ESC:
  1599. learnClassReleaseDB();
  1600. uISetNextStatus(UIS_MENU_LOCATION_SEL);
  1601. break;
  1602. case MKEY_VALUE_DOWN:classInfoDetailShow(1);break;
  1603. case MKEY_VALUE_UP:classInfoDetailShow(2);break;
  1604. }
  1605. }
  1606. }
  1607. typedef struct{
  1608. int id;
  1609. char time[15];
  1610. char title[30];
  1611. }NOTICE_DEF;
  1612. typedef struct{
  1613. unsigned int item;//rankResult实际使用的个数
  1614. unsigned int num;//rankResult分配的个数(释放时使用)
  1615. NOTICE_DEF **noticeResult;
  1616. }NOTICE_RESULT_DEF;
  1617. NOTICE_RESULT_DEF notices={0,0,0,NULL};
  1618. bool noticeShowReady;
  1619. static int noticetIndex=0;
  1620. static void noticeInfoDetailShow(unsigned char direction){
  1621. if(notices.item==0){
  1622. guiShowMessageBox("无数据");
  1623. return;
  1624. }else if(notices.item==1) noticetIndex=0;
  1625. else{
  1626. if(direction==0) noticetIndex=0;
  1627. else if(direction==1){
  1628. if(++noticetIndex>=notices.item) noticetIndex=0;
  1629. }else if(direction==2){
  1630. if(noticetIndex==0) noticetIndex=notices.item-1;
  1631. else noticetIndex--;
  1632. }
  1633. }
  1634. guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,UI_BOTTOM_SHOW_Y-2,guiGetBackColor());
  1635. //显示
  1636. if(notices.noticeResult==NULL){
  1637. MSG_WARN(1, "notice no data");
  1638. return;
  1639. }
  1640. char info[50];
  1641. int x=1,y=UI_CONTENT_SHOW_Y;
  1642. //显示title
  1643. snprintf(info, sizeof(info), "title:%s", notices.noticeResult[noticetIndex]->title);
  1644. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1645. y+=17;
  1646. //显示time
  1647. snprintf(info, sizeof(info), "time:%s", notices.noticeResult[noticetIndex]->time);
  1648. guiShowStr(x, y, info, FONT_MODE_16X16, REVERSED_NO, COLOR_BLACK, guiGetBackColor());
  1649. }
  1650. static void getNoticeShowMessage(void);
  1651. /*消息通知*/
  1652. void uiShowLearnNoticeDetail(char update){
  1653. int ret;
  1654. static bool needGetUinfo=false;
  1655. if(update){
  1656. guiClearAll(guiGetBackColor());
  1657. guiShowCaption(0,"消息通知",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  1658. uiMenuShowBottomLine();
  1659. uiMenuShowBottomIndacitor("阅读", "返回");
  1660. if(sutApp.pocPpp==0){
  1661. guiShowMessageBox("无网络");
  1662. nwy_sleep(1500);
  1663. uISetNextStatus(UIS_MENU_LOCATION_SEL);
  1664. return;
  1665. }
  1666. if(noticeShowReady==false){
  1667. showInfoBox("请稍候",3000);
  1668. sdMount();
  1669. if(isUserInfoReady()==false){//如果未获取用户信息,先获取用户信息
  1670. needGetUinfo=true;
  1671. learnUpdateStatus(LEARN_DB_WAIT_INFO);
  1672. learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,true);
  1673. }else{//否则可以直接获取课程表
  1674. needGetUinfo=false;
  1675. learnUpdateStatus(LEARN_NOTICE_GET_DETAIL);
  1676. learnTaskUpdate(LEARN_NOTICE_GET_DETAIL,NULL, NULL,true);
  1677. MSG_ERR(1, "update notice detail");
  1678. }
  1679. }
  1680. }
  1681. if(false==noticeShowReady){
  1682. ret=getHttpLearnStatus();
  1683. if(uTimerExpired(&learnTick) || ret!=1){
  1684. MSG_INFO(1, "WAIT NOTICE:%d",ret);
  1685. switch(ret){
  1686. case 0://功获取到了信息
  1687. if(needGetUinfo==true){
  1688. needGetUinfo=false;
  1689. learnUpdateStatus(LEARN_NOTICE_GET_DETAIL);
  1690. learnTaskUpdate(LEARN_NOTICE_GET_DETAIL,NULL, NULL,true);
  1691. MSG_ERR(1, "update notice detail");
  1692. }else{//处理
  1693. MSG_INFO(1, "notice info get ok");
  1694. noticeShowReady=true;
  1695. getNoticeShowMessage();
  1696. noticeInfoDetailShow(0);
  1697. }
  1698. return;
  1699. case 2://获取失败
  1700. guiShowMessageBox("获取失败");
  1701. break;
  1702. default://获取超时
  1703. hearnHttpOverTime();
  1704. guiShowMessageBox("获取超时");
  1705. break;
  1706. }
  1707. nwy_sleep(1500);
  1708. getStackStruct()->ok_back=1;
  1709. uISetNextStatus(UIS_MENU_LOCATION_SEL);
  1710. }
  1711. }
  1712. }
  1713. static void learnNoticeReleaseDB(void);
  1714. unsigned char noticeHandle;
  1715. void LearnNoticeResponse(void){
  1716. if(noticeShowReady==true){
  1717. switch(getKeyValue()){
  1718. case MKEY_VALUE_ESC:
  1719. learnNoticeReleaseDB();
  1720. noticeShowReady=false;
  1721. uISetNextStatus(UIS_MENU_LOCATION_SEL);
  1722. break;
  1723. case MKEY_VALUE_DOWN:noticeInfoDetailShow(1);break;
  1724. case MKEY_VALUE_UP:noticeInfoDetailShow(2);break;
  1725. case MKEY_VALUE_MENU:
  1726. uISetNextStatus(UIS_MENU_LOCATION_NOTICE_DETAIL);
  1727. break;
  1728. }
  1729. }
  1730. }
  1731. bool noticeDetailReady=false;
  1732. /*消息通知详情*/
  1733. void uiShowLearnNoticeDetailShow(char update){
  1734. int ret;
  1735. if(update){
  1736. guiClearAll(guiGetBackColor());
  1737. guiShowCaption(0,notices.noticeResult[noticetIndex]->title,UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
  1738. uiMenuShowBottomLine();
  1739. uiMenuShowBottomIndacitor(NULL, "返回");
  1740. if(sutApp.pocPpp==0){
  1741. guiShowMessageBox("无网络");
  1742. nwy_sleep(1500);
  1743. uISetNextStatus(UIS_MENU_LOCATION_SEL);
  1744. return;
  1745. }
  1746. showInfoBox("请稍候",3000);
  1747. sdMount();
  1748. noticeDetailReady=false;
  1749. learnUpdateStatus(LEARN_NOTICE_GET_DETAIL_SHOW);
  1750. learnTaskUpdate(LEARN_NOTICE_GET_DETAIL_SHOW,(void *)&notices.noticeResult[noticetIndex]->id, NULL,true);
  1751. MSG_ERR(1, "update notice detail show");
  1752. }
  1753. if(false==noticeDetailReady){
  1754. ret=getHttpLearnStatus();
  1755. if(uTimerExpired(&learnTick) || ret!=1){
  1756. MSG_INFO(1, "WAIT NOTICE SHOW:%d",ret);
  1757. switch(ret){
  1758. case 0://功获取到了信息
  1759. //处理
  1760. noticeDetailReady=true;
  1761. MSG_INFO(1, "notice info get ok");
  1762. noticeInfoDetailShowContent(0);
  1763. return;
  1764. case 2://获取失败
  1765. guiShowMessageBox("获取失败");
  1766. break;
  1767. default://获取超时
  1768. hearnHttpOverTime();
  1769. guiShowMessageBox("获取超时");
  1770. break;
  1771. }
  1772. nwy_sleep(1500);
  1773. noticeShowReady=false;
  1774. getStackStruct()->ok_back=1;
  1775. uISetNextStatus(UIS_MENU_LOCATION_SEL);
  1776. }
  1777. }
  1778. }
  1779. void LearnNoticeDetailResponse(void){
  1780. if(noticeDetailReady==true){
  1781. switch(getKeyValue()){
  1782. case MKEY_VALUE_ESC:
  1783. noticeShowReady=false;
  1784. uISetNextStatus(UIS_MENU_LOCATION_NOTICE);
  1785. break;
  1786. case MKEY_VALUE_DOWN:noticeInfoDetailShowContent(1);break;
  1787. //case MKEY_VALUE_UP:noticeInfoDetailShowContent(2);break;
  1788. }
  1789. }
  1790. }
  1791. #define OBJECT_AVG_NAME "avg"
  1792. #define OBJECT_SCORE_NAME "score"
  1793. #define OBJECT_RANKING_NAME "ranking"
  1794. #define OBJECT_NUM_NAME "num"
  1795. /*
  1796. msg:json buffer 数据,长度为len
  1797. {
  1798. "gid":555,
  1799. "uid":12345,
  1800. "list":[
  1801. {"week":29,"avg":518,"score":562,"ranking":5,"num":35},
  1802. {"week":28,"avg":518,"score":581,"ranking":8,"num":28},
  1803. {"week":27,"avg":518,"score":558,"ranking":10,"num":40},
  1804. {"week":26,"avg":518,"score":592,"ranking":2,"num":37},
  1805. ]
  1806. }
  1807. {
  1808. "gid":555,
  1809. "uid":12345,
  1810. "list":[
  1811. {"month":8,"avg":518,"score":562,"ranking":5,"num":35},
  1812. {"month":7,"avg":518,"score":581,"ranking":8,"num":28},
  1813. {"month":6,"avg":518,"score":558,"ranking":10,"num":40},
  1814. {"month":5,"avg":518,"score":592,"ranking":2,"num":37},
  1815. ]
  1816. }
  1817. 这里将list提取出到buffer并输出
  1818. */
  1819. static char *rankBuffer=NULL;
  1820. cJSON* rankJson=NULL;
  1821. static void learnRankReleaseDB(void){
  1822. int i;
  1823. releaseBuf(&rankBuffer);
  1824. if(NULL!=ranks.rankResult){
  1825. for(i=0;i<ranks.num;i++){
  1826. if(ranks.rankResult[i]!=NULL) releaseBuf(&ranks.rankResult[i]);
  1827. }
  1828. releaseBuf(&ranks.rankResult);
  1829. }
  1830. releaseJson(&rankJson);
  1831. }
  1832. static void getRankShowMessage(unsigned char ranktype){
  1833. //从LEARN_RANK文件中读取内容出来解析
  1834. RANK_DEF **rankPtr=NULL;
  1835. int fd=-1,i=0;
  1836. char info[50];
  1837. ranks.item=0;
  1838. snprintf(info, sizeof(info), "%s/%s", SD_TOKEN,LEARN_RANK);
  1839. fd=nwy_sdk_fopen(info, NWY_RDONLY);
  1840. if(fd<0){
  1841. MSG_WARN(1, "Rank file open failed");
  1842. goto R_EXIT;
  1843. }
  1844. long size=nwy_sdk_fsize_fd(fd);
  1845. if(size<=0){
  1846. MSG_WARN(1, "Rank file data error");
  1847. goto R_EXIT;
  1848. }
  1849. releaseBuf(&rankBuffer);
  1850. rankBuffer=(char *)createBuf(size);
  1851. //rankBuffer=(char *)malloc(size);
  1852. if(NULL == rankBuffer){
  1853. MSG_ERR(1, "rank buffer malloc error");
  1854. goto R_EXIT;
  1855. }
  1856. //MSG_INFO(1, "[mem malloc]%x", rankBuffer);
  1857. memset(rankBuffer, 0, size);
  1858. nwy_sdk_fread(fd, rankBuffer, size);
  1859. nwy_sdk_fclose(fd);
  1860. fd=-1;
  1861. //解析json
  1862. MSG_INFO(1, "Rank data analyse len:%d, type:%d",size, ranktype);
  1863. if(NULL!=ranks.rankResult){
  1864. for(i=0;i<ranks.num;i++){
  1865. if(ranks.rankResult[i]!=NULL) releaseBuf(&ranks.rankResult[i]);
  1866. }
  1867. releaseBuf(&ranks.rankResult);
  1868. }
  1869. ranks.num=0;
  1870. if(0==ranktype) snprintf(info, sizeof(info), "month");
  1871. else snprintf(info, sizeof(info), "week");
  1872. rankJson = createJson(rankBuffer);
  1873. //rankJson = cJSON_Parse(rankBuffer);
  1874. if(NULL==rankJson){
  1875. MSG_WARN(1, "rank json null");
  1876. goto R_EXIT;
  1877. }
  1878. //MSG_INFO(1, "rank json:%x", rankJson);
  1879. cJSON* item = cJSON_GetObjectItem(rankJson, OBJECT_LIST);
  1880. if(NULL==item){
  1881. MSG_ERR(1, "rank json failed");
  1882. goto R_EXIT;
  1883. }
  1884. int num=cJSON_GetArraySize(item);
  1885. if(num<=0){
  1886. MSG_WARN(1, "rank array num:%d",num);
  1887. goto R_EXIT;
  1888. }
  1889. MSG_INFO(1, "rank num:%d",num);
  1890. rankPtr=(RANK_DEF **)createBuf(sizeof(RANK_DEF *)*num);
  1891. //rankPtr=(RANK_DEF **)malloc(sizeof(RANK_DEF *)*num);
  1892. if(NULL==rankPtr){
  1893. MSG_ERR(1,"rank malloc failed");
  1894. goto R_EXIT;
  1895. }
  1896. //MSG_INFO(1, "[mem malloc]%x", rankPtr);
  1897. ranks.num=num;
  1898. for(i=0;i<num;i++) rankPtr[i]=NULL;
  1899. for(i=0;i<num;i++){
  1900. rankPtr[i]=(RANK_DEF *)createBuf(sizeof(RANK_DEF));
  1901. //rankPtr[i]=(RANK_DEF *)malloc(sizeof(RANK_DEF));
  1902. if(NULL==rankPtr[i]){
  1903. MSG_ERR(1, "rank[%d] malloc failed", i);
  1904. goto R_EXIT;
  1905. }
  1906. //MSG_INFO(1, "[mem malloc %d]%x", i, rankPtr[i]);
  1907. }
  1908. cJSON* element,*t;
  1909. i=0;
  1910. for(;;){
  1911. element=cJSON_GetArrayItem(item,i);
  1912. if(NULL==element) break;
  1913. //month/week
  1914. rankPtr[i]->type=ranktype;
  1915. t=cJSON_GetObjectItem(element, info);
  1916. if(NULL==t) rankPtr[i]->typeIndex=-1;
  1917. else rankPtr[i]->typeIndex=atoi(t->valuestring);
  1918. //avg
  1919. t=cJSON_GetObjectItem(element, OBJECT_AVG_NAME);
  1920. if(NULL==t) rankPtr[i]->avg=-1;
  1921. else rankPtr[i]->avg=atoi(t->valuestring);
  1922. //score
  1923. t=cJSON_GetObjectItem(element, OBJECT_SCORE_NAME);
  1924. if(NULL==t) rankPtr[i]->score=-1;
  1925. else rankPtr[i]->score=atoi(t->valuestring);
  1926. //ranking
  1927. t=cJSON_GetObjectItem(element, OBJECT_RANKING_NAME);
  1928. if(NULL==t) rankPtr[i]->ranking=-1;
  1929. else rankPtr[i]->ranking=atoi(t->valuestring);
  1930. //num
  1931. t=cJSON_GetObjectItem(element, OBJECT_NUM_NAME);
  1932. if(NULL==t) rankPtr[i]->num=-1;
  1933. else rankPtr[i]->num=atoi(t->valuestring);
  1934. i++;
  1935. }
  1936. ranks.item=i;
  1937. ranks.rankResult=rankPtr;
  1938. MSG_INFO(1, "rank valid num:%d",i);
  1939. return;
  1940. R_EXIT:
  1941. releaseJson(&rankJson);
  1942. releaseBuf(&rankBuffer);
  1943. if(fd>0) nwy_sdk_fclose(fd);
  1944. if(rankPtr != NULL){
  1945. for(i=0;i<num;i++) releaseBuf(&rankPtr[i]);
  1946. releaseBuf(&rankPtr);
  1947. }
  1948. }
  1949. #define OBJECT_WEEK_NAME "week"
  1950. #define OBJECT_TIME_NAME "time"
  1951. #define OBJECT_SUBJECT_NAME "subject"
  1952. static char *classBuffer=NULL;
  1953. cJSON* classJson=NULL;
  1954. static void learnClassReleaseDB(void){
  1955. int i;
  1956. releaseBuf(&classBuffer);
  1957. if(NULL!=classes.classResult){
  1958. for(i=0;i<classes.num;i++){
  1959. if(classes.classResult[i]!=NULL) releaseBuf(&classes.classResult[i]);
  1960. }
  1961. releaseBuf(&classes.classResult);
  1962. }
  1963. releaseJson(&classJson);
  1964. }
  1965. static void getClassShowMessage(void){
  1966. //从LEARN_CLASS文件中读取内容出来解析
  1967. CLASS_DEF **classPtr=NULL;
  1968. int fd=-1,i=0;
  1969. char info[50];
  1970. ranks.item=0;
  1971. snprintf(info, sizeof(info), "%s/%s", SD_TOKEN,LEARN_CLASS);
  1972. fd=nwy_sdk_fopen(info, NWY_RDONLY);
  1973. if(fd<0){
  1974. MSG_WARN(1, "Class file open failed");
  1975. goto R_EXIT;
  1976. }
  1977. long size=nwy_sdk_fsize_fd(fd);
  1978. if(size<=0){
  1979. MSG_WARN(1, "Class file data error");
  1980. goto R_EXIT;
  1981. }
  1982. releaseBuf(&classBuffer);
  1983. classBuffer=(char *)createBuf(size);
  1984. //classBuffer=(char *)malloc(size);
  1985. if(NULL == classBuffer){
  1986. MSG_ERR(1, "class buffer malloc error");
  1987. goto R_EXIT;
  1988. }
  1989. //MSG_INFO(1, "[mem malloc]%x", classBuffer);
  1990. memset(classBuffer, 0, size);
  1991. nwy_sdk_fread(fd, classBuffer, size);
  1992. nwy_sdk_fclose(fd);
  1993. fd=-1;
  1994. //解析json
  1995. MSG_INFO(1, "Class data analyse len:%d",size);
  1996. if(NULL!=classes.classResult){
  1997. for(i=0;i<classes.num;i++){
  1998. if(classes.classResult[i]!=NULL) releaseBuf(&classes.classResult[i]);
  1999. }
  2000. releaseBuf(&classes.classResult);
  2001. }
  2002. classes.num=0;
  2003. classJson = createJson(classBuffer);
  2004. //classJson = cJSON_Parse(classBuffer);
  2005. if(NULL==classJson){
  2006. MSG_WARN(1, "class json null");
  2007. goto R_EXIT;
  2008. }
  2009. //MSG_INFO(1, "class json:%x", classJson);
  2010. cJSON* item = cJSON_GetObjectItem(classJson, OBJECT_LIST);
  2011. if(NULL==item){
  2012. MSG_ERR(1, "class json failed");
  2013. goto R_EXIT;
  2014. }
  2015. int num=cJSON_GetArraySize(item);
  2016. if(num<=0){
  2017. MSG_WARN(1, "class array num:%d",num);
  2018. goto R_EXIT;
  2019. }
  2020. MSG_INFO(1, "class num:%d",num);
  2021. classPtr=(CLASS_DEF **)createBuf(sizeof(CLASS_DEF *)*num);
  2022. //classPtr=(CLASS_DEF **)malloc(sizeof(CLASS_DEF *)*num);
  2023. if(NULL==classPtr){
  2024. MSG_ERR(1,"class malloc failed");
  2025. goto R_EXIT;
  2026. }
  2027. //MSG_INFO(1, "[mem malloc]%x", classPtr);
  2028. classes.num=num;
  2029. for(i=0;i<num;i++) classPtr[i]=NULL;
  2030. for(i=0;i<num;i++){
  2031. classPtr[i]=(CLASS_DEF *)createBuf(sizeof(CLASS_DEF));
  2032. //classPtr[i]=(CLASS_DEF *)malloc(sizeof(CLASS_DEF));
  2033. if(NULL==classPtr[i]){
  2034. MSG_ERR(1, "class[%d] malloc failed", i);
  2035. goto R_EXIT;
  2036. }
  2037. //MSG_INFO(1, "[mem malloc %d]%x", i, classPtr[i]);
  2038. }
  2039. cJSON* element,*t;
  2040. i=0;
  2041. for(;;){
  2042. element=cJSON_GetArrayItem(item,i);
  2043. if(NULL==element) break;
  2044. //week
  2045. t=cJSON_GetObjectItem(element, OBJECT_WEEK_NAME);
  2046. if(NULL==t) classPtr[i]->week=-1;
  2047. else classPtr[i]->week=atoi(t->valuestring);
  2048. //time
  2049. t=cJSON_GetObjectItem(element, OBJECT_TIME_NAME);
  2050. if(NULL==t) classPtr[i]->time[0]='\0';
  2051. else snprintf(classPtr[i]->time, sizeof(classPtr[i]->time), "%s", t->valuestring);
  2052. //subject
  2053. t=cJSON_GetObjectItem(element, OBJECT_SUBJECT_NAME);
  2054. if(NULL==t) classPtr[i]->subject[0]='\0';
  2055. else snprintf(classPtr[i]->subject, sizeof(classPtr[i]->subject), "%s", t->valuestring);
  2056. i++;
  2057. }
  2058. classes.item=i;
  2059. classes.classResult=classPtr;
  2060. MSG_INFO(1, "class valid num:%d",i);
  2061. return;
  2062. R_EXIT:
  2063. releaseJson(&classJson);
  2064. releaseBuf(&classBuffer);
  2065. if(fd>0) nwy_sdk_fclose(fd);
  2066. if(classPtr != NULL){
  2067. for(i=0;i<num;i++) releaseBuf(&classPtr[i]);
  2068. releaseBuf(&classPtr);
  2069. }
  2070. }
  2071. #define OBJECT_ID_NAME "id"
  2072. #define OBJECT_TITLE_NAME "title"
  2073. static char *noticeBuffer=NULL;
  2074. cJSON* noticeJson=NULL;
  2075. static void learnNoticeReleaseDB(void){
  2076. int i;
  2077. releaseBuf(&noticeBuffer);
  2078. if(NULL!=notices.noticeResult){
  2079. for(i=0;i<notices.num;i++){
  2080. if(notices.noticeResult[i]!=NULL) releaseBuf(&notices.noticeResult[i]);
  2081. }
  2082. releaseBuf(&notices.noticeResult);
  2083. }
  2084. releaseJson(&noticeJson);
  2085. }
  2086. static void getNoticeShowMessage(void){
  2087. //从LEARN_CLASS文件中读取内容出来解析
  2088. NOTICE_DEF **noticePtr=NULL;
  2089. int fd=-1,i=0;
  2090. char info[50];
  2091. notices.item=0;
  2092. snprintf(info, sizeof(info), "%s/%s", SD_TOKEN,LEARN_NOTICE);
  2093. fd=nwy_sdk_fopen(info, NWY_RDONLY);
  2094. if(fd<0){
  2095. MSG_WARN(1, "Notice file open failed");
  2096. goto R_EXIT;
  2097. }
  2098. long size=nwy_sdk_fsize_fd(fd);
  2099. if(size<=0){
  2100. MSG_WARN(1, "Notice file data error");
  2101. goto R_EXIT;
  2102. }
  2103. releaseBuf(&noticeBuffer);
  2104. noticeBuffer=(char *)createBuf(size);
  2105. //noticeBuffer=(char *)malloc(size);
  2106. if(NULL == noticeBuffer){
  2107. MSG_ERR(1, "notice buffer malloc error");
  2108. goto R_EXIT;
  2109. }
  2110. //MSG_INFO(1, "[mem malloc]%x", noticeBuffer);
  2111. memset(noticeBuffer, 0, size);
  2112. nwy_sdk_fread(fd, noticeBuffer, size);
  2113. nwy_sdk_fclose(fd);
  2114. fd=-1;
  2115. //解析json
  2116. MSG_INFO(1, "Notice data analyse len:%d",size);
  2117. if(NULL!=notices.noticeResult){
  2118. for(i=0;i<notices.num;i++){
  2119. if(notices.noticeResult[i]!=NULL) releaseBuf(&notices.noticeResult[i]);
  2120. }
  2121. releaseBuf(&notices.noticeResult);
  2122. }
  2123. notices.num=0;
  2124. noticeJson = createJson(noticeBuffer);
  2125. //noticeJson = cJSON_Parse(noticeBuffer);
  2126. if(NULL==noticeJson){
  2127. MSG_WARN(1, "notice json null");
  2128. goto R_EXIT;
  2129. }
  2130. //MSG_INFO(1, "notice json:%x", noticeJson);
  2131. cJSON* item = cJSON_GetObjectItem(noticeJson, OBJECT_LIST);
  2132. if(NULL==item){
  2133. MSG_ERR(1, "notice json failed");
  2134. goto R_EXIT;
  2135. }
  2136. int num=cJSON_GetArraySize(item);
  2137. if(num<=0){
  2138. MSG_WARN(1, "notice array num:%d",num);
  2139. goto R_EXIT;
  2140. }
  2141. MSG_INFO(1, "notice num:%d",num);
  2142. noticePtr=(NOTICE_DEF **)createBuf(sizeof(NOTICE_DEF *)*num);
  2143. //noticePtr=(NOTICE_DEF **)malloc(sizeof(NOTICE_DEF *)*num);
  2144. if(NULL==noticePtr){
  2145. MSG_ERR(1,"notice malloc failed");
  2146. goto R_EXIT;
  2147. }
  2148. //MSG_INFO(1, "[mem malloc]%x", noticePtr);
  2149. notices.num=num;
  2150. for(i=0;i<num;i++) noticePtr[i]=NULL;
  2151. for(i=0;i<num;i++){
  2152. noticePtr[i]=(NOTICE_DEF *)createBuf(sizeof(NOTICE_DEF));
  2153. //noticePtr[i]=(CLASS_DEF *)malloc(sizeof(CLASS_DEF));
  2154. if(NULL==noticePtr[i]){
  2155. MSG_ERR(1, "notice[%d] malloc failed", i);
  2156. goto R_EXIT;
  2157. }
  2158. //MSG_INFO(1, "[mem malloc %d]%x", i, noticePtr[i]);
  2159. }
  2160. cJSON* element,*t;
  2161. i=0;
  2162. for(;;){
  2163. element=cJSON_GetArrayItem(item,i);
  2164. if(NULL==element) break;
  2165. //id
  2166. t=cJSON_GetObjectItem(element, OBJECT_ID_NAME);
  2167. if(NULL==t) noticePtr[i]->id=-1;
  2168. else noticePtr[i]->id=atoi(t->valuestring);
  2169. //time
  2170. t=cJSON_GetObjectItem(element, OBJECT_TIME_NAME);
  2171. if(NULL==t) noticePtr[i]->time[0]='\0';
  2172. else snprintf(noticePtr[i]->time, sizeof(noticePtr[i]->time), "%s", t->valuestring);
  2173. //title
  2174. t=cJSON_GetObjectItem(element, OBJECT_TITLE_NAME);
  2175. if(NULL==t) noticePtr[i]->title[0]='\0';
  2176. else snprintf(noticePtr[i]->title, sizeof(noticePtr[i]->title), "%s", t->valuestring);
  2177. i++;
  2178. }
  2179. notices.item=i;
  2180. notices.noticeResult=noticePtr;
  2181. MSG_INFO(1, "notice valid num:%d",i);
  2182. return;
  2183. R_EXIT:
  2184. releaseJson(&noticeJson);
  2185. releaseBuf(&noticeBuffer);
  2186. if(fd>0) nwy_sdk_fclose(fd);
  2187. if(noticePtr != NULL){
  2188. for(i=0;i<num;i++) releaseBuf(&noticePtr[i]);
  2189. releaseBuf(&noticePtr);
  2190. }
  2191. }
  2192. char *noticeDetailContent=NULL;
  2193. //char *testShowData="这是一条测试信息,长度为100,然后呢就一直显示吧,我也不知道能显示多少,所以只能临时搞一段文字来显示看看效果如何了,然后再给100000000000元作者吧,作为酬劳,我也不知道是否足够呢。";
  2194. void noticeInfoDetailShowContent(char direction){
  2195. int x=1,y=UI_CONTENT_SHOW_Y;
  2196. char *ptr=noticeDetailContent;
  2197. static int showlen,showIndex,len;
  2198. if(direction==0){
  2199. showlen=strlen(ptr);
  2200. showIndex=0;
  2201. }
  2202. guiClearRect(0,UI_CONTENT_SHOW_Y,GLCD_WIDTH-1,UI_BOTTOM_SHOW_Y-2,guiGetBackColor());
  2203. MessageEditInit(&sutMEdit, x, y+2 , ptr, FONT_MODE_16X16);
  2204. len=MessageEditShow(&sutMEdit,ptr+showIndex);
  2205. if(len !=0) showIndex+=len;
  2206. else showIndex=0;
  2207. }
  2208. void cJSONTakeContent(char *msg, int len){
  2209. //msg={"id":"7","content":"通知测试2"}
  2210. //提取"content"内容项到noticeInfoDetailShowContent中
  2211. releaseBuf(&noticeDetailContent);
  2212. cJSON* nJson=NULL;
  2213. nJson = createJson(msg);
  2214. if(NULL==nJson){
  2215. MSG_WARN(1, "notice detail show json null");
  2216. goto R_EXIT;
  2217. }
  2218. cJSON* item = cJSON_GetObjectItem(nJson, OBJECT_CONTENT_DETAIL);
  2219. if(NULL==item){
  2220. MSG_ERR(1, "notice detail show json failed");
  2221. goto R_EXIT;
  2222. }
  2223. int length=strlen(item->valuestring)+1;
  2224. char *ptr=(char *)createBuf(len*sizeof(char));
  2225. if(ptr==NULL){
  2226. MSG_ERR(1, "notice detail show malloc err");
  2227. goto R_EXIT;
  2228. }
  2229. memcpy(ptr, item->valuestring, len);
  2230. ptr[len]=0;
  2231. noticeDetailContent=ptr;
  2232. R_EXIT:
  2233. releaseJson(&nJson);
  2234. }
  2235. void cJSONTakeParam(char *msg, int len){
  2236. //msg={"scoreSpeedParam": "1.0","scoreVolumeParam": "1.0"}
  2237. bool sparamOk=false;
  2238. bool vparamOk=false;
  2239. cJSON* nJson=NULL;
  2240. nJson = createJson(msg);
  2241. if(NULL==nJson){
  2242. MSG_WARN(1, "param detail json null");
  2243. goto R_EXIT;
  2244. }
  2245. cJSON* item = cJSON_GetObjectItem(nJson, OBJECT_SPEED_PARAM);
  2246. if(NULL==item) MSG_ERR(1, "param speed json failed");
  2247. else{
  2248. usr.scoreSpeedParam=atof(item->valuestring);
  2249. sparamOk=true;
  2250. }
  2251. item = cJSON_GetObjectItem(nJson, OBJECT_VOLUME_PARAM);
  2252. if(NULL==item) MSG_ERR(1, "param volume json failed");
  2253. else{
  2254. usr.scoreVolumeParam=atof(item->valuestring);
  2255. vparamOk=true;
  2256. }
  2257. if(sparamOk==true && vparamOk==true){
  2258. MSG_INFO(1, "sparam:%f, vparam:%f", usr.scoreSpeedParam, usr.scoreVolumeParam);
  2259. usr.paramReady=true;
  2260. }
  2261. R_EXIT:
  2262. releaseJson(&nJson);
  2263. }
  2264. //没获取账户信息,则定时尝试获取
  2265. void LearnUsrInfoCheck(unsigned int interval){
  2266. static char step=0;
  2267. static unsigned int waitTimer;
  2268. unsigned char ret;
  2269. if(sutPocStatus.logined==0) return;
  2270. if(true==isUserInfoReady() && true==usr.paramReady){
  2271. if(step!=0) step=0;
  2272. return;
  2273. }
  2274. switch(step){
  2275. case 0://发起获取账户信息请求
  2276. step=1;
  2277. learnUpdateStatus(LEARN_DB_WAIT_INFO);
  2278. learnTaskUpdate(LEARN_DB_GET_INFO,NULL, NULL,false);
  2279. uTimerStart(&waitTimer, 5000);
  2280. break;
  2281. case 1://等待获取结果
  2282. ret=getHttpLearnStatus();
  2283. if(uTimerExpired(&waitTimer) || ret !=1){
  2284. MSG_INFO(1, "Wait user account:%d", ret);
  2285. if(ret==0) step=2;
  2286. else step=0;//重新获取
  2287. }
  2288. break;
  2289. case 2://发起参数获取请求
  2290. step=3;
  2291. learnUpdateStatus(LEARN_GET_PARAM);
  2292. learnTaskUpdate(LEARN_GET_PARAM,NULL, NULL,false);
  2293. uTimerStart(&waitTimer, 5000);
  2294. break;
  2295. case 3://等待获取结果
  2296. ret=getHttpLearnStatus();
  2297. if(uTimerExpired(&waitTimer) || ret !=1){
  2298. MSG_INFO(1, "Wait param:%d", ret);
  2299. if(ret==0) step=4;//停止
  2300. else step=2;//重新获取
  2301. }
  2302. break;
  2303. case 4://IDLE
  2304. break;
  2305. }
  2306. }
  2307. void uiShowLearnGroup(char type){
  2308. static unsigned int gid=0xffffffff;
  2309. if(false==isUserInfoReady()) return;
  2310. if(type) goto S_NOW;
  2311. if(gid == getLearnGid()) return;
  2312. gid=getLearnGid();
  2313. S_NOW:
  2314. uiShowLearnGName(getLearnGName());
  2315. }
  2316. static bool sdMountStatus=false;
  2317. void sdUnmount(void){
  2318. sdCardCtl(false);
  2319. sdMountStatus=false;
  2320. }
  2321. void sdMount(void){
  2322. if(sdMountStatus==false){
  2323. sdCardCtl(true);
  2324. sdMountStatus=true;
  2325. }
  2326. }
  2327. bool sdCardTest(void){
  2328. const char *table="sdTest.txt";
  2329. char file[50];
  2330. int fd=NULL;
  2331. bool ret=false;
  2332. sdCardCtl(true);
  2333. snprintf(file, sizeof(file), "%s/%s",SD_TOKEN,table);
  2334. fd = nwy_sdk_fopen(file, NWY_CREAT | NWY_RDWR|NWY_TRUNC);//清0式
  2335. if(fd<0){
  2336. MSG_WARN(1, "fopen to write failed:%s",table);
  2337. goto SD_END;
  2338. }
  2339. nwy_sdk_fwrite(fd, table, strlen(table));
  2340. nwy_sdk_fclose(fd);
  2341. fd = nwy_sdk_fopen(file, NWY_RDONLY);
  2342. if(fd < 0){
  2343. MSG_WARN(1, "fopen to read failed:%s",table);
  2344. goto SD_END;
  2345. }
  2346. memset(file, 0, sizeof(file));
  2347. nwy_sdk_fread(fd, file, strlen(table));
  2348. if(0==memcmp(file, table, strlen(file))) ret=true;
  2349. SD_END:
  2350. if(fd != NULL) nwy_sdk_fclose(fd);
  2351. sdCardCtl(false);
  2352. return ret;
  2353. }