From 782d16c249986bb3c710d7b599f87c73d206d05d Mon Sep 17 00:00:00 2001 From: Kobetao <15503630572@163.com> Date: Fri, 31 May 2024 11:46:02 +0800 Subject: [PATCH 1/3] support gnss by struct --- .../location/VirtualLocation.java | 149 +++++++++++++++++- .../location/VirtualLocationManager.java | 13 +- 2 files changed, 157 insertions(+), 5 deletions(-) diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java b/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java index f8fe2ae..1b2d53e 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java @@ -45,6 +45,7 @@ import android.telephony.CellInfoGsm; import android.telephony.CellInfoLte; import android.telephony.CellInfoWcdma; import android.telephony.TelephonyManager; +import android.util.Log; import androidx.annotation.RequiresApi; import androidx.core.app.ActivityCompat; @@ -58,8 +59,11 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -315,7 +319,9 @@ public class VirtualLocation { } gnssMesurementsJson.put("measurements", gnssMesurementsJsonArray); - mGnssMeasurementsDataListener.onRecvData(gnssMesurementsJson.toString()); + // Log.i(TAG,"jwt gnssMesurementsJson:" + gnssMesurementsJson.toString()); + mGnssMeasurementsDataListener.onRecvData(getData(event)); + //mGnssMeasurementsDataListener.onRecvData(gnssMesurementsJson.toString()); } @RequiresApi(api = Build.VERSION_CODES.N) @@ -371,6 +377,110 @@ public class VirtualLocation { return jsonObject; } + private static boolean DEBUG = true; + + @RequiresApi(api = Build.VERSION_CODES.N) + private static void gnssMeasurementData(ByteBuffer buffer, GnssMeasurement measurement) { + int flags = 0; + + if (measurement.hasCarrierFrequencyHz()) { + flags = flags | HAS_CARRIER_FREQUENCY; + } + + if (measurement.hasCarrierCycles()) { + flags = flags | HAS_CARRIER_CYCLES; + } + + if (measurement.hasCarrierPhase()) { + flags = flags | HAS_CARRIER_PHASE; + } + + if (measurement.hasCarrierPhaseUncertainty()) { + flags = flags | HAS_CARRIER_PHASE_UNCERTAINTY; + } + + if (measurement.hasSnrInDb()) { + flags = flags | HAS_SNR; + } + + if (SDK_INT >= Build.VERSION_CODES.O) { + if (measurement.hasAutomaticGainControlLevelDb()) { + flags = flags | HAS_AUTOMATIC_GAIN_CONTROL; + } + } + + buffer.putInt((short) flags); + buffer.putShort((short) measurement.getSvid()); + buffer.put((byte) measurement.getConstellationType()); + buffer.putDouble(measurement.getTimeOffsetNanos()); + buffer.putInt(measurement.getState()); + buffer.putLong(measurement.getReceivedSvTimeNanos()); + buffer.putLong(measurement.getReceivedSvTimeUncertaintyNanos()); + buffer.putDouble(measurement.getCn0DbHz()); + buffer.putDouble(measurement.getPseudorangeRateMetersPerSecond()); + buffer.putDouble(measurement.getPseudorangeRateUncertaintyMetersPerSecond()); + buffer.putShort((short) measurement.getAccumulatedDeltaRangeState()); + buffer.putDouble(measurement.getAccumulatedDeltaRangeMeters()); + buffer.putDouble(measurement.getAccumulatedDeltaRangeUncertaintyMeters()); + buffer.putFloat(measurement.getCarrierFrequencyHz()); + buffer.putLong(measurement.getCarrierCycles()); + buffer.putDouble(measurement.getCarrierPhase()); + buffer.putDouble(measurement.getCarrierPhaseUncertainty()); + buffer.put((byte) measurement.getMultipathIndicator()); + buffer.putDouble(measurement.getSnrInDb()); + // buffer.putDouble(measurement.getAutomaticGainControlLevelDb()); + if (DEBUG) + Log.i(TAG, "@@tm@@ " + buffer.position() + " =====>:" + Arrays.toString(buffer.array())); + DEBUG = false; + } + + @RequiresApi(api = Build.VERSION_CODES.N) + private static void gnssClockData(ByteBuffer buffer, GnssClock gnssClock) { + int flags = 0; + + if (gnssClock.hasLeapSecond()) { + flags = flags | HAS_LEAP_SECOND; + } + + if (gnssClock.hasTimeUncertaintyNanos()) { + flags = flags | HAS_TIME_UNCERTAINTY; + } + + if (gnssClock.hasFullBiasNanos()) { + flags = flags | HAS_FULL_BIAS; + } + + if (gnssClock.hasBiasNanos()) { + flags = flags | HAS_BIAS; + } + + if (gnssClock.hasBiasUncertaintyNanos()) { + flags = flags | HAS_BIAS_UNCERTAINTY; + } + + if (gnssClock.hasDriftNanosPerSecond()) { + flags = flags | HAS_DRIFT; + } + + if (gnssClock.hasDriftUncertaintyNanosPerSecond()) { + flags = flags | HAS_DRIFT_UNCERTAINTY; + } + + buffer.putShort((short) flags); + buffer.putShort((short) gnssClock.getLeapSecond()); + buffer.putLong(gnssClock.getTimeNanos()); + buffer.putDouble(gnssClock.getTimeUncertaintyNanos()); + buffer.putLong(gnssClock.getFullBiasNanos()); + buffer.putDouble(gnssClock.getBiasNanos()); + buffer.putDouble(gnssClock.getLeapSecond()); + buffer.putDouble(gnssClock.getDriftNanosPerSecond()); + buffer.putDouble(gnssClock.getDriftUncertaintyNanosPerSecond()); + buffer.putInt(gnssClock.getHardwareClockDiscontinuityCount()); + //buffer.putInt(140); + if (DEBUG) + Log.i(TAG, "@@tm@@ " + buffer.position() + " =====>:" + Arrays.toString(buffer.array())); + } + @RequiresApi(api = Build.VERSION_CODES.N) private JSONObject gnssMeasurementToJsonObject(GnssMeasurement measurement) throws JSONException { DecimalFormat numberFormat = new DecimalFormat("#.#"); @@ -441,6 +551,43 @@ public class VirtualLocation { jsonObject.put("flags", flags); return jsonObject; } + + public static String byteArrayToString(byte[] byteArray) { + StringBuilder sb = new StringBuilder(); + for (byte b : byteArray) { + sb.append(String.format("%02X ", b)); + } + return sb.toString().trim(); + } + @RequiresApi(api = Build.VERSION_CODES.N) + public static ByteBuffer getData(GnssMeasurementsEvent event) { + // 创建ByteBuffer,大小为结构体的字节数 + ByteBuffer buffer = ByteBuffer.allocate(7896); + + // 设置字节序为小端序(与packed属性相对应) + buffer.order(ByteOrder.BIG_ENDIAN); + gnssClockData(buffer, event.getClock()); +/* byte[] data = new byte[buffer.position()]; + System.arraycopy(buffer.array(),0,data,0,data.length); + CASLog.i(TAG, "jwt gnssClockData ===> %s",byteArrayToString(data));*/ + buffer.put((byte) event.getMeasurements().size()); + int x = (byte) event.getMeasurements().size(); + CASLog.i(TAG, "jwt event.getMeasurements().size()=%d", x); + + for (GnssMeasurement measurement : event.getMeasurements()) { + byte Constellation = (byte)measurement.getConstellationType(); + int svid = measurement.getSvid(); + double pseudorangeRateMps = measurement.getPseudorangeRateMetersPerSecond(); + long receivedSvTimeInNs = measurement.getReceivedSvTimeNanos(); + short accumulatedDeltaRangeState = (short)measurement.getAccumulatedDeltaRangeState(); + int state = measurement.getState(); + //CASLog.i(TAG, "jwt Constellation=%d", Constellation); + CASLog.i(TAG, "jwt svid=%d, Constellation=%d, pseudorangeRateMps=%f, receivedSvTimeInNs=%d, accumulatedDeltaRangeState=%d, state=%d " + + "",svid , Constellation, pseudorangeRateMps, receivedSvTimeInNs, accumulatedDeltaRangeState, state); + gnssMeasurementData(buffer, measurement); + } + return buffer; + } private class CellInfoData { private String cellType = ""; diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocationManager.java b/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocationManager.java index fc778f6..2fda54c 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocationManager.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocationManager.java @@ -15,6 +15,7 @@ import com.huawei.cloudphone.common.CASLog; import com.huawei.cloudphone.virtualdevice.common.IVirtualDeviceDataListener; import com.huawei.cloudphone.virtualdevice.common.VirtualDeviceManager; import com.huawei.cloudphone.virtualdevice.common.VirtualDeviceProtocol; +import java.nio.ByteBuffer; public class VirtualLocationManager extends VirtualDeviceManager { private static final String TAG = "VirtualLocationManager"; @@ -64,6 +65,7 @@ public class VirtualLocationManager extends VirtualDeviceManager { @RequiresApi(api = Build.VERSION_CODES.P) public void processMsg(VirtualDeviceProtocol.MsgHeader header, byte[] body) { + Log.i(TAG,"processMsg:" + header); switch (header.mOptType) { case OPT_LOCATION_OPEN_REQ: Log.i(TAG, "processMsg: open location"); @@ -109,14 +111,17 @@ public class VirtualLocationManager extends VirtualDeviceManager { @Override public void onRecvData(Object... args) { - String body = (String) args[0]; +// String body = (String) args[0]; int type = 0; - int bodyLen = body.getBytes().length; +// int bodyLen = body.getBytes().length; + ByteBuffer body = (ByteBuffer) args[0]; + int bodyLen = body.position(); + CASLog.i(TAG, "gnssMeasurements size=" + bodyLen); int rspMsgLen = bodyLen + MSG_HEADER_LEN; - CASLog.i(TAG, "gnss bodyLen=" + bodyLen + " body=" + body); VirtualDeviceProtocol.MsgHeader header = new VirtualDeviceProtocol.MsgHeader(OPT_GNSS_MEASUREMENT_DATA, DEV_TYPE_LOCATION, (short) type, rspMsgLen); byte[] rspBody = new byte[bodyLen]; - System.arraycopy(body.getBytes(), 0, rspBody, 0, bodyLen); + System.arraycopy(body.array(), 0, rspBody, 0, bodyLen); +// System.arraycopy(body.getBytes(), 0, rspBody, 0, bodyLen); mVirtualDeviceProtocol.sendMsg(header, rspBody, LOCATION_DATA); } } -- Gitee From e1959fcddca12ff4a1a621b7da0ec64c88aa46f4 Mon Sep 17 00:00:00 2001 From: Kobetao <15503630572@163.com> Date: Sat, 1 Jun 2024 16:53:12 +0800 Subject: [PATCH 2/3] support gnss by struct fix1 --- app/build.gradle | 2 +- .../huawei/cloudapp/ui/CasCloudDebugActivity.java | 2 +- .../huawei/cloudapp/ui/CasCloudPhoneActivity.java | 2 +- .../huawei/cloudphone/service/CasProcessor.java | 1 + .../virtualdevice/location/VirtualLocation.java | 15 +++++++++++---- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4c0274f..55292f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -74,7 +74,7 @@ dependencies { implementation 'androidx.cardview:cardview:1.0.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.14.0' implementation 'com.hyman:flowlayout-lib:1.1.2' - implementation 'com.github.Petterpx:FloatingX:1.3.3' + // implementation 'com.github.Petterpx:FloatingX:1.3.3' implementation 'com.android.support:design:28.0.0' implementation 'com.github.shem8:material-login:2.1.1' implementation 'com.github.Justson.AgentWeb:agentweb-core:v5.0.6-androidx' diff --git a/app/src/main/java/com/huawei/cloudapp/ui/CasCloudDebugActivity.java b/app/src/main/java/com/huawei/cloudapp/ui/CasCloudDebugActivity.java index a39c376..63994e3 100644 --- a/app/src/main/java/com/huawei/cloudapp/ui/CasCloudDebugActivity.java +++ b/app/src/main/java/com/huawei/cloudapp/ui/CasCloudDebugActivity.java @@ -118,7 +118,7 @@ public class CasCloudDebugActivity extends Activity { connectorInfo.setSessionId(sessionId); connectorInfo.setTicket("ticket_xxxxxx"); // 32位16进制数,测试使用 - connectorInfo.setAesKey("a6b0986c973f4dbf9015b8f07c1f4524"); + connectorInfo.setAesKey("d252bf88dccf4affa7c490f707a37dd2"); connectorInfo.setAuthTs("987654321"); connectorInfo.setTouchTimeout("0"); return connectorInfo; diff --git a/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java b/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java index 7273a46..b04fc89 100644 --- a/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java +++ b/app/src/main/java/com/huawei/cloudapp/ui/CasCloudPhoneActivity.java @@ -919,7 +919,7 @@ public class CasCloudPhoneActivity extends FragmentActivity { connectorInfo.setSessionId(sessionId); connectorInfo.setTicket("ticket_xxxxxx"); // 32位16进制数,测试使用 - connectorInfo.setAesKey("11111111111111111111111111111111"); + connectorInfo.setAesKey("d252bf88dccf4affa7c490f707a37dd2"); connectorInfo.setAuthTs("987654321"); connectorInfo.setTouchTimeout(touchTimeout.isEmpty() ? "0" : touchTimeout); return connectorInfo; diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/service/CasProcessor.java b/cloudphone/src/main/java/com/huawei/cloudphone/service/CasProcessor.java index 1185123..24e25d9 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/service/CasProcessor.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/service/CasProcessor.java @@ -285,6 +285,7 @@ public class CasProcessor { jsonObj.put("user_id", connectorInfo.getUserId()); jsonObj.put("touch_timeout", connectorInfo.getTouchTimeout()); // 加密信息 + CASLog.i(TAG, "aeskey = " + connectorInfo.getAesKey()); String encryptedData = CasAESUtils.encryptWithAESGCM(jsonObj.toString(), connectorInfo.getAesKey(), connectorInfo.getAesIv()); return encryptedData; } diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java b/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java index 1b2d53e..be16ea4 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java @@ -430,7 +430,7 @@ public class VirtualLocation { buffer.putDouble(measurement.getSnrInDb()); // buffer.putDouble(measurement.getAutomaticGainControlLevelDb()); if (DEBUG) - Log.i(TAG, "@@tm@@ " + buffer.position() + " =====>:" + Arrays.toString(buffer.array())); + Log.i(TAG, "taotao" + buffer.position() + " =====>:" + Arrays.toString(buffer.array())); DEBUG = false; } @@ -478,7 +478,7 @@ public class VirtualLocation { buffer.putInt(gnssClock.getHardwareClockDiscontinuityCount()); //buffer.putInt(140); if (DEBUG) - Log.i(TAG, "@@tm@@ " + buffer.position() + " =====>:" + Arrays.toString(buffer.array())); + Log.i(TAG, "taotao" + buffer.position() + " =====>:" + Arrays.toString(buffer.array())); } @RequiresApi(api = Build.VERSION_CODES.N) @@ -574,17 +574,24 @@ public class VirtualLocation { int x = (byte) event.getMeasurements().size(); CASLog.i(TAG, "jwt event.getMeasurements().size()=%d", x); + int measurementCount = 1; for (GnssMeasurement measurement : event.getMeasurements()) { + if (measurementCount > 64){ + break; + } + byte Constellation = (byte)measurement.getConstellationType(); int svid = measurement.getSvid(); double pseudorangeRateMps = measurement.getPseudorangeRateMetersPerSecond(); long receivedSvTimeInNs = measurement.getReceivedSvTimeNanos(); short accumulatedDeltaRangeState = (short)measurement.getAccumulatedDeltaRangeState(); int state = measurement.getState(); + float carrierFrequencyHz= measurement.getCarrierFrequencyHz(); //CASLog.i(TAG, "jwt Constellation=%d", Constellation); - CASLog.i(TAG, "jwt svid=%d, Constellation=%d, pseudorangeRateMps=%f, receivedSvTimeInNs=%d, accumulatedDeltaRangeState=%d, state=%d " + - "",svid , Constellation, pseudorangeRateMps, receivedSvTimeInNs, accumulatedDeltaRangeState, state); + CASLog.i(TAG, "jwt measurementCount=%d, svid=%d, Constellation=%d, pseudorangeRateMps=%f, receivedSvTimeInNs=%d, accumulatedDeltaRangeState=%d, state=%d, carrierFrequencyHz = %f" + + "",measurementCount, svid , Constellation, pseudorangeRateMps, receivedSvTimeInNs, accumulatedDeltaRangeState, state, carrierFrequencyHz); gnssMeasurementData(buffer, measurement); + measurementCount+=1; } return buffer; } -- Gitee From 2a1889a65716d280321a75b54bbcd6f0f0ede3e1 Mon Sep 17 00:00:00 2001 From: Kobetao <15503630572@163.com> Date: Mon, 3 Jun 2024 21:12:29 +0800 Subject: [PATCH 3/3] support gnss by struct fix2 --- .../location/VirtualLocation.java | 88 ++++++++++++++++--- 1 file changed, 74 insertions(+), 14 deletions(-) diff --git a/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java b/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java index be16ea4..8e477ac 100644 --- a/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java +++ b/cloudphone/src/main/java/com/huawei/cloudphone/virtualdevice/location/VirtualLocation.java @@ -422,13 +422,39 @@ public class VirtualLocation { buffer.putShort((short) measurement.getAccumulatedDeltaRangeState()); buffer.putDouble(measurement.getAccumulatedDeltaRangeMeters()); buffer.putDouble(measurement.getAccumulatedDeltaRangeUncertaintyMeters()); - buffer.putFloat(measurement.getCarrierFrequencyHz()); - buffer.putLong(measurement.getCarrierCycles()); - buffer.putDouble(measurement.getCarrierPhase()); - buffer.putDouble(measurement.getCarrierPhaseUncertainty()); + + if (measurement.hasCarrierFrequencyHz()) { + buffer.putFloat(measurement.getCarrierFrequencyHz()); + } else { + buffer.putFloat(0); + } + + if (measurement.hasCarrierCycles()) { + buffer.putLong(measurement.getCarrierCycles()); + } else { + buffer.putLong(0); + } + + if (measurement.hasCarrierPhase()) { + buffer.putDouble(measurement.getCarrierPhase()); + } else { + buffer.putDouble(0); + } + + if (measurement.hasCarrierPhaseUncertainty()) { + buffer.putDouble(measurement.getCarrierPhaseUncertainty()); + } else { + buffer.putDouble(0); + } + buffer.put((byte) measurement.getMultipathIndicator()); - buffer.putDouble(measurement.getSnrInDb()); - // buffer.putDouble(measurement.getAutomaticGainControlLevelDb()); + + if (measurement.hasSnrInDb()) { + buffer.putDouble(measurement.getSnrInDb()); + } else { + buffer.putDouble(0); + } + //buffer.putDouble(measurement.getAutomaticGainControlLevelDb()); if (DEBUG) Log.i(TAG, "taotao" + buffer.position() + " =====>:" + Arrays.toString(buffer.array())); DEBUG = false; @@ -467,16 +493,50 @@ public class VirtualLocation { } buffer.putShort((short) flags); - buffer.putShort((short) gnssClock.getLeapSecond()); + if (gnssClock.hasLeapSecond()) { + buffer.putShort((short) gnssClock.getLeapSecond()); + } else { + buffer.putShort((short) 0); + } + buffer.putLong(gnssClock.getTimeNanos()); - buffer.putDouble(gnssClock.getTimeUncertaintyNanos()); - buffer.putLong(gnssClock.getFullBiasNanos()); - buffer.putDouble(gnssClock.getBiasNanos()); - buffer.putDouble(gnssClock.getLeapSecond()); - buffer.putDouble(gnssClock.getDriftNanosPerSecond()); - buffer.putDouble(gnssClock.getDriftUncertaintyNanosPerSecond()); + + if (gnssClock.hasTimeUncertaintyNanos()) { + buffer.putDouble(gnssClock.getTimeUncertaintyNanos()); + } else { + buffer.putDouble(0); + } + + if (gnssClock.hasFullBiasNanos()) { + buffer.putLong(gnssClock.getFullBiasNanos()); + } else { + buffer.putLong(0); + } + + if (gnssClock.hasBiasNanos()) { + buffer.putDouble(gnssClock.getBiasNanos()); + } else { + buffer.putDouble(0); + } + + if (gnssClock.hasBiasUncertaintyNanos()) { + buffer.putDouble(gnssClock.getBiasUncertaintyNanos()); + } else { + buffer.putDouble(0); + } + + if (gnssClock.hasDriftNanosPerSecond()) { + buffer.putDouble(gnssClock.getDriftNanosPerSecond()); + } else { + buffer.putDouble(0); + } + + if (gnssClock.hasDriftUncertaintyNanosPerSecond()) { + buffer.putDouble(gnssClock.getDriftUncertaintyNanosPerSecond()); + } else { + buffer.putDouble(0); + } buffer.putInt(gnssClock.getHardwareClockDiscontinuityCount()); - //buffer.putInt(140); if (DEBUG) Log.i(TAG, "taotao" + buffer.position() + " =====>:" + Arrays.toString(buffer.array())); } -- Gitee