0
0

deviceapi.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. // JavaScript Document
  2. var W_OK = 0;//检查成功
  3. var W_TRY = 1;//试用
  4. var W_NO_FOUND =2;//没有找到校验服务器
  5. var W_EXCEED_NUM =3;//超过用户数了
  6. function getEvent(parseEvent) {
  7. // if(g_msg) return;
  8. $.ajax({
  9. type: "post",
  10. url: "http://127.0.0.1:3001/msg/",
  11. dataType: "jsonp",
  12. timeout: 30000,
  13. data: {"act": "get","timeout":30000},
  14. //data中的timeout值要跟前面AJAX的timeout值相等,不设置默认是30000
  15. success: function (data,textStatus) {
  16. // $("#StatusArea").append("--- " + data );
  17. if(textStatus == "success")
  18. {
  19. getEvent(parseEvent);
  20. }
  21. if(data != null)
  22. {
  23. //AppendStatus(data+ "--\r\n");
  24. parseEvent(data.ch,data.e_type,data.e_handle,data.l_result,data.e_data);
  25. }
  26. },
  27. complete:function(XMLHttpRequest,textStatus){
  28. if(XMLHttpRequest.readyState=="4"){
  29. //alert(XMLHttpRequest.responseText);
  30. }
  31. },
  32. error: function (XMLHttpRequest, textStatus, errorThrown) {
  33. //$("#StatusArea").append("[state: " + textStatus + ", error: " + errorThrown + " ]<br/>");
  34. if (textStatus == "timeout") { // 请求超时
  35. // 递归调用
  36. getEvent(parseEvent);
  37. // 其他错误,如网络错误等
  38. } else {
  39. getEvent(parseEvent);
  40. }
  41. }
  42. });
  43. //setTimeout(getEvent ,1000);
  44. }
  45. function sendCmd(cmd_name,paraObj,resultCallback)
  46. {
  47. var nResult = -99;
  48. var bSync = false;
  49. $.ajax({
  50. type: "post",
  51. url: "http://127.0.0.1:3001/cmd/",
  52. dataType: "jsonp",
  53. data: {"act": cmd_name,"para":JSON.stringify(paraObj)},
  54. async:false,
  55. success: function (data,textStatus) {
  56. // $("#StatusArea").append("--- " + data );
  57. bSync = true;
  58. nResult = data.result;
  59. if(resultCallback!="" && resultCallback != null)
  60. resultCallback(nResult);
  61. return nResult;
  62. },
  63. complete:function(XMLHttpRequest,textStatus){
  64. if(XMLHttpRequest.readyState=="4"){
  65. //alert(XMLHttpRequest.responseText);
  66. }
  67. },
  68. error: function (XMLHttpRequest, textStatus, errorThrown) {
  69. console.log("网络错误! " + textStatus + ", error: " + errorThrown );
  70. if (textStatus == "timeout") { // 请求超时
  71. //getEvent(); // 递归调用
  72. // 其他错误,如网络错误等
  73. } else {
  74. //getEvent();
  75. }
  76. bSync = true;
  77. }
  78. });
  79. // Sleep(500);
  80. // var timestamp=new Date().getTime();
  81. // alert(timestamp+"---"+ nResult);
  82. return nResult;
  83. }
  84. //检查本地设备服务程序是否安装命令
  85. function check_ver(iVer,nextFunc)
  86. {
  87. var nResult = -99;
  88. var paraObj={};
  89. paraObj.a= iVer;
  90. $.ajax({
  91. type: "post",
  92. url: "http://127.0.0.1:3001/cmd/",
  93. dataType: "jsonp",
  94. data: {"act": "check_ver","para":JSON.stringify(paraObj)},
  95. timeout: 1000,
  96. //async:false,
  97. success: function (data,textStatus) {
  98. // $("#StatusArea").append("--- " + data );
  99. nResult = data.result;
  100. if(nextFunc!="" && nextFunc != null)
  101. nextFunc(nResult);
  102. return nResult;
  103. },
  104. complete:function(XMLHttpRequest,textStatus){
  105. if(XMLHttpRequest.readyState=="4"){
  106. //alert(XMLHttpRequest.responseText);
  107. }
  108. },
  109. error: function (XMLHttpRequest, textStatus, errorThrown) {
  110. //alert("没有安装! " + textStatus + ", error: " + errorThrown );
  111. nextFunc(nResult);
  112. if (textStatus == "timeout") { // 请求超时
  113. //getEvent(); // 递归调用
  114. // 其他错误,如网络错误等
  115. } else {
  116. //getEvent();
  117. }
  118. return nResult;
  119. }
  120. });
  121. return nResult;
  122. }
  123. function set_check_data_url(strUrl,nextFunc)
  124. {
  125. var nResult = -99;
  126. var paraObj={};
  127. paraObj.a= strUrl;
  128. nResult = sendCmd("set_check_url",paraObj,nextFunc);
  129. return nResult;
  130. }
  131. //最右边的是执行下一个函数的参数
  132. //下一步函数格式为function nextFunc(nResult)内含上次函数执行后返回的结果
  133. function OpenDevice(nDevice_type,nextFunc) {
  134. var nResult = -99;
  135. var paraObj={};
  136. paraObj.a=nDevice_type;
  137. paraObj.b = 0;
  138. nResult = sendCmd("QNV_OpenDevice",paraObj,nextFunc);
  139. return nResult;
  140. }
  141. function CloseDevice(nDevice_type,nextFunc) {
  142. var nResult = -99;
  143. var paraObj={};
  144. paraObj.a=nDevice_type;
  145. paraObj.b = 0;
  146. nResult = sendCmd("QNV_CloseDevice",paraObj,nextFunc);
  147. return nResult;
  148. }
  149. function SetDevCtrl( nChannelID, uCtrlType, nValue,nextFunc)
  150. {
  151. var nResult = -99;
  152. var paraObj = {};
  153. paraObj.a = nChannelID;
  154. paraObj.b = uCtrlType;
  155. paraObj.c = nValue;
  156. nResult = sendCmd("QNV_SetDevCtrl",paraObj,nextFunc);
  157. return nResult;
  158. }
  159. function GetDevCtrl(nChannelID,uCtrlType,nextFunc)
  160. {
  161. var nResult = -99;
  162. var paraObj = {};
  163. paraObj.a = nChannelID;
  164. paraObj.b = uCtrlType;
  165. nResult = sendCmd("QNV_GetDevCtrl",paraObj,nextFunc);
  166. return nResult;
  167. }
  168. function SetParam( nChannelID, uParamType, nValue,nextFunc)
  169. {
  170. var nResult = -99;
  171. var paraObj = {};
  172. paraObj.a = nChannelID;
  173. paraObj.b = uParamType;
  174. paraObj.c = nValue;
  175. nResult = sendCmd("QNV_SetParam",paraObj,nextFunc);
  176. return nResult;
  177. }
  178. function GetParam( nChannelID, uParamType,nextFunc )
  179. {
  180. var nResult = -99;
  181. var paraObj = {};
  182. paraObj.a = nChannelID;
  183. paraObj.b = uParamType;
  184. nResult = sendCmd("QNV_GetParam",paraObj,nextFunc);
  185. return nResult;
  186. }
  187. function PlayFile( nChannelID, uPlayType, nValue, nValueEx, pValue,nextFunc)
  188. {
  189. var nResult = -99;
  190. var paraObj = {};
  191. paraObj.a = nChannelID;
  192. paraObj.b = uPlayType;
  193. paraObj.c = nValue;
  194. paraObj.d = nValueEx;
  195. paraObj.e = pValue;
  196. nResult = sendCmd("QNV_PlayFile",paraObj,nextFunc);
  197. return nResult;
  198. }
  199. function PlayMultiFile( nChannelID, uPlayType, nValue, nValueEx, pValue,nextFunc)
  200. {
  201. var nResult = -99;
  202. var paraObj = {};
  203. paraObj.a = nChannelID;
  204. paraObj.b = uPlayType;
  205. paraObj.c = nValue;
  206. paraObj.d = nValueEx;
  207. paraObj.e = pValue;
  208. nResult = sendCmd("QNV_PlayMultiFile",paraObj,nextFunc);
  209. return nResult;
  210. }
  211. function PlayString( nChannelID, uPlayType, nValue, nValueEx, pValue,nextFunc)
  212. {
  213. var nResult = -99;
  214. var paraObj = {};
  215. paraObj.a = nChannelID;
  216. paraObj.b = uPlayType;
  217. paraObj.c = nValue;
  218. paraObj.d = nValueEx;
  219. paraObj.e = pValue;
  220. nResult = sendCmd("QNV_PlayString",paraObj,nextFunc);
  221. return nResult;
  222. }
  223. function RecordFile( nChannelID, uRecordType, nValue, nValueEx, pValue,nextFunc)
  224. {
  225. var nResult = -99;
  226. var paraObj = {};
  227. paraObj.a = nChannelID;
  228. paraObj.b = uRecordType;
  229. paraObj.c = nValue;
  230. paraObj.d = nValueEx;
  231. paraObj.e = pValue;
  232. nResult = sendCmd("QNV_RecordFile",paraObj,nextFunc);
  233. return nResult;
  234. }
  235. function Conference( nChannelID, nConfID, uConfType, nValue, pValue,nextFunc)
  236. {
  237. var nResult = -99;
  238. var paraObj = {};
  239. paraObj.a = nChannelID;
  240. paraObj.b = nConfID;
  241. paraObj.c = uConfType;
  242. paraObj.d = nValue;
  243. paraObj.e = pValue;
  244. nResult = sendCmd("QNV_Conference",paraObj,nextFunc);
  245. return nResult;
  246. }
  247. function General( nChannelID, uGeneralType, nValue, pValue,nextFunc)
  248. {
  249. var nResult = -99;
  250. var paraObj = {};
  251. paraObj.a = nChannelID;
  252. paraObj.b = uGeneralType;
  253. paraObj.c = nValue;
  254. paraObj.d = pValue;
  255. nResult = sendCmd("QNV_General",paraObj,nextFunc);
  256. return nResult;
  257. }
  258. function DevInfo( nChannelID, uDevInfoType,nextFunc)
  259. {
  260. var nResult = -99;
  261. var paraObj = {};
  262. paraObj.a = nChannelID;
  263. paraObj.b = uDevInfoType;
  264. nResult = sendCmd("QNV_DevInfo",paraObj,nextFunc);
  265. return nResult;
  266. }
  267. //nextFunc参数是一个对象包含result和缓存
  268. function Storage( nDevID, uOPType, uSeek, pPwd, pValue,nextFunc )
  269. {
  270. var paraObj = {};
  271. paraObj.a = nDevID;
  272. paraObj.b = uOPType;
  273. paraObj.c = uSeek;
  274. paraObj.d = pPwd;
  275. paraObj.e = pValue;
  276. var objResult ={};
  277. objResult.result = -99;
  278. $.ajax({
  279. type: "post",
  280. url: "http://127.0.0.1:3001/cmd/",
  281. dataType: "jsonp",
  282. data: {"act": "QNV_Storage","para":JSON.stringify(paraObj)},
  283. async:false,
  284. success: function (data) {
  285. // $("#StatusArea").append("--- " + data );
  286. objResult.result = data.result;
  287. objResult.content = data.content;
  288. if(data.outbuf != null )
  289. objResult.outbuf = decodeURIComponent(data.outbuf);
  290. if(nextFunc != null)
  291. nextFunc(objResult);
  292. },
  293. complete:function(XMLHttpRequest,textStatus){
  294. if(XMLHttpRequest.readyState=="4"){
  295. //alert(XMLHttpRequest.responseText);
  296. }
  297. },
  298. error: function (XMLHttpRequest, textStatus, errorThrown) {
  299. alert("网络错误! " + textStatus + ", error: " + errorThrown );
  300. if (textStatus == "timeout") { // 请求超时
  301. //getEvent(); // 递归调用
  302. // 其他错误,如网络错误等
  303. } else {
  304. //getEvent();
  305. }
  306. }
  307. });
  308. return objResult;
  309. }
  310. //接受文件在asp,php的参数为filedata1="文件名"
  311. function Remote( uRemoteType, nValue, pInValue, pInValueEx, pOutValue, nBufSize,nextFunc)
  312. {
  313. var nResult = -99;
  314. var paraObj = {};
  315. paraObj.a = uRemoteType;
  316. paraObj.b = nValue;
  317. paraObj.c = pInValue;
  318. paraObj.d = pInValueEx;
  319. paraObj.e = pOutValue;
  320. nResult = sendCmd("QNV_Remote",paraObj,nextFunc);
  321. return nResult;
  322. }
  323. //接受文件在asp,php的参数为filedata1="文件名"
  324. function Remote( uRemoteType, nValue, pInValue, pInValueEx, pOutValue, nBufSize,nextFunc)
  325. {
  326. var nResult = -99;
  327. var paraObj = {};
  328. paraObj.a = uRemoteType;
  329. paraObj.b = nValue;
  330. paraObj.c = pInValue;
  331. paraObj.d = pInValueEx;
  332. paraObj.e = pOutValue;
  333. nResult = sendCmd("QNV_Remote",paraObj,nextFunc);
  334. return nResult;
  335. }
  336. //返回一个结果对象
  337. function Tool( uToolType, nValue, pInValue, pInValueEx, nextFunc )
  338. {
  339. var objResult ={};
  340. var paraObj = {};
  341. paraObj.a = uToolType;
  342. paraObj.b = nValue;
  343. paraObj.c = pInValue;
  344. paraObj.d = pInValueEx;
  345. objResult.result = -99;
  346. $.ajax({
  347. type: "post",
  348. url: "http://127.0.0.1:3001/cmd/",
  349. dataType: "jsonp",
  350. data: {"act": "QNV_Tool","para":JSON.stringify(paraObj)},
  351. async:false,
  352. success: function (data) {
  353. // $("#StatusArea").append("--- " + data );
  354. objResult.result = data.result;
  355. objResult.content = data.content;
  356. objResult.outbuf = "";
  357. if(data.outbuf != null )
  358. {
  359. objResult.outbuf = decodeURIComponent(data.outbuf);
  360. }
  361. switch(uToolType) {
  362. case QNV_TOOL_PSTNEND:
  363. case QNV_TOOL_CODETYPE:
  364. if(nextFunc != null)
  365. nextFunc(objResult.result);
  366. return objResult.result;
  367. case QNV_TOOL_LOCATION:
  368. {
  369. if(nextFunc != null)
  370. nextFunc(objResult.outbuf);
  371. return objResult.outbuf;
  372. }
  373. case QNV_TOOL_DISKFREESPACE:
  374. case QNV_TOOL_DISKTOTALSPACE:
  375. {
  376. if(nextFunc != null)
  377. nextFunc(objResult.result);
  378. return objResult.result;
  379. }
  380. case QNV_TOOL_DISKLIST:
  381. {
  382. if(nextFunc != null)
  383. nextFunc(objResult.outbuf);
  384. return objResult.outbuf;
  385. }
  386. case QNV_TOOL_CONVERTFMT:
  387. if(nextFunc != null)
  388. nextFunc(objResult.result);
  389. return objResult.result;
  390. case QNV_TOOL_SELECTDIRECTORY:
  391. {
  392. if(nextFunc != null)
  393. nextFunc(objResult.outbuf);
  394. return objResult.outbuf;
  395. }
  396. case QNV_TOOL_SELECTFILE:
  397. {
  398. if(nextFunc != null)
  399. {
  400. nextFunc(objResult.outbuf);
  401. }
  402. return objResult.outbuf;
  403. }
  404. case QNV_TOOL_CONVERTTOTIFF:
  405. {
  406. if(nextFunc != null)
  407. nextFunc(objResult.result);
  408. return objResult.result;
  409. }
  410. case QNV_TOOL_SLEEP:
  411. if(nextFunc != null)
  412. nextFunc(objResult.result);
  413. return objResult.result;
  414. }
  415. },
  416. complete:function(XMLHttpRequest,textStatus){
  417. if(XMLHttpRequest.readyState=="4"){
  418. //alert(XMLHttpRequest.responseText);
  419. }
  420. },
  421. error: function (XMLHttpRequest, textStatus, errorThrown) {
  422. alert("网络错误! " + textStatus + ", error: " + errorThrown );
  423. if (textStatus == "timeout") { // 请求超时
  424. //getEvent(); // 递归调用
  425. // 其他错误,如网络错误等
  426. } else {
  427. //getEvent();
  428. }
  429. }
  430. });
  431. return objResult;
  432. }
  433. function CallLog( nChannelID, uLogType,nextFunc)
  434. {
  435. var objResult ={};
  436. var paraObj = {};
  437. paraObj.a = nChannelID;
  438. paraObj.b = uLogType;
  439. objResult.result = -99;
  440. $.ajax({
  441. type: "post",
  442. url: "http://127.0.0.1:3001/cmd/",
  443. dataType: "jsonp",
  444. data: {"act": "QNV_CallLog","para":JSON.stringify(paraObj)},
  445. async:false,
  446. success: function (data) {
  447. // $("#StatusArea").append("--- " + data );
  448. objResult.result = data.result;
  449. objResult.content = data.content;
  450. if(data.outbuf != null )
  451. objResult.outbuf = decodeURIComponent(data.outbuf);
  452. switch(uToolType) {
  453. case QNV_CALLLOG_BEGINTIME:
  454. case QNV_CALLLOG_RINGBACKTIME:
  455. case QNV_CALLLOG_CONNECTEDTIME:
  456. case QNV_CALLLOG_ENDTIME:
  457. case QNV_CALLLOG_CALLTYPE:
  458. case QNV_CALLLOG_CALLRESULT:
  459. case QNV_CALLLOG_DELRECFILE:
  460. case QNV_CALLLOG_RESET:
  461. if(nextFunc != null)
  462. nextFunc(objResult.result);
  463. return objResult.result;
  464. case QNV_CALLLOG_CALLID:
  465. case QNV_CALLLOG_CALLRECFILE:
  466. if(nextFunc != null)
  467. nextFunc(objResult.outbuf);
  468. return objResult.outbuf;;
  469. }
  470. },
  471. complete:function(XMLHttpRequest,textStatus){
  472. if(XMLHttpRequest.readyState=="4"){
  473. //alert(XMLHttpRequest.responseText);
  474. }
  475. },
  476. error: function (XMLHttpRequest, textStatus, errorThrown) {
  477. alert("网络错误! " + textStatus + ", error: " + errorThrown );
  478. if (textStatus == "timeout") { // 请求超时
  479. //getEvent(); // 递归调用
  480. // 其他错误,如网络错误等
  481. } else {
  482. //getEvent();
  483. }
  484. }
  485. });
  486. return objResult;
  487. }
  488. //URL中所有参数可以以p1=v1&p2=v2赋值,以post格式传送
  489. ////接受文件在asp,php的参数为file="文件名
  490. //strFilePath问文件本地路径
  491. //nextFunc下一条函数
  492. function UploadFile( strUrl, strFilePath,nextFunc)
  493. {
  494. var nResult = -99;
  495. var paraObj = {};
  496. paraObj.a = strUrl;
  497. paraObj.b = strFilePath;
  498. nResult = sendCmd("UploadFile",paraObj,nextFunc);
  499. return nResult;
  500. }