fix: 修复数据大小端问题
修复IP地址输入框无法输入符号问题 将时间戳单位修改为毫秒
This commit is contained in:
parent
bf391ba7c0
commit
729d782815
|
@ -110,7 +110,7 @@ class MainActivity : AppCompatActivity(), SendDialogFragment.NoticeDialogListene
|
||||||
Log.i(tag, getPoseLandmarksDebugString(landmarks))*/
|
Log.i(tag, getPoseLandmarksDebugString(landmarks))*/
|
||||||
val landmarks = PacketGetter.getProto(it,
|
val landmarks = PacketGetter.getProto(it,
|
||||||
NormalizedLandmarkList.getDefaultInstance())
|
NormalizedLandmarkList.getDefaultInstance())
|
||||||
val poseLandmarks = PoseLandmark.valueOf(landmarks, it.timestamp)
|
val poseLandmarks = PoseLandmark.valueOf(landmarks, System.currentTimeMillis())
|
||||||
|
|
||||||
val buffer = ByteBuffer.allocate(
|
val buffer = ByteBuffer.allocate(
|
||||||
poseLandmarks.size * PoseLandmark.packetLength)
|
poseLandmarks.size * PoseLandmark.packetLength)
|
||||||
|
@ -176,8 +176,17 @@ class MainActivity : AppCompatActivity(), SendDialogFragment.NoticeDialogListene
|
||||||
override fun onDialogPositiveClick(dialog: DialogFragment) {
|
override fun onDialogPositiveClick(dialog: DialogFragment) {
|
||||||
Log.i(tag, "Confirm Button Clicked.")
|
Log.i(tag, "Confirm Button Clicked.")
|
||||||
|
|
||||||
val ipInput = findViewById<EditText>(R.id.targetIP).text.toString()
|
val ipEditText = dialog.dialog?.findViewById<EditText>(R.id.targetIP)
|
||||||
val portInput = findViewById<EditText>(R.id.targetPort).text.toString()
|
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 {
|
try {
|
||||||
val port = portInput.toInt()
|
val port = portInput.toInt()
|
||||||
if (isSet) {
|
if (isSet) {
|
||||||
|
@ -188,7 +197,7 @@ class MainActivity : AppCompatActivity(), SendDialogFragment.NoticeDialogListene
|
||||||
sender = UdpSender(ipInput, port)
|
sender = UdpSender(ipInput, port)
|
||||||
isSet = true
|
isSet = true
|
||||||
|
|
||||||
showToastMessage("Server set successfully!")
|
showToastMessage("Server $ipInput:$portInput set successfully! ")
|
||||||
} catch (e: java.lang.NumberFormatException) {
|
} catch (e: java.lang.NumberFormatException) {
|
||||||
Log.e(tag, "Input error: $e")
|
Log.e(tag, "Input error: $e")
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package top.rrricardo.motioncapture.models
|
||||||
|
|
||||||
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmarkList
|
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmarkList
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
import java.nio.ByteOrder
|
||||||
|
|
||||||
class PoseLandmark(
|
class PoseLandmark(
|
||||||
private val Type: Int,
|
private val Type: Int,
|
||||||
|
@ -13,6 +14,7 @@ class PoseLandmark(
|
||||||
|
|
||||||
fun toByteArray(): ByteArray {
|
fun toByteArray(): ByteArray {
|
||||||
val result = ByteBuffer.allocate(packetLength)
|
val result = ByteBuffer.allocate(packetLength)
|
||||||
|
result.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|
||||||
result.putInt(Type)
|
result.putInt(Type)
|
||||||
result.putFloat(X)
|
result.putFloat(X)
|
||||||
|
@ -25,10 +27,11 @@ class PoseLandmark(
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val packetLength = 28;
|
const val packetLength = 28
|
||||||
|
|
||||||
fun valueOf(data: ByteArray): PoseLandmark {
|
fun valueOf(data: ByteArray): PoseLandmark {
|
||||||
val buffer = ByteBuffer.wrap(data)
|
val buffer = ByteBuffer.wrap(data)
|
||||||
|
buffer.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|
||||||
val type = buffer.int
|
val type = buffer.int
|
||||||
val x = buffer.float
|
val x = buffer.float
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/targetIP"
|
android:id="@+id/targetIP"
|
||||||
android:inputType="number"
|
android:inputType="text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="20dp"
|
android:layout_margin="20dp"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user