diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 348eb88..99e23dd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -66,6 +66,9 @@
android:name=".view.ObjectDetailActivity"
android:theme="@style/Theme.ActivityDialogStyle" />
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 348eb88..99e23dd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -66,6 +66,9 @@
android:name=".view.ObjectDetailActivity"
android:theme="@style/Theme.ActivityDialogStyle" />
+
diff --git a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
index ca5c1f8..535729f 100644
--- a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
@@ -23,7 +23,7 @@
while (!isInterrupted) {
var size: Int
try {
- val buffer = ByteArray(64)
+ val buffer = ByteArray(32)
if (inputStream == null) return
size = inputStream!!.read(buffer)
if (size > 0) {
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 348eb88..99e23dd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -66,6 +66,9 @@
android:name=".view.ObjectDetailActivity"
android:theme="@style/Theme.ActivityDialogStyle" />
+
diff --git a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
index ca5c1f8..535729f 100644
--- a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
@@ -23,7 +23,7 @@
while (!isInterrupted) {
var size: Int
try {
- val buffer = ByteArray(64)
+ val buffer = ByteArray(32)
if (inputStream == null) return
size = inputStream!!.read(buffer)
if (size > 0) {
diff --git a/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
new file mode 100644
index 0000000..7b98c27
--- /dev/null
+++ b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
@@ -0,0 +1,38 @@
+package com.casic.detector.view
+
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Bundle
+import android.view.Gravity
+import androidx.appcompat.app.AppCompatActivity
+import com.casic.detector.R
+import com.pengxh.kt.lite.extensions.getScreenHeight
+import com.pengxh.kt.lite.extensions.getScreenWidth
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.utils.Constant
+import kotlinx.android.synthetic.main.activity_object_detail.*
+
+class NewObjectDetailActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_new_object_detail)
+
+ window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
+ window.decorView.setBackgroundColor(Color.TRANSPARENT)
+ window.setGravity(Gravity.CENTER)
+ val params = window.attributes
+ params.width = ((getScreenWidth() * 0.9).toInt())
+ params.height = ((getScreenHeight() * 0.3).toInt())
+ window.attributes = params
+
+ val identifierId = intent.getStringExtra(Constant.INTENT_PARAM)!!
+ identifierIdView.text = identifierId
+
+ closeView.setOnClickListener { finish() }
+ showImageView.setOnClickListener {
+ finish()
+ "此对象没相关照片".show(this)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 348eb88..99e23dd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -66,6 +66,9 @@
android:name=".view.ObjectDetailActivity"
android:theme="@style/Theme.ActivityDialogStyle" />
+
diff --git a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
index ca5c1f8..535729f 100644
--- a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
@@ -23,7 +23,7 @@
while (!isInterrupted) {
var size: Int
try {
- val buffer = ByteArray(64)
+ val buffer = ByteArray(32)
if (inputStream == null) return
size = inputStream!!.read(buffer)
if (size > 0) {
diff --git a/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
new file mode 100644
index 0000000..7b98c27
--- /dev/null
+++ b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
@@ -0,0 +1,38 @@
+package com.casic.detector.view
+
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Bundle
+import android.view.Gravity
+import androidx.appcompat.app.AppCompatActivity
+import com.casic.detector.R
+import com.pengxh.kt.lite.extensions.getScreenHeight
+import com.pengxh.kt.lite.extensions.getScreenWidth
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.utils.Constant
+import kotlinx.android.synthetic.main.activity_object_detail.*
+
+class NewObjectDetailActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_new_object_detail)
+
+ window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
+ window.decorView.setBackgroundColor(Color.TRANSPARENT)
+ window.setGravity(Gravity.CENTER)
+ val params = window.attributes
+ params.width = ((getScreenWidth() * 0.9).toInt())
+ params.height = ((getScreenHeight() * 0.3).toInt())
+ window.attributes = params
+
+ val identifierId = intent.getStringExtra(Constant.INTENT_PARAM)!!
+ identifierIdView.text = identifierId
+
+ closeView.setOnClickListener { finish() }
+ showImageView.setOnClickListener {
+ finish()
+ "此对象没相关照片".show(this)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
index 3140bc3..0531dda 100644
--- a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
+++ b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
@@ -1,24 +1,208 @@
package com.casic.detector.view
+import android.graphics.Color
+import android.media.AudioManager
+import android.media.SoundPool
import android.os.Bundle
+import android.os.Handler
+import android.os.Message
+import android.view.animation.Animation
+import android.view.animation.RotateAnimation
import com.casic.detector.R
import com.casic.detector.base.SerialPortActivity
+import com.casic.detector.extensions.hexToString
import com.casic.detector.extensions.initLayoutImmersionBar
+import com.casic.detector.extensions.toHex
+import com.casic.detector.utils.DataBaseManager
+import com.casic.detector.utils.GpioManager
+import com.casic.detector.utils.LoadingDialogHub
import com.gyf.immersionbar.ImmersionBar
+import com.pengxh.kt.lite.extensions.navigatePageTo
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.extensions.toJson
+import com.pengxh.kt.lite.utils.WeakReferenceHandler
+import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog
import kotlinx.android.synthetic.main.activity_search_label.*
+import java.io.IOException
+import java.text.DecimalFormat
+import java.util.*
-class SearchLabelActivity : SerialPortActivity() {
+class SearchLabelActivity : SerialPortActivity(), Handler.Callback {
+
+ private val kTag = "SearchLabelActivity"
+ private lateinit var soundPool: SoundPool
+ private val gpioManager by lazy { GpioManager() }
+ private lateinit var weakReferenceHandler: WeakReferenceHandler
+ private val timer by lazy { Timer() }
+ private val decimal by lazy { DecimalFormat("#.0") }
+ private var isDetectDepth = false
+ private var identifierId = ""
override fun initData(savedInstanceState: Bundle?) {
+ gpioManager.setGpioHigh("18")
+ weakReferenceHandler = WeakReferenceHandler(this)
+
+ soundPool = SoundPool(10, AudioManager.STREAM_SYSTEM, 5)
+ soundPool.load(this, R.raw.ring2, 1)
+
+ //搜索信号
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("2".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
+
+ //发送搜索能量指令
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("6".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
}
override fun initEvent() {
- leftBackView.setOnClickListener { finish() }
+ backButton.setOnClickListener { finish() }
+
+ depthButton.setOnClickListener {
+ isDetectDepth = true
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ val tag = when (result.first().identifierType) {
+ "EM30" -> {
+ "7"
+ }
+ "EM50" -> {
+ "8"
+ }
+ "EM14" -> {
+ "9"
+ }
+ else -> {
+ "1"
+ }
+ }
+ if (tag == "1") {
+ "此标识器无法读取埋深!".show(this)
+ } else {
+ // 发送读取标识器埋设深度指令*
+ LoadingDialogHub.show(this, "正在测距,请稍后...")
+ try {
+ outputStream?.write(tag.toByteArray())
+ outputStream?.flush()
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ } else {
+ "标识器未安装,安装成功后即可读取埋深!".show(this)
+ }
+ }
+
+ degreeButton.setOnClickListener {
+ //查库
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ navigatePageTo(result.first().toJson())
+ } else {
+ navigatePageTo(identifierId)
+ }
+ }
}
override fun onDataReceived(buffer: ByteArray?, size: Int) {
+ val message = weakReferenceHandler.obtainMessage()
+ message.what = 2023061901
+ message.obj = buffer
+ weakReferenceHandler.sendMessage(message)
+ }
+ override fun handleMessage(msg: Message): Boolean {
+ if (msg.what == 2023061901) {
+ val buffer = msg.obj as ByteArray
+ val hex = buffer.toHex()
+// Log.d(kTag, "hex => $hex")
+
+ //能量强度
+ //4E30363634000000000000000000000000000000000000000000000000000000
+
+ //ID
+ //3030303839383735313400000000000000000000000000000000000000000000
+
+ //埋深
+ //5330303736000000000000000000000000000000000000000000000000000000
+ if (hex.startsWith("4E")) {
+ try {
+ //4E转为String为N,代表能量值
+ //用能量值转动表盘
+ val energyResponse = hex.substring(0, 10).hexToString()
+ //去掉前缀并缩小100倍
+ var energy = energyResponse.substring(1).toInt() / 100
+ if (energy >= 50) {
+ //测试过程最大值(5189)52
+ energy = 50
+ }
+ //转换为转动的角度
+ val degree = (energy.toFloat() / 50) * 180
+ energyValueView.text = decimal.format(degree)
+
+ val animation = RotateAnimation(
+ 0f, degree,
+ Animation.RELATIVE_TO_SELF, 0.5f,
+ Animation.RELATIVE_TO_SELF, 0.5f
+ )
+ animation.duration = 0
+ animation.fillAfter = true
+ needleView.startAnimation(animation)
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else if (hex.startsWith("53")) {
+ try {
+ LoadingDialogHub.dismiss()
+ //53转为String为S,代表深度
+ val depthResponse = hex.substring(0, 10).hexToString()
+ val depth = depthResponse.substring(1).toInt()
+ AlertMessageDialog.Builder()
+ .setContext(this)
+ .setTitle("温馨提示")
+ .setMessage("标识器埋深:${depth}厘米")
+ .setPositiveButton("知道了")
+ .setOnDialogButtonClickListener(object :
+ AlertMessageDialog.OnDialogButtonClickListener {
+ override fun onConfirmClick() {
+ isDetectDepth = false
+ }
+ }).build().show()
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else {
+ identifierId = hex.substring(0, 20).hexToString()
+ val regex = "^[a-z0-9A-Z]+$"
+ if (identifierId.matches(Regex(regex))) {
+ searchResultView.text = "已搜索到标识器"
+ searchResultView.setTextColor(Color.RED)
+ depthButton.isEnabled = true
+ degreeButton.isEnabled = true
+ }
+ }
+ }
+ return true
}
override fun initLayoutView(): Int = R.layout.activity_search_label
@@ -31,4 +215,9 @@
ImmersionBar.with(this).statusBarDarkFont(true).init()
initLayoutImmersionBar(rootView)
}
+
+ override fun onDestroy() {
+ gpioManager.setGpioLow("18")
+ super.onDestroy()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 348eb88..99e23dd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -66,6 +66,9 @@
android:name=".view.ObjectDetailActivity"
android:theme="@style/Theme.ActivityDialogStyle" />
+
diff --git a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
index ca5c1f8..535729f 100644
--- a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
@@ -23,7 +23,7 @@
while (!isInterrupted) {
var size: Int
try {
- val buffer = ByteArray(64)
+ val buffer = ByteArray(32)
if (inputStream == null) return
size = inputStream!!.read(buffer)
if (size > 0) {
diff --git a/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
new file mode 100644
index 0000000..7b98c27
--- /dev/null
+++ b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
@@ -0,0 +1,38 @@
+package com.casic.detector.view
+
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Bundle
+import android.view.Gravity
+import androidx.appcompat.app.AppCompatActivity
+import com.casic.detector.R
+import com.pengxh.kt.lite.extensions.getScreenHeight
+import com.pengxh.kt.lite.extensions.getScreenWidth
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.utils.Constant
+import kotlinx.android.synthetic.main.activity_object_detail.*
+
+class NewObjectDetailActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_new_object_detail)
+
+ window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
+ window.decorView.setBackgroundColor(Color.TRANSPARENT)
+ window.setGravity(Gravity.CENTER)
+ val params = window.attributes
+ params.width = ((getScreenWidth() * 0.9).toInt())
+ params.height = ((getScreenHeight() * 0.3).toInt())
+ window.attributes = params
+
+ val identifierId = intent.getStringExtra(Constant.INTENT_PARAM)!!
+ identifierIdView.text = identifierId
+
+ closeView.setOnClickListener { finish() }
+ showImageView.setOnClickListener {
+ finish()
+ "此对象没相关照片".show(this)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
index 3140bc3..0531dda 100644
--- a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
+++ b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
@@ -1,24 +1,208 @@
package com.casic.detector.view
+import android.graphics.Color
+import android.media.AudioManager
+import android.media.SoundPool
import android.os.Bundle
+import android.os.Handler
+import android.os.Message
+import android.view.animation.Animation
+import android.view.animation.RotateAnimation
import com.casic.detector.R
import com.casic.detector.base.SerialPortActivity
+import com.casic.detector.extensions.hexToString
import com.casic.detector.extensions.initLayoutImmersionBar
+import com.casic.detector.extensions.toHex
+import com.casic.detector.utils.DataBaseManager
+import com.casic.detector.utils.GpioManager
+import com.casic.detector.utils.LoadingDialogHub
import com.gyf.immersionbar.ImmersionBar
+import com.pengxh.kt.lite.extensions.navigatePageTo
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.extensions.toJson
+import com.pengxh.kt.lite.utils.WeakReferenceHandler
+import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog
import kotlinx.android.synthetic.main.activity_search_label.*
+import java.io.IOException
+import java.text.DecimalFormat
+import java.util.*
-class SearchLabelActivity : SerialPortActivity() {
+class SearchLabelActivity : SerialPortActivity(), Handler.Callback {
+
+ private val kTag = "SearchLabelActivity"
+ private lateinit var soundPool: SoundPool
+ private val gpioManager by lazy { GpioManager() }
+ private lateinit var weakReferenceHandler: WeakReferenceHandler
+ private val timer by lazy { Timer() }
+ private val decimal by lazy { DecimalFormat("#.0") }
+ private var isDetectDepth = false
+ private var identifierId = ""
override fun initData(savedInstanceState: Bundle?) {
+ gpioManager.setGpioHigh("18")
+ weakReferenceHandler = WeakReferenceHandler(this)
+
+ soundPool = SoundPool(10, AudioManager.STREAM_SYSTEM, 5)
+ soundPool.load(this, R.raw.ring2, 1)
+
+ //搜索信号
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("2".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
+
+ //发送搜索能量指令
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("6".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
}
override fun initEvent() {
- leftBackView.setOnClickListener { finish() }
+ backButton.setOnClickListener { finish() }
+
+ depthButton.setOnClickListener {
+ isDetectDepth = true
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ val tag = when (result.first().identifierType) {
+ "EM30" -> {
+ "7"
+ }
+ "EM50" -> {
+ "8"
+ }
+ "EM14" -> {
+ "9"
+ }
+ else -> {
+ "1"
+ }
+ }
+ if (tag == "1") {
+ "此标识器无法读取埋深!".show(this)
+ } else {
+ // 发送读取标识器埋设深度指令*
+ LoadingDialogHub.show(this, "正在测距,请稍后...")
+ try {
+ outputStream?.write(tag.toByteArray())
+ outputStream?.flush()
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ } else {
+ "标识器未安装,安装成功后即可读取埋深!".show(this)
+ }
+ }
+
+ degreeButton.setOnClickListener {
+ //查库
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ navigatePageTo(result.first().toJson())
+ } else {
+ navigatePageTo(identifierId)
+ }
+ }
}
override fun onDataReceived(buffer: ByteArray?, size: Int) {
+ val message = weakReferenceHandler.obtainMessage()
+ message.what = 2023061901
+ message.obj = buffer
+ weakReferenceHandler.sendMessage(message)
+ }
+ override fun handleMessage(msg: Message): Boolean {
+ if (msg.what == 2023061901) {
+ val buffer = msg.obj as ByteArray
+ val hex = buffer.toHex()
+// Log.d(kTag, "hex => $hex")
+
+ //能量强度
+ //4E30363634000000000000000000000000000000000000000000000000000000
+
+ //ID
+ //3030303839383735313400000000000000000000000000000000000000000000
+
+ //埋深
+ //5330303736000000000000000000000000000000000000000000000000000000
+ if (hex.startsWith("4E")) {
+ try {
+ //4E转为String为N,代表能量值
+ //用能量值转动表盘
+ val energyResponse = hex.substring(0, 10).hexToString()
+ //去掉前缀并缩小100倍
+ var energy = energyResponse.substring(1).toInt() / 100
+ if (energy >= 50) {
+ //测试过程最大值(5189)52
+ energy = 50
+ }
+ //转换为转动的角度
+ val degree = (energy.toFloat() / 50) * 180
+ energyValueView.text = decimal.format(degree)
+
+ val animation = RotateAnimation(
+ 0f, degree,
+ Animation.RELATIVE_TO_SELF, 0.5f,
+ Animation.RELATIVE_TO_SELF, 0.5f
+ )
+ animation.duration = 0
+ animation.fillAfter = true
+ needleView.startAnimation(animation)
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else if (hex.startsWith("53")) {
+ try {
+ LoadingDialogHub.dismiss()
+ //53转为String为S,代表深度
+ val depthResponse = hex.substring(0, 10).hexToString()
+ val depth = depthResponse.substring(1).toInt()
+ AlertMessageDialog.Builder()
+ .setContext(this)
+ .setTitle("温馨提示")
+ .setMessage("标识器埋深:${depth}厘米")
+ .setPositiveButton("知道了")
+ .setOnDialogButtonClickListener(object :
+ AlertMessageDialog.OnDialogButtonClickListener {
+ override fun onConfirmClick() {
+ isDetectDepth = false
+ }
+ }).build().show()
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else {
+ identifierId = hex.substring(0, 20).hexToString()
+ val regex = "^[a-z0-9A-Z]+$"
+ if (identifierId.matches(Regex(regex))) {
+ searchResultView.text = "已搜索到标识器"
+ searchResultView.setTextColor(Color.RED)
+ depthButton.isEnabled = true
+ degreeButton.isEnabled = true
+ }
+ }
+ }
+ return true
}
override fun initLayoutView(): Int = R.layout.activity_search_label
@@ -31,4 +215,9 @@
ImmersionBar.with(this).statusBarDarkFont(true).init()
initLayoutImmersionBar(rootView)
}
+
+ override fun onDestroy() {
+ gpioManager.setGpioLow("18")
+ super.onDestroy()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_arrow.xml b/app/src/main/res/drawable/ic_arrow.xml
new file mode 100644
index 0000000..0be7d94
--- /dev/null
+++ b/app/src/main/res/drawable/ic_arrow.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 348eb88..99e23dd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -66,6 +66,9 @@
android:name=".view.ObjectDetailActivity"
android:theme="@style/Theme.ActivityDialogStyle" />
+
diff --git a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
index ca5c1f8..535729f 100644
--- a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
@@ -23,7 +23,7 @@
while (!isInterrupted) {
var size: Int
try {
- val buffer = ByteArray(64)
+ val buffer = ByteArray(32)
if (inputStream == null) return
size = inputStream!!.read(buffer)
if (size > 0) {
diff --git a/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
new file mode 100644
index 0000000..7b98c27
--- /dev/null
+++ b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
@@ -0,0 +1,38 @@
+package com.casic.detector.view
+
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Bundle
+import android.view.Gravity
+import androidx.appcompat.app.AppCompatActivity
+import com.casic.detector.R
+import com.pengxh.kt.lite.extensions.getScreenHeight
+import com.pengxh.kt.lite.extensions.getScreenWidth
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.utils.Constant
+import kotlinx.android.synthetic.main.activity_object_detail.*
+
+class NewObjectDetailActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_new_object_detail)
+
+ window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
+ window.decorView.setBackgroundColor(Color.TRANSPARENT)
+ window.setGravity(Gravity.CENTER)
+ val params = window.attributes
+ params.width = ((getScreenWidth() * 0.9).toInt())
+ params.height = ((getScreenHeight() * 0.3).toInt())
+ window.attributes = params
+
+ val identifierId = intent.getStringExtra(Constant.INTENT_PARAM)!!
+ identifierIdView.text = identifierId
+
+ closeView.setOnClickListener { finish() }
+ showImageView.setOnClickListener {
+ finish()
+ "此对象没相关照片".show(this)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
index 3140bc3..0531dda 100644
--- a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
+++ b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
@@ -1,24 +1,208 @@
package com.casic.detector.view
+import android.graphics.Color
+import android.media.AudioManager
+import android.media.SoundPool
import android.os.Bundle
+import android.os.Handler
+import android.os.Message
+import android.view.animation.Animation
+import android.view.animation.RotateAnimation
import com.casic.detector.R
import com.casic.detector.base.SerialPortActivity
+import com.casic.detector.extensions.hexToString
import com.casic.detector.extensions.initLayoutImmersionBar
+import com.casic.detector.extensions.toHex
+import com.casic.detector.utils.DataBaseManager
+import com.casic.detector.utils.GpioManager
+import com.casic.detector.utils.LoadingDialogHub
import com.gyf.immersionbar.ImmersionBar
+import com.pengxh.kt.lite.extensions.navigatePageTo
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.extensions.toJson
+import com.pengxh.kt.lite.utils.WeakReferenceHandler
+import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog
import kotlinx.android.synthetic.main.activity_search_label.*
+import java.io.IOException
+import java.text.DecimalFormat
+import java.util.*
-class SearchLabelActivity : SerialPortActivity() {
+class SearchLabelActivity : SerialPortActivity(), Handler.Callback {
+
+ private val kTag = "SearchLabelActivity"
+ private lateinit var soundPool: SoundPool
+ private val gpioManager by lazy { GpioManager() }
+ private lateinit var weakReferenceHandler: WeakReferenceHandler
+ private val timer by lazy { Timer() }
+ private val decimal by lazy { DecimalFormat("#.0") }
+ private var isDetectDepth = false
+ private var identifierId = ""
override fun initData(savedInstanceState: Bundle?) {
+ gpioManager.setGpioHigh("18")
+ weakReferenceHandler = WeakReferenceHandler(this)
+
+ soundPool = SoundPool(10, AudioManager.STREAM_SYSTEM, 5)
+ soundPool.load(this, R.raw.ring2, 1)
+
+ //搜索信号
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("2".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
+
+ //发送搜索能量指令
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("6".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
}
override fun initEvent() {
- leftBackView.setOnClickListener { finish() }
+ backButton.setOnClickListener { finish() }
+
+ depthButton.setOnClickListener {
+ isDetectDepth = true
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ val tag = when (result.first().identifierType) {
+ "EM30" -> {
+ "7"
+ }
+ "EM50" -> {
+ "8"
+ }
+ "EM14" -> {
+ "9"
+ }
+ else -> {
+ "1"
+ }
+ }
+ if (tag == "1") {
+ "此标识器无法读取埋深!".show(this)
+ } else {
+ // 发送读取标识器埋设深度指令*
+ LoadingDialogHub.show(this, "正在测距,请稍后...")
+ try {
+ outputStream?.write(tag.toByteArray())
+ outputStream?.flush()
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ } else {
+ "标识器未安装,安装成功后即可读取埋深!".show(this)
+ }
+ }
+
+ degreeButton.setOnClickListener {
+ //查库
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ navigatePageTo(result.first().toJson())
+ } else {
+ navigatePageTo(identifierId)
+ }
+ }
}
override fun onDataReceived(buffer: ByteArray?, size: Int) {
+ val message = weakReferenceHandler.obtainMessage()
+ message.what = 2023061901
+ message.obj = buffer
+ weakReferenceHandler.sendMessage(message)
+ }
+ override fun handleMessage(msg: Message): Boolean {
+ if (msg.what == 2023061901) {
+ val buffer = msg.obj as ByteArray
+ val hex = buffer.toHex()
+// Log.d(kTag, "hex => $hex")
+
+ //能量强度
+ //4E30363634000000000000000000000000000000000000000000000000000000
+
+ //ID
+ //3030303839383735313400000000000000000000000000000000000000000000
+
+ //埋深
+ //5330303736000000000000000000000000000000000000000000000000000000
+ if (hex.startsWith("4E")) {
+ try {
+ //4E转为String为N,代表能量值
+ //用能量值转动表盘
+ val energyResponse = hex.substring(0, 10).hexToString()
+ //去掉前缀并缩小100倍
+ var energy = energyResponse.substring(1).toInt() / 100
+ if (energy >= 50) {
+ //测试过程最大值(5189)52
+ energy = 50
+ }
+ //转换为转动的角度
+ val degree = (energy.toFloat() / 50) * 180
+ energyValueView.text = decimal.format(degree)
+
+ val animation = RotateAnimation(
+ 0f, degree,
+ Animation.RELATIVE_TO_SELF, 0.5f,
+ Animation.RELATIVE_TO_SELF, 0.5f
+ )
+ animation.duration = 0
+ animation.fillAfter = true
+ needleView.startAnimation(animation)
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else if (hex.startsWith("53")) {
+ try {
+ LoadingDialogHub.dismiss()
+ //53转为String为S,代表深度
+ val depthResponse = hex.substring(0, 10).hexToString()
+ val depth = depthResponse.substring(1).toInt()
+ AlertMessageDialog.Builder()
+ .setContext(this)
+ .setTitle("温馨提示")
+ .setMessage("标识器埋深:${depth}厘米")
+ .setPositiveButton("知道了")
+ .setOnDialogButtonClickListener(object :
+ AlertMessageDialog.OnDialogButtonClickListener {
+ override fun onConfirmClick() {
+ isDetectDepth = false
+ }
+ }).build().show()
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else {
+ identifierId = hex.substring(0, 20).hexToString()
+ val regex = "^[a-z0-9A-Z]+$"
+ if (identifierId.matches(Regex(regex))) {
+ searchResultView.text = "已搜索到标识器"
+ searchResultView.setTextColor(Color.RED)
+ depthButton.isEnabled = true
+ degreeButton.isEnabled = true
+ }
+ }
+ }
+ return true
}
override fun initLayoutView(): Int = R.layout.activity_search_label
@@ -31,4 +215,9 @@
ImmersionBar.with(this).statusBarDarkFont(true).init()
initLayoutImmersionBar(rootView)
}
+
+ override fun onDestroy() {
+ gpioManager.setGpioLow("18")
+ super.onDestroy()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_arrow.xml b/app/src/main/res/drawable/ic_arrow.xml
new file mode 100644
index 0000000..0be7d94
--- /dev/null
+++ b/app/src/main/res/drawable/ic_arrow.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_close.xml b/app/src/main/res/drawable/ic_close.xml
index 4d3c44d..4d69cb1 100644
--- a/app/src/main/res/drawable/ic_close.xml
+++ b/app/src/main/res/drawable/ic_close.xml
@@ -1,6 +1,6 @@
+
diff --git a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
index ca5c1f8..535729f 100644
--- a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
@@ -23,7 +23,7 @@
while (!isInterrupted) {
var size: Int
try {
- val buffer = ByteArray(64)
+ val buffer = ByteArray(32)
if (inputStream == null) return
size = inputStream!!.read(buffer)
if (size > 0) {
diff --git a/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
new file mode 100644
index 0000000..7b98c27
--- /dev/null
+++ b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
@@ -0,0 +1,38 @@
+package com.casic.detector.view
+
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Bundle
+import android.view.Gravity
+import androidx.appcompat.app.AppCompatActivity
+import com.casic.detector.R
+import com.pengxh.kt.lite.extensions.getScreenHeight
+import com.pengxh.kt.lite.extensions.getScreenWidth
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.utils.Constant
+import kotlinx.android.synthetic.main.activity_object_detail.*
+
+class NewObjectDetailActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_new_object_detail)
+
+ window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
+ window.decorView.setBackgroundColor(Color.TRANSPARENT)
+ window.setGravity(Gravity.CENTER)
+ val params = window.attributes
+ params.width = ((getScreenWidth() * 0.9).toInt())
+ params.height = ((getScreenHeight() * 0.3).toInt())
+ window.attributes = params
+
+ val identifierId = intent.getStringExtra(Constant.INTENT_PARAM)!!
+ identifierIdView.text = identifierId
+
+ closeView.setOnClickListener { finish() }
+ showImageView.setOnClickListener {
+ finish()
+ "此对象没相关照片".show(this)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
index 3140bc3..0531dda 100644
--- a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
+++ b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
@@ -1,24 +1,208 @@
package com.casic.detector.view
+import android.graphics.Color
+import android.media.AudioManager
+import android.media.SoundPool
import android.os.Bundle
+import android.os.Handler
+import android.os.Message
+import android.view.animation.Animation
+import android.view.animation.RotateAnimation
import com.casic.detector.R
import com.casic.detector.base.SerialPortActivity
+import com.casic.detector.extensions.hexToString
import com.casic.detector.extensions.initLayoutImmersionBar
+import com.casic.detector.extensions.toHex
+import com.casic.detector.utils.DataBaseManager
+import com.casic.detector.utils.GpioManager
+import com.casic.detector.utils.LoadingDialogHub
import com.gyf.immersionbar.ImmersionBar
+import com.pengxh.kt.lite.extensions.navigatePageTo
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.extensions.toJson
+import com.pengxh.kt.lite.utils.WeakReferenceHandler
+import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog
import kotlinx.android.synthetic.main.activity_search_label.*
+import java.io.IOException
+import java.text.DecimalFormat
+import java.util.*
-class SearchLabelActivity : SerialPortActivity() {
+class SearchLabelActivity : SerialPortActivity(), Handler.Callback {
+
+ private val kTag = "SearchLabelActivity"
+ private lateinit var soundPool: SoundPool
+ private val gpioManager by lazy { GpioManager() }
+ private lateinit var weakReferenceHandler: WeakReferenceHandler
+ private val timer by lazy { Timer() }
+ private val decimal by lazy { DecimalFormat("#.0") }
+ private var isDetectDepth = false
+ private var identifierId = ""
override fun initData(savedInstanceState: Bundle?) {
+ gpioManager.setGpioHigh("18")
+ weakReferenceHandler = WeakReferenceHandler(this)
+
+ soundPool = SoundPool(10, AudioManager.STREAM_SYSTEM, 5)
+ soundPool.load(this, R.raw.ring2, 1)
+
+ //搜索信号
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("2".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
+
+ //发送搜索能量指令
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("6".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
}
override fun initEvent() {
- leftBackView.setOnClickListener { finish() }
+ backButton.setOnClickListener { finish() }
+
+ depthButton.setOnClickListener {
+ isDetectDepth = true
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ val tag = when (result.first().identifierType) {
+ "EM30" -> {
+ "7"
+ }
+ "EM50" -> {
+ "8"
+ }
+ "EM14" -> {
+ "9"
+ }
+ else -> {
+ "1"
+ }
+ }
+ if (tag == "1") {
+ "此标识器无法读取埋深!".show(this)
+ } else {
+ // 发送读取标识器埋设深度指令*
+ LoadingDialogHub.show(this, "正在测距,请稍后...")
+ try {
+ outputStream?.write(tag.toByteArray())
+ outputStream?.flush()
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ } else {
+ "标识器未安装,安装成功后即可读取埋深!".show(this)
+ }
+ }
+
+ degreeButton.setOnClickListener {
+ //查库
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ navigatePageTo(result.first().toJson())
+ } else {
+ navigatePageTo(identifierId)
+ }
+ }
}
override fun onDataReceived(buffer: ByteArray?, size: Int) {
+ val message = weakReferenceHandler.obtainMessage()
+ message.what = 2023061901
+ message.obj = buffer
+ weakReferenceHandler.sendMessage(message)
+ }
+ override fun handleMessage(msg: Message): Boolean {
+ if (msg.what == 2023061901) {
+ val buffer = msg.obj as ByteArray
+ val hex = buffer.toHex()
+// Log.d(kTag, "hex => $hex")
+
+ //能量强度
+ //4E30363634000000000000000000000000000000000000000000000000000000
+
+ //ID
+ //3030303839383735313400000000000000000000000000000000000000000000
+
+ //埋深
+ //5330303736000000000000000000000000000000000000000000000000000000
+ if (hex.startsWith("4E")) {
+ try {
+ //4E转为String为N,代表能量值
+ //用能量值转动表盘
+ val energyResponse = hex.substring(0, 10).hexToString()
+ //去掉前缀并缩小100倍
+ var energy = energyResponse.substring(1).toInt() / 100
+ if (energy >= 50) {
+ //测试过程最大值(5189)52
+ energy = 50
+ }
+ //转换为转动的角度
+ val degree = (energy.toFloat() / 50) * 180
+ energyValueView.text = decimal.format(degree)
+
+ val animation = RotateAnimation(
+ 0f, degree,
+ Animation.RELATIVE_TO_SELF, 0.5f,
+ Animation.RELATIVE_TO_SELF, 0.5f
+ )
+ animation.duration = 0
+ animation.fillAfter = true
+ needleView.startAnimation(animation)
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else if (hex.startsWith("53")) {
+ try {
+ LoadingDialogHub.dismiss()
+ //53转为String为S,代表深度
+ val depthResponse = hex.substring(0, 10).hexToString()
+ val depth = depthResponse.substring(1).toInt()
+ AlertMessageDialog.Builder()
+ .setContext(this)
+ .setTitle("温馨提示")
+ .setMessage("标识器埋深:${depth}厘米")
+ .setPositiveButton("知道了")
+ .setOnDialogButtonClickListener(object :
+ AlertMessageDialog.OnDialogButtonClickListener {
+ override fun onConfirmClick() {
+ isDetectDepth = false
+ }
+ }).build().show()
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else {
+ identifierId = hex.substring(0, 20).hexToString()
+ val regex = "^[a-z0-9A-Z]+$"
+ if (identifierId.matches(Regex(regex))) {
+ searchResultView.text = "已搜索到标识器"
+ searchResultView.setTextColor(Color.RED)
+ depthButton.isEnabled = true
+ degreeButton.isEnabled = true
+ }
+ }
+ }
+ return true
}
override fun initLayoutView(): Int = R.layout.activity_search_label
@@ -31,4 +215,9 @@
ImmersionBar.with(this).statusBarDarkFont(true).init()
initLayoutImmersionBar(rootView)
}
+
+ override fun onDestroy() {
+ gpioManager.setGpioLow("18")
+ super.onDestroy()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_arrow.xml b/app/src/main/res/drawable/ic_arrow.xml
new file mode 100644
index 0000000..0be7d94
--- /dev/null
+++ b/app/src/main/res/drawable/ic_arrow.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_close.xml b/app/src/main/res/drawable/ic_close.xml
index 4d3c44d..4d69cb1 100644
--- a/app/src/main/res/drawable/ic_close.xml
+++ b/app/src/main/res/drawable/ic_close.xml
@@ -1,6 +1,6 @@
+
diff --git a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
index ca5c1f8..535729f 100644
--- a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
@@ -23,7 +23,7 @@
while (!isInterrupted) {
var size: Int
try {
- val buffer = ByteArray(64)
+ val buffer = ByteArray(32)
if (inputStream == null) return
size = inputStream!!.read(buffer)
if (size > 0) {
diff --git a/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
new file mode 100644
index 0000000..7b98c27
--- /dev/null
+++ b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
@@ -0,0 +1,38 @@
+package com.casic.detector.view
+
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Bundle
+import android.view.Gravity
+import androidx.appcompat.app.AppCompatActivity
+import com.casic.detector.R
+import com.pengxh.kt.lite.extensions.getScreenHeight
+import com.pengxh.kt.lite.extensions.getScreenWidth
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.utils.Constant
+import kotlinx.android.synthetic.main.activity_object_detail.*
+
+class NewObjectDetailActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_new_object_detail)
+
+ window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
+ window.decorView.setBackgroundColor(Color.TRANSPARENT)
+ window.setGravity(Gravity.CENTER)
+ val params = window.attributes
+ params.width = ((getScreenWidth() * 0.9).toInt())
+ params.height = ((getScreenHeight() * 0.3).toInt())
+ window.attributes = params
+
+ val identifierId = intent.getStringExtra(Constant.INTENT_PARAM)!!
+ identifierIdView.text = identifierId
+
+ closeView.setOnClickListener { finish() }
+ showImageView.setOnClickListener {
+ finish()
+ "此对象没相关照片".show(this)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
index 3140bc3..0531dda 100644
--- a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
+++ b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
@@ -1,24 +1,208 @@
package com.casic.detector.view
+import android.graphics.Color
+import android.media.AudioManager
+import android.media.SoundPool
import android.os.Bundle
+import android.os.Handler
+import android.os.Message
+import android.view.animation.Animation
+import android.view.animation.RotateAnimation
import com.casic.detector.R
import com.casic.detector.base.SerialPortActivity
+import com.casic.detector.extensions.hexToString
import com.casic.detector.extensions.initLayoutImmersionBar
+import com.casic.detector.extensions.toHex
+import com.casic.detector.utils.DataBaseManager
+import com.casic.detector.utils.GpioManager
+import com.casic.detector.utils.LoadingDialogHub
import com.gyf.immersionbar.ImmersionBar
+import com.pengxh.kt.lite.extensions.navigatePageTo
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.extensions.toJson
+import com.pengxh.kt.lite.utils.WeakReferenceHandler
+import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog
import kotlinx.android.synthetic.main.activity_search_label.*
+import java.io.IOException
+import java.text.DecimalFormat
+import java.util.*
-class SearchLabelActivity : SerialPortActivity() {
+class SearchLabelActivity : SerialPortActivity(), Handler.Callback {
+
+ private val kTag = "SearchLabelActivity"
+ private lateinit var soundPool: SoundPool
+ private val gpioManager by lazy { GpioManager() }
+ private lateinit var weakReferenceHandler: WeakReferenceHandler
+ private val timer by lazy { Timer() }
+ private val decimal by lazy { DecimalFormat("#.0") }
+ private var isDetectDepth = false
+ private var identifierId = ""
override fun initData(savedInstanceState: Bundle?) {
+ gpioManager.setGpioHigh("18")
+ weakReferenceHandler = WeakReferenceHandler(this)
+
+ soundPool = SoundPool(10, AudioManager.STREAM_SYSTEM, 5)
+ soundPool.load(this, R.raw.ring2, 1)
+
+ //搜索信号
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("2".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
+
+ //发送搜索能量指令
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("6".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
}
override fun initEvent() {
- leftBackView.setOnClickListener { finish() }
+ backButton.setOnClickListener { finish() }
+
+ depthButton.setOnClickListener {
+ isDetectDepth = true
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ val tag = when (result.first().identifierType) {
+ "EM30" -> {
+ "7"
+ }
+ "EM50" -> {
+ "8"
+ }
+ "EM14" -> {
+ "9"
+ }
+ else -> {
+ "1"
+ }
+ }
+ if (tag == "1") {
+ "此标识器无法读取埋深!".show(this)
+ } else {
+ // 发送读取标识器埋设深度指令*
+ LoadingDialogHub.show(this, "正在测距,请稍后...")
+ try {
+ outputStream?.write(tag.toByteArray())
+ outputStream?.flush()
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ } else {
+ "标识器未安装,安装成功后即可读取埋深!".show(this)
+ }
+ }
+
+ degreeButton.setOnClickListener {
+ //查库
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ navigatePageTo(result.first().toJson())
+ } else {
+ navigatePageTo(identifierId)
+ }
+ }
}
override fun onDataReceived(buffer: ByteArray?, size: Int) {
+ val message = weakReferenceHandler.obtainMessage()
+ message.what = 2023061901
+ message.obj = buffer
+ weakReferenceHandler.sendMessage(message)
+ }
+ override fun handleMessage(msg: Message): Boolean {
+ if (msg.what == 2023061901) {
+ val buffer = msg.obj as ByteArray
+ val hex = buffer.toHex()
+// Log.d(kTag, "hex => $hex")
+
+ //能量强度
+ //4E30363634000000000000000000000000000000000000000000000000000000
+
+ //ID
+ //3030303839383735313400000000000000000000000000000000000000000000
+
+ //埋深
+ //5330303736000000000000000000000000000000000000000000000000000000
+ if (hex.startsWith("4E")) {
+ try {
+ //4E转为String为N,代表能量值
+ //用能量值转动表盘
+ val energyResponse = hex.substring(0, 10).hexToString()
+ //去掉前缀并缩小100倍
+ var energy = energyResponse.substring(1).toInt() / 100
+ if (energy >= 50) {
+ //测试过程最大值(5189)52
+ energy = 50
+ }
+ //转换为转动的角度
+ val degree = (energy.toFloat() / 50) * 180
+ energyValueView.text = decimal.format(degree)
+
+ val animation = RotateAnimation(
+ 0f, degree,
+ Animation.RELATIVE_TO_SELF, 0.5f,
+ Animation.RELATIVE_TO_SELF, 0.5f
+ )
+ animation.duration = 0
+ animation.fillAfter = true
+ needleView.startAnimation(animation)
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else if (hex.startsWith("53")) {
+ try {
+ LoadingDialogHub.dismiss()
+ //53转为String为S,代表深度
+ val depthResponse = hex.substring(0, 10).hexToString()
+ val depth = depthResponse.substring(1).toInt()
+ AlertMessageDialog.Builder()
+ .setContext(this)
+ .setTitle("温馨提示")
+ .setMessage("标识器埋深:${depth}厘米")
+ .setPositiveButton("知道了")
+ .setOnDialogButtonClickListener(object :
+ AlertMessageDialog.OnDialogButtonClickListener {
+ override fun onConfirmClick() {
+ isDetectDepth = false
+ }
+ }).build().show()
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else {
+ identifierId = hex.substring(0, 20).hexToString()
+ val regex = "^[a-z0-9A-Z]+$"
+ if (identifierId.matches(Regex(regex))) {
+ searchResultView.text = "已搜索到标识器"
+ searchResultView.setTextColor(Color.RED)
+ depthButton.isEnabled = true
+ degreeButton.isEnabled = true
+ }
+ }
+ }
+ return true
}
override fun initLayoutView(): Int = R.layout.activity_search_label
@@ -31,4 +215,9 @@
ImmersionBar.with(this).statusBarDarkFont(true).init()
initLayoutImmersionBar(rootView)
}
+
+ override fun onDestroy() {
+ gpioManager.setGpioLow("18")
+ super.onDestroy()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_arrow.xml b/app/src/main/res/drawable/ic_arrow.xml
new file mode 100644
index 0000000..0be7d94
--- /dev/null
+++ b/app/src/main/res/drawable/ic_arrow.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_close.xml b/app/src/main/res/drawable/ic_close.xml
index 4d3c44d..4d69cb1 100644
--- a/app/src/main/res/drawable/ic_close.xml
+++ b/app/src/main/res/drawable/ic_close.xml
@@ -1,6 +1,6 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 348eb88..99e23dd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -66,6 +66,9 @@
android:name=".view.ObjectDetailActivity"
android:theme="@style/Theme.ActivityDialogStyle" />
+
diff --git a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
index ca5c1f8..535729f 100644
--- a/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
+++ b/app/src/main/java/com/casic/detector/base/SerialPortActivity.kt
@@ -23,7 +23,7 @@
while (!isInterrupted) {
var size: Int
try {
- val buffer = ByteArray(64)
+ val buffer = ByteArray(32)
if (inputStream == null) return
size = inputStream!!.read(buffer)
if (size > 0) {
diff --git a/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
new file mode 100644
index 0000000..7b98c27
--- /dev/null
+++ b/app/src/main/java/com/casic/detector/view/NewObjectDetailActivity.kt
@@ -0,0 +1,38 @@
+package com.casic.detector.view
+
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Bundle
+import android.view.Gravity
+import androidx.appcompat.app.AppCompatActivity
+import com.casic.detector.R
+import com.pengxh.kt.lite.extensions.getScreenHeight
+import com.pengxh.kt.lite.extensions.getScreenWidth
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.utils.Constant
+import kotlinx.android.synthetic.main.activity_object_detail.*
+
+class NewObjectDetailActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_new_object_detail)
+
+ window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
+ window.decorView.setBackgroundColor(Color.TRANSPARENT)
+ window.setGravity(Gravity.CENTER)
+ val params = window.attributes
+ params.width = ((getScreenWidth() * 0.9).toInt())
+ params.height = ((getScreenHeight() * 0.3).toInt())
+ window.attributes = params
+
+ val identifierId = intent.getStringExtra(Constant.INTENT_PARAM)!!
+ identifierIdView.text = identifierId
+
+ closeView.setOnClickListener { finish() }
+ showImageView.setOnClickListener {
+ finish()
+ "此对象没相关照片".show(this)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
index 3140bc3..0531dda 100644
--- a/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
+++ b/app/src/main/java/com/casic/detector/view/SearchLabelActivity.kt
@@ -1,24 +1,208 @@
package com.casic.detector.view
+import android.graphics.Color
+import android.media.AudioManager
+import android.media.SoundPool
import android.os.Bundle
+import android.os.Handler
+import android.os.Message
+import android.view.animation.Animation
+import android.view.animation.RotateAnimation
import com.casic.detector.R
import com.casic.detector.base.SerialPortActivity
+import com.casic.detector.extensions.hexToString
import com.casic.detector.extensions.initLayoutImmersionBar
+import com.casic.detector.extensions.toHex
+import com.casic.detector.utils.DataBaseManager
+import com.casic.detector.utils.GpioManager
+import com.casic.detector.utils.LoadingDialogHub
import com.gyf.immersionbar.ImmersionBar
+import com.pengxh.kt.lite.extensions.navigatePageTo
+import com.pengxh.kt.lite.extensions.show
+import com.pengxh.kt.lite.extensions.toJson
+import com.pengxh.kt.lite.utils.WeakReferenceHandler
+import com.pengxh.kt.lite.widget.dialog.AlertMessageDialog
import kotlinx.android.synthetic.main.activity_search_label.*
+import java.io.IOException
+import java.text.DecimalFormat
+import java.util.*
-class SearchLabelActivity : SerialPortActivity() {
+class SearchLabelActivity : SerialPortActivity(), Handler.Callback {
+
+ private val kTag = "SearchLabelActivity"
+ private lateinit var soundPool: SoundPool
+ private val gpioManager by lazy { GpioManager() }
+ private lateinit var weakReferenceHandler: WeakReferenceHandler
+ private val timer by lazy { Timer() }
+ private val decimal by lazy { DecimalFormat("#.0") }
+ private var isDetectDepth = false
+ private var identifierId = ""
override fun initData(savedInstanceState: Bundle?) {
+ gpioManager.setGpioHigh("18")
+ weakReferenceHandler = WeakReferenceHandler(this)
+
+ soundPool = SoundPool(10, AudioManager.STREAM_SYSTEM, 5)
+ soundPool.load(this, R.raw.ring2, 1)
+
+ //搜索信号
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("2".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
+
+ //发送搜索能量指令
+ timer.schedule(object : TimerTask() {
+ override fun run() {
+ try {
+ if (!isDetectDepth) {
+ outputStream?.write("6".toByteArray())
+ outputStream?.flush()
+ }
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ }, 150, 100)
}
override fun initEvent() {
- leftBackView.setOnClickListener { finish() }
+ backButton.setOnClickListener { finish() }
+
+ depthButton.setOnClickListener {
+ isDetectDepth = true
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ val tag = when (result.first().identifierType) {
+ "EM30" -> {
+ "7"
+ }
+ "EM50" -> {
+ "8"
+ }
+ "EM14" -> {
+ "9"
+ }
+ else -> {
+ "1"
+ }
+ }
+ if (tag == "1") {
+ "此标识器无法读取埋深!".show(this)
+ } else {
+ // 发送读取标识器埋设深度指令*
+ LoadingDialogHub.show(this, "正在测距,请稍后...")
+ try {
+ outputStream?.write(tag.toByteArray())
+ outputStream?.flush()
+ } catch (e: IOException) {
+ e.printStackTrace()
+ }
+ }
+ } else {
+ "标识器未安装,安装成功后即可读取埋深!".show(this)
+ }
+ }
+
+ degreeButton.setOnClickListener {
+ //查库
+ val result = DataBaseManager.get.queryLabelById(identifierId)
+ if (result.isNotEmpty()) {
+ navigatePageTo(result.first().toJson())
+ } else {
+ navigatePageTo(identifierId)
+ }
+ }
}
override fun onDataReceived(buffer: ByteArray?, size: Int) {
+ val message = weakReferenceHandler.obtainMessage()
+ message.what = 2023061901
+ message.obj = buffer
+ weakReferenceHandler.sendMessage(message)
+ }
+ override fun handleMessage(msg: Message): Boolean {
+ if (msg.what == 2023061901) {
+ val buffer = msg.obj as ByteArray
+ val hex = buffer.toHex()
+// Log.d(kTag, "hex => $hex")
+
+ //能量强度
+ //4E30363634000000000000000000000000000000000000000000000000000000
+
+ //ID
+ //3030303839383735313400000000000000000000000000000000000000000000
+
+ //埋深
+ //5330303736000000000000000000000000000000000000000000000000000000
+ if (hex.startsWith("4E")) {
+ try {
+ //4E转为String为N,代表能量值
+ //用能量值转动表盘
+ val energyResponse = hex.substring(0, 10).hexToString()
+ //去掉前缀并缩小100倍
+ var energy = energyResponse.substring(1).toInt() / 100
+ if (energy >= 50) {
+ //测试过程最大值(5189)52
+ energy = 50
+ }
+ //转换为转动的角度
+ val degree = (energy.toFloat() / 50) * 180
+ energyValueView.text = decimal.format(degree)
+
+ val animation = RotateAnimation(
+ 0f, degree,
+ Animation.RELATIVE_TO_SELF, 0.5f,
+ Animation.RELATIVE_TO_SELF, 0.5f
+ )
+ animation.duration = 0
+ animation.fillAfter = true
+ needleView.startAnimation(animation)
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else if (hex.startsWith("53")) {
+ try {
+ LoadingDialogHub.dismiss()
+ //53转为String为S,代表深度
+ val depthResponse = hex.substring(0, 10).hexToString()
+ val depth = depthResponse.substring(1).toInt()
+ AlertMessageDialog.Builder()
+ .setContext(this)
+ .setTitle("温馨提示")
+ .setMessage("标识器埋深:${depth}厘米")
+ .setPositiveButton("知道了")
+ .setOnDialogButtonClickListener(object :
+ AlertMessageDialog.OnDialogButtonClickListener {
+ override fun onConfirmClick() {
+ isDetectDepth = false
+ }
+ }).build().show()
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ } else {
+ identifierId = hex.substring(0, 20).hexToString()
+ val regex = "^[a-z0-9A-Z]+$"
+ if (identifierId.matches(Regex(regex))) {
+ searchResultView.text = "已搜索到标识器"
+ searchResultView.setTextColor(Color.RED)
+ depthButton.isEnabled = true
+ degreeButton.isEnabled = true
+ }
+ }
+ }
+ return true
}
override fun initLayoutView(): Int = R.layout.activity_search_label
@@ -31,4 +215,9 @@
ImmersionBar.with(this).statusBarDarkFont(true).init()
initLayoutImmersionBar(rootView)
}
+
+ override fun onDestroy() {
+ gpioManager.setGpioLow("18")
+ super.onDestroy()
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_arrow.xml b/app/src/main/res/drawable/ic_arrow.xml
new file mode 100644
index 0000000..0be7d94
--- /dev/null
+++ b/app/src/main/res/drawable/ic_arrow.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_close.xml b/app/src/main/res/drawable/ic_close.xml
index 4d3c44d..4d69cb1 100644
--- a/app/src/main/res/drawable/ic_close.xml
+++ b/app/src/main/res/drawable/ic_close.xml
@@ -1,6 +1,6 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_search_label.xml b/app/src/main/res/layout/activity_search_label.xml
index 4c3538f..53ddb46 100644
--- a/app/src/main/res/layout/activity_search_label.xml
+++ b/app/src/main/res/layout/activity_search_label.xml
@@ -8,7 +8,7 @@
+ android:layout_height="@dimen/AndroidChartHeight">
+ android:id="@+id/needleView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ android:src="@drawable/ic_arrow" />
@@ -39,62 +41,61 @@
android:orientation="horizontal">
+ android:fontFamily="@font/digifaw"
+ android:text="10"
+ android:textColor="@color/white"
+ android:textSize="70sp" />
-
+ android:layout_weight="1"
+ android:gravity="center"
+ android:orientation="vertical">
-
+
\ No newline at end of file