protected void init() { AxisCameraConfig config = parentSensor.getConfiguration(); presetsHandler = new PtzPresetsHandler(config.ptz); // get PTZ limits try { URL optionsURL = new URL(parentSensor.getHostUrl() + "/view/param.cgi?action=list&group=PTZ.Limit"); InputStream is = optionsURL.openStream(); BufferedReader bReader = new BufferedReader(new InputStreamReader(is)); // get limit values from IP stream String line; while ((line = bReader.readLine()) != null) { // parse response String[] tokens = line.split("="); if (tokens[0].trim().equalsIgnoreCase("root.PTZ.Limit.L1.MinPan")) minPan = Double.parseDouble(tokens[1]); else if (tokens[0].trim().equalsIgnoreCase("root.PTZ.Limit.L1.MaxPan")) maxPan = Double.parseDouble(tokens[1]); else if (tokens[0].trim().equalsIgnoreCase("root.PTZ.Limit.L1.MinTilt")) minTilt = Double.parseDouble(tokens[1]); else if (tokens[0].trim().equalsIgnoreCase("root.PTZ.Limit.L1.MaxTilt")) maxTilt = Double.parseDouble(tokens[1]); else if (tokens[0].trim().equalsIgnoreCase("root.PTZ.Limit.L1.MaxZoom")) maxZoom = Double.parseDouble(tokens[1]); } } catch (Exception e) { e.printStackTrace(); } // build SWE data structure for the tasking parameters VideoCamHelper videoHelper = new VideoCamHelper(); Collection<String> presetList = presetsHandler.getPresetNames(); commandData = videoHelper.getPtzTaskParameters( getName(), minPan, maxPan, minTilt, maxTilt, minZoom, maxZoom, presetList); }
@Override public CommandStatus execCommand(DataBlock command) throws SensorException { // associate command data to msg structure definition DataChoice commandMsg = (DataChoice) commandData.copy(); commandMsg.setData(command); DataComponent component = ((DataChoiceImpl) commandMsg).getSelectedItem(); String itemID = component.getName(); DataBlock data = component.getData(); String itemValue = data.getStringValue(); // NOTE: you can use validate() method in DataComponent // component.validateData(errorList); // give it a list so it can store the errors // if (errorList != empty) //then you have an error try { // set parameter value on camera // NOTE: except for "presets", the item IDs are labeled the same as the Axis parameters so // just use those in the command if (itemID.equals(VideoCamHelper.TASKING_PTZPRESET)) { PtzPreset preset = presetsHandler.getPreset(data.getStringValue()); // pan + tilt + zoom (supported since v2 at least) URL optionsURL = new URL( parentSensor.getHostUrl() + "/com/ptz.cgi?pan=" + preset.pan + "&tilt=" + preset.tilt + "&zoom=" + preset.zoom); InputStream is = optionsURL.openStream(); is.close(); } // Act on full PTZ Position else if (itemID.equalsIgnoreCase(VideoCamHelper.TASKING_PTZ_POS)) { URL optionsURL = new URL( parentSensor.getHostUrl() + "/com/ptz.cgi?pan=" + data.getStringValue(0) + "&tilt=" + data.getStringValue(1) + "&zoom=" + data.getStringValue(2)); InputStream is = optionsURL.openStream(); is.close(); } else { String cmd = " "; if (itemID.equals(VideoCamHelper.TASKING_PAN)) cmd = "pan"; else if (itemID.equals(VideoCamHelper.TASKING_RPAN)) cmd = "rpan"; else if (itemID.equals(VideoCamHelper.TASKING_TILT)) cmd = "tilt"; else if (itemID.equals(VideoCamHelper.TASKING_RTILT)) cmd = "rtilt"; else if (itemID.equals(VideoCamHelper.TASKING_ZOOM)) cmd = "zoom"; else if (itemID.equals(VideoCamHelper.TASKING_RZOOM)) cmd = "rzoom"; URL optionsURL = new URL(parentSensor.getHostUrl() + "/com/ptz.cgi?" + cmd + "=" + itemValue); InputStream is = optionsURL.openStream(); is.close(); } } catch (Exception e) { throw new SensorException("Error connecting to Axis PTZ control", e); } CommandStatus cmdStatus = new CommandStatus(); cmdStatus.status = StatusCode.COMPLETED; return cmdStatus; }