Skip to content

Commit

Permalink
Allow getting the record mode of a camera
Browse files Browse the repository at this point in the history
  • Loading branch information
kk7ds committed Jun 7, 2016
1 parent 64bec7a commit e6d41b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
14 changes: 13 additions & 1 deletion uvcclient/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def main():
parser.add_option('-l', '--list', action='store_true', default=False)
parser.add_option('--recordmode', default=None,
help='Recording mode (none,full,motion)')
parser.add_option('--get-recordmode', default=None, action='store_true',
help='Show recording mode')
parser.add_option('--recordchannel', default=None,
help='Recording channel (high,medium,low)')
parser.add_option('-p', '--get-picture-settings', action='store_true',
Expand Down Expand Up @@ -127,6 +129,8 @@ def main():
client.dump(opts.uuid)
elif opts.list:
for cam in client.index():
ident = cam[client.camera_identifier]
recmode = client.get_recordmode(ident)
if not cam['managed']:
status = 'new'
elif cam['state'] == 'FIRMWARE_OUTDATED':
Expand All @@ -139,7 +143,8 @@ def main():
status = 'online'
else:
status = 'unknown:%s' % cam['state']
print('%s: %-24.24s [%10s]' % (cam['uuid'], cam['name'], status))
print('%s: %-24.24s [%10s] %s' % (cam['uuid'], cam['name'], status,
recmode))
elif opts.recordmode:
if not opts.uuid:
print('Name or UUID is required')
Expand All @@ -151,6 +156,13 @@ def main():
return 0
else:
return 1
elif opts.get_recordmode:
if not opts.uuid:
print('Name or UUID is required')
return 1
r = client.get_recordmode(opts.uuid)
print(r)
return r == 'none'
elif opts.get_picture_settings:
settings = client.get_picture_settings(opts.uuid)
print(','.join(['%s=%s' % (k, v) for k, v in settings.items()]))
Expand Down
18 changes: 18 additions & 0 deletions uvcclient/nvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ def server_version(self):
int(x) for x in self._bootstrap['systemInfo']['version'].split('.')
)

@property
def camera_identifier(self):
if self.server_version >= (3, 2, 0):
return 'id'
else:
return 'uuid'

def _safe_request(self, *args, **kwargs):
try:
conn = httplib.HTTPConnection(self._host, self._port)
Expand Down Expand Up @@ -160,6 +167,17 @@ def set_recordmode(self, uuid, mode, chan=None):
updated = data['data'][0]['recordingSettings']
return settings == updated

def get_recordmode(self, uuid):
url = '/api/2.0/camera/%s' % uuid
data = self._uvc_request(url)
recmodes = data['data'][0]['recordingSettings']
if recmodes['fullTimeRecordEnabled']:
return 'full'
elif recmodes['motionRecordEnabled']:
return 'motion'
else:
return 'none'

def get_picture_settings(self, uuid):
url = '/api/2.0/camera/%s' % uuid
data = self._uvc_request(url)
Expand Down

0 comments on commit e6d41b2

Please sign in to comment.