learnTask.c 73 KB

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