-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargus-sread.js
More file actions
executable file
·164 lines (123 loc) · 3.22 KB
/
Copy pathargus-sread.js
File metadata and controls
executable file
·164 lines (123 loc) · 3.22 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
var piid=6;
var vidcount;
fs = require('fs');
var serialport = require("serialport");
var GPIO = require('onoff').Gpio,
pin4 = new GPIO(4, 'out'),
pin17 = new GPIO(17, 'out');
var SerialPort = serialport.SerialPort;
var cmd=require('node-cmd');
var port = new SerialPort("/dev/ttyAMA0", {
baudrate: 9600,
parser: serialport.parsers.readline("\n")
}, false); // this is the openImmediately flag [default is true]
var recV = {
cmd: "ca 1"}
var stopV = {
cmd: "ca 1"}
var http = require('http');
http.post = require('http-post');
port.open(function(error) {
if (error) {
console.log('failed to open: ' + error);
} else {
// port.write("A");
console.log('Serial open');
port.on('data', function(data) {
console.log(piid+' command received= ' + data);
if (data[0]==piid){
if (piid+" pin4 on"==data){
console.log("GPIO 4 HIGH");
pin4.writeSync(1);
}
if (piid+" vidcount"==data){
fs.readFile('/home/pi/Desktop/argus/vidcount.txt', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
console.log(data);
});
}
if (piid+" pin4 off"==data){
console.log("GPIO 4 LOW");
pin4.writeSync(0);
}
if (piid+" pin17 on"==data){
console.log("GPIO 17 HIGH");
pin17.writeSync(1);
}
if (piid+" pin17 off"==data){
console.log("GPIO 17 LOW");
pin17.writeSync(0);
}
if (piid+" camera start"==data){
cmd.run('/home/pi/RPi_Cam_Web_Interface/./start.sh');
console.log("Starting Camera Service");
}
if (piid+" camera stop"==data){
cmd.run('/home/pi/RPi_Cam_Web_Interface/./stop.sh');
console.log("Stopping Camera Service");
// cmd.run('./stop.sh');
}
if (piid+" web rec"==data){
cmd.run('sudo pkill raspivid');
console.log("killing raspivid");
setTimeout(function(){
cmd.run('/home/pi/RPi_Cam_Web_Interface/./start.sh');//cmd.run('./stop.sh');
console.log("starting camera servie start");
}, 1000);
setTimeout(function(){
http.post('http://localhost/html/cmd_pipe.php?cmd=ca 1', {}, function(res){
console.log("web record start");
});
}, 15000);
}
if (piid+" serial rec"==data){
cmd.run('/home/pi/RPi_Cam_Web_Interface/./stop.sh');
console.log("stopping camera service");
pin17.writeSync(1);
fs.readFile('/home/pi/Desktop/argus/vidcount.txt', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
vidcount=data;
if(parseInt(vidcount)>4){
vidcount=0;
}
setTimeout(function(){
if(data==""){
vidcount=0;
}
cmd.run('cd /home/pi/Desktop/argus/');
cmd.run('sudo raspivid -t 999999 -o K'+vidcount+'.h264 &');
console.log("serial record start");
console.log("VICCOUNT = "+vidcount);
fs.writeFile("/home/pi/Desktop/argus/vidcount.txt", parseInt(vidcount)+1, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
}, 5000);
});
}
if (piid+" rec stop"==data){
http.post('http://localhost/html/cmd_pipe.php?cmd=ca 0', {}, function(res){
console.log("web record stop");
});
setTimeout(function(){
cmd.run('sudo pkill raspivid');
console.log("serial record stop");
}, 5000);
}
} // port.write("A");
});
}
});
function exit() {
pin4.unexport();
pin17.unexport();
process.exit();
}
process.on('SIGINT', exit);
// button.watch(light);