heavily cleaned up osc2cam
This commit is contained in:
parent
0b27742af0
commit
1c6b7157e8
|
@ -0,0 +1,35 @@
|
||||||
|
*.py[cod]
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Packages
|
||||||
|
*.egg
|
||||||
|
*.egg-info
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
eggs
|
||||||
|
parts
|
||||||
|
bin
|
||||||
|
var
|
||||||
|
sdist
|
||||||
|
develop-eggs
|
||||||
|
.installed.cfg
|
||||||
|
lib
|
||||||
|
lib64
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
.coverage
|
||||||
|
.tox
|
||||||
|
nosetests.xml
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
|
||||||
|
# Mr Developer
|
||||||
|
.mr.developer.cfg
|
||||||
|
.project
|
||||||
|
.pydevproject
|
|
@ -2,129 +2,155 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import ConfigParser
|
|
||||||
import os.path
|
|
||||||
import random
|
|
||||||
import re
|
import re
|
||||||
import select
|
|
||||||
import serial
|
|
||||||
import socket
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import httplib
|
||||||
import struct
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
from chaosc.simpleOSCServer import SimpleOSCServer
|
from chaosc.simpleOSCServer import SimpleOSCServer
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from chaosc.c_osc_lib import *
|
|
||||||
except ImportError as e:
|
|
||||||
print(e)
|
|
||||||
from chaosc.osc_lib import *
|
|
||||||
|
|
||||||
|
|
||||||
class OSC2CamServer(SimpleOSCServer):
|
class OSC2CamServer(SimpleOSCServer):
|
||||||
"""OSC filtering/transcoding middleware
|
"""OSC filtering/transcoding middleware
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, args, cams):
|
def __init__(self, args, cams):
|
||||||
"""ctor for filter server
|
"""ctor for a osc udp 2 ptz ip cam bridge
|
||||||
|
|
||||||
starts the server, loads scene filters and transcoders and chooses
|
starts the server, creates http connections to specified cams
|
||||||
the request handler, which is one of
|
|
||||||
forward only, forward and dump, dump only.
|
|
||||||
|
|
||||||
:param result: return value of argparse.parse_args
|
:param args: return value of argparse.parse_args
|
||||||
:type result: namespace object
|
:type args: namespace object
|
||||||
|
|
||||||
|
:param cams: return value of argparse.parse_args
|
||||||
|
:type cams: list of 2 item tuples
|
||||||
"""
|
"""
|
||||||
|
|
||||||
d = datetime.now().strftime("%x %X")
|
SimpleOSCServer.__init__(self, ("", args.port))
|
||||||
print "%s: starting up chaosc_filter-%s..." % (d, chaosc._version.__version__)
|
|
||||||
print "%s: binding to %s:%r" % (d, "0.0.0.0", args.own_port)
|
|
||||||
SimpleOSCServer.__init__(self, ("0.0.0.0", args.own_port))
|
|
||||||
|
|
||||||
self.set_url = "http://<servername>/cgi-bin/admin/"
|
self.set_url = "/cgi-bin/admin/"
|
||||||
self.get_url = "http://<servername>/cgi-bin/view/"
|
self.get_url = "/cgi-bin/view/"
|
||||||
self.ptz_ctl_url = "http://myserver/cgi-bin/operator/ptzset"
|
self.ptz_ctl_url = "/cgi-bin/operator/ptzset"
|
||||||
self.ptz_config_url = "http://myserver/cgi-bin/operator/ptzconfig"
|
self.ptz_config_url = "/cgi-bin/operator/ptzconfig"
|
||||||
self.connections = [socket.create_connection(cam) for cam in cams]
|
self.connections = [httplib.HTTPConnection(host, port) for host, port in cams]
|
||||||
self.resetCams()
|
self.resetCams()
|
||||||
|
|
||||||
def resetCams(self):
|
def resetCams(self):
|
||||||
|
""" configures each ip cam"""
|
||||||
|
|
||||||
for connection in self.connections:
|
for connection in self.connections:
|
||||||
connection.sendall("%sparam?action=update&Image.I0.MJPEG.Resolution=640x480" % self.set_url)
|
connection.request("GET", "%sparam?action=update&Image.I0.MJPEG.Resolution=640x480" % self.set_url)
|
||||||
connection.sendall("%sparam?action=update&Image.I0.Appearance.Compression=75" % self.set_url)
|
conn_result = connection.getresponse()
|
||||||
connection.sendall("%sparam?action=update&Image.I0.MJPEG.FPS=25" % self.set_url)
|
print conn_result.status, conn_result.reason
|
||||||
|
connection.request("GET", "%sparam?action=update&Image.I0.Appearance.Compression=75" % self.set_url)
|
||||||
|
conn_result = connection.getresponse()
|
||||||
|
print conn_result.status, conn_result.reason
|
||||||
|
connection.request("GET", "%sparam?action=update&Image.I0.MJPEG.FPS=25" % self.set_url)
|
||||||
|
conn_result = connection.getresponse()
|
||||||
|
print conn_result.status, conn_result.reason
|
||||||
|
|
||||||
|
|
||||||
def moveCam(self, cam_id, args):
|
def move_cam(self, cam_id, args):
|
||||||
|
""" moves given ip cam"""
|
||||||
|
|
||||||
direction = args[0]
|
direction = args[0]
|
||||||
if direction in ("home", "up", "down", "left", "right", "upleft", "upright", "downleft", "downright", "repeat", "stop"):
|
if direction in ("home", "up", "down", "left", "right", "upleft", "upright", "downleft", "downright", "repeat", "stop"):
|
||||||
self.connections[cam_id].sendall("%s?move=%s" % (self.ptz_ctl_url, direction))
|
connection = self.connections[cam_id]
|
||||||
|
connection.request("GET", "%s?move=%s" % (self.ptz_ctl_url, direction))
|
||||||
|
conn_result = connection.getresponse()
|
||||||
|
print conn_result.status, conn_result.reason
|
||||||
|
|
||||||
|
|
||||||
def useCamPreset(self, cam_id, args):
|
def use_cam_preset(self, cam_id, args):
|
||||||
|
""" says given ip cam to use a predefined position preset"""
|
||||||
|
|
||||||
presetno = args[0]
|
presetno = args[0]
|
||||||
self.connections[cam_id].sendall("%s?gotoserverpresetno=%d" % (self.ptz_ctl_url, presetno))
|
connection = self.connections[cam_id]
|
||||||
|
connection.request("GET", "%s?gotoserverpresetno=%d" % (self.ptz_ctl_url, presetno))
|
||||||
|
conn_result = connection.getresponse()
|
||||||
|
print conn_result.status, conn_result.reason
|
||||||
|
|
||||||
|
|
||||||
def setCamPreset(self, cam_id, args):
|
def set_cam_preset(self, cam_id, args):
|
||||||
|
""" saves the actual position of given ip cam to a preset"""
|
||||||
|
|
||||||
presetno = args[0]
|
presetno = args[0]
|
||||||
self.connections[cam_id].sendall("%s?setserverpresetno=%d&home=yes" % (self.ptz_config_url, presetno))
|
connection = self.connections[cam_id]
|
||||||
|
connection.request("GET", "%s?setserverpresetno=%d&home=yes" % (self.ptz_config_url, presetno))
|
||||||
|
conn_result = connection.getresponse()
|
||||||
|
print conn_result.status, conn_result.reason
|
||||||
|
|
||||||
|
|
||||||
def zoomCam(self, cam_id, args):
|
def zoom_cam(self, cam_id, args):
|
||||||
|
""" tells given ip cam to zoom in or out"""
|
||||||
|
|
||||||
direction = None
|
direction = None
|
||||||
arg = args[0]
|
arg = args[0]
|
||||||
if arg == "out":
|
if arg == "out":
|
||||||
direction = 0
|
direction = 0
|
||||||
elif arg == "in":
|
elif arg == "in":
|
||||||
direction = 1
|
direction = 1
|
||||||
self.connections[cam_id].sendall("%s?%szoom=%s" % (self.ptz_ctl_url, direction))
|
connection = self.connections[cam_id]
|
||||||
|
connection.request("GET", "%s?zoom=%s" % (self.ptz_ctl_url, direction))
|
||||||
|
conn_result = connection.getresponse()
|
||||||
|
print conn_result.status, conn_result.reason
|
||||||
|
|
||||||
|
|
||||||
def toggleNightView(self, cam_id, args):
|
def toggle_night_view(self, cam_id, args):
|
||||||
|
""" toggles the night view function of given ip cam"""
|
||||||
|
|
||||||
arg = args[0]
|
arg = args[0]
|
||||||
state = None
|
state = None
|
||||||
if arg == "on":
|
if arg == "on":
|
||||||
state = "auto"
|
state = "auto"
|
||||||
else:
|
else:
|
||||||
state = "off"
|
state = "off"
|
||||||
connection.sendall("%sparam?action=update&Image.I0.Appearance.NightMode=%s" % (self.set_url, state))
|
|
||||||
|
connection = self.connections[cam_id]
|
||||||
|
connection.request("GET", "%sparam?action=update&Image.I0.Appearance.NightMode=%s" % (self.set_url, state))
|
||||||
|
conn_result = connection.getresponse()
|
||||||
|
print conn_result.status, conn_result.reason
|
||||||
|
|
||||||
|
|
||||||
def dispatchMessage(self, osc_address, typetags, args, packet, client_address):
|
def dispatchMessage(self, osc_address, typetags, args, packet, client_address):
|
||||||
m = re.compile("/(.*?)/(\d+)/(.*?)")
|
""" dispatches parsed osc messages to the ip cam command methods"""
|
||||||
res = m.match(osc_address)
|
rule = re.compile("^/(.*?)/(\d+)/(.*?)$")
|
||||||
|
res = rule.match(osc_address)
|
||||||
if res:
|
if res:
|
||||||
dust, cam_id, command
|
_, cam_id, command = res.groups()
|
||||||
|
cam_id = int(cam_id)
|
||||||
if command == "moveCam":
|
if command == "moveCam":
|
||||||
self.moveCam(cam_id, args)
|
self.move_cam(cam_id, args)
|
||||||
elif osc_address == "/setCamPreset":
|
elif command == "setCamPreset":
|
||||||
self.setCamPreset(cam_id, args)
|
self.set_cam_preset(cam_id, args)
|
||||||
elif osc_address == "/useCamPreset":
|
elif command == "useCamPreset":
|
||||||
self.useCamPreset(cam_id, args)
|
self.use_cam_preset(cam_id, args)
|
||||||
elif osc_address == "zoomCam":
|
elif command == "zoomCam":
|
||||||
self.zoomCam(cam_id, args)
|
self.zoom_cam(cam_id, args)
|
||||||
elif osc_address == "toggleNightView":
|
elif command == "toggleNightView":
|
||||||
self.toggleNightView(cam_id, args)
|
self.toggle_night_view(cam_id, args)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(prog='psychose_actor')
|
parser = argparse.ArgumentParser(prog='osc2cam')
|
||||||
parser.add_argument('-o', "--own_host", required=True,
|
parser.add_argument('-p', "--port", required=True,
|
||||||
type=str, help='my host')
|
|
||||||
parser.add_argument('-r', "--own_port", required=True,
|
|
||||||
type=int, help='my port')
|
type=int, help='my port')
|
||||||
|
|
||||||
args = parser.parse_args(sys.argv[1:])
|
args = parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
|
|
||||||
cams = [
|
cams = [
|
||||||
"192.168.1.51",
|
("192.168.1.51", args.port + 1),
|
||||||
"192.168.1.52",
|
("192.168.1.52", args.port + 2),
|
||||||
"192.168.1.53"
|
("192.168.1.53", args.port + 3),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
cams = [
|
||||||
|
("localhost", args.port + 1),
|
||||||
|
("localhost", args.port + 2),
|
||||||
|
("localhost", args.port + 3),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
server = OSC2CamServer(args, cams)
|
server = OSC2CamServer(args, cams)
|
||||||
|
server.serve_forever()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue