Guest User

Untitled

a guest
Dec 13th, 2018
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | None | 0 0
  1. var ref = require("ref");
  2. var ffi = require('ffi');
  3. var path = require('path');
  4.  
  5. var config = {
  6. username: 'admin',
  7. password: 'audio123',
  8. ip : '10.191.95.197',
  9. port: 37777
  10. }
  11. var cameraLibrary = ffi.Library(path.join(__dirname, 'libs/libviewpath.so'), {
  12.  
  13. "openCameraLensCover": ['int', ['string', 'string', 'string', 'int']],
  14. "closeCameraLensCover": ['int', ['string', 'string', 'string', 'int']],
  15.  
  16. "ptzControlZoomIn": ['bool', ['string', 'string', 'string', 'int', 'int']],
  17. "ptzControlZoomOut": ['bool', ['string', 'string', 'string', 'int', 'int']],
  18. "ptzControlMoveUp": ['bool', ['string', 'string', 'string', 'int', 'int']],
  19. "ptzControlMoveDown": ['bool', ['string', 'string', 'string', 'int', 'int']],
  20. "ptzControlMoveLeft": ['bool', ['string', 'string', 'string', 'int', 'int']],
  21. "ptzControlMoveRight": ['bool', ['string', 'string', 'string', 'int', 'int']],
  22.  
  23. "cameraStartRecordingInSDCard": ['bool', ['string', 'string', 'string', 'int']],
  24. "cameraStoptRecordingInSDCard": ['bool', ['string', 'string', 'string', 'int']],
  25.  
  26. "cameraStartDownLoadFromSDCard": ['bool', ['string', 'string', 'string', 'string', 'string', 'string', 'int', 'pointer']],
  27.  
  28. "fisheyeMode": ['bool', ['string', 'string', 'string', 'int', 'int']],
  29.  
  30. "cameraGetCurrentMode": ['int', ['string', 'string', 'string', 'int']]
  31. //"registerDownloadCompleteEventCallBack": ['void', ['pointer']]
  32. });
  33.  
  34.  
  35.  
  36. function closeLens(){
  37. console.log("config: ",config)
  38. result = cameraLibrary.closeCameraLensCover(config.username, config.password, config.ip, config.port);
  39. console.log("\n************* Camera Close Response: ", result);
  40. }
  41.  
  42. function openLens(){
  43. result = cameraLibrary.openCameraLensCover(config.username, config.password, config.ip, config.port);
  44. console.log("\n************* Camera Open Response: ", result)
  45. }
  46.  
  47. try{
  48. console.log("=---------------------")
  49. openLens();
  50. // closeLens();
  51. // openLens();
  52. // closeLens();
  53. // openLens();
  54. // closeLens();
  55. // openLens();
  56. // closeLens();
  57. // openLens();
  58. // closeLens();
  59. // openLens();
  60. // closeLens();
  61. // openLens();
  62. // closeLens();
  63. // openLens();
  64. // closeLens();
  65. // openLens();
  66. // closeLens();
  67. // openLens();
  68. // closeLens();
  69. // openLens();
  70. // closeLens();
  71. // openLens();
  72. // closeLens();
  73.  
  74. /*setTimeout(function(){
  75. openLens();
  76. setTimeout(function () {
  77. closeLens();
  78. }, 1000);
  79. },2000);
  80.  
  81.  
  82. setTimeout(function () {
  83. openLens();
  84. setTimeout(function () {
  85. closeLens();
  86. }, 1000);
  87. }, 4000);
  88.  
  89.  
  90. setTimeout(function () {
  91. openLens();
  92. setTimeout(function () {
  93. closeLens();
  94. }, 1000);
  95. }, 10000);*/
  96.  
  97.  
  98. /*var _send = {
  99. recStart : '2018,12,12,16,54,00',
  100. recStop: '2018,12,12,23,59,00',
  101. filename : 'camera.mp4'
  102. }*/
  103.  
  104. /* //1.2 GB Fie
  105. var _send = {
  106. recStart: '2018,12,12,12,00,0',
  107. recStop: '2018,12,12,21,53,0',
  108. filename: 'camera.mp4'
  109. }
  110. */
  111.  
  112.  
  113. ///failing at 57%
  114. var _send = {
  115. recStart: '2018,12,12,21,43,0',
  116. recStop: '2018,12,12,21,44,30',
  117. filename: 'camera2.mp4'
  118. }
  119.  
  120. /* 148744 kb 140bm
  121. //working same file
  122. var _send = {
  123. recStart: '2018,12,12,21,42,0',
  124. recStop: '2018,12,12,21,44,40',
  125. filename: 'camera2.mp4'
  126. }
  127. */
  128. /*
  129. var _send = {
  130. recStart: '2018,12,13,15,35,0',
  131. recStop: '2018,12,13,15,44,30',
  132. filename: 'camera2.mp4'
  133. }
  134.  
  135. */
  136. // // Callback from the native lib back into js
  137. // var callback = ffi.Callback('void', ['string'],
  138. // function (name) {
  139. // console.log("***********************************************************************************");
  140. // console.log("***********************************************************************************");
  141. // console.log("***********************************************************************************");
  142. // console.log("***********************************************************************************");
  143. // console.log("*********************************Download Completd call back received filename is : ", name);
  144. // console.log("***********************************************************************************");
  145. // console.log("***********************************************************************************");
  146. // console.log("***********************************************************************************");
  147. // console.log("***********************************************************************************");
  148. // });
  149.  
  150. // console.log("registering the callback");
  151. // cameraLibrary.registerDownloadCompleteEventCallBack(callback);
  152. // console.log('done');
  153.  
  154.  
  155.  
  156. // var downloadResult = cameraLibrary.cameraStartDownLoadFromSDCard.async(config.username, config.password, config.ip, _send.recStart, _send.recStop, _send.filename, config.port, () => {
  157.  
  158. // console.log("************* download result ", downloadResult)
  159. // });
  160.  
  161.  
  162. // Callback from the native lib back into js
  163. var callback = ffi.Callback('void', ['string'],
  164. function (name) {
  165. console.log("***********************************************************************************");
  166. console.log("***********************************************************************************");
  167. console.log("***********************************************************************************");
  168. console.log("***********************************************************************************");
  169. console.log("*********************************Download Completd call back received filename is : ", name);
  170. console.log("***********************************************************************************");
  171. console.log("***********************************************************************************");
  172. console.log("***********************************************************************************");
  173. console.log("***********************************************************************************");
  174. });
  175.  
  176. /*console.log("registering the callback");
  177. cameraLibrary.registerDownloadCompleteEventCallBack(callback);
  178. console.log('done');*/
  179.  
  180.  
  181.  
  182. // var downloadResult = cameraLibrary.cameraStartDownLoadFromSDCard.async(config.username, config.password, config.ip, _send.recStart, _send.recStop, _send.filename, config.port, callback, () => {
  183.  
  184. // console.log("************* download result ", downloadResult)
  185. // });
  186.  
  187.  
  188.  
  189. var downloadResult = cameraLibrary.cameraStartDownLoadFromSDCard(config.username, config.password, config.ip, _send.recStart, _send.recStop, _send.filename, config.port, callback );
  190.  
  191.  
  192.  
  193.  
  194.  
  195. setTimeout(function () {
  196. console.log('Blah blah blah blah extra-blah');
  197. }, 300000);
  198.  
  199.  
  200. /*startDownload();
  201.  
  202.  
  203.  
  204. var count = 1;
  205. var max = 3;
  206. function startDownload(){
  207. console.log("Download starting for : ", count);
  208. var downloadResult = cameraLibrary.cameraStartDownLoadFromSDCard.async(config.username, config.password, config.ip, _send.recStart, _send.recStop, _send.filename, config.port, () => {
  209.  
  210. console.log("************* download result ", downloadResult)
  211.  
  212. count++;
  213. if(count <= max){
  214. startDownload();
  215. }
  216. });
  217. }
  218. */
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226. /*
  227. new Promise(function(resolve, reject){
  228. var downloadResult = cameraLibrary.cameraStartDownLoadFromSDCard.async(config.username, config.password, config.ip, _send.recStart, _send.recStop, _send.filename, config.port, () => {
  229. console.log("************* download 1 result In Callback ", downloadResult)
  230. });
  231. }).then(function(){
  232. }).catch(function(ex){
  233. console.log("*****************************************************************exception from download 1 ",ex.toString())
  234. }).then(function(){
  235. setTimeout(function(){
  236. console.log("execution 2-----------")
  237. var downloadResult = cameraLibrary.cameraStartDownLoadFromSDCard.async(config.username, config.password, config.ip, _send.recStart, _send.recStop, _send.filename, config.port, () => {
  238. console.log("************* download 2 result In Callback ", downloadResult)
  239. });
  240.  
  241. },2000)
  242. });
  243. */
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251. }catch(ex){
  252. console.log(ex);
  253. }
  254. // console.log(cameraLibrary);
Add Comment
Please, Sign In to add comment