|
@@ -0,0 +1,109 @@
|
|
|
+package com.its.op.service.its.cctv;
|
|
|
+
|
|
|
+import org.apache.http.HttpStatus;
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+
|
|
|
+public class SNP3120VHControl {
|
|
|
+ private String baseUrl;
|
|
|
+ private int timeout;
|
|
|
+
|
|
|
+ private CloseableHttpClient httpClient;
|
|
|
+ private RequestConfig requestConfig;
|
|
|
+
|
|
|
+ public SNP3120VHControl(String ipAddress, int port, String username, String password) {
|
|
|
+
|
|
|
+ this.requestConfig = RequestConfig.custom()
|
|
|
+ .setConnectTimeout(3000)
|
|
|
+ .setConnectionRequestTimeout(3000)
|
|
|
+ .setSocketTimeout(5000)
|
|
|
+ .build();
|
|
|
+ this.httpClient = HttpClients.custom()
|
|
|
+ .setDefaultRequestConfig(requestConfig)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void moveUp(int speed) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&tilt=up&speed=" + speed;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void moveDown(int speed) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&tilt=down&speed=" + speed;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void moveLeft(int speed) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&pan=left&speed=" + speed;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void moveRight(int speed) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&pan=right&speed=" + speed;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void zoomIn(int speed) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&zoom=tele&speed=" + speed;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void zoomOut(int speed) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&zoom=wide&speed=" + speed;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void focusNear(int speed) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&focus=near&speed=" + speed;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void focusFar(int speed) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&focus=far&speed=" + speed;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void goToPreset(int presetNumber) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/presetcontrol.cgi?action=goto&number=" + presetNumber;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setPreset(int presetNumber) throws IOException {
|
|
|
+ String command = "/cgi-bin/stw-cgi/presetcontrol.cgi?action=set&number=" + presetNumber;
|
|
|
+ executeCommand(command);
|
|
|
+ }
|
|
|
+ public void deletePreset(String presetNumber) throws IOException {
|
|
|
+ String url = String.format("%s/stw-cgi/presetcontrol.cgi?action=remove&name=%s", this.baseUrl, presetNumber);
|
|
|
+ HttpGet httpGet = new HttpGet(url);
|
|
|
+ RequestConfig requestConfig = RequestConfig.custom()
|
|
|
+ .setSocketTimeout(this.timeout)
|
|
|
+ .setConnectTimeout(this.timeout)
|
|
|
+ .build();
|
|
|
+ httpGet.setConfig(requestConfig);
|
|
|
+ try (CloseableHttpResponse response = this.httpClient.execute(httpGet)) {
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
+ if (statusCode != HttpStatus.SC_OK) {
|
|
|
+ throw new IOException(String.format("Failed to delete preset %s: HTTP status code %d", presetNumber, statusCode));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private String executeCommand(String command) throws IOException {
|
|
|
+ String[] commandArray = new String[]{"bash", "-c", command};
|
|
|
+ Process process = Runtime.getRuntime().exec(commandArray);
|
|
|
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ String line;
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ stringBuilder.append(line).append("\n");
|
|
|
+ }
|
|
|
+ return stringBuilder.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|