public void GenericZoomTranslation() { RunTest(() => { PTZNode[] nodes = GetNodes(); foreach (PTZNode node in nodes) { // select node that supports RelativeZoomPositionSpace Space1DDescription[] relativeZoomSpaces = node.SupportedPTZSpaces.RelativeZoomTranslationSpace; if (relativeZoomSpaces != null) { LogTestEvent(string.Format("Node (token = {0}) supports RelativeZoom move{1}", node.token, System.Environment.NewLine)); } else { // if current node doesn't support RelativeZoomPositionSpace // then check next node continue; } // verify that RelativeZoomPositionSpace contains Translation Generic Zoom Space Space1DDescription translationGenericZoomSpace = relativeZoomSpaces.FirstOrDefault(space => space.URI == _relativeZoomSpace); Assert(translationGenericZoomSpace != null, "RelativeZoomPositionSpace element doesn't contain mandatory space", "Verifying of Translation Generic Zoom Space presence"); // verify that allowed range is specified Assert(translationGenericZoomSpace.XRange.Max >= translationGenericZoomSpace.XRange.Min, "Incorrect space range", "Verifying of space range"); // configure and select a media profile PTZConfigurationOptions options; Profile profile = GetPTZProfile(node, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); PTZVector vector = new PTZVector(); vector.Zoom = new Vector1D(); // check max ranges vector.Zoom.space = translationGenericZoomSpace.URI; vector.Zoom.x = translationGenericZoomSpace.XRange.Max; RelativeMove(profile.token, vector, null); // check min ranges vector.Zoom.space = translationGenericZoomSpace.URI; vector.Zoom.x = translationGenericZoomSpace.XRange.Min; RelativeMove(profile.token, vector, null); } }); }
public void GenericZoomVelocity() { RunTest(() => { PTZNode[] nodes = GetNodes(); foreach (PTZNode node in nodes) { string reason = null; Assert(ValidatePTZNode(node, out reason), reason, Resources.StepValidatePTZNode_Title); Space1DDescription[] spaces = node.SupportedPTZSpaces.ContinuousZoomVelocitySpace; Space1DDescription generic = spaces != null ? spaces.FirstOrDefault(space => string.Compare(space.URI, _continuousZoomSpace) == 0) : null; Assert((generic != null) && (generic.XRange != null), "Node does not support generic continuous zoom velocity space or space ranges are missing", "Validating generic continuous zoom velocity space"); PTZConfigurationOptions options; Profile profile = GetPTZProfile(node, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); //PTZNode node = GetNode(profile.PTZConfiguration.NodeToken); //check max ranges PTZSpeed velocity = new PTZSpeed(); velocity.Zoom = new Vector1D(); velocity.Zoom.space = generic.URI; velocity.Zoom.x = generic.XRange.Max; ContinuousMove(profile.token, velocity, null); RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); //check min ranges velocity.Zoom.x = generic.XRange.Min; ContinuousMove(profile.token, velocity, null); RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); Stop(profile.token, false, true); } }); }
public void Setup(PTZConfiguration config, PTZSpaces spaces) { absPanTiltPosition = GetDefaultSpace( spaces.absolutePanTiltPositionSpace, s => s.uri, config.defaultAbsolutePantTiltPositionSpace ); absZoomPosition = GetDefaultSpace( spaces.absoluteZoomPositionSpace, s => s.uri, config.defaultAbsoluteZoomPositionSpace ); relPanTiltTranslation = GetDefaultSpace( spaces.relativePanTiltTranslationSpace, s => s.uri, config.defaultRelativePanTiltTranslationSpace ); relZoomTranslation = GetDefaultSpace( spaces.relativeZoomTranslationSpace, s => s.uri, config.defaultRelativeZoomTranslationSpace ); contPanTiltVelocity = GetDefaultSpace( spaces.continuousPanTiltVelocitySpace, s => s.uri, config.defaultContinuousPanTiltVelocitySpace ); contZoomVelocity = GetDefaultSpace( spaces.continuousZoomVelocitySpace, s => s.uri, config.defaultContinuousZoomVelocitySpace ); absRelPanTiltSpeed = GetDefaultSpace( spaces.panTiltSpeedSpace, s => s.uri, config.IfNotNull(c => c.defaultPTZSpeed.IfNotNull(s => s.panTilt.IfNotNull(v => v.space))) ); absRelZoomSpeed = GetDefaultSpace( spaces.zoomSpeedSpace, s => s.uri, config.IfNotNull(c => c.defaultPTZSpeed.IfNotNull(s => s.zoom.IfNotNull(v => v.space))) ); }
public void GenericZoomPosition() { RunTest(() => { PTZNode[] nodes = GetNodes(); foreach (PTZNode node in nodes) { string reason = null; Assert(ValidatePTZNode(node, out reason), reason, Resources.StepValidatePTZNode_Title); Space1DDescription[] spaces = node.SupportedPTZSpaces.AbsoluteZoomPositionSpace; Space1DDescription generic = spaces != null ? spaces.FirstOrDefault(space => string.Compare(space.URI, _absoluteZoomSpace) == 0) : null; Assert((generic != null) && (generic.XRange != null), "Node does not support generic absolute zoom position space or space ranges are missing", "Validating generic absolute zoom position space"); PTZConfigurationOptions options; Profile profile = GetPTZProfile(node, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); //check max ranges PTZVector vector = new PTZVector(); vector.Zoom = new Vector1D(); vector.Zoom.space = generic.URI; vector.Zoom.x = generic.XRange.Max; AbsoluteMove(profile.token, vector, null); //check min ranges vector.Zoom.x = generic.XRange.Min; AbsoluteMove(profile.token, vector, null); } }); }
public void SetGetPreset() { string presetToken = null; Profile profile = null; RunTest(() => { Assert(Features.ContainsFeature(Feature.PTZAbsoluteOrRelative), "No Absolute or Relative movement is supported", "Check that Absolute or Relative movement is supported"); PTZConfigurationOptions options; profile = GetPTZProfile(_ptzNodeToken, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); string reason; Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); //absolute or relative move should be supported - use generic space for position or translation bool absoluteMoveSupported = Features.Contains(Feature.PTZAbsolute); PTZVector vector = new PTZVector(); Space2DDescription pantiltSpace = null; Space1DDescription zoomSpace = null; // pantilt movement is used if corresponding Pan/Tilt is supported bool panTilt = (absoluteMoveSupported && Features.ContainsFeature(Feature.PTZAbsolutePanTilt)) || (!absoluteMoveSupported && Features.ContainsFeature(Feature.PTZRelativePanTilt)); bool absoluteZoom = absoluteMoveSupported && Features.Contains(Feature.PTZAbsoluteZoom); bool relativeZoom = !absoluteMoveSupported && Features.Contains(Feature.PTZRelativeZoom); bool zoom = absoluteZoom || relativeZoom; if (panTilt) { pantiltSpace = absoluteMoveSupported ? options.Spaces.AbsolutePanTiltPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absolutePanTiltSpace, true) == 0) : options.Spaces.RelativePanTiltTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativePanTiltSpace, true) == 0); vector.PanTilt = new Vector2D(); vector.PanTilt.space = pantiltSpace.URI; vector.PanTilt.x = pantiltSpace.XRange.Min / 2; vector.PanTilt.y = pantiltSpace.YRange.Min / 2; } if (zoom) { zoomSpace = absoluteZoom ? options.Spaces.AbsoluteZoomPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absoluteZoomSpace, true) == 0) : options.Spaces.RelativeZoomTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativeZoomSpace, true) == 0); vector.Zoom = new Vector1D(); vector.Zoom.space = zoomSpace.URI; vector.Zoom.x = zoomSpace.XRange.Min; } if (absoluteMoveSupported) { AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); string presetName = "Test"; presetToken = SetPreset(profile.token, presetName, null); PTZPreset[] presets = GetPresets(profile.token); CheckPreset(presets, presetToken, presetName, vector, pantiltSpace, zoomSpace); //move to another position if (vector.PanTilt != null) { vector.PanTilt.x = pantiltSpace.XRange.Max / 2; vector.PanTilt.y = pantiltSpace.YRange.Max / 2; } if (vector.Zoom != null) { vector.Zoom.x = zoomSpace.XRange.Max; } if (absoluteMoveSupported) { AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); SetPreset(profile.token, presetName, presetToken); presets = GetPresets(profile.token); if (!absoluteMoveSupported && (vector.PanTilt != null)) { //in case of relative move consider camera should return to 0,0 vector.PanTilt.x = 0; vector.PanTilt.y = 0; } CheckPreset(presets, presetToken, presetName, vector, pantiltSpace, zoomSpace); RemovePreset(profile.token, presetToken); presetToken = null; }, () => { if ((presetToken != null) && (profile != null)) { RemovePreset(profile.token, presetToken); } }); }
public void GotoPreset() { string presetToken = null; Profile profile = null; RunTest(() => { Assert(Features.ContainsFeature(Feature.PTZAbsoluteOrRelative), "No Absolute or Relative movement is supported", "Check that Absolute or Relative movement is supported"); PTZConfigurationOptions options; profile = GetPTZProfile(_ptzNodeToken, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); string reason; Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); //absolute or relative move should be supported - use generic space for position or translation bool absoluteMoveSupported = Features.Contains(Feature.PTZAbsolute); // pantilt movement is used if correcponding Pan/Tilt is supported bool panTilt = (absoluteMoveSupported && Features.ContainsFeature(Feature.PTZAbsolutePanTilt)) || (!absoluteMoveSupported && Features.ContainsFeature(Feature.PTZRelativePanTilt)); bool absoluteZoom = absoluteMoveSupported && Features.Contains(Feature.PTZAbsoluteZoom); bool relativeZoom = !absoluteMoveSupported && Features.Contains(Feature.PTZRelativeZoom); bool zoom = absoluteZoom || relativeZoom; PTZVector vector = new PTZVector(); Space2DDescription pantiltSpace = null; Space1DDescription zoomSpace = null; if (panTilt) { pantiltSpace = absoluteMoveSupported ? options.Spaces.AbsolutePanTiltPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absolutePanTiltSpace, true) == 0) : options.Spaces.RelativePanTiltTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativePanTiltSpace, true) == 0); vector.PanTilt = new Vector2D(); vector.PanTilt.space = pantiltSpace.URI; vector.PanTilt.x = pantiltSpace.XRange.Min; vector.PanTilt.y = pantiltSpace.YRange.Min; } if (zoom) { zoomSpace = absoluteMoveSupported ? options.Spaces.AbsoluteZoomPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absoluteZoomSpace, true) == 0) : options.Spaces.RelativeZoomTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativeZoomSpace, true) == 0); vector.Zoom = new Vector1D(); vector.Zoom.space = zoomSpace.URI; vector.Zoom.x = zoomSpace.XRange.Min; } if (absoluteMoveSupported) { // correct PanTilt values according to PanTiltLimits field if (profile.PTZConfiguration.PanTiltLimits != null) { vector.PanTilt.x = profile.PTZConfiguration.PanTiltLimits.Range.XRange.Min; vector.PanTilt.y = profile.PTZConfiguration.PanTiltLimits.Range.YRange.Min; } // correct Zoom value according to ZoomLimits field if (profile.PTZConfiguration.ZoomLimits != null) { vector.Zoom.x = profile.PTZConfiguration.ZoomLimits.Range.XRange.Min; } AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } RunStep(() => Thread.Sleep(OperationDelay), string.Format("Waiting {0} seconds for camera to move", OperationDelay / 1000)); string presetName = "Test"; presetToken = SetPreset(profile.token, presetName, null); //move to another position Vector2D oldPanTilt = vector.PanTilt; if (oldPanTilt != null) { vector.PanTilt = new Vector2D(); vector.PanTilt.space = oldPanTilt.space; vector.PanTilt.x = pantiltSpace.XRange.Max; vector.PanTilt.y = pantiltSpace.YRange.Max; } Vector1D oldZoom = vector.Zoom; if (oldZoom != null) { vector.Zoom = new Vector1D(); vector.Zoom.space = oldZoom.space; vector.Zoom.x = zoomSpace.XRange.Max; } if (absoluteMoveSupported) { // correct PanTilt values according to PanTiltLimits field if (profile.PTZConfiguration.PanTiltLimits != null) { vector.PanTilt.x = profile.PTZConfiguration.PanTiltLimits.Range.XRange.Max; vector.PanTilt.y = profile.PTZConfiguration.PanTiltLimits.Range.YRange.Max; } // correct Zoom value according to ZoomLimits field if (profile.PTZConfiguration.ZoomLimits != null) { if (profile.PTZConfiguration.ZoomLimits.Range != null && profile.PTZConfiguration.ZoomLimits.Range.URI != null && vector.Zoom.space != null && profile.PTZConfiguration.ZoomLimits.Range.URI == vector.Zoom.space) { vector.Zoom.x = profile.PTZConfiguration.ZoomLimits.Range.XRange.Max; } } AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } RunStep(() => Thread.Sleep(OperationDelay), string.Format("Waiting {0} seconds for camera to move", OperationDelay / 1000)); GotoPreset(profile.token, presetToken, null); RunStep(() => Thread.Sleep(OperationDelay), string.Format("Waiting {0} seconds for camera to move", OperationDelay / 1000)); PTZStatus status = GetPTZStatus(profile.token); vector.PanTilt = oldPanTilt; vector.Zoom = oldZoom; if (status.Position != null) { CheckPTZPosition(status.Position, vector, vector, pantiltSpace, zoomSpace); } RemovePreset(profile.token, presetToken); presetToken = null; }, () => { CloseVideo(); if ((presetToken != null) && (profile != null)) { RemovePreset(profile.token, presetToken); } }); }
void CompareConfigurations(PTZConfiguration configuration1, PTZConfiguration configuration2) { bool ok = true; bool currentOk; StringBuilder sb = new StringBuilder(); //Name if (configuration1.Name != configuration2.Name) { ok = false; sb.AppendLine("'Name' properties are different"); } //Name if (configuration1.token != configuration2.token) { ok = false; sb.AppendLine("'token' properties are different"); } //UseCount if (configuration1.UseCount != configuration2.UseCount) { ok = false; sb.AppendLine("'UseCount' properties are different"); } //DefaultAbsolutePantTiltPositionSpace currentOk = StringsAreEqual(configuration1.DefaultAbsolutePantTiltPositionSpace, configuration2.DefaultAbsolutePantTiltPositionSpace, "DefaultAbsolutePantTiltPositionSpace", sb); ok = ok && currentOk; //DefaultAbsoluteZoomPositionSpace currentOk = StringsAreEqual(configuration1.DefaultAbsoluteZoomPositionSpace, configuration2.DefaultAbsoluteZoomPositionSpace, "DefaultAbsoluteZoomPositionSpace", sb); ok = ok && currentOk; //DefaultContinuousPanTiltVelocitySpace currentOk = StringsAreEqual(configuration1.DefaultContinuousPanTiltVelocitySpace, configuration2.DefaultContinuousPanTiltVelocitySpace, "DefaultContinuousPanTiltVelocitySpace", sb); ok = ok && currentOk; //DefaultContinuousZoomVelocitySpace currentOk = StringsAreEqual(configuration1.DefaultContinuousZoomVelocitySpace, configuration2.DefaultContinuousZoomVelocitySpace, "DefaultContinuousZoomVelocitySpace", sb); ok = ok && currentOk; //DefaultPTZSpeed if (configuration1.DefaultPTZSpeed != null && configuration2.DefaultPTZSpeed != null) { PTZSpeed speed1 = configuration1.DefaultPTZSpeed; PTZSpeed speed2 = configuration2.DefaultPTZSpeed; if (speed1.PanTilt != null && speed2.PanTilt != null) { if (!(speed1.PanTilt.space == speed2.PanTilt.space && speed1.PanTilt.x == speed2.PanTilt.x && speed1.PanTilt.y == speed2.PanTilt.y)) { ok = false; sb.AppendLine("PanTilt settings in DefaultPTZSpeed are different"); } } else if (!(speed1.PanTilt == null && speed2.PanTilt == null)) { ok = false; sb.AppendLine("PanTilt settings in DefaultPTZSpeed are defined for only one configuration"); } if (speed1.Zoom != null && speed2.Zoom != null) { if (!(speed1.Zoom.space == speed2.Zoom.space && speed1.Zoom.x == speed2.Zoom.x)) { ok = false; sb.AppendLine("Zoom settings in DefaultPTZSpeed are different"); } } else if (!(speed1.Zoom == null && speed2.Zoom == null)) { ok = false; sb.AppendLine("Zoom settings in DefaultPTZSpeed are defined for only one configuration"); } } else { if (!(configuration1.DefaultPTZSpeed == null && configuration2.DefaultPTZSpeed == null)) { ok = false; sb.AppendLine("DefaultPTZSpeed are defined for only one configuration"); } } //DefaultPTZTimeout //currentOk = StringsAreEqual(configuration1.DefaultPTZTimeout, // configuration2.DefaultPTZTimeout, // "DefaultPTZTimeout", sb); //ok = ok && currentOk; //DefaultRelativePanTiltTranslationSpace currentOk = StringsAreEqual(configuration1.DefaultRelativePanTiltTranslationSpace, configuration2.DefaultRelativePanTiltTranslationSpace, "DefaultRelativePanTiltTranslationSpace", sb); ok = ok && currentOk; //DefaultRelativeZoomTranslationSpace currentOk = StringsAreEqual(configuration1.DefaultRelativeZoomTranslationSpace, configuration2.DefaultRelativeZoomTranslationSpace, "DefaultRelativeZoomTranslationSpace", sb); ok = ok && currentOk; //NodeToken if (configuration1.NodeToken != configuration2.NodeToken) { ok = false; sb.AppendLine("'NodeToken' properties are different"); } //PanTiltLimits if (configuration1.PanTiltLimits != null && configuration2.PanTiltLimits != null) { Space2DDescription range1 = configuration1.PanTiltLimits.Range; Space2DDescription range2 = configuration2.PanTiltLimits.Range; if (range1 != null && range2 != null) { if (range1.URI != range2.URI) { ok = false; sb.AppendLine("URI in 'PanTiltLimits' ranges are different"); } FloatRange r1 = range1.XRange; FloatRange r2 = range2.XRange; if (r1 != null && r2 != null) { if (r1.Max != r2.Max || r1.Min != r2.Min) { ok = false; sb.AppendLine("XRange in PanTiltLimits range are different"); } } else { if (!(r1 == null && r2 == null)) { ok = false; sb.AppendLine("XRange in PanTiltLimits range is defined for only one configuration"); } } r1 = range1.YRange; r2 = range2.YRange; if (r1 != null && r2 != null) { if (r1.Max != r2.Max || r1.Min != r2.Min) { ok = false; sb.AppendLine("YRange in PanTiltLimits range are different"); } } else { if (!(r1 == null && r2 == null)) { ok = false; sb.AppendLine("YRange in PanTiltLimits range is defined for only one configuration"); } } } else { ok = false; sb.AppendLine("'PanTiltLimits' range is defined for only one configuration"); } } else { if (!(configuration1.PanTiltLimits == null && configuration2.PanTiltLimits == null)) { ok = false; sb.AppendLine("PanTiltLimits are defined for only one configuration"); } } //ZoomLimits if (configuration1.ZoomLimits != null && configuration2.ZoomLimits != null) { Space1DDescription range1 = configuration1.ZoomLimits.Range; Space1DDescription range2 = configuration2.ZoomLimits.Range; if (range1 != null && range2 != null) { if (range1.URI != range2.URI) { ok = false; sb.AppendLine("URI in ZoomLimits ranges are different"); } FloatRange r1 = range1.XRange; FloatRange r2 = range2.XRange; if (r1 != null && r2 != null) { if (r1.Max != r2.Max || r1.Min != r2.Min) { ok = false; sb.AppendLine("XRange in ZoomLimits range are different"); } } else { if (!(r1 == null && r2 == null)) { ok = false; sb.AppendLine("XRange in ZoomLimits range is defined for only one configuration"); } } } else { ok = false; sb.AppendLine("'ZoomLimits' range is defined for only one configuration"); } } else { if (!(configuration1.ZoomLimits == null && configuration2.ZoomLimits == null)) { ok = false; sb.AppendLine("ZoomLimits are defined for only one configuration"); } } Assert(ok, sb.ToStringTrimNewLine(), "Check that configurations are the same"); }
public void GenericZoomSpeed() { RunTest(() => { Assert(Features.ContainsFeature(Feature.PTZAbsoluteOrRelativeZoom), "No Absolute or Relative Zoom movement is supported", "Check that Absolute or Relative Zoom movement is supported"); PTZNode[] nodes = GetNodes(); foreach (PTZNode node in nodes) { string reason = null; Assert(ValidatePTZNode(node, out reason), reason, Resources.StepValidatePTZNode_Title); Space1DDescription[] spaces = node.SupportedPTZSpaces.ZoomSpeedSpace; Space1DDescription generic = spaces != null ? spaces.FirstOrDefault(space => string.Compare(space.URI, _speedZoomSpace) == 0) : null; Assert((generic != null) && (generic.XRange != null), "Node does not support generic zoom speed space or space ranges are missing", "Validating generic zoom speed space"); PTZConfigurationOptions options; Profile profile = GetPTZProfile(node, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.token, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); //check max ranges bool absoulteMoveSupported = Features.Contains(Feature.PTZAbsoluteZoom); PTZVector vector = new PTZVector(); vector.Zoom = new Vector1D(); //absolute or relative move should be supported - use generic space for position or translation Space1DDescription zoomSpace = absoulteMoveSupported ? options.Spaces.AbsoluteZoomPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absoluteZoomSpace, true) == 0) : options.Spaces.RelativeZoomTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativeZoomSpace, true) == 0); vector.Zoom.space = zoomSpace.URI; vector.Zoom.x = zoomSpace.XRange.Min; PTZSpeed speed = new PTZSpeed(); speed.Zoom = new Vector1D(); speed.Zoom.space = generic.URI; speed.Zoom.x = generic.XRange.Max; if (absoulteMoveSupported) { AbsoluteMove(profile.token, vector, speed); } else { RelativeMove(profile.token, vector, speed); } //check min ranges speed.Zoom.x = generic.XRange.Min; if (absoulteMoveSupported) { AbsoluteMove(profile.token, vector, speed); } else { RelativeMove(profile.token, vector, speed); } } }); }
public void GenericZoomVelocityBis() { RunTest(() => { PTZNode[] nodes = GetNodes(); int Count = 0; foreach (PTZNode node in nodes) { // select node that supports ContinuousZoomPositionSpace Space1DDescription[] spaces = node.SupportedPTZSpaces.ContinuousZoomVelocitySpace; if (spaces != null) { LogTestEvent(string.Format("Node (token = {0}) supports ContinuousZoom move{1}", node.token, System.Environment.NewLine)); } else { // if current node doesn't support RelativeZoomPositionSpace // then check next node continue; } Count++; // verify that ContinuousZoomPositionSpace contains Velocity Generic Zoom Space Space1DDescription generic = spaces.FirstOrDefault(space => space.URI == _continuousZoomSpace); Assert((generic != null) && (generic.XRange != null), "ContinuousZoomVelocitySpace element doesn't contain mandatory space", "Verifying of Continuous Generic Zoom Space presence"); // verify that allowed range is specified Assert(generic.XRange.Max >= generic.XRange.Min, "Incorrect space range", "Verifying of space range"); // configure and select a media profile PTZConfigurationOptions options; Profile profile = GetPTZProfile(node, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); PTZSpeed velocity = new PTZSpeed(); velocity.Zoom = new Vector1D(); velocity.Zoom.space = generic.URI; // check max ranges velocity.Zoom.x = generic.XRange.Max; ContinuousMove(profile.token, velocity, null); RunStep(() => Thread.Sleep(OperationDelay), string.Format("Waiting {0} seconds for camera to move", OperationDelay / 1000)); // check min ranges velocity.Zoom.x = generic.XRange.Min; ContinuousMove(profile.token, velocity, null); RunStep(() => Thread.Sleep(10000), "Waiting 10 seconds for camera to move"); Stop(profile.token, false, true); } //Assert(Count > 0, // "Continuous is a must, but no nodes support it", // "Verifying ContinuousZoom support nodes count"); }); }
public void GenericZoomSpeedBis() { RunTest(() => { PTZNode[] nodes = GetNodes(); foreach (PTZNode node in nodes) { // select node that supports SpeedZoomSpace Space1DDescription[] spaces = node.SupportedPTZSpaces.ZoomSpeedSpace; if (spaces != null) { LogTestEvent(string.Format("Node (token = {0}) supports Speed for Zoom move{1}", node.token, System.Environment.NewLine)); } else { // if current node doesn't support SpeedZoomSpace // then check next node continue; } // verify that SpeedZoomSpace contains Speed Generic Zoom Space Space1DDescription generic = spaces.FirstOrDefault(space => space.URI == _speedZoomSpace); Assert((generic != null) && (generic.XRange != null), "SpeedZoomSpace element doesn't contain mandatory space", "Verifying of Speed Generic Zoom Space presence"); // verify that allowed range is specified Assert(generic.XRange.Max >= generic.XRange.Min, "Incorrect space range", "Verifying of space range"); // configure and select a media profile PTZConfigurationOptions options; Profile profile = GetPTZProfile(node, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); Assert(!(null == options.Spaces.AbsoluteZoomPositionSpace && null == options.Spaces.RelativeZoomTranslationSpace), "There are no options for Absolute command nor Relative move command in the selected PTZ configuration", "Check there are options for Absolute command or Relative move command in selected PTZ configuration"); // check max range PTZVector vector = new PTZVector(); vector.Zoom = new Vector1D(); PTZSpeed speed = new PTZSpeed(); speed.Zoom = new Vector1D(); Space1DDescription zoomSpace = null; bool Absolute = true; try { //absolute or relative move should be supported - use generic space for position or translation zoomSpace = options.Spaces.AbsoluteZoomPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absoluteZoomSpace, true) == 0); vector.Zoom.space = zoomSpace.URI; vector.Zoom.x = zoomSpace.XRange.Max; speed.Zoom.space = generic.URI; speed.Zoom.x = generic.XRange.Max; // correct Zoom value according to ZoomLimits field if (profile.PTZConfiguration.ZoomLimits != null) { vector.Zoom.x = profile.PTZConfiguration.ZoomLimits.Range.XRange.Max; } AbsoluteMove(profile.token, vector, speed); } catch (System.Exception) { Absolute = false; zoomSpace = options.Spaces.RelativeZoomTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativeZoomSpace, true) == 0); vector.Zoom.space = zoomSpace.URI; vector.Zoom.x = zoomSpace.XRange.Max; RelativeMove(profile.token, vector, speed); } // check min range vector.Zoom.x = zoomSpace.XRange.Min; speed.Zoom.x = generic.XRange.Min; if (Absolute) { // correct Zoom value according to ZoomLimits field if (profile.PTZConfiguration.ZoomLimits != null) { vector.Zoom.x = profile.PTZConfiguration.ZoomLimits.Range.XRange.Min; } AbsoluteMove(profile.token, vector, speed); } else { RelativeMove(profile.token, vector, speed); } } }); }
public void RelativeMoveTest() { RunTest(() => { PTZConfigurationOptions options; Profile profile = GetPTZProfile(_ptzNodeToken, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); string reason = null; Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); Assert(options.Spaces.RelativePanTiltTranslationSpace != null || options.Spaces.RelativeZoomTranslationSpace != null, "Node does not support Relative move", "Check if Relative move is supported"); //Set default spaces to generic, if they are not. We need it to get position in generic spaces bool changed = false; string dump = string.Empty; BeginStep("Check if configuration needs to be updated"); if (Features.Contains(Feature.PTZRelativePanTilt) && (string.IsNullOrEmpty(profile.PTZConfiguration.DefaultRelativePanTiltTranslationSpace) || !EqualSpaces(_relativePanTiltSpace, profile.PTZConfiguration.DefaultRelativePanTiltTranslationSpace))) { profile.PTZConfiguration.DefaultRelativePanTiltTranslationSpace = _relativePanTiltSpace; changed = true; dump = string.Format("DefaultRelativePanTiltTranslationSpace={0}", profile.PTZConfiguration.DefaultRelativePanTiltTranslationSpace); } if (Features.Contains(Feature.PTZRelativeZoom) && (string.IsNullOrEmpty(profile.PTZConfiguration.DefaultRelativeZoomTranslationSpace) || !EqualSpaces(_relativeZoomSpace, profile.PTZConfiguration.DefaultRelativeZoomTranslationSpace))) { profile.PTZConfiguration.DefaultRelativeZoomTranslationSpace = _relativeZoomSpace; changed = true; if (!string.IsNullOrEmpty(dump)) { dump += ", "; } dump += string.Format("DefaultRelativeZoomTranslationSpace={0}", profile.PTZConfiguration.DefaultRelativeZoomTranslationSpace); } StepPassed(); if (changed) { SetConfiguration(profile.PTZConfiguration, false, dump); } PTZStatus status = GetPTZStatus(profile.token); PTZVector oldPosition = status.Position; PTZVector pantilt = null; PTZVector zoom = null; Space1DDescription zoomOptions = null; if (Features.Contains(Feature.PTZRelativeZoom)) { zoomOptions = options.Spaces.RelativeZoomTranslationSpace.FirstOrDefault( o => string.Compare(o.URI, _relativeZoomSpace, true) == 0); } Space2DDescription pantiltOptions = null; if (Features.Contains(Feature.PTZRelativePanTilt)) { pantiltOptions = options.Spaces.RelativePanTiltTranslationSpace.FirstOrDefault( o => string.Compare(o.URI, _relativePanTiltSpace, true) == 0); } if (Features.Contains(Feature.PTZRelativePanTilt)) { PTZSpeed speed = null; if ((options.Spaces.PanTiltSpeedSpace != null) && (options.Spaces.PanTiltSpeedSpace.Length > 0)) { Space1DDescription space = options.Spaces.PanTiltSpeedSpace[0]; speed = new PTZSpeed(); speed.PanTilt = new Vector2D(); speed.PanTilt.space = space.URI; speed.PanTilt.x = space.XRange.Max; speed.PanTilt.y = space.XRange.Max; } pantilt = new PTZVector(); pantilt.PanTilt = new Vector2D(); //use generic space, so we can calculate new position pantilt.PanTilt.space = pantiltOptions.URI; //options.Spaces.RelativePanTiltTranslationSpace[0].URI; pantilt.PanTilt.x = pantiltOptions.XRange.Max; // options.Spaces.RelativePanTiltTranslationSpace[0].XRange.Max; pantilt.PanTilt.y = pantiltOptions.YRange.Max; // options.Spaces.RelativePanTiltTranslationSpace[0].YRange.Max; RelativeMove(profile.token, pantilt, speed); } if (Features.Contains(Feature.PTZRelativeZoom)) { PTZSpeed speed = null; if ((options.Spaces.ZoomSpeedSpace != null) && (options.Spaces.ZoomSpeedSpace.Length > 0)) { Space1DDescription space = options.Spaces.ZoomSpeedSpace[0]; speed = new PTZSpeed(); speed.Zoom = new Vector1D(); speed.Zoom.space = space.URI; speed.Zoom.x = space.XRange.Max; } zoom = new PTZVector(); zoom.Zoom = new Vector1D(); zoom.Zoom.space = zoomOptions.URI; zoom.Zoom.x = zoomOptions.XRange.Max; RelativeMove(profile.token, zoom, speed); } status = GetPTZStatus(profile.token); if ((status.Position != null) && (oldPosition != null)) { //translate position if ((oldPosition.PanTilt != null) && (pantilt != null)) { pantilt.PanTilt.x = pantilt.PanTilt.x + oldPosition.PanTilt.x > 1 ? 1 : pantilt.PanTilt.x + oldPosition.PanTilt.x; pantilt.PanTilt.y = pantilt.PanTilt.y + oldPosition.PanTilt.y > 1 ? 1 : pantilt.PanTilt.y + oldPosition.PanTilt.y; } if ((oldPosition.Zoom != null) && (zoom != null)) { zoom.Zoom.x = zoom.Zoom.x + oldPosition.Zoom.x > 1 ? 1 : zoom.Zoom.x + oldPosition.Zoom.x; } //change relative spaces to absolute spaces, because status returns position in absolute space if (pantilt != null) { pantilt.PanTilt.space = _absolutePanTiltSpace; } if (zoom != null) { zoom.Zoom.space = _absoluteZoomSpace; } CheckPTZPosition(status.Position, pantilt, zoom, pantiltOptions, zoomOptions); } }); }
public void AbsoluteMoveTest() { RunTest(() => { PTZConfigurationOptions options; Media.Profile profile = GetPTZProfile(_ptzNodeToken, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); string reason = null; Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); //select pantilt and zoom spaces Space2DDescription pantiltSpace = null; Space1DDescription zoomSpace = null; if (Features.Contains(Feature.PTZAbsolutePanTilt)) { pantiltSpace = options.Spaces.AbsolutePanTiltPositionSpace[0]; } if (Features.Contains(Feature.PTZAbsoluteZoom)) { zoomSpace = options.Spaces.AbsoluteZoomPositionSpace[0]; } //set selected spaces as default if they are not (we need it to get position in these spaces) if (((pantiltSpace != null) && !EqualSpaces(pantiltSpace.URI, profile.PTZConfiguration.DefaultAbsolutePantTiltPositionSpace)) || ((zoomSpace != null) && !EqualSpaces(zoomSpace.URI, profile.PTZConfiguration.DefaultAbsoluteZoomPositionSpace))) { profile.PTZConfiguration.DefaultAbsolutePantTiltPositionSpace = pantiltSpace != null ? pantiltSpace.URI : null; profile.PTZConfiguration.DefaultAbsoluteZoomPositionSpace = zoomSpace != null ? zoomSpace.URI : null; SetConfiguration(profile.PTZConfiguration, false, string.Format("DefaultAbsolutePantTiltPositionSpace={0}, DefaultAbsoluteZoomPositionSpace={1}", profile.PTZConfiguration.DefaultAbsolutePantTiltPositionSpace, profile.PTZConfiguration.DefaultAbsoluteZoomPositionSpace)); } PTZStatus status = GetPTZStatus(profile.token); PTZVector pantilt = null; PTZVector zoom = null; if (pantiltSpace != null) { PTZSpeed speed = null; if ((options.Spaces.PanTiltSpeedSpace != null) && (options.Spaces.PanTiltSpeedSpace.Length > 0)) { Space1DDescription space = options.Spaces.PanTiltSpeedSpace[0]; speed = new PTZSpeed(); speed.PanTilt = new Vector2D(); speed.PanTilt.space = space.URI; speed.PanTilt.x = space.XRange.Max; speed.PanTilt.y = space.XRange.Max; } pantilt = new PTZVector(); pantilt.PanTilt = new Vector2D(); pantilt.PanTilt.space = pantiltSpace.URI; pantilt.PanTilt.x = pantiltSpace.XRange.Max; pantilt.PanTilt.y = pantiltSpace.YRange.Max; AbsoluteMove(profile.token, pantilt, speed); } if (zoomSpace != null) { PTZSpeed speed = null; if ((options.Spaces.ZoomSpeedSpace != null) && (options.Spaces.ZoomSpeedSpace.Length > 0)) { Space1DDescription space = options.Spaces.ZoomSpeedSpace[0]; speed = new PTZSpeed(); speed.Zoom = new Vector1D(); speed.Zoom.space = space.URI; speed.Zoom.x = space.XRange.Max; } zoom = new PTZVector(); zoom.Zoom = new Vector1D(); zoom.Zoom.space = zoomSpace.URI; zoom.Zoom.x = zoomSpace.XRange.Max; AbsoluteMove(profile.token, zoom, speed); } status = GetPTZStatus(profile.token); if (status.Position != null) { CheckPTZPosition(status.Position, pantilt, zoom); } }); }
public void ConfigurableHome() { RunTest(() => { Assert(Features.ContainsFeature(Feature.PTZAbsoluteOrRelative), "No Absolute or Relative movement is supported", "Check that Absolute or Relative movement is supported"); PTZConfigurationOptions options; Profile profile = GetPTZProfile(_ptzNodeToken, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); string reason; Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); //absolute or relative move should be supported - use generic space for position or translation bool absoluteMoveSupported = Features.Contains(Feature.PTZAbsolute); Space2DDescription pantiltSpace = null; Space1DDescription zoomSpace = null; // pantilt movement is used if corresponding Pan/Tilt is supported bool panTilt = (absoluteMoveSupported && Features.ContainsFeature(Feature.PTZAbsolutePanTilt)) || (!absoluteMoveSupported && Features.ContainsFeature(Feature.PTZRelativePanTilt)); bool absoluteZoom = absoluteMoveSupported && Features.Contains(Feature.PTZAbsoluteZoom); bool relativeZoom = !absoluteMoveSupported && Features.Contains(Feature.PTZRelativeZoom); bool zoom = absoluteZoom || relativeZoom; PTZVector vector = new PTZVector(); if (panTilt) { pantiltSpace = absoluteMoveSupported ? options.Spaces.AbsolutePanTiltPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absolutePanTiltSpace, true) == 0) : options.Spaces.RelativePanTiltTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativePanTiltSpace, true) == 0); vector.PanTilt = new Vector2D(); vector.PanTilt.space = pantiltSpace.URI; vector.PanTilt.x = pantiltSpace.XRange.Min; vector.PanTilt.y = pantiltSpace.YRange.Min; } if (zoom) { zoomSpace = absoluteZoom ? options.Spaces.AbsoluteZoomPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absoluteZoomSpace, true) == 0) : options.Spaces.RelativeZoomTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativeZoomSpace, true) == 0); vector.Zoom = new Vector1D(); vector.Zoom.space = zoomSpace.URI; vector.Zoom.x = zoomSpace.XRange.Min; } if (absoluteMoveSupported) { AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); SetHomePosition(profile.token); //move to another position Vector2D oldPanTilt = vector.PanTilt; if (oldPanTilt != null) { vector.PanTilt = new Vector2D(); vector.PanTilt.space = oldPanTilt.space; vector.PanTilt.x = pantiltSpace.XRange.Max; vector.PanTilt.y = pantiltSpace.YRange.Max; } Vector1D oldZoom = vector.Zoom; if (oldZoom != null) { vector.Zoom = new Vector1D(); vector.Zoom.space = oldZoom.space; vector.Zoom.x = zoomSpace.XRange.Max; } if (absoluteMoveSupported) { AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); GotoHomePosition(profile.token, null, _homeMoveTimeout); RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); PTZStatus status = GetPTZStatus(profile.token); vector.PanTilt = oldPanTilt; vector.Zoom = oldZoom; if (status.Position != null) { CheckPTZPosition(status.Position, vector, vector, pantiltSpace, zoomSpace); } }, () => { CloseVideo(); }); }
public void FixedHome() { RunTest(() => { Assert(Features.ContainsFeature(Feature.PTZAbsoluteOrRelative), "No Absolute or Relative movement is supported", "Check that Absolute or Relative movement is supported"); PTZConfigurationOptions options; Profile profile = GetPTZProfile(_ptzNodeToken, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); string reason; Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); GotoHomePosition(profile.token, null, _homeMoveTimeout); //absolute or relative move should be supported - use generic space for position or translation bool absoluteMoveSupported = Features.Contains(Feature.PTZAbsolute); // pantilt movement is used if correcponding Pan/Tilt is supported bool panTilt = (absoluteMoveSupported && Features.ContainsFeature(Feature.PTZAbsolutePanTilt)) || (!absoluteMoveSupported && Features.ContainsFeature(Feature.PTZRelativePanTilt)); bool absoluteZoom = absoluteMoveSupported && Features.Contains(Feature.PTZAbsoluteZoom); bool relativeZoom = !absoluteMoveSupported && Features.Contains(Feature.PTZRelativeZoom); bool zoom = absoluteZoom || relativeZoom; PTZVector vector = new PTZVector(); Space2DDescription pantiltSpace = null; Space1DDescription zoomSpace = null; if (panTilt) { pantiltSpace = absoluteMoveSupported ? options.Spaces.AbsolutePanTiltPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absolutePanTiltSpace, true) == 0) : options.Spaces.RelativePanTiltTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativePanTiltSpace, true) == 0); vector.PanTilt = new Vector2D(); vector.PanTilt.space = pantiltSpace.URI; vector.PanTilt.x = pantiltSpace.XRange.Max; vector.PanTilt.y = pantiltSpace.YRange.Max; } if (zoom) { zoomSpace = absoluteZoom ? options.Spaces.AbsoluteZoomPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absoluteZoomSpace, true) == 0) : options.Spaces.RelativeZoomTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativeZoomSpace, true) == 0); vector.Zoom = new Vector1D(); vector.Zoom.space = zoomSpace.URI; vector.Zoom.x = zoomSpace.XRange.Max; } //make sure current position is different to destination PTZStatus status = GetPTZStatus(profile.token); PTZVector homePosition = status.Position; if ((homePosition != null) && (EqualPositions(homePosition, vector))) { if (vector.PanTilt != null) { vector.PanTilt.x = 0; } else if (vector.Zoom != null) { vector.Zoom.x = 0; } } if (absoluteMoveSupported) { AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } double delay = ((double)_operationDelay) / 1000; RunStep(() => { Sleep(_operationDelay); }, string.Format("Waiting {0} seconds for camera to stop", delay.ToString("0.000"))); SetFixedHomePosition(profile.token); GotoHomePosition(profile.token, null, _homeMoveTimeout); status = GetPTZStatus(profile.token); if (status.Position != null) { CheckPTZPosition(status.Position, homePosition, homePosition, pantiltSpace, zoomSpace); } }, () => { CloseVideo(); }); }
private void Connect() { if (Initialized) { return; } try { DateTime deviceTime = GetDeviceTime(); if (!_connectionParameters.Credentials.IsEmpty()) { byte[] nonceBytes = new byte[20]; var random = new Random(); random.NextBytes(nonceBytes); var token = new SecurityToken(deviceTime, nonceBytes); _onvifClientFactory.SetSecurityToken(token); } _deviceCapabilities = GetDeviceCapabilities(); if (_deviceCapabilities?.Media?.XAddr == null) { throw new ApplicationException("No media endpoints found"); } var mediaUri = new Uri(_deviceCapabilities.Media.XAddr); var ep = new EndpointAddress(GetServiceUri(mediaUri.PathAndQuery)); var mediaClient = _onvifClientFactory.CreateClient <Media>(ep, _connectionParameters, MessageVersion.Soap12, _timeout); var profiles = mediaClient.GetProfiles(new GetProfilesRequest()).Profiles.ToList(); var streamSetup = new StreamSetup { Stream = StreamType.RTPUnicast, Transport = new Transport { Protocol = TransportProtocol.RTSP } }; List <MediaEndpoint> uris = new List <MediaEndpoint>(); for (var i = 0; i < profiles.Count(); i++) { var p = profiles[i]; MediaUri l; try { l = mediaClient.GetStreamUri(streamSetup, p.token); } catch (Exception ex) { profiles.Remove(p); i--; Logger.LogException(ex); continue; } //make sure using correct ip address (for external access) var u = new UriBuilder(l.Uri) { Host = ServiceUri.Host }; if (_rtspPort > 0) { u.Port = _rtspPort; } l.Uri = u.ToString(); if (!string.IsNullOrEmpty(_credential.UserName)) { l.Uri = l.Uri.ReplaceFirst("://", "://" + Uri.EscapeDataString(_credential.UserName) + ":" + Uri.EscapeDataString(_credential.Password) + "@"); } var s = p.VideoEncoderConfiguration; if (s != null) { uris.Add(new MediaEndpoint(l, s)); } else { var e = p.VideoSourceConfiguration; if (e != null) { uris.Add(new MediaEndpoint(l, e)); } } } _mediaEndpoints = uris.ToArray(); _profiles = profiles.ToArray(); DefaultPTSpeed = new Space2DDescription { XRange = { Max = 1, Min = -1 }, YRange = { Max = 1, Min = -1 }, URI = null }; DefaultZSpeed = new Space1DDescription { XRange = { Max = 1, Min = -1 }, URI = null }; try { if (_deviceCapabilities.PTZ != null) { var ptzUri = new Uri(_deviceCapabilities.PTZ.XAddr); ep = new EndpointAddress(GetServiceUri(ptzUri.PathAndQuery)); PTZ = _onvifClientFactory.CreateClient <PTZ>(ep, _connectionParameters, MessageVersion.Soap12, _timeout); try { var gc = PTZ.GetConfigurationsAsync(new GetConfigurationsRequest()).Result; var ptzcfg = PTZ.GetConfigurationOptions(gc.PTZConfiguration[0].NodeToken); DefaultPTSpeed = ptzcfg.Spaces.ContinuousPanTiltVelocitySpace[0]; DefaultZSpeed = ptzcfg.Spaces.ContinuousZoomVelocitySpace[0]; } catch (Exception ex) { //ignore - use defaults Logger.LogException(ex); } } } catch (Exception ex) { Logger.LogException(ex, "Onvif PTZ"); } Initialized = true; } catch (Exception ex) { _profiles = new Profile[] { }; _mediaEndpoints = new MediaEndpoint[] { }; Logger.LogException(ex, "ONVIF Device"); } }
public void GotoPreset() { string presetToken = null; Media.Profile profile = null; RunTest(() => { PTZConfigurationOptions options; profile = GetPTZProfile(_ptzNodeToken, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); string reason; Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.token, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); //absolute or relative move should be supported - use generic space for position or translation bool absoulteMoveSupported = Features.Contains(Feature.PTZAbsolute); PTZVector vector = new PTZVector(); Space2DDescription pantiltSpace = null; Space1DDescription zoomSpace = null; if (Features.Contains(Feature.PTZAbsolutePanTilt) || Features.Contains(Feature.PTZRelativePanTilt)) { pantiltSpace = absoulteMoveSupported ? options.Spaces.AbsolutePanTiltPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absolutePanTiltSpace, true) == 0) : options.Spaces.RelativePanTiltTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativePanTiltSpace, true) == 0); vector.PanTilt = new Vector2D(); vector.PanTilt.space = pantiltSpace.URI; vector.PanTilt.x = pantiltSpace.XRange.Min; vector.PanTilt.y = pantiltSpace.YRange.Min; } if (Features.Contains(Feature.PTZAbsoluteZoom) || Features.Contains(Feature.PTZRelativeZoom)) { zoomSpace = absoulteMoveSupported ? options.Spaces.AbsoluteZoomPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absoluteZoomSpace, true) == 0) : options.Spaces.RelativeZoomTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativeZoomSpace, true) == 0); vector.Zoom = new Vector1D(); vector.Zoom.space = zoomSpace.URI; vector.Zoom.x = zoomSpace.XRange.Min; } if (absoulteMoveSupported) { AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); string presetName = "Test"; presetToken = SetPreset(profile.token, presetName, null); //move to another position Vector2D oldPanTilt = vector.PanTilt; if (oldPanTilt != null) { vector.PanTilt = new Vector2D(); vector.PanTilt.space = oldPanTilt.space; vector.PanTilt.x = pantiltSpace.XRange.Max; vector.PanTilt.y = pantiltSpace.YRange.Max; } Vector1D oldZoom = vector.Zoom; if (oldZoom != null) { vector.Zoom = new Vector1D(); vector.Zoom.space = oldZoom.space; vector.Zoom.x = zoomSpace.XRange.Max; } if (absoulteMoveSupported) { AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); GotoPreset(profile.token, presetToken, null); RunStep(() => { Thread.Sleep(10000); }, string.Format("Waiting 10 seconds for camera to move")); PTZStatus status = GetPTZStatus(profile.token); vector.PanTilt = oldPanTilt; vector.Zoom = oldZoom; if (status.Position != null) { CheckPTZPosition(status.Position, vector, vector); } else { OpenVideo(); Assert(_operator.GetYesNoAnswer(string.Format("Is camera in position [{0}]?", PositionToString(vector))), "Camera is in wrong position", "Camera position check (manual)"); CloseVideo(); } RemovePreset(profile.token, presetToken); presetToken = null; }, () => { CloseVideo(); if ((presetToken != null) && (profile != null)) { RemovePreset(profile.token, presetToken); } }); }
bool CheckConfigurationAndSpaces(PTZConfiguration configuration, PTZSpaces spaces, StringBuilder sb) { bool ok = true; if (!string.IsNullOrEmpty(configuration.DefaultAbsolutePantTiltPositionSpace)) { bool supported = true; if (spaces.AbsolutePanTiltPositionSpace == null) { supported = false; } else { //DefaultAbsolutePanTiltPositionSpace from PTZConfiguration is not included in one of SupportedPTZSpaces.AbsolutePanTiltPositionSpace from GetNodesResponse. if (spaces.AbsolutePanTiltPositionSpace.Where( S => S.URI == configuration.DefaultAbsolutePantTiltPositionSpace).FirstOrDefault() == null) { supported = false; } } if (!supported) { ok = false; sb.AppendLine( string.Format("PanTiltPositionSpace with URI = '{0}' not found in SupportedPTZSpaces", configuration.DefaultAbsolutePantTiltPositionSpace)); } } // DefaultAbsoluteZoomPositionSpace from PTZConfiguration is not included in one of SupportedPTZSpaces.AbsoluteZoomPositionSpace from GetNodesResponse. if (!string.IsNullOrEmpty(configuration.DefaultAbsoluteZoomPositionSpace)) { bool supported = true; if (spaces.AbsoluteZoomPositionSpace == null) { supported = false; } else { if (spaces.AbsoluteZoomPositionSpace.Where( S => S.URI == configuration.DefaultAbsoluteZoomPositionSpace).FirstOrDefault() == null) { supported = false; } } if (!supported) { ok = false; sb.AppendLine( string.Format("AbsoluteZoomPositionSpace with URI = '{0}' not found in SupportedPTZSpaces", configuration.DefaultAbsoluteZoomPositionSpace)); } } // DefaultRelativePanTiltTranslationSpace from PTZConfiguration is not included in one of SupportedPTZSpaces.RelativePanTiltTranslationSpace from GetNodesResponse. if (!string.IsNullOrEmpty(configuration.DefaultRelativePanTiltTranslationSpace)) { bool supported = true; if (spaces.RelativePanTiltTranslationSpace == null) { supported = false; } else { if (spaces.RelativePanTiltTranslationSpace.Where( S => S.URI == configuration.DefaultRelativePanTiltTranslationSpace).FirstOrDefault() == null) { supported = false; } } if (!supported) { ok = false; sb.AppendLine( string.Format("RelativePanTiltTranslationSpace with URI = '{0}' not found in SupportedPTZSpaces", configuration.DefaultRelativePanTiltTranslationSpace)); } } // DefaultRelativeZoomTranslationSpace from PTZConfiguration is not included in one of SupportedPTZSpaces.RelativeZoomTranslationSpace from GetNodesResponse. if (!string.IsNullOrEmpty(configuration.DefaultRelativeZoomTranslationSpace)) { bool supported = true; if (spaces.RelativeZoomTranslationSpace == null) { supported = false; } else { if (spaces.RelativeZoomTranslationSpace.Where( S => S.URI == configuration.DefaultRelativeZoomTranslationSpace).FirstOrDefault() == null) { supported = false; } } if (!supported) { ok = false; sb.AppendLine( string.Format("RelativeZoomTranslationSpace with URI = '{0}' not found in SupportedPTZSpaces", configuration.DefaultRelativeZoomTranslationSpace)); } } // DefaultContinuousPanTiltVelocitySpace from PTZConfiguration is not included in one of SupportedPTZSpaces.ContinuousPanTiltVelocitySpacefrom GetNodesResponse. if (!string.IsNullOrEmpty(configuration.DefaultContinuousPanTiltVelocitySpace)) { bool supported = true; if (spaces.ContinuousPanTiltVelocitySpace == null) { supported = false; } else { if (spaces.ContinuousPanTiltVelocitySpace.Where( S => S.URI == configuration.DefaultContinuousPanTiltVelocitySpace).FirstOrDefault() == null) { supported = false; } } if (!supported) { ok = false; sb.AppendLine( string.Format("ContinuousPanTiltVelocitySpace with URI = '{0}' not found in SupportedPTZSpaces", configuration.DefaultContinuousPanTiltVelocitySpace)); } } // DefaultContinuousZoomVelocitySpace from PTZConfiguration is not included in one of SupportedPTZSpaces.ContinuousZoomVelocitySpace from GetNodesResponse. if (!string.IsNullOrEmpty(configuration.DefaultContinuousZoomVelocitySpace)) { bool supported = true; if (spaces.ContinuousZoomVelocitySpace == null) { supported = false; } else { if (spaces.ContinuousZoomVelocitySpace.Where( S => S.URI == configuration.DefaultContinuousZoomVelocitySpace).FirstOrDefault() == null) { supported = false; } } if (!supported) { ok = false; sb.AppendLine( string.Format("ContinuousZoomVelocitySpace with URI = '{0}' not found in SupportedPTZSpaces", configuration.DefaultContinuousZoomVelocitySpace)); } } if (configuration.DefaultPTZSpeed != null) { if (configuration.DefaultPTZSpeed.PanTilt != null) { bool supported = true; // DefaultPTZSpeed.PanTilt.space from PTZConfiguration is not included in one of PanTiltSpeedSpace.URI section from GetNodesResponse Space1DDescription space = null; if (spaces.PanTiltSpeedSpace == null) { supported = false; } else { space = spaces.PanTiltSpeedSpace.Where( S => S.URI == configuration.DefaultPTZSpeed.PanTilt.space).FirstOrDefault(); if (space == null) { supported = false; } } if (!supported) { ok = false; sb.AppendLine( string.Format( "PanTiltSpeedSpace with URI = '{0}' not found in SupportedPTZSpaces", configuration.DefaultPTZSpeed.PanTilt.space)); } // DefaultPTZSpeed.PanTilt.x is not between SupportedPTZSpaces.PanTiltSpeedSpace.XRange.Min and SupportedPTZSpaces.PanTiltSpeedSpace.XRange.Max for appropriate PanTiltSpeedSpace.URI from GetNodesResponse. // DefaultPTZSpeed.PanTilt.y is not between SupportedPTZSpaces.PanTiltSpeedSpace.YRange.Min and SupportedPTZSpaces.PanTiltSpeedSpace.YRange.Max for appropriate PanTiltSpeedSpace.URI from GetNodesResponse. (see Questions) // see questions = PanTile.y not defined =( if (space != null && space.XRange != null) { if (configuration.DefaultPTZSpeed.PanTilt.x < space.XRange.Min || configuration.DefaultPTZSpeed.PanTilt.x > space.XRange.Max) { ok = false; sb.AppendLine(string.Format("DefaultPTZSpeed.PanTilt.x ({0}) is out of range ([{1},{2}])", configuration.DefaultPTZSpeed.PanTilt.x, space.XRange.Min, space.XRange.Max)); } if (configuration.DefaultPTZSpeed.PanTilt.y < space.XRange.Min || configuration.DefaultPTZSpeed.PanTilt.y > space.XRange.Max) { ok = false; sb.AppendLine(string.Format("DefaultPTZSpeed.PanTilt.y ({0}) is out of range ([{1},{2}])", configuration.DefaultPTZSpeed.PanTilt.y, space.XRange.Min, space.XRange.Max)); } } } if (configuration.DefaultPTZSpeed.Zoom != null) { bool supported = true; // DefaultPTZSpeed.Zoom.Space is not included in one of ZoomSpeedSpace.URI section of GetNodesResponse Space1DDescription space = null; if (spaces.ZoomSpeedSpace == null) { supported = false; } else { space = spaces.ZoomSpeedSpace.Where( S => S.URI == configuration.DefaultPTZSpeed.Zoom.space).FirstOrDefault(); if (space == null) { supported = false; } } if (!supported) { ok = false; sb.AppendLine( string.Format( "PanTiltZoomSpace with URI = '{0}' not found in SupportedPTZSpaces", configuration.DefaultPTZSpeed.Zoom.space)); } // DefaultPTZSpeed.Zoom.x is not between SupportedPTZSpaces.ZoomSpeedSpace.XRange.Min and SupportedPTZSpaces.ZoomSpeedSpace.XRange.Max for appropriate ZoomSpeedSpace.URI from GetNodesResponse. if (space != null && space.XRange != null) { if (configuration.DefaultPTZSpeed.Zoom.x < space.XRange.Min || configuration.DefaultPTZSpeed.Zoom.x > space.XRange.Max) { ok = false; sb.AppendLine(string.Format("DefaultPTZSpeed.Zoom.x ({0}) is out of range ([{1}, {2}])", configuration.DefaultPTZSpeed.Zoom.x, space.XRange.Min, space.XRange.Max)); } } } } return(ok); }
public void AbsoluteMoveTest() { RunTest(() => { PTZConfigurationOptions options; Profile profile = GetPTZProfile(_ptzNodeToken, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); string reason = null; Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.NodeToken, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); Assert(options.Spaces.AbsolutePanTiltPositionSpace != null || options.Spaces.AbsoluteZoomPositionSpace != null, "Node does not support Absolute move", "Check if Absolute move is supported"); //select pantilt and zoom spaces Space2DDescription pantiltSpace = null; Space1DDescription zoomSpace = null; //set selected spaces as default if they are not (we need it to get position in these spaces) BeginStep("Check if configuration needs to be updated"); bool updateNeeded = false; string dump = string.Empty; if (Features.Contains(Feature.PTZAbsolutePanTilt)) { pantiltSpace = options.Spaces.AbsolutePanTiltPositionSpace[0]; bool update = false; if (string.IsNullOrEmpty(profile.PTZConfiguration.DefaultAbsolutePantTiltPositionSpace)) { update = true; } else { update = (!EqualSpaces(pantiltSpace.URI, profile.PTZConfiguration.DefaultAbsolutePantTiltPositionSpace)); } if (update) { updateNeeded = true; dump += string.Format("DefaultAbsolutePantTiltPositionSpace={0}", pantiltSpace.URI); profile.PTZConfiguration.DefaultAbsolutePantTiltPositionSpace = pantiltSpace.URI; } } if (Features.Contains(Feature.PTZAbsoluteZoom)) { zoomSpace = options.Spaces.AbsoluteZoomPositionSpace[0]; bool update = false; if (string.IsNullOrEmpty(profile.PTZConfiguration.DefaultAbsoluteZoomPositionSpace)) { update = true; } else { update = !EqualSpaces(zoomSpace.URI, profile.PTZConfiguration.DefaultAbsoluteZoomPositionSpace); } if (update) { updateNeeded = true; string localdump = string.Format( "DefaultAbsoluteZoomPositionSpace={0}", zoomSpace.URI); if (string.IsNullOrEmpty(dump)) { dump = localdump; } else { dump += string.Format(", {0}", localdump); } profile.PTZConfiguration.DefaultAbsoluteZoomPositionSpace = zoomSpace.URI; } } StepPassed(); if (updateNeeded) { SetConfiguration(profile.PTZConfiguration, false, dump); } PTZStatus status = GetPTZStatus(profile.token); PTZVector pantilt = null; PTZVector zoom = null; if (pantiltSpace != null) { PTZSpeed speed = null; if ((options.Spaces.PanTiltSpeedSpace != null) && (options.Spaces.PanTiltSpeedSpace.Length > 0)) { Space1DDescription space = options.Spaces.PanTiltSpeedSpace[0]; speed = new PTZSpeed(); speed.PanTilt = new Vector2D(); speed.PanTilt.space = space.URI; speed.PanTilt.x = space.XRange.Max; speed.PanTilt.y = space.XRange.Max; } pantilt = new PTZVector(); pantilt.PanTilt = new Vector2D(); pantilt.PanTilt.space = pantiltSpace.URI; pantilt.PanTilt.x = pantiltSpace.XRange.Max; pantilt.PanTilt.y = pantiltSpace.YRange.Max; AbsoluteMove(profile.token, pantilt, speed); } if (zoomSpace != null) { PTZSpeed speed = null; if ((options.Spaces.ZoomSpeedSpace != null) && (options.Spaces.ZoomSpeedSpace.Length > 0)) { Space1DDescription space = options.Spaces.ZoomSpeedSpace[0]; speed = new PTZSpeed(); speed.Zoom = new Vector1D(); speed.Zoom.space = space.URI; speed.Zoom.x = space.XRange.Max; } zoom = new PTZVector(); zoom.Zoom = new Vector1D(); zoom.Zoom.space = zoomSpace.URI; zoom.Zoom.x = zoomSpace.XRange.Max; AbsoluteMove(profile.token, zoom, speed); } status = GetPTZStatus(profile.token); if (status.Position != null) { CheckPTZPosition(status.Position, pantilt, zoom, pantiltSpace, zoomSpace); } }); }
public void FixedHome() { RunTest(() => { PTZConfigurationOptions options; Media.Profile profile = GetPTZProfile(_ptzNodeToken, out options); Assert((profile != null) && (profile.PTZConfiguration != null), Resources.ErrorNoPTZProfile, Resources.StepValidatePTZProfile); string reason; Assert(ValidatePTZConfigurationOptions(options, profile.PTZConfiguration.token, out reason), reason, Resources.StepValidatePTZConfigOptions_Title); GotoHomePosition(profile.token, null, _homeMoveTimeout); //absolute or relative move should be supported - use generic space for position or translation bool absoulteMoveSupported = Features.Contains(Feature.PTZAbsolute); PTZVector vector = new PTZVector(); Space2DDescription pantiltSpace = null; Space1DDescription zoomSpace = null; if (Features.Contains(Feature.PTZAbsolutePanTilt) || Features.Contains(Feature.PTZRelativePanTilt)) { pantiltSpace = absoulteMoveSupported ? options.Spaces.AbsolutePanTiltPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absolutePanTiltSpace, true) == 0) : options.Spaces.RelativePanTiltTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativePanTiltSpace, true) == 0); vector.PanTilt = new Vector2D(); vector.PanTilt.space = pantiltSpace.URI; vector.PanTilt.x = pantiltSpace.XRange.Max; vector.PanTilt.y = pantiltSpace.YRange.Max; } if (Features.Contains(Feature.PTZAbsoluteZoom) || Features.Contains(Feature.PTZRelativeZoom)) { zoomSpace = absoulteMoveSupported ? options.Spaces.AbsoluteZoomPositionSpace.FirstOrDefault(s => string.Compare(s.URI, _absoluteZoomSpace, true) == 0) : options.Spaces.RelativeZoomTranslationSpace.FirstOrDefault(s => string.Compare(s.URI, _relativeZoomSpace, true) == 0); vector.Zoom = new Vector1D(); vector.Zoom.space = zoomSpace.URI; vector.Zoom.x = zoomSpace.XRange.Max; } //make sure current position is different to destination PTZStatus status = GetPTZStatus(profile.token); PTZVector homePosition = status.Position; if ((homePosition != null) && (EqualPositions(homePosition, vector))) { if (vector.PanTilt != null) { vector.PanTilt.x = 0; } else if (vector.Zoom != null) { vector.Zoom.x = 0; } } if (absoulteMoveSupported) { AbsoluteMove(profile.token, vector, null); } else { RelativeMove(profile.token, vector, null); } SetFixedHomePosition(profile.token); GotoHomePosition(profile.token, null, _homeMoveTimeout); status = GetPTZStatus(profile.token); if (status.Position != null) { CheckPTZPosition(status.Position, homePosition, homePosition); } else { OpenVideo(); Assert(_operator.GetYesNoAnswer(string.Format("Is camera in position [{0}]?", PositionToString(homePosition))), "Camera is in wrong position", "Camera position check (manual)"); CloseVideo(); } }, () => { CloseVideo(); }); }