learnTask.c 75 KB

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