setting(7653).c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #include "includes.h"
  2. static void savePsnNow(ACCOUNT_DEF account);
  3. void cmdSetting(char *msg){
  4. char info[100],buf[50],ipAddr[40];
  5. char needSendAt=0;
  6. char needFeedSms=0;
  7. char needSaveSys=0;
  8. int len,port;
  9. unsigned long psn;
  10. //if(sutApp.gtMode==0) return;//为了测试,可以写号
  11. if(sutApp.gtTMode!=0){
  12. msgAtSends(msg, strlen(msg));
  13. return;
  14. }
  15. if(msgCmp(msg, "GT+TM")){
  16. snprintf(info, sizeof(info), "TM Mode:OK\r\n");
  17. needFeedSms=1;
  18. sutApp.gtTMode=1;
  19. }else if(msgCmp(msg, "GT+PWM=")){
  20. // if(msg[7]>='0' && msg[7]<='9') beepStart(atoi(msg+7));
  21. }else if(msgCmp(msg, "GT+SNET")){ //GT+SNET:TNET=4;GT+SNET:TNET=5;
  22. len=GetParaFromStr(msg, "TNET", buf);
  23. if(len!=1){
  24. TNET_ERR:
  25. snprintf(info, sizeof(info),"GT+SNET:FAIL[PSN Invalid]\r\n");
  26. needFeedSms=1;
  27. goto SETTING_END;
  28. }
  29. psn=atoi(buf);
  30. if(psn!=4&&psn!=5) goto TNET_ERR;
  31. MSG_INFO(1,"psn=====%d",psn);
  32. if(psn!=sutApp.UserInfo.tnet){
  33. sutApp.UserInfo.tnet=psn;
  34. saveInfoNow(&sutApp.UserInfo);
  35. }
  36. snprintf(info,sizeof(info),"GT+SNET:TNET=%d\r\n",psn);
  37. needFeedSms=1;
  38. }else if(msgCmp(msg, "GT+RNET")){
  39. snprintf(info, sizeof(info),"GT+RNET:TNET=%d;\r\n",sutApp.UserInfo.tnet);
  40. needFeedSms=1;
  41. }else if(msgCmp(msg, "GT+SZZD")){
  42. len=GetParaFromStr(msg,"ID",buf);
  43. if(len<1 || len>15){
  44. snprintf(info, sizeof(info),"GT+SZZD:FAIL[ID Invalid]\r\n");
  45. needFeedSms=1;
  46. goto SETTING_END;
  47. }
  48. strcpy(sutApp.UserInfo.OtherId,buf);
  49. if(len<1 || len>19){
  50. snprintf(info, sizeof(info),"GT+SZZD:FAIL[PWD Invalid]\r\n");
  51. needFeedSms=1;
  52. goto SETTING_END;
  53. }
  54. len=GetParaFromStr(msg,"PWD",buf);
  55. strcpy(sutApp.UserInfo.OtherPassWord,buf);
  56. snprintf(info, sizeof(info),"GT+SZZD:ID=%s;PWD=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  57. needFeedSms=1;
  58. saveInfoNow(&sutApp.UserInfo);
  59. }
  60. else if(msgCmp(msg, "GT+RZZD")){
  61. snprintf(info, sizeof(info),"GT+RZZD:Id=%s;Pwd=%s;\r\n",sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  62. needFeedSms=1;
  63. goto SETTING_END;
  64. }
  65. //unsigned char platform[20];
  66. //unsigned char pFormatMark[20];
  67. else if(msgCmp(msg, "GT+SDOMAIN")){
  68. len=GetParaFromStr(msg,"PLAT",buf);
  69. if(len<1 || len>15){
  70. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[ID Invalid]\r\n");
  71. needFeedSms=1;
  72. goto SETTING_END;
  73. }
  74. strcpy(sutApp.UserInfo.platform,buf);
  75. if(len<1 || len>19){
  76. snprintf(info, sizeof(info),"GT+SDOMAIN:FAIL[PWD Invalid]\r\n");
  77. needFeedSms=1;
  78. goto SETTING_END;
  79. }
  80. len=GetParaFromStr(msg,"MARK",buf);
  81. strcpy(sutApp.UserInfo.pFormatMark,buf);
  82. snprintf(info, sizeof(info),"GT+SDOMAIN:PLAT=%s;MARK=%s;\r\n",sutApp.UserInfo.platform,sutApp.UserInfo.pFormatMark);
  83. needFeedSms=1;
  84. saveInfoNow(&sutApp.UserInfo);
  85. }
  86. else if(msgCmp(msg, "GT+RDOMAIN")){
  87. snprintf(info, sizeof(info),"GT+RDOMAIN:PLAT=%s;MARK=%s;\r\n",sutApp.UserInfo.platform,sutApp.UserInfo.pFormatMark);
  88. needFeedSms=1;
  89. goto SETTING_END;
  90. }
  91. SETTING_END:
  92. if(needSendAt!=0) msgAtSends(info, strlen(info));
  93. if(needFeedSms!=0) usbOutPut(info, strlen(info));
  94. }
  95. //sysini文件处理
  96. #define SYSINI_FILE "sys.ini"
  97. SYSINI_HS191X_DEF newPara;
  98. char menu_key[6]="502800";//如果资源文件中没有定义服务器菜单密码,则默认使用此密码
  99. char *getMenuKey(void){return menu_key;}
  100. static void ttsToBEStr(char *tts, int len){
  101. int i;
  102. char tmp[2];
  103. if(len % 4) return;
  104. for(i=0;i<len/4;i++){
  105. tmp[0]=tts[4*i];tmp[1]=tts[4*i+1];
  106. tts[4*i]=tts[4*i+2];
  107. tts[4*i+1]=tts[4*i+3];
  108. tts[4*i+2]=tmp[0];
  109. tts[4*i+3]=tmp[1];
  110. }
  111. }
  112. void sysIniSave(void){
  113. int fd;
  114. MSG_INFO(1,"%s save start",SYSINI_FILE);
  115. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0x0);
  116. if(fd<0){
  117. MSG_ERR(1,"%s open failed",SYSINI_FILE);
  118. return;
  119. }
  120. //保存
  121. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  122. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  123. //nwy_sdk_fsync(fd);
  124. LSAPI_FS_Close(fd);
  125. MSG_INFO(1,"%s save done", SYSINI_FILE);
  126. }
  127. void setFactoryParam(void);
  128. void sysIniRead(void){
  129. int fd;
  130. char needsave=0;
  131. fd=LSAPI_FS_Open(SYSINI_FILE, LSAPI_FS_O_RDWR,0);
  132. if(fd<0){
  133. MSG_ERR(1,"%s open read failed", SYSINI_FILE);
  134. return;
  135. }
  136. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  137. LSAPI_FS_Read(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  138. if(newPara.ConfigFlag==0){
  139. MSG_INFO(1, "First run");
  140. newPara.itemShowType=0;
  141. newPara.ConfigFlag=1;
  142. newPara.lockType=0;//锁正面
  143. needsave=1;
  144. //检测TTS是否是UNICODE,是则将其从BE转换为LE,后面就可以直接播放了
  145. if(newPara.ttsMessage[0]!=0 && newPara.ttsCodeType==0) ttsToBEStr(newPara.ttsMessage, strlen(newPara.ttsMessage));
  146. newPara.spkVol=6;
  147. newPara.micGain=MIC_GAIN_DEFAULT;
  148. newPara.spkGain=SPK_GAIN_DEFAULT;
  149. // #ifndef DEVELOP_MODE
  150. // setFactoryParam();
  151. // #endif
  152. }
  153. if(newPara.serverMenuPass!=NULL) memcpy(menu_key, newPara.serverMenuPass,6);
  154. //测试开始
  155. //newPara.gpsEnable=0;
  156. //newPara.bubiaoEnable=0;
  157. //newPara.KeySound=1;
  158. //测试结束
  159. if(newPara.spkVol>MAX_SPK_VOL){
  160. newPara.spkVol=6;
  161. needsave=1;
  162. }
  163. if(newPara.gpsEnable!=0){//GPS使能,必需打开布标
  164. MSG_WARN(1, "gpsEnable, force bubiaoEnable");
  165. newPara.bubiaoEnable=1;
  166. needsave=1;
  167. }
  168. if(needsave!=0){
  169. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  170. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  171. //nwy_sdk_fsync(fd);
  172. }
  173. LSAPI_FS_Close(fd);
  174. }
  175. //保存PSN文件处理
  176. #define PSN_FILE "m5700_f2"
  177. void saveInfoNow(USER_STOR_INFO *info){
  178. int fd;
  179. MSG_INFO(1,"%s save start:",PSN_FILE);
  180. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDWR |LSAPI_FS_O_CREAT,0x0);
  181. if(fd<0){
  182. MSG_ERR(1,"%s open failed",PSN_FILE);
  183. return;
  184. }
  185. if(info->tnet!=4&&info->tnet!=5){
  186. info->tnet=4;
  187. }
  188. //淇濆瓨
  189. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  190. LSAPI_FS_Write(fd, (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO));
  191. //nwy_sdk_fsync(fd);
  192. LSAPI_FS_Close(fd);
  193. MSG_INFO(1,"%s save done", PSN_FILE);
  194. }
  195. void readInfoNow(void){
  196. int fd;
  197. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDONLY,0);
  198. if(fd<0){
  199. MSG_ERR(1,"%s open read failed", PSN_FILE);
  200. return;
  201. }
  202. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  203. LSAPI_FS_Read(fd, (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO));
  204. LSAPI_FS_Close(fd);
  205. MSG_INFO(1, "%s get info:%s,%s",PSN_FILE, sutApp.UserInfo.OtherId, sutApp.UserInfo.OtherPassWord);
  206. }
  207. void setFactoryParam(void){
  208. // sutApp.account.psn=newPara.defaultPsn;
  209. // saveInfoNow(sutApp.account);
  210. // MSG_INFO(1, "set factory psn:%d", sutApp.account.psn);
  211. }
  212. void setPocPara(){
  213. unsigned char Databuf[120]={0};
  214. unsigned char len;
  215. char *Addr="0.0.0.0";
  216. snprintf(&Databuf[16], sizeof(Databuf)-16, "addr:%s&user:GPS001&pass:123456", Addr);
  217. len=strlen(Databuf+16);
  218. snprintf(Databuf, sizeof(Databuf), "AT+POC=setinfo%02x%s",len, Databuf+16);
  219. msgAtSend(Databuf);
  220. MSG_INFO(1,Databuf);
  221. }
  222. char showPIP[40];
  223. char showGIP[40];
  224. const char invalidIp[]="1.1.1.1";
  225. char *getPIPAddr(void){
  226. char *retAddr=NULL;
  227. switch(newPara.serList.defaultuse){
  228. case SERVER_HZ: retAddr=newPara.serList.zh.pip;break;
  229. case SERVER_SD: retAddr=newPara.serList.sd.pip;break;
  230. case SERVER_FENFA:retAddr=(char *)invalidIp;break;
  231. case SERVER_JIQUN:retAddr=(char *)invalidIp;break;
  232. case SERVER_UR: retAddr=newPara.serList.ur.pip;break;
  233. }
  234. memset(showPIP, 0, sizeof(showPIP));
  235. strcpy(showPIP, retAddr);
  236. return retAddr;
  237. }
  238. char *getGIPAddr(void){
  239. char *retAddr=NULL;
  240. switch(newPara.serList.defaultuse){
  241. case SERVER_HZ: retAddr=newPara.serList.zh.gip;break;
  242. case SERVER_SD: retAddr=newPara.serList.sd.gip;break;
  243. case SERVER_FENFA: break;
  244. case SERVER_JIQUN: break;
  245. case SERVER_UR: retAddr=newPara.serList.ur.gip;break;
  246. }
  247. if(retAddr==NULL) showGIP[0]=0;
  248. else strcpy(showGIP, retAddr);
  249. return retAddr;
  250. }
  251. char *getDOMAINAddr(void)
  252. {
  253. char *retAddr=NULL;
  254. switch(newPara.serList.defaultuse){
  255. case SERVER_HZ:break;
  256. case SERVER_SD:break;
  257. case SERVER_FENFA:retAddr=newPara.serList.ipFenFa;break;
  258. case SERVER_JIQUN:retAddr=newPara.serList.jiqun;break;
  259. case SERVER_UR:break;
  260. }
  261. return retAddr;
  262. }