-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgoprocam.rb
334 lines (322 loc) · 8.43 KB
/
goprocam.rb
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
require 'open-uri'
require 'socket'
require 'json'
require_relative 'constants'
GPIP = "10.5.5.9"
GOPROCONTROL = "http://10.5.5.9/gp/gpControl/"
GOPROMEDIA = "http://10.5.5.9/gp/gpMediaList/"
class Camera
def initialize()
#check if camera is ON:
#power_on()
#check if camera status is connected
while status(Status::Status, Status::STATUS::IsConnected) == 0
status(Status::Status, Status::STATUS::IsConnected)
end
end
def gpControlSet(param,value)
response = open(GOPROCONTROL + 'setting/' + param + '/' + value).read
puts response
end
def gpControlCommand(param)
response = open(GOPROCONTROL + 'command/' + param).read
puts response
end
def status_raw()
response = open(GOPROCONTROL + 'status').read
puts response
end
def status(value, param)
response = open(GOPROCONTROL + 'status').read
parsed_resp = JSON.parse(response)
return parsed_resp[value][param]
end
def info_camera(option)
response = open(GOPROCONTROL + 'info').read
parsed_resp = JSON.parse(response)
return parsed_resp["info"][option]
end
def parse_value(param,value)
puts case param
when "mode"
puts case value
when 0
return "Video"
when 1
return "Photo"
when 2
return "Multi-Shot"
end
when "sub_mode"
puts case status(Status::Status, Status::STATUS::Mode)
when 0
puts case value
when 0
return "Video"
when 1
return "TimeLapse Video"
when 2
return "Video+Photo"
when 3
return "Looping"
end
when 1
puts case value
when 0
return "Single Pic"
when 1
return "Burst"
when 2
return "NightPhoto"
end
when 2
puts case value
when 0
return "Burst"
when 1
return "TimeLapse"
when 2
return "Night lapse"
end
end
when "recording"
puts case value
when 0
return "Not recording - standby"
when 1
return "RECORDING!"
end
when "battery"
puts case value
when 0
return "Nearly Empty"
when 1
return "LOW"
when 2
return "Halfway"
when 3
return "Full"
when 4
return "Charging"
end
when "video_left"
return Time.at(value).utc.strftime("%H:%M:%S")
when "rem_space"
return (value.to_f/1000000).round(2).to_s
when "video_res"
puts case value
when 1
return "4k"
when 2
return "4kSV"
when 4
return "2k"
when 5
return "2kSV"
when 6
return "2k4by3"
when 7
return "1440p"
when 8
return "1080pSV"
when 9
return "1080p"
when 10
return "960p"
when 11
return "720pSV"
when 12
return "720p"
when 13
return "480p"
end
when "video_fr"
puts case value
when 0
return "240"
when 1
return "120"
when 2
return "100"
when 5
return "60"
when 6
return "50"
when 7
return "48"
when 8
return "30"
when 9
return "25"
when 10
return "24"
end
end
end
def overview()
puts "camera overview"
puts "current mode: ", " " + parse_value("mode",status(Status::Status, Status::STATUS::Mode))
puts "current submode: ", " " + parse_value("sub_mode",status(Status::Status, Status::STATUS::SubMode))
puts "current video resolution: ", " " + parse_value("video_res",status(Status::Settings, Video::RESOLUTION))
puts "current video framerate: ", " " + parse_value("video_fr",status(Status::Settings, Video::FRAME_RATE))
puts "pictures taken: ", " " + status(Status::Status, Status::STATUS::PhotosTaken).to_s
puts "videos taken: ", " " + status(Status::Status, Status::STATUS::VideosTaken).to_s
puts "videos left: ", " " + parse_value("video_left",status(Status::Status, Status::STATUS::RemVideoTime))
puts "pictures left: ", " " + status(Status::Status, Status::STATUS::RemPhotos).to_s
puts "battery left: ", " " + parse_value("battery",status(Status::Status, Status::STATUS::BatteryLevel))
puts "space left in sd (GBs): ", " " + parse_value("rem_space",status(Status::Status, Status::STATUS::RemainingSpace))
puts "camera SSID: ", " " + status(Status::Status, Status::STATUS::CamName).to_s
puts "Is Recording:", " " + parse_value("recording",status(Status::Status, Status::STATUS::IsRecording))
puts "Clients connected: ", " " + status(Status::Status, Status::STATUS::IsConnected).to_s
puts "camera model: ", " " + info_camera(Camera::Name)
puts "camera ssid name: ", " " + info_camera(Camera::SSID)
puts "firmware version: ", " " + info_camera(Camera::Firmware)
puts "serial number: ", " " + info_camera(Camera::SerialNumber)
end
def shutter(value)
response = gpControlCommand('shutter?p=' + value)
puts response
end
def take_photo()
if status(Status::Status, Status::STATUS::IsRecording) == "1"
shutter(Shutter::OFF)
end
camera_mode(Mode::PhotoMode)
shutter(Shutter::ON)
end
def camera_mode(mode, submode="0")
response = gpControlCommand('sub_mode?mode=' + mode + '&sub_mode=' + submode)
puts response
end
def delete(option)
response = gpControlCommand('storage/delete/' + option)
puts response
end
def delete_file(folder,file)
response = gpControlCommand('storage/delete?p=' + folder + "/" + file)
puts response
end
def locate(param)
response = gpControlCommand('system/locate?p=' + param)
puts response
end
def hilight()
response = gpControlCommand('storage/tag_moment')
puts response
end
def power_off()
response = gpControlCommand('system/sleep')
puts response
end
def ap_setting(ssid,pass)
response = gpControlCommand('wireless/ap/ssid?ssid=' + ssid + "&pw=" + passwd)
puts response
end
def reset(option)
#videoPT, photoPT, msPT, camera, etc...
puts case option
when Reset::VideoPT
#reset video PT
response = gpControlCommand('video/protune/reset')
puts response
when Reset::PhotoPT
#reset photo PT
response = gpControlCommand('photo/protune/reset')
puts response
when Reset::MultiShotPT
#reset Ms PT
response = gpControlCommand('multi_shot/protune/reset')
puts response
when Reset::CamReset
response = gpControlCommand('system/factory/reset')
puts response
end
end
def list_media()
response = open(GOPROMEDIA).read
return JSON.pretty_generate JSON.parse(response)
end
def get_media()
folder=""
file=""
response = open(GOPROMEDIA).read
parsed_resp = JSON.parse(response)
parsed_resp['media'].each do |child|
folder = child['d']
end
parsed_resp['media'].each do |child|
child['fs'].each do |child|
file = child['n']
end
end
return "http://10.5.5.9:8080/videos/DCIM/" + folder + "/" + file
end
def get_media_info(option)
folder=""
file=""
size=""
response = open(GOPROMEDIA).read
parsed_resp = JSON.parse(response)
parsed_resp['media'].each do |child|
folder = child['d']
end
parsed_resp['media'].each do |child|
child['fs'].each do |child|
file = child['n']
size = child['s']
end
end
puts case option
when "folder"
return folder
when "file"
return file
when "size"
return size
end
end
def sync_time()
datestr_year=Time.new.year.to_s.reverse[0...2].reverse.to_i.to_s(16)
datestr_month=Time.new.month.to_s(16)
datestr_day=Time.new.day.to_s(16)
datestr_hour=Time.new.hour.to_s(16)
datestr_min=Time.new.min.to_s(16)
datestr_sec=Time.new.sec.to_s(16)
datestr="%"+datestr_year+"%"+datestr_month+"%"+datestr_day+"%"+datestr_hour+"%"+datestr_min+"%"+datestr_sec
response = gpControlCommand('setup/date_time?p=' + datestr)
puts response
end
def dl_media()
folder=""
file=""
response = open(GOPROMEDIA).read
parsed_resp = JSON.parse(response)
parsed_resp['media'].each do |child|
folder = child['d']
end
parsed_resp['media'].each do |child|
child['fs'].each do |child|
file = child['n']
end
end
url = get_media()
open(url) {|f|
File.open(folder+"-"+file,"wb") do |file|
file.puts f.read
end
}
end
def livestream(option)
puts case option
when "start"
response = open(GOPROCONTROL + 'execute?p1=gpStream&a1=proto_v2&c1=start').read
puts response
when "stop"
response = open(GOPROCONTROL + 'execute?p1=gpStream&a1=proto_v2&c1=stop').read
puts response
when "restart"
response = open(GOPROCONTROL + 'execute?p1=gpStream&a1=proto_v2&c1=restart').read
puts response
end
end
end