fix: 修复数据大小端问题

修复IP地址输入框无法输入符号问题
将时间戳单位修改为毫秒
This commit is contained in:
jackfiled 2023-02-10 17:41:30 +08:00
parent bf391ba7c0
commit 729d782815
3 changed files with 18 additions and 6 deletions

View File

@ -110,7 +110,7 @@ class MainActivity : AppCompatActivity(), SendDialogFragment.NoticeDialogListene
Log.i(tag, getPoseLandmarksDebugString(landmarks))*/
val landmarks = PacketGetter.getProto(it,
NormalizedLandmarkList.getDefaultInstance())
val poseLandmarks = PoseLandmark.valueOf(landmarks, it.timestamp)
val poseLandmarks = PoseLandmark.valueOf(landmarks, System.currentTimeMillis())
val buffer = ByteBuffer.allocate(
poseLandmarks.size * PoseLandmark.packetLength)
@ -176,8 +176,17 @@ class MainActivity : AppCompatActivity(), SendDialogFragment.NoticeDialogListene
override fun onDialogPositiveClick(dialog: DialogFragment) {
Log.i(tag, "Confirm Button Clicked.")
val ipInput = findViewById<EditText>(R.id.targetIP).text.toString()
val portInput = findViewById<EditText>(R.id.targetPort).text.toString()
val ipEditText = dialog.dialog?.findViewById<EditText>(R.id.targetIP)
val portEditText = dialog.dialog?.findViewById<EditText>(R.id.targetPort)
if (ipEditText == null || portEditText == null) {
Log.e(tag, "Get EditText Failed.")
return
}
val ipInput = ipEditText.text.toString()
val portInput = portEditText.text.toString()
try {
val port = portInput.toInt()
if (isSet) {
@ -188,7 +197,7 @@ class MainActivity : AppCompatActivity(), SendDialogFragment.NoticeDialogListene
sender = UdpSender(ipInput, port)
isSet = true
showToastMessage("Server set successfully!")
showToastMessage("Server $ipInput:$portInput set successfully! ")
} catch (e: java.lang.NumberFormatException) {
Log.e(tag, "Input error: $e")
}

View File

@ -2,6 +2,7 @@ package top.rrricardo.motioncapture.models
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmarkList
import java.nio.ByteBuffer
import java.nio.ByteOrder
class PoseLandmark(
private val Type: Int,
@ -13,6 +14,7 @@ class PoseLandmark(
fun toByteArray(): ByteArray {
val result = ByteBuffer.allocate(packetLength)
result.order(ByteOrder.LITTLE_ENDIAN)
result.putInt(Type)
result.putFloat(X)
@ -25,10 +27,11 @@ class PoseLandmark(
}
companion object {
const val packetLength = 28;
const val packetLength = 28
fun valueOf(data: ByteArray): PoseLandmark {
val buffer = ByteBuffer.wrap(data)
buffer.order(ByteOrder.LITTLE_ENDIAN)
val type = buffer.int
val x = buffer.float

View File

@ -12,7 +12,7 @@
<EditText
android:id="@+id/targetIP"
android:inputType="number"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"