From 33030ca2b789bb8afc51c9f6c0cbbfa000b2309f Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 23 Sep 2024 16:31:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=8E=86=E5=8F=B2=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E5=85=85=E7=94=B5=E7=94=B5=E5=8E=8B=E5=B9=B6=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xypower/mpmaster/AppMaster.java | 28 ++------- .../com/xypower/mpmaster/MpMasterService.java | 60 ++++++++++++++++++- 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java b/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java index e1b82b7f..7a6858b8 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/AppMaster.java @@ -272,12 +272,16 @@ public class AppMaster { // } try { - String battery = getBatteryVoltage() + "V/" + getChargingBatteryVoltage() + "V"; + String battery = mService.getBatteryVoltage() + "V/" + mService.getChargingBatteryVoltage() + "V"; postParams.add(new Pair("battery", battery)); } catch (Exception ex) { ex.printStackTrace(); } + if (mService.isSeparateNetwork()) { + postParams.add(new Pair("maxBCV", mService.getAndResetMaxBCV())); + } + for (int idx = 0; idx < 3; idx++) { try { httpURLConnection = (HttpURLConnection) url.openConnection(); @@ -481,29 +485,7 @@ public class AppMaster { return ((cnts[0] == 0) && (cnts[1] == 0)) ? null : Integer.toString(cnts[0]) + " " + Integer.toString(cnts[1]); } - private String getBatteryVoltage() { - int val = 0; - for (int idx = 0; idx < 3; idx++) { - val = MpMasterService.getInt(115); - if (val > 0) { - return Integer.toString(val / 1000) + "." + Integer.toString((val % 1000) / 100); - } - } - - return ""; - } - - private String getChargingBatteryVoltage() { - int val = 0; - for (int idx = 0; idx < 3; idx++) { - val = MpMasterService.getInt(112); - if (val > 0) { - return Integer.toString(val / 1000) + "." + Integer.toString((val % 1000) / 100); - } - } - return ""; - } private String getImei(int number) { return (number == 1) ? SysApi.getImei(mService) : SysApi.getImei2(mService); diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java index 31403c38..ff92754a 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java @@ -128,6 +128,9 @@ public class MpMasterService extends Service { private long mPreviousMpHbTime = 0; + private int mMaxBCV = 0; + private long mMaxBCVTime = 0; + private String mIccid1 = null; private String mIccid2 = null; @@ -199,6 +202,8 @@ public class MpMasterService extends Service { mPreviousMpHbTime = System.currentTimeMillis(); + buildChargingBatteryVoltage(System.currentTimeMillis()); + logger.info("MpMaster started version=" + mMpMasterVersion); mHander = new Handler(); @@ -541,6 +546,8 @@ public class MpMasterService extends Service { mService.mPreviousHeartbeatTime = 0; mService.registerHeartbeatTimer(); + mService.buildChargingBatteryVoltage(System.currentTimeMillis()); + if (!keepAlive) { mService.startMaster(false); } @@ -557,6 +564,7 @@ public class MpMasterService extends Service { mService.registerHeartbeatTimer(); + mService.buildChargingBatteryVoltage(System.currentTimeMillis()); if (!mService.mSeparateNetwork && (!mService.mMntnMode)) { mService.startMaster(true); } @@ -620,7 +628,6 @@ public class MpMasterService extends Service { SysApi.installOTA(context, context.getPackageName(), path); } }); - } private void registerHeartbeatTimer() { @@ -930,6 +937,57 @@ public class MpMasterService extends Service { return signalLevel; } + public static String getBatteryVoltage() { + int val = 0; + for (int idx = 0; idx < 3; idx++) { + val = MpMasterService.getInt(115); + if (val > 0) { + return Integer.toString(val / 1000) + "." + Integer.toString((val % 1000) / 100); + } + } + + return ""; + } + + private void buildChargingBatteryVoltage(long ts) { + int val = 0; + for (int idx = 0; idx < 3; idx++) { + val = MpMasterService.getInt(112); + if (val > 0) { + break; + } + } + + if (val > 0) { + if (val > mMaxBCV) { + mMaxBCV = val; + mMaxBCVTime = ts; + } + } + } + + public String getAndResetMaxBCV() { + String val = Integer.toString(mMaxBCV / 1000) + "." + Integer.toString((mMaxBCV % 1000) / 100) + + "/" + Long.toString(mMaxBCVTime / 1000); + + mMaxBCV = 0; + mMaxBCVTime = 0; + + return val; + } + + public static String getChargingBatteryVoltage() { + int val = 0; + for (int idx = 0; idx < 3; idx++) { + val = MpMasterService.getInt(112); + if (val > 0) { + return Integer.toString(val / 1000) + "." + Integer.toString((val % 1000) / 100); + } + } + + return ""; + } + public void downloadAndInstall(final String url) { final Context context = getApplicationContext();