setting(152).c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. #include "includes.h"
  2. void saveInfoNow(USER_STOR_INFO *info);
  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. if(newPara.spkVol>MAX_SPK_VOL){
  155. newPara.spkVol=6;
  156. needsave=1;
  157. }
  158. if(newPara.gpsEnable!=0){//GPS使能,必需打开布标
  159. MSG_WARN(1, "gpsEnable, force bubiaoEnable");
  160. newPara.bubiaoEnable=1;
  161. needsave=1;
  162. }
  163. if(needsave!=0){
  164. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  165. LSAPI_FS_Write(fd, (unsigned char *)&newPara, sizeof(SYSINI_HS191X_DEF));
  166. //nwy_sdk_fsync(fd);
  167. }
  168. LSAPI_FS_Close(fd);
  169. }
  170. //保存PSN文件处理
  171. #define PSN_FILE "m5700_f2"
  172. void saveInfoNow(USER_STOR_INFO *info){
  173. int fd;
  174. MSG_INFO(1,"%s save start:",PSN_FILE);
  175. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDWR |LSAPI_FS_O_CREAT,0x0);
  176. if(fd<0){
  177. MSG_ERR(1,"%s open failed",PSN_FILE);
  178. return;
  179. }
  180. if(info->tnet!=4&&info->tnet!=5){
  181. info->tnet=4;
  182. }
  183. //淇濆瓨
  184. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  185. LSAPI_FS_Write(fd, (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO));
  186. //nwy_sdk_fsync(fd);
  187. LSAPI_FS_Close(fd);
  188. MSG_INFO(1,"%s save done", PSN_FILE);
  189. }
  190. void readInfoNow(void){
  191. int fd;
  192. fd=LSAPI_FS_Open(PSN_FILE, LSAPI_FS_O_RDONLY,0);
  193. if(fd<0){
  194. MSG_ERR(1,"%s open read failed", PSN_FILE);
  195. return;
  196. }
  197. LSAPI_FS_Seek(fd, 0L, LSAPI_FS_SEEK_SET);
  198. LSAPI_FS_Read(fd, (unsigned char *)&sutApp.UserInfo, sizeof(USER_STOR_INFO));
  199. LSAPI_FS_Close(fd);
  200. MSG_INFO(1, "%s get info:%s,%s",PSN_FILE, sutApp.UserInfo.OtherId, sutApp.UserInfo.OtherPassWord);
  201. }
  202. void setFactoryParam(void){
  203. // sutApp.account.psn=newPara.defaultPsn;
  204. // saveInfoNow(sutApp.account);
  205. // MSG_INFO(1, "set factory psn:%d", sutApp.account.psn);
  206. }
  207. void setPocPara(){
  208. unsigned char Databuf[120]={0};
  209. unsigned char len;
  210. char *Addr="0.0.0.0";
  211. snprintf(&Databuf[16], sizeof(Databuf)-16, "addr:%s&user:%s&pass:%s", Addr,sutApp.UserInfo.OtherId,sutApp.UserInfo.OtherPassWord);
  212. len=strlen(Databuf+16);
  213. snprintf(Databuf, sizeof(Databuf), "AT+POC=setinfo%02x%s",len, Databuf+16);
  214. msgAtSend(Databuf);
  215. MSG_INFO(1,Databuf);
  216. }
  217. char showPIP[40];
  218. char showGIP[40];