diff --git a/app/src/main/assets/DeviceParameter.json b/app/src/main/assets/DeviceParameter.json index 6ea3c8f..650e097 100644 --- a/app/src/main/assets/DeviceParameter.json +++ b/app/src/main/assets/DeviceParameter.json @@ -1,24 +1,24 @@ [ { - "deviceName": "YTJ010001", + "deviceName": "AQS001", "wifi": "YTJ010001_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.151" }, { - "deviceName": "YTJ010002", + "deviceName": "AQS002", "wifi": "YTJ010002_5G", "pwd": "zhsz20311hw", "cameraIp": "192.168.10.137" }, { - "deviceName": "YTJ010003", + "deviceName": "AQS003", "wifi": "YTJ010003_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.153" }, { - "deviceName": "YTJ010004", + "deviceName": "AQS004", "wifi": "YTJ010004_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.154" diff --git a/app/src/main/assets/DeviceParameter.json b/app/src/main/assets/DeviceParameter.json index 6ea3c8f..650e097 100644 --- a/app/src/main/assets/DeviceParameter.json +++ b/app/src/main/assets/DeviceParameter.json @@ -1,24 +1,24 @@ [ { - "deviceName": "YTJ010001", + "deviceName": "AQS001", "wifi": "YTJ010001_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.151" }, { - "deviceName": "YTJ010002", + "deviceName": "AQS002", "wifi": "YTJ010002_5G", "pwd": "zhsz20311hw", "cameraIp": "192.168.10.137" }, { - "deviceName": "YTJ010003", + "deviceName": "AQS003", "wifi": "YTJ010003_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.153" }, { - "deviceName": "YTJ010004", + "deviceName": "AQS004", "wifi": "YTJ010004_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.154" diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 07a4d94..ad2074b 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -183,4 +183,15 @@ @Body requestBody: RequestBody, @QueryMap projectId: Map ): String + + /** + * 执行设备控制指令 + */ + @GET("/cgi-bin/ptz_cgi") + suspend fun executeDeviceCommand( + @Query("action") action: String, + @Query("user") user: String, + @Query("pwd") pwd: String, + @Query("Speed") Speed: String + ): String } \ No newline at end of file diff --git a/app/src/main/assets/DeviceParameter.json b/app/src/main/assets/DeviceParameter.json index 6ea3c8f..650e097 100644 --- a/app/src/main/assets/DeviceParameter.json +++ b/app/src/main/assets/DeviceParameter.json @@ -1,24 +1,24 @@ [ { - "deviceName": "YTJ010001", + "deviceName": "AQS001", "wifi": "YTJ010001_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.151" }, { - "deviceName": "YTJ010002", + "deviceName": "AQS002", "wifi": "YTJ010002_5G", "pwd": "zhsz20311hw", "cameraIp": "192.168.10.137" }, { - "deviceName": "YTJ010003", + "deviceName": "AQS003", "wifi": "YTJ010003_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.153" }, { - "deviceName": "YTJ010004", + "deviceName": "AQS004", "wifi": "YTJ010004_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.154" diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 07a4d94..ad2074b 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -183,4 +183,15 @@ @Body requestBody: RequestBody, @QueryMap projectId: Map ): String + + /** + * 执行设备控制指令 + */ + @GET("/cgi-bin/ptz_cgi") + suspend fun executeDeviceCommand( + @Query("action") action: String, + @Query("user") user: String, + @Query("pwd") pwd: String, + @Query("Speed") Speed: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 395aa7e..f99d6d4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -1,5 +1,6 @@ package com.casic.br.operationsite.retrofit +import android.util.Log import com.casic.br.operationsite.model.ImageModel import com.casic.br.operationsite.utils.AuthenticationHelper import com.casic.br.operationsite.utils.LocaleConstant @@ -19,6 +20,7 @@ object RetrofitServiceManager { + private const val kTag = "RetrofitServiceManager" private val gson by lazy { Gson() } private val api by lazy { @@ -293,4 +295,19 @@ ) return aiApi.postRegion(requestBody) } + + /** + * 执行设备控制指令 + */ + suspend fun executeDeviceCommand(action: String, speed: Int): String { + val httpConfig = SaveKeyValues.getValue( + LocaleConstant.DEVICE_CONTROL_SERVER_CONFIG, "" + ) as String + if (httpConfig == "") { + Log.d(kTag, "executeDeviceCommand: httpConfig is null") + return "" + } + val service = RetrofitFactory.createRetrofit("http://${httpConfig}") + return service.executeDeviceCommand(action, "admin", "admin", speed.toString()) + } } \ No newline at end of file diff --git a/app/src/main/assets/DeviceParameter.json b/app/src/main/assets/DeviceParameter.json index 6ea3c8f..650e097 100644 --- a/app/src/main/assets/DeviceParameter.json +++ b/app/src/main/assets/DeviceParameter.json @@ -1,24 +1,24 @@ [ { - "deviceName": "YTJ010001", + "deviceName": "AQS001", "wifi": "YTJ010001_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.151" }, { - "deviceName": "YTJ010002", + "deviceName": "AQS002", "wifi": "YTJ010002_5G", "pwd": "zhsz20311hw", "cameraIp": "192.168.10.137" }, { - "deviceName": "YTJ010003", + "deviceName": "AQS003", "wifi": "YTJ010003_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.153" }, { - "deviceName": "YTJ010004", + "deviceName": "AQS004", "wifi": "YTJ010004_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.154" diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 07a4d94..ad2074b 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -183,4 +183,15 @@ @Body requestBody: RequestBody, @QueryMap projectId: Map ): String + + /** + * 执行设备控制指令 + */ + @GET("/cgi-bin/ptz_cgi") + suspend fun executeDeviceCommand( + @Query("action") action: String, + @Query("user") user: String, + @Query("pwd") pwd: String, + @Query("Speed") Speed: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 395aa7e..f99d6d4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -1,5 +1,6 @@ package com.casic.br.operationsite.retrofit +import android.util.Log import com.casic.br.operationsite.model.ImageModel import com.casic.br.operationsite.utils.AuthenticationHelper import com.casic.br.operationsite.utils.LocaleConstant @@ -19,6 +20,7 @@ object RetrofitServiceManager { + private const val kTag = "RetrofitServiceManager" private val gson by lazy { Gson() } private val api by lazy { @@ -293,4 +295,19 @@ ) return aiApi.postRegion(requestBody) } + + /** + * 执行设备控制指令 + */ + suspend fun executeDeviceCommand(action: String, speed: Int): String { + val httpConfig = SaveKeyValues.getValue( + LocaleConstant.DEVICE_CONTROL_SERVER_CONFIG, "" + ) as String + if (httpConfig == "") { + Log.d(kTag, "executeDeviceCommand: httpConfig is null") + return "" + } + val service = RetrofitFactory.createRetrofit("http://${httpConfig}") + return service.executeDeviceCommand(action, "admin", "admin", speed.toString()) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 30fe8b7..17e6688 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -67,6 +67,7 @@ const val DEVICE_CONTROLLER_URL = "https://gbs.ntvgbs.cn/login/" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val AI_SERVER_CONFIG = "aiServerConfig" + const val DEVICE_CONTROL_SERVER_CONFIG = "deviceControlServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" diff --git a/app/src/main/assets/DeviceParameter.json b/app/src/main/assets/DeviceParameter.json index 6ea3c8f..650e097 100644 --- a/app/src/main/assets/DeviceParameter.json +++ b/app/src/main/assets/DeviceParameter.json @@ -1,24 +1,24 @@ [ { - "deviceName": "YTJ010001", + "deviceName": "AQS001", "wifi": "YTJ010001_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.151" }, { - "deviceName": "YTJ010002", + "deviceName": "AQS002", "wifi": "YTJ010002_5G", "pwd": "zhsz20311hw", "cameraIp": "192.168.10.137" }, { - "deviceName": "YTJ010003", + "deviceName": "AQS003", "wifi": "YTJ010003_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.153" }, { - "deviceName": "YTJ010004", + "deviceName": "AQS004", "wifi": "YTJ010004_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.154" diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 07a4d94..ad2074b 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -183,4 +183,15 @@ @Body requestBody: RequestBody, @QueryMap projectId: Map ): String + + /** + * 执行设备控制指令 + */ + @GET("/cgi-bin/ptz_cgi") + suspend fun executeDeviceCommand( + @Query("action") action: String, + @Query("user") user: String, + @Query("pwd") pwd: String, + @Query("Speed") Speed: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 395aa7e..f99d6d4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -1,5 +1,6 @@ package com.casic.br.operationsite.retrofit +import android.util.Log import com.casic.br.operationsite.model.ImageModel import com.casic.br.operationsite.utils.AuthenticationHelper import com.casic.br.operationsite.utils.LocaleConstant @@ -19,6 +20,7 @@ object RetrofitServiceManager { + private const val kTag = "RetrofitServiceManager" private val gson by lazy { Gson() } private val api by lazy { @@ -293,4 +295,19 @@ ) return aiApi.postRegion(requestBody) } + + /** + * 执行设备控制指令 + */ + suspend fun executeDeviceCommand(action: String, speed: Int): String { + val httpConfig = SaveKeyValues.getValue( + LocaleConstant.DEVICE_CONTROL_SERVER_CONFIG, "" + ) as String + if (httpConfig == "") { + Log.d(kTag, "executeDeviceCommand: httpConfig is null") + return "" + } + val service = RetrofitFactory.createRetrofit("http://${httpConfig}") + return service.executeDeviceCommand(action, "admin", "admin", speed.toString()) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 30fe8b7..17e6688 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -67,6 +67,7 @@ const val DEVICE_CONTROLLER_URL = "https://gbs.ntvgbs.cn/login/" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val AI_SERVER_CONFIG = "aiServerConfig" + const val DEVICE_CONTROL_SERVER_CONFIG = "deviceControlServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" diff --git a/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt index 4bc90b8..8141c65 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt @@ -12,11 +12,14 @@ import android.util.Log import android.view.MotionEvent import android.widget.LinearLayout +import androidx.lifecycle.ViewModelProvider import com.casic.br.operationsite.R import com.casic.br.operationsite.databinding.ActivityDeviceControlByNativeBinding import com.casic.br.operationsite.extensions.initImmersionBar import com.casic.br.operationsite.model.DeviceParameterModel +import com.casic.br.operationsite.utils.LocaleConstant import com.casic.br.operationsite.utils.VideoPlayerManager +import com.casic.br.operationsite.vm.DeviceViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseActivity @@ -25,6 +28,7 @@ import com.pengxh.kt.lite.extensions.readAssetsFile import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.ActivityStackManager +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.widget.TitleBarView import com.pengxh.kt.lite.widget.dialog.BottomActionSheet @@ -34,7 +38,9 @@ private val context = this private val gson by lazy { Gson() } private lateinit var deviceParams: List + private lateinit var deviceViewModel: DeviceViewModel private var connectivityManager: ConnectivityManager? = null + private var speed = 5 @SuppressLint("ClickableViewAccessibility") override fun initEvent() { @@ -53,6 +59,10 @@ binding.configSelectView.text = deviceArray[position] val parameter = deviceParams[position] + //保存相机控制地址 + SaveKeyValues.putValue( + LocaleConstant.DEVICE_CONTROL_SERVER_CONFIG, parameter.cameraIp + ) //设置rtsp相机地址 val rtsp = "rtsp://${parameter.cameraIp}:554/h265/ch1/sub/av_stream" @@ -81,94 +91,71 @@ binding.leftButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Left") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.topButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Up") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.rightButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Right") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.bottomButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Down") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.upScaleButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("ZoomAdd") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.downScaleButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("ZoomSub") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false + } + + binding.accelerateButton.setOnClickListener { + speed++ + if (speed >= 8) { + speed = 8 + } + binding.currentSpeedView.text = "速度:${speed}" + } + + binding.decelerationButton.setOnClickListener { + speed-- + if (speed <= 1) { + speed = 1 + } + binding.currentSpeedView.text = "速度:${speed}" } } - private val networkCallback = object : ConnectivityManager.NetworkCallback() { - override fun onAvailable(network: Network) { - super.onAvailable(network) - if (connectivityManager?.bindProcessToNetwork(network) == true) { - "设备连接成功".show(context) - } - } - - override fun onUnavailable() { - - } + private fun executeCommand(action: String) { + deviceViewModel.executeDeviceCommand(action, speed) } override fun initOnCreate(savedInstanceState: Bundle?) { @@ -179,6 +166,11 @@ assetsFile, object : TypeToken>() {}.type ) + deviceViewModel = ViewModelProvider(this)[DeviceViewModel::class.java] + deviceViewModel.commandResult.observe(this) { + Log.d(kTag, "initOnCreate: $it") + } + //动态设置rtspPlayerView宽高 val params = binding.rtspPlayerView.layoutParams as LinearLayout.LayoutParams val videoWidth = getScreenWidth() @@ -186,6 +178,8 @@ params.width = videoWidth params.height = videoHeight.toInt() binding.rtspPlayerView.layoutParams = params + + binding.currentSpeedView.text = "速度:${speed}" } override fun initViewBinding(): ActivityDeviceControlByNativeBinding { @@ -208,4 +202,17 @@ } }) } + + private val networkCallback = object : ConnectivityManager.NetworkCallback() { + override fun onAvailable(network: Network) { + super.onAvailable(network) + if (connectivityManager?.bindProcessToNetwork(network) == true) { + "设备连接成功".show(context) + } + } + + override fun onUnavailable() { + + } + } } \ No newline at end of file diff --git a/app/src/main/assets/DeviceParameter.json b/app/src/main/assets/DeviceParameter.json index 6ea3c8f..650e097 100644 --- a/app/src/main/assets/DeviceParameter.json +++ b/app/src/main/assets/DeviceParameter.json @@ -1,24 +1,24 @@ [ { - "deviceName": "YTJ010001", + "deviceName": "AQS001", "wifi": "YTJ010001_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.151" }, { - "deviceName": "YTJ010002", + "deviceName": "AQS002", "wifi": "YTJ010002_5G", "pwd": "zhsz20311hw", "cameraIp": "192.168.10.137" }, { - "deviceName": "YTJ010003", + "deviceName": "AQS003", "wifi": "YTJ010003_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.153" }, { - "deviceName": "YTJ010004", + "deviceName": "AQS004", "wifi": "YTJ010004_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.154" diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 07a4d94..ad2074b 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -183,4 +183,15 @@ @Body requestBody: RequestBody, @QueryMap projectId: Map ): String + + /** + * 执行设备控制指令 + */ + @GET("/cgi-bin/ptz_cgi") + suspend fun executeDeviceCommand( + @Query("action") action: String, + @Query("user") user: String, + @Query("pwd") pwd: String, + @Query("Speed") Speed: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 395aa7e..f99d6d4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -1,5 +1,6 @@ package com.casic.br.operationsite.retrofit +import android.util.Log import com.casic.br.operationsite.model.ImageModel import com.casic.br.operationsite.utils.AuthenticationHelper import com.casic.br.operationsite.utils.LocaleConstant @@ -19,6 +20,7 @@ object RetrofitServiceManager { + private const val kTag = "RetrofitServiceManager" private val gson by lazy { Gson() } private val api by lazy { @@ -293,4 +295,19 @@ ) return aiApi.postRegion(requestBody) } + + /** + * 执行设备控制指令 + */ + suspend fun executeDeviceCommand(action: String, speed: Int): String { + val httpConfig = SaveKeyValues.getValue( + LocaleConstant.DEVICE_CONTROL_SERVER_CONFIG, "" + ) as String + if (httpConfig == "") { + Log.d(kTag, "executeDeviceCommand: httpConfig is null") + return "" + } + val service = RetrofitFactory.createRetrofit("http://${httpConfig}") + return service.executeDeviceCommand(action, "admin", "admin", speed.toString()) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 30fe8b7..17e6688 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -67,6 +67,7 @@ const val DEVICE_CONTROLLER_URL = "https://gbs.ntvgbs.cn/login/" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val AI_SERVER_CONFIG = "aiServerConfig" + const val DEVICE_CONTROL_SERVER_CONFIG = "deviceControlServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" diff --git a/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt index 4bc90b8..8141c65 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt @@ -12,11 +12,14 @@ import android.util.Log import android.view.MotionEvent import android.widget.LinearLayout +import androidx.lifecycle.ViewModelProvider import com.casic.br.operationsite.R import com.casic.br.operationsite.databinding.ActivityDeviceControlByNativeBinding import com.casic.br.operationsite.extensions.initImmersionBar import com.casic.br.operationsite.model.DeviceParameterModel +import com.casic.br.operationsite.utils.LocaleConstant import com.casic.br.operationsite.utils.VideoPlayerManager +import com.casic.br.operationsite.vm.DeviceViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseActivity @@ -25,6 +28,7 @@ import com.pengxh.kt.lite.extensions.readAssetsFile import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.ActivityStackManager +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.widget.TitleBarView import com.pengxh.kt.lite.widget.dialog.BottomActionSheet @@ -34,7 +38,9 @@ private val context = this private val gson by lazy { Gson() } private lateinit var deviceParams: List + private lateinit var deviceViewModel: DeviceViewModel private var connectivityManager: ConnectivityManager? = null + private var speed = 5 @SuppressLint("ClickableViewAccessibility") override fun initEvent() { @@ -53,6 +59,10 @@ binding.configSelectView.text = deviceArray[position] val parameter = deviceParams[position] + //保存相机控制地址 + SaveKeyValues.putValue( + LocaleConstant.DEVICE_CONTROL_SERVER_CONFIG, parameter.cameraIp + ) //设置rtsp相机地址 val rtsp = "rtsp://${parameter.cameraIp}:554/h265/ch1/sub/av_stream" @@ -81,94 +91,71 @@ binding.leftButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Left") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.topButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Up") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.rightButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Right") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.bottomButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Down") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.upScaleButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("ZoomAdd") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.downScaleButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("ZoomSub") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false + } + + binding.accelerateButton.setOnClickListener { + speed++ + if (speed >= 8) { + speed = 8 + } + binding.currentSpeedView.text = "速度:${speed}" + } + + binding.decelerationButton.setOnClickListener { + speed-- + if (speed <= 1) { + speed = 1 + } + binding.currentSpeedView.text = "速度:${speed}" } } - private val networkCallback = object : ConnectivityManager.NetworkCallback() { - override fun onAvailable(network: Network) { - super.onAvailable(network) - if (connectivityManager?.bindProcessToNetwork(network) == true) { - "设备连接成功".show(context) - } - } - - override fun onUnavailable() { - - } + private fun executeCommand(action: String) { + deviceViewModel.executeDeviceCommand(action, speed) } override fun initOnCreate(savedInstanceState: Bundle?) { @@ -179,6 +166,11 @@ assetsFile, object : TypeToken>() {}.type ) + deviceViewModel = ViewModelProvider(this)[DeviceViewModel::class.java] + deviceViewModel.commandResult.observe(this) { + Log.d(kTag, "initOnCreate: $it") + } + //动态设置rtspPlayerView宽高 val params = binding.rtspPlayerView.layoutParams as LinearLayout.LayoutParams val videoWidth = getScreenWidth() @@ -186,6 +178,8 @@ params.width = videoWidth params.height = videoHeight.toInt() binding.rtspPlayerView.layoutParams = params + + binding.currentSpeedView.text = "速度:${speed}" } override fun initViewBinding(): ActivityDeviceControlByNativeBinding { @@ -208,4 +202,17 @@ } }) } + + private val networkCallback = object : ConnectivityManager.NetworkCallback() { + override fun onAvailable(network: Network) { + super.onAvailable(network) + if (connectivityManager?.bindProcessToNetwork(network) == true) { + "设备连接成功".show(context) + } + } + + override fun onUnavailable() { + + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/br/operationsite/vm/DeviceViewModel.kt index ffb40ae..3e1e90e 100644 --- a/app/src/main/java/com/casic/br/operationsite/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/br/operationsite/vm/DeviceViewModel.kt @@ -21,6 +21,7 @@ val deviceModels = MutableLiveData() val setThresholdResult = MutableLiveData() val thresholdResult = MutableLiveData() + val commandResult = MutableLiveData() fun getDeviceList( context: Context, @@ -95,4 +96,13 @@ loadState.value = LoadState.Fail it.printStackTrace() }) + + /** + * 执行设备控制指令 + */ + fun executeDeviceCommand(action: String, speed: Int) = launch({ + commandResult.value = RetrofitServiceManager.executeDeviceCommand(action, speed) + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/assets/DeviceParameter.json b/app/src/main/assets/DeviceParameter.json index 6ea3c8f..650e097 100644 --- a/app/src/main/assets/DeviceParameter.json +++ b/app/src/main/assets/DeviceParameter.json @@ -1,24 +1,24 @@ [ { - "deviceName": "YTJ010001", + "deviceName": "AQS001", "wifi": "YTJ010001_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.151" }, { - "deviceName": "YTJ010002", + "deviceName": "AQS002", "wifi": "YTJ010002_5G", "pwd": "zhsz20311hw", "cameraIp": "192.168.10.137" }, { - "deviceName": "YTJ010003", + "deviceName": "AQS003", "wifi": "YTJ010003_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.153" }, { - "deviceName": "YTJ010004", + "deviceName": "AQS004", "wifi": "YTJ010004_5G", "pwd": "abcd1234", "cameraIp": "192.168.10.154" diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt index 07a4d94..ad2074b 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitService.kt @@ -183,4 +183,15 @@ @Body requestBody: RequestBody, @QueryMap projectId: Map ): String + + /** + * 执行设备控制指令 + */ + @GET("/cgi-bin/ptz_cgi") + suspend fun executeDeviceCommand( + @Query("action") action: String, + @Query("user") user: String, + @Query("pwd") pwd: String, + @Query("Speed") Speed: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt index 395aa7e..f99d6d4 100644 --- a/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/br/operationsite/retrofit/RetrofitServiceManager.kt @@ -1,5 +1,6 @@ package com.casic.br.operationsite.retrofit +import android.util.Log import com.casic.br.operationsite.model.ImageModel import com.casic.br.operationsite.utils.AuthenticationHelper import com.casic.br.operationsite.utils.LocaleConstant @@ -19,6 +20,7 @@ object RetrofitServiceManager { + private const val kTag = "RetrofitServiceManager" private val gson by lazy { Gson() } private val api by lazy { @@ -293,4 +295,19 @@ ) return aiApi.postRegion(requestBody) } + + /** + * 执行设备控制指令 + */ + suspend fun executeDeviceCommand(action: String, speed: Int): String { + val httpConfig = SaveKeyValues.getValue( + LocaleConstant.DEVICE_CONTROL_SERVER_CONFIG, "" + ) as String + if (httpConfig == "") { + Log.d(kTag, "executeDeviceCommand: httpConfig is null") + return "" + } + val service = RetrofitFactory.createRetrofit("http://${httpConfig}") + return service.executeDeviceCommand(action, "admin", "admin", speed.toString()) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt index 30fe8b7..17e6688 100644 --- a/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/br/operationsite/utils/LocaleConstant.kt @@ -67,6 +67,7 @@ const val DEVICE_CONTROLLER_URL = "https://gbs.ntvgbs.cn/login/" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val AI_SERVER_CONFIG = "aiServerConfig" + const val DEVICE_CONTROL_SERVER_CONFIG = "deviceControlServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" const val SEARCH_ACTION = "searchAction" diff --git a/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt index 4bc90b8..8141c65 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/DeviceControlByNativeActivity.kt @@ -12,11 +12,14 @@ import android.util.Log import android.view.MotionEvent import android.widget.LinearLayout +import androidx.lifecycle.ViewModelProvider import com.casic.br.operationsite.R import com.casic.br.operationsite.databinding.ActivityDeviceControlByNativeBinding import com.casic.br.operationsite.extensions.initImmersionBar import com.casic.br.operationsite.model.DeviceParameterModel +import com.casic.br.operationsite.utils.LocaleConstant import com.casic.br.operationsite.utils.VideoPlayerManager +import com.casic.br.operationsite.vm.DeviceViewModel import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.pengxh.kt.lite.base.KotlinBaseActivity @@ -25,6 +28,7 @@ import com.pengxh.kt.lite.extensions.readAssetsFile import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.utils.ActivityStackManager +import com.pengxh.kt.lite.utils.SaveKeyValues import com.pengxh.kt.lite.widget.TitleBarView import com.pengxh.kt.lite.widget.dialog.BottomActionSheet @@ -34,7 +38,9 @@ private val context = this private val gson by lazy { Gson() } private lateinit var deviceParams: List + private lateinit var deviceViewModel: DeviceViewModel private var connectivityManager: ConnectivityManager? = null + private var speed = 5 @SuppressLint("ClickableViewAccessibility") override fun initEvent() { @@ -53,6 +59,10 @@ binding.configSelectView.text = deviceArray[position] val parameter = deviceParams[position] + //保存相机控制地址 + SaveKeyValues.putValue( + LocaleConstant.DEVICE_CONTROL_SERVER_CONFIG, parameter.cameraIp + ) //设置rtsp相机地址 val rtsp = "rtsp://${parameter.cameraIp}:554/h265/ch1/sub/av_stream" @@ -81,94 +91,71 @@ binding.leftButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Left") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.topButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Up") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.rightButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Right") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.bottomButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("Down") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.upScaleButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("ZoomAdd") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false } binding.downScaleButton.setOnTouchListener { _, event -> when (event.action) { - MotionEvent.ACTION_DOWN -> { - Log.d(kTag, "initEvent: 按下") - } - - MotionEvent.ACTION_UP -> { - Log.d(kTag, "initEvent: 抬起") - } + MotionEvent.ACTION_DOWN -> executeCommand("ZoomSub") + MotionEvent.ACTION_UP -> executeCommand("Stop") } - true + false + } + + binding.accelerateButton.setOnClickListener { + speed++ + if (speed >= 8) { + speed = 8 + } + binding.currentSpeedView.text = "速度:${speed}" + } + + binding.decelerationButton.setOnClickListener { + speed-- + if (speed <= 1) { + speed = 1 + } + binding.currentSpeedView.text = "速度:${speed}" } } - private val networkCallback = object : ConnectivityManager.NetworkCallback() { - override fun onAvailable(network: Network) { - super.onAvailable(network) - if (connectivityManager?.bindProcessToNetwork(network) == true) { - "设备连接成功".show(context) - } - } - - override fun onUnavailable() { - - } + private fun executeCommand(action: String) { + deviceViewModel.executeDeviceCommand(action, speed) } override fun initOnCreate(savedInstanceState: Bundle?) { @@ -179,6 +166,11 @@ assetsFile, object : TypeToken>() {}.type ) + deviceViewModel = ViewModelProvider(this)[DeviceViewModel::class.java] + deviceViewModel.commandResult.observe(this) { + Log.d(kTag, "initOnCreate: $it") + } + //动态设置rtspPlayerView宽高 val params = binding.rtspPlayerView.layoutParams as LinearLayout.LayoutParams val videoWidth = getScreenWidth() @@ -186,6 +178,8 @@ params.width = videoWidth params.height = videoHeight.toInt() binding.rtspPlayerView.layoutParams = params + + binding.currentSpeedView.text = "速度:${speed}" } override fun initViewBinding(): ActivityDeviceControlByNativeBinding { @@ -208,4 +202,17 @@ } }) } + + private val networkCallback = object : ConnectivityManager.NetworkCallback() { + override fun onAvailable(network: Network) { + super.onAvailable(network) + if (connectivityManager?.bindProcessToNetwork(network) == true) { + "设备连接成功".show(context) + } + } + + override fun onUnavailable() { + + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/br/operationsite/vm/DeviceViewModel.kt index ffb40ae..3e1e90e 100644 --- a/app/src/main/java/com/casic/br/operationsite/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/br/operationsite/vm/DeviceViewModel.kt @@ -21,6 +21,7 @@ val deviceModels = MutableLiveData() val setThresholdResult = MutableLiveData() val thresholdResult = MutableLiveData() + val commandResult = MutableLiveData() fun getDeviceList( context: Context, @@ -95,4 +96,13 @@ loadState.value = LoadState.Fail it.printStackTrace() }) + + /** + * 执行设备控制指令 + */ + fun executeDeviceCommand(action: String, speed: Int) = launch({ + commandResult.value = RetrofitServiceManager.executeDeviceCommand(action, speed) + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_device_control_by_native.xml b/app/src/main/res/layout/activity_device_control_by_native.xml index b1b98af..725e71a 100644 --- a/app/src/main/res/layout/activity_device_control_by_native.xml +++ b/app/src/main/res/layout/activity_device_control_by_native.xml @@ -158,6 +158,46 @@ android:background="@drawable/selector_scale_button" android:src="@drawable/ic_minus" /> + + + + + + + + + \ No newline at end of file