-
Notifications
You must be signed in to change notification settings - Fork 5
/
ipcam.js
executable file
·85 lines (81 loc) · 2.71 KB
/
ipcam.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/local/bin/node
var program = require('commander');
var IPCamera = require('./index.js');
program
.arguments('<action>')
.option('-u, --user <user>', 'The user to authenticate as')
.option('-p, --password <password>', 'The user\'s password')
.option('-a, --address <address>', 'The camera ip address')
.option('-m, --modelType <modelType>', 'The camera model type (e.g.: sricamAF004)')
.option('-d, --duration <duration>', 'The move duration in milliseconds')
.option('-s, --schedule <schedule>', 'Schedule given action for n times during schedule times: for instance \'-s 30\' schedule for 1 time the given action from now to now+30 minutes')
.option('-c, --count <count>', 'Use it in combination with schedule to configure how many times during schedule time the given action should start: for instance -s 30 -c 3 schedule fo 3 times the given action during 30 minutes from now where now is the command start execution time')
.option('-n --cameraName <cameraName>','The camera name identifier')
.action(function(action){
var user = program.user;
var pwd = program.password;
var cameraType = program.modelType;
var ip = program.address;
var duration = program.duration;
var schedule = program.schedule;
var count = program.count;
var name = program.name;
console.log('camera: %s action: %s user: %s pwd: %s ip: %s, duration: %s, schedule: %s, count: %s',
cameraType, action, user, pwd, ip, duration, schedule, count);
var config = {
ip: ip,
name: name||"Camera",
type: cameraType,
user: user,
pwd: pwd,
duration: duration
}
var camera = new IPCamera();
camera.createCamera(config.name,cameraType,config);
if(!schedule){
doNow(camera,action,duration);
}else{
scheduleActionFor(camera,action,duration,schedule,count||1);
}
})
.parse(process.argv);
function scheduleActionFor(camera,action,duration,during,times){
console.log("scheduleActionFor: %s, %s, %s", action, during, times);
var fun = null;
switch (action) {
case 'left':
fun = function(){camera.moveLeftFor(duration);}
break;
case 'right':
fun = function(){camera.moveRightFor(duration);}
break;
case 'up':
fun = function(){camera.moveUpFor(duration);}
break;
case 'down':
fun = function(){camera.moveDownFor(duration);}
break;
default:
break;
}
camera.schedule(fun,during,times);
}
function doNow(camera,action,duration){
console.log("doNow");
switch(action){
case 'left':
camera.moveLeftFor(duration);
break;
case 'right':
camera.moveRightFor(duration);
break;
case 'up':
camera.moveUpFor(duration);
break;
case 'down':
camera.moveDownFor(duration);
break;
default:
break;
}
}