public void PtzSetConfiguration() { RunTest(() => { PTZConfiguration[] configuarions = GetConfigurations(); Assert((configuarions != null) && (configuarions.Length > 0), Resources.ErrorNoPTZConfig_Text, Resources.StepValidateGetConfigurations_Title); PTZConfiguration configuration = configuarions[0]; string reason = null; Assert(ValidatePTZConfiguration(configuration, out reason), reason, Resources.StepValidatePTZConfig_Title); //according to Tests interpretation.xls 61 PTZConfigurationOptions options = GetConfigurationOptions(configuration.token); Assert(ValidatePTZConfigurationOptions(options, configuration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); configuration.DefaultPTZTimeout = GetModifiedTimeout(configuration.DefaultPTZTimeout, options); SetConfiguration(configuration, false, string.Format("Default timeout = {0}", configuration.DefaultPTZTimeout)); PTZConfiguration newConfig = GetConfiguration(configuration.token); Assert( EqualConfigs(configuration, newConfig, out reason), string.Format(Resources.PTZConfigsNotEqual_Format, reason), Resources.StepValidateNewPTZConfig_Title); }); }
public OnVifPTZController(OnVifDevice OnVifDevice) : base(OnVifDevice) { // m_onVifDevice = OnVifDevice; // m_mediaClient = null; //m_profile = null; m_Timer = null; m_velocity = null; m_vector = null; m_options = null; m_relative = false; m_initialised = false; m_direction = m_direction = Direction.None; m_Presets = null; m_capabilities = null; m_ptzClient = null; m_ErrorMessage = ""; m_configs = null; m_initialised = false; m_panDistance = 0; m_tiltDistance = 0; m_bMoveActiv = false; m_timeinmsec = 200; m_doContineousMode = false; m_ProfileRefToken = ""; }
private void Stop_zoom(object sender, RoutedEventArgs e) { bool flag = combobox.Items.Count > 0 && combobox.SelectedIndex != 2; if (flag) { PTZClient pTZClient = GetPTZClient(); PTZConfigurationOptions configurationOptions = pTZClient.GetConfigurationOptions(profiles[combobox.SelectedIndex].PTZConfiguration.token); pTZClient.Stop(profiles[combobox.SelectedIndex].token, true, true); } }
public void PtzConfigurationOptions() { RunTest(() => { PTZConfiguration[] configuarions = GetConfigurations(); Assert((configuarions != null) && (configuarions.Length > 0), Resources.ErrorNoPTZConfig_Text, Resources.StepValidateGetConfigurations_Title); PTZConfiguration configuration = configuarions[0]; PTZConfigurationOptions options = GetConfigurationOptions(configuration.token); string reason = null; Assert(ValidatePTZConfigurationOptions(options, configuration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); }); }
/// <summary> /// Tilt the camera (uses the first media profile that is PTZ capable) /// </summary> /// <param name="speed">Percent of max speed to move the camera (1-100)</param> public void Tilt(float speed) { Onvif_Interface.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PTZConfigurationOptions ptzConfigurationOptions = PtzClient.GetConfigurationOptions(mediaProfile.PTZConfiguration.token); PTZSpeed velocity = new PTZSpeed(); velocity.PanTilt = new Vector2D() { x = 0, y = speed * ptzConfigurationOptions.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Max }; PtzClient.ContinuousMove(mediaProfile.token, velocity, null); }
internal StepType GetConfigurationOptionsTest(out PTZConfigurationOptions target, out SoapException ex, out int Timeout, string ConfigurationToken) { StepType res = StepType.None; Timeout = 0; ex = null; target = null; bool passed = true; string logMessage = ""; string tmpCommandName = "GetConfigurationOptions"; int tmpCommandNumber = GetConfigurationOptions; //Get step list for command XmlNodeList m_testList = m_TestCommon.GetStepsForCommand(ServiceName + "." + tmpCommandName); //TEMP: for backward compatibility if (m_testList.Count == 0) { m_testList = m_TestCommon.GetStepsForCommand(tmpCommandName); } if (m_testList.Count != 0) { //Get current step XmlNode test = m_testList[m_commandCount[tmpCommandNumber]]; #region Analyze request //ConfigurationToken CommonCompare.StringCompare("RequestParameters/ConfigurationToken", "ConfigurationToken", ConfigurationToken, ref logMessage, ref passed, test); #endregion //Analyze request //Generate response object targetObj; res = m_TestCommon.GenerateResponseStepTypeNotVoid(test, out targetObj, out ex, out Timeout, typeof(PTZConfigurationOptions)); target = (PTZConfigurationOptions)targetObj; //Log message m_TestCommon.writeToLog(test, logMessage, passed); Increment(m_testList.Count, tmpCommandNumber); } else { throw new SoapException("NO " + ServiceName + "." + tmpCommandName + " COMMAND IN SCRIPT", SoapException.ServerFaultCode); } return(res); }
/// <summary> /// Pan the camera (uses the first media profile that is PTZ capable) /// </summary> /// <param name="speed">Percent of max speed to move the camera (1-100)</param> public void Pan(float speed) { Onvif_Interface.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PTZConfigurationOptions ptzConfigurationOptions = PtzClient.GetConfigurationOptions(mediaProfile.PTZConfiguration.token); File.AppendAllText("info.txt", string.Format("Media Profile [Name: {0}, Token: {1}, PTZ Config. Name: {2}, PTZ Config. Token: {3}]\n", mediaProfile.Name, mediaProfile.token, mediaProfile.PTZConfiguration.Name, mediaProfile.PTZConfiguration.token)); PTZSpeed velocity = new PTZSpeed(); velocity.PanTilt = new Vector2D() { x = speed * ptzConfigurationOptions.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Max, y = 0 }; PtzClient.ContinuousMove(mediaProfile.token, velocity, null); }
/// <summary> /// Pan the camera (uses the media profile provided to the constructor) /// </summary> /// <param name="speed">Percent of max speed to move the camera (-1.00 to 1.00)</param> private void Pan(float speed) { RTSP_Viewer.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PTZConfigurationOptions ptzConfigurationOptions = PtzClient.GetConfigurationOptions(mediaProfile.PTZConfiguration.token); PTZSpeed velocity = new PTZSpeed(); velocity.PanTilt = new Vector2D() { x = speed * ptzConfigurationOptions.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Max, y = 0 }; PtzClient.ContinuousMove(mediaProfile.token, velocity, null); PtzMoving = true; }
private void zoomin(object sender, RoutedEventArgs e) { bool flag = combobox.Items.Count > 0 && combobox.SelectedIndex != 2; if (flag) { PTZClient pTZClient = GetPTZClient(); PTZConfigurationOptions configurationOptions = pTZClient.GetConfigurationOptions(profiles[combobox.SelectedIndex].PTZConfiguration.token); ROCKFIRM.PTZ.PTZSpeed velocity = new ROCKFIRM.PTZ.PTZSpeed { Zoom = new ROCKFIRM.PTZ.Vector1D { x = 0.5f } }; pTZClient.ContinuousMove(profiles[combobox.SelectedIndex].token, velocity, null); } }
void CheckOptionsAndConfiguration(PTZConfiguration configuration, PTZConfigurationOptions options) { bool ok = true; bool warning = false; StringBuilder sb = new StringBuilder(); ok = CheckConfigurationAndSpaces(configuration, options.Spaces, sb); if (options.PTZTimeout != null && !string.IsNullOrEmpty(configuration.DefaultPTZTimeout)) { double minTimeout = options.PTZTimeout.Min.DurationToSeconds(); double maxTimeout = options.PTZTimeout.Max.DurationToSeconds(); double timeout = configuration.DefaultPTZTimeout.DurationToSeconds(); if (double.IsNaN(minTimeout) || double.IsNaN(maxTimeout) || double.IsNaN(timeout)) { warning = true; sb.AppendLine("WARNING: some of timeout values contain date part. Comparison will be omitted."); } else { if (!(minTimeout <= timeout && maxTimeout >= timeout)) { ok = false; sb.AppendLine(string.Format("DefaultPTZTimeout ({0}) is out of range ([{1}, {2}])", configuration.DefaultPTZTimeout, options.PTZTimeout.Min, options.PTZTimeout.Max)); } } } BeginStep("Check that PTZ configuration and configuration options are consistent"); if (!ok) { throw new AssertException(sb.ToStringTrimNewLine()); } else { if (warning) { LogStepEvent(sb.ToStringTrimNewLine()); } } StepPassed(); }
public void PtzConfigurationAndOptionsConsistencyTest() { RunTest(() => { PTZConfiguration[] configurations = GetConfigurations(); Assert((configurations != null) && (configurations.Length > 0), Resources.ErrorNoPTZConfig_Text, Resources.StepValidateGetConfigurations_Title); foreach (PTZConfiguration configuration in configurations) { string token = configuration.token; PTZConfigurationOptions options = GetConfigurationOptions(token); string reason = null; Assert(ValidatePTZConfigurationOptions(options, configuration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); CheckOptionsAndConfiguration(configuration, options); } }); }
/// <summary> /// Combined Pan and Tilt of the camera (uses the media profile provided to the constructor) /// </summary> /// <param name="panSpeed">Percent of max speed to move the camera (-1.00 to 1.00)</param> /// <param name="tiltSpeed">Percent of max speed to move the camera (-1.00 to 1.00)</param> public void PanTilt(float panSpeed, float tiltSpeed) { RTSP_Viewer.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PTZConfigurationOptions ptzConfigurationOptions = PtzClient.GetConfigurationOptions(mediaProfile.PTZConfiguration.token); PTZSpeed velocity = new PTZSpeed(); velocity.PanTilt = new Vector2D() { x = panSpeed * ptzConfigurationOptions.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Max, y = tiltSpeed * ptzConfigurationOptions.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Max }; try { PtzClient.ContinuousMove(mediaProfile.token, velocity, null); PtzMoving = true; log.Debug("Pan/Tilt Ptz command sent"); } catch (Exception ex) { log.Error(string.Format("Exception executing Pan/Tilt command. {0}", ex.Message)); } }
/// <summary> /// Zoom the camera (uses the media profile provided to the constructor) /// </summary> /// <param name="speed">Percent of max speed to move the camera (-100 to 100). Negative zooms out, Positive zooms in</param> public void Zoom(int speed) { if (speed > 100) { speed = 100; } if (speed < -100) { speed = -100; } log.Debug(string.Format("Zoom @ velocity of {0}", speed)); RTSP_Viewer.OnvifMediaServiceReference.Profile mediaProfile = GetMediaProfile(); PTZConfigurationOptions ptzConfigurationOptions = PtzClient.GetConfigurationOptions(mediaProfile.PTZConfiguration.token); PTZSpeed velocity = new PTZSpeed(); velocity.Zoom = new Vector1D() { x = ((float)speed / 100) * ptzConfigurationOptions.Spaces.ContinuousZoomVelocitySpace[0].XRange.Max }; string timeout = null; //"PT5S"; try { PtzClient.ContinuousMove(mediaProfile.token, velocity, timeout); PtzMoving = true; } catch (Exception ex) { log.Error(string.Format("Exception executing Zoom command. {0}", ex.Message)); } }
public bool Initialise(string cameraAddress, string userName, string password) { bool result = false; try { var messageElement = new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.CreateVersion( EnvelopeVersion.Soap12, AddressingVersion.None) }; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement() { AuthenticationScheme = AuthenticationSchemes.Digest }; CustomBinding bind = new CustomBinding(messageElement, httpBinding); mediaClient = new MediaClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/Media")); mediaClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; mediaClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; mediaClient.ClientCredentials.HttpDigest.ClientCredential.Password = password; ptzClient = new PTZClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/PTZ")); ptzClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; ptzClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; ptzClient.ClientCredentials.HttpDigest.ClientCredential.Password = password; var profs = mediaClient.GetProfiles(); profile = mediaClient.GetProfile(profs[0].token); var configs = ptzClient.GetConfigurations(); options = ptzClient.GetConfigurationOptions(configs[0].token); velocity = new OnvifPTZService.PTZSpeed() { PanTilt = new OnvifPTZService.Vector2D() { x = 0, y = 0, space = options.Spaces.ContinuousPanTiltVelocitySpace[0].URI, }, Zoom = new OnvifPTZService.Vector1D() { x = 0, space = options.Spaces.ContinuousZoomVelocitySpace[0].URI, } }; if (relative) { timer = new Timer(TimerInterval); timer.Elapsed += Timer_Elapsed; velocity.PanTilt.space = options.Spaces.RelativePanTiltTranslationSpace[0].URI; panDistance = (options.Spaces.RelativePanTiltTranslationSpace[0].XRange.Max - options.Spaces.RelativePanTiltTranslationSpace[0].XRange.Min) / PanIncrements; tiltDistance = (options.Spaces.RelativePanTiltTranslationSpace[0].YRange.Max - options.Spaces.RelativePanTiltTranslationSpace[0].YRange.Min) / TiltIncrements; } vector = new PTZVector() { PanTilt = new OnvifPTZService.Vector2D() { x = 0, y = 0, space = options.Spaces.RelativePanTiltTranslationSpace[0].URI } }; ErrorMessage = ""; result = initialised = true; } catch (Exception ex) { ErrorMessage = ex.Message; } return(result); }
// public bool IsInitialized { get { return m_initialised; } } public override async Task <bool> InitalizeAsync() { if (this.m_onVifDevice.ServicesResponse == null) { bool b = await this.m_onVifDevice.InitalizeDeviceAsync(); if (this.m_onVifDevice.ServicesResponse == null) { return(false); } } try { foreach (var service in this.m_onVifDevice.ServicesResponse.Service) { if (service.Namespace == "http://www.onvif.org/ver20/ptz/wsdl") { string serviceAdress = service.XAddr; m_ErrorMessage = ""; // m_profile = this.m_media10Services.ProfilesResponse.Profiles[0]; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = AuthenticationSchemes.Digest; var messageElement = new TextMessageEncodingBindingElement(); messageElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None); CustomBinding binding = new CustomBinding(messageElement, httpBinding); this.m_ptzClient = new PTZClient(binding, new EndpointAddress(serviceAdress)); /* * while (m_ptzClient.Endpoint.EndpointBehaviors.Count > 0) * { * m_ptzClient.Endpoint.EndpointBehaviors.RemoveAt(0); * } */ m_ptzClient.Endpoint.EndpointBehaviors.Add(m_onVifDevice.GetBasicBasicAuthBehaviour); m_ptzClient.Endpoint.EndpointBehaviors.Add(m_onVifDevice.GetPasswordDigestBehavior); m_configs = await m_ptzClient.GetConfigurationsAsync(); m_options = await m_ptzClient.GetConfigurationOptionsAsync(m_configs.PTZConfiguration[0].token); m_capabilities = await m_ptzClient.GetServiceCapabilitiesAsync(); m_velocity = new OnvifPTZService.PTZSpeed() { PanTilt = new OnvifPTZService.Vector2D() { x = 0, y = 0, space = m_options.Spaces.ContinuousPanTiltVelocitySpace[0].URI, } , Zoom = new OnvifPTZService.Vector1D() { x = 0, space = m_options.Spaces.ContinuousZoomVelocitySpace[0].URI, } }; m_vector = new PTZVector() { PanTilt = new OnvifPTZService.Vector2D() { x = 0, y = 0, space = m_options.Spaces.RelativePanTiltTranslationSpace[0].URI } }; m_initialised = true; m_bMoveActiv = false; if (m_relative) { m_velocity.PanTilt.space = m_options.Spaces.ContinuousPanTiltVelocitySpace[0].URI; m_velocity.PanTilt.space = m_configs.PTZConfiguration[0].DefaultPTZSpeed.PanTilt.space; m_panDistance = (m_options.Spaces.RelativePanTiltTranslationSpace[0].XRange.Max - m_options.Spaces.RelativePanTiltTranslationSpace[0].XRange.Min) / PanIncrements; m_tiltDistance = (m_options.Spaces.RelativePanTiltTranslationSpace[0].YRange.Max - m_options.Spaces.RelativePanTiltTranslationSpace[0].YRange.Min) / TiltIncrements; } break; } } } catch (Exception ex) { m_ErrorMessage = ex.Message; throw new OnVifException("OnVifPTZController.InitalizeAsync", ex); // return false; } return(m_initialised); }
public bool Initialise(string cameraAddress, string userName, string password) { bool result = false; cam_ip = cameraAddress; cam_id = userName; cam_pw = password; //ConnectCam(); try { var messageElement = new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.CreateVersion( EnvelopeVersion.Soap12, AddressingVersion.None) }; HttpTransportBindingElement httpBinding = new HttpTransportBindingElement(); httpBinding.AuthenticationScheme = System.Net.AuthenticationSchemes.Digest; CustomBinding bind = new CustomBinding(messageElement, httpBinding); //mediaClient = new Media2Client(bind, // new EndpointAddress($"http://{cameraAddress}/onvif/device_service")); //mediaClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = // System.Security.Principal.TokenImpersonationLevel.Impersonation; //mediaClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; //mediaClient.ClientCredentials.HttpDigest.ClientCredential.Password = password; //ptzClient = new PTZClient(bind, // new EndpointAddress($"http://{cameraAddress}/onvif/device_service")); //ptzClient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = // System.Security.Principal.TokenImpersonationLevel.Impersonation; //ptzClient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; //ptzClient.ClientCredentials.HttpDigest.ClientCredential.Password = password; deviceclient = new DeviceClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/device_service")); deviceclient.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; deviceclient.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; deviceclient.ClientCredentials.HttpDigest.ClientCredential.Password = password; mediaClient10 = new MediaClient(bind, new EndpointAddress($"http://{cameraAddress}/onvif/media_service")); mediaClient10.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; mediaClient10.ClientCredentials.HttpDigest.ClientCredential.UserName = userName; mediaClient10.ClientCredentials.HttpDigest.ClientCredential.Password = password; //onvif ver 1.0 var profs = mediaClient10.GetProfiles(); profile10 = mediaClient10.GetProfile(profs[0].token); ONVIF_MediaProfilDashboard.Media10.StreamSetup streamSetup = new ONVIF_MediaProfilDashboard.Media10.StreamSetup() { }; streamSetup.Stream = StreamType.RTPUnicast; streamSetup.Transport = new Transport(); streamSetup.Transport.Protocol = TransportProtocol.RTSP; MediaUri mediaUri = mediaClient10.GetStreamUri(streamSetup, profs[0].token); //string string2222 = deviceclient.GetWsdlUrl(); var configs = ptzClient.GetConfigurations(); options = ptzClient.GetConfigurationOptions(configs[0].token); velocity = new OnvifPTZService.PTZSpeed() { PanTilt = new OnvifPTZService.Vector2D() { x = 0, y = 0, space = options.Spaces.ContinuousPanTiltVelocitySpace[0].URI, }, Zoom = new OnvifPTZService.Vector1D() { x = 0, space = options.Spaces.ContinuousZoomVelocitySpace[0].URI, } }; ErrorMessage = ""; result = initialised = true; } catch (Exception ex) { ErrorMessage = ex.Message; } return(result); }