-
Notifications
You must be signed in to change notification settings - Fork 1
/
thetas.sh
executable file
·165 lines (132 loc) · 3.11 KB
/
thetas.sh
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
#!/usr/bin/env bash
# Author: Kirill Kovalevskiy
# Email: [email protected]
# Command line interface for RICON Theta S API
# https://developers.theta360.com/en/docs/v2.1/api_reference/
# You should have latest firmware that support API 2.1
# Camera API routes
cam_addr="192.168.1.1:80"
execute_addr="${cam_addr}/osc/commands/execute"
function printb {
# Print text bold
BOLD='\e[1m'
NORM='\e[0m'
printf ${BOLD}"$@"${NORM}
return 0
}
function print_help {
# Display help for the tool
printf "\n"
printb "NAME\n"
printf "\n"
printf " thetas - Command line interface for RICON Theta S camera\n"
printf "\n"
printb "COMMANDS\n"
printf "\n"
printf " init run it first to configure canera api\n"
printf " state print camera status\n"
printf " snap take a single still picture\n"
printf " getlast download last captured image\n"
printf " list list files on the device\n"
printb "\nEXAMPLES\n"
printf "\n"
printf " Take a single picture\n"
printf " thetas pic\n"
printf "\n"
}
function set_api_version {
# By default you camera might have API 2.0 active
# This command will switch it to 2.1
# Start camera session since a session should be started before executing commands in API v2.0
session=$( curl -s --data '{"name": "camera.startSession", "parameters": {}}' ${execute_addr} )
session_id=`echo ${session} | jq .results.sessionId`
version=$1
if [[ -z ${version} ]]; then
version=2
fi
data="{
\"name\": \"camera.setOptions\",
\"parameters\": {
\"sessionId\": ${session_id},
\"options\": {
\"clientVersion\": ${version}
}
}
}"
curl -s --data "${data}" ${execute_addr}
# end_session ${session_id}
}
function end_session {
# Close camera session by its id
session_id=$1
data="{
\"name\": \"camera.closeSession\",
\"parameters\": {
\"sessionId\": ${session_id}
}
}"
echo $data
curl -s --data "${data}" ${execute_addr}
}
function get_state {
# Show camera state info
curl -s -X POST ${cam_addr}/osc/state
}
function take_picture {
# Take a single picture
# Camera should be in photo mode
data="{\"name\": \"camera.takePicture\"}"
curl -s --data "${data}" ${execute_addr}
}
function list_files {
count=$1
if [[ -z $count ]]; then
count=-1 # Default to list all available files
fi
data="{
\"name\": \"camera.listFiles\",
\"parameters\": {
\"fileType\": \"all\",
\"entryCount\": ${count},
\"maxThumbSize\": 0
}
}"
curl -s --data "${data}" ${execute_addr}
}
function download_latest {
img_path="latest.jpg"
url=$(get_state | jq -r .state._latestFileUrl)
curl -o ${img_path} ${url}
open ${img_path}
}
# Process commands
cmd=$1
case $cmd in
"init")
shift
set_api_version 2
;;
"state")
shift
get_state | jq
;;
"snap")
shift
take_picture "$@" | jq
;;
"getlast")
shift
download_latest "$@" | jq
;;
"list")
shift
list_files "$@" | jq
;;
"test")
shift
# echo "Hello this is me!"
list_files "$@"
;;
*)
print_help
esac