调整运维获取电压的方式

lowmem
Matthew 1 month ago
parent dc17a15210
commit 3bc6775f84

@ -34,6 +34,7 @@
#define MAX_STRING_LEN 32
#define PATH_MPAPP_STATS "/sdcard/com.xypower.mpapp/data/stats/"
#define PATH_MPAPP_BATTERY "/sdcard/com.xypower.mpapp/data/bv"
#define PATH_MPAPP_RUNNING "/sdcard/com.xypower.mpapp/running"
//extern int bspatch_main(int argc,char * argv[]);
@ -217,3 +218,42 @@ Java_com_xypower_mpmaster_MpMasterService_applyDiff(JNIEnv *env, jclass clazz, j
return result == 0 ? JNI_TRUE : JNI_FALSE;
}
extern "C"
JNIEXPORT jlongArray JNICALL
Java_com_xypower_mpmaster_MpMasterService_getBatteryInfo(JNIEnv *env, jclass clazz) {
FILE* file = NULL;
for (int idx = 0; idx < 3; idx++)
{
file = fopen(PATH_MPAPP_BATTERY, "r");
if (file != NULL)
{
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
if (file == NULL)
{
return NULL;
}
std::vector<uint8_t> data;
data.resize(0, sizeof(int) + sizeof(int) + sizeof(uint64_t));
size_t length = fread(&data[0], 1, data.size(), file);
fclose(file);
if (length < data.size())
{
return NULL;
}
jlong items[3] = { 0 };
items[0] = *((int *)(&data[0]));
items[1] = *((int *)(&data[sizeof(int)]));
items[2] = *((uint64_t *)(&data[sizeof(int) + sizeof(int)]));
size_t intLength = 3;
jlongArray result = env->NewLongArray(intLength);
env->SetLongArrayRegion(result, 0, intLength, (const jlong*)items);
return result;
}

@ -280,7 +280,12 @@ public class AppMaster {
// }
try {
String battery = mService.getBatteryVoltage() + "V/" + mService.getChargingBatteryVoltage() + "V";
long[] batteryInfo = MpMasterService.getBatteryInfo();
String battery = "";
if (batteryInfo.length == 3 && batteryInfo[2] > 0) {
battery = Float.toString(batteryInfo[0] / 1000) + "V/" + Float.toString(batteryInfo[1] / 1000) + "V";
}
postParams.add(new Pair<String, String>("battery", battery));
} catch (Exception ex) {
ex.printStackTrace();

@ -93,7 +93,6 @@ public class MpMasterService extends Service {
private int mPrevDateForLogs = 0;
private int mMasterTimers = 0;
private SingletonThread batterySingleThread;
public static class STATE_SERVICE {
public static final int CONNECTED = 10;
@ -234,8 +233,6 @@ public class MpMasterService extends Service {
mPreviousMpHbTime = System.currentTimeMillis();
mTimeToStartMpApp = mPreviousMpHbTime;
buildChargingBatteryVoltage(System.currentTimeMillis());
logger.info("MpMaster started version=" + mMpMasterVersion);
mHander = new Handler();
@ -336,9 +333,7 @@ public class MpMasterService extends Service {
} catch (Exception ex) {
}
}
if (batterySingleThread != null) {
batterySingleThread.shutdown();
}
super.onDestroy();
}
@ -670,8 +665,6 @@ public class MpMasterService extends Service {
mService.mPreviousHeartbeatTime = 0;
mService.registerHeartbeatTimer();
mService.buildChargingBatteryVoltage(System.currentTimeMillis());
if (!keepAlive) {
mService.startMaster(false);
}
@ -687,7 +680,6 @@ public class MpMasterService extends Service {
mService.registerHeartbeatTimer();
mService.buildChargingBatteryVoltage(System.currentTimeMillis());
if (!mService.mSeparateNetwork && (!mService.mMntnMode)) {
mService.startMaster(true);
}
@ -702,7 +694,6 @@ public class MpMasterService extends Service {
mService.registerHeartbeatTimer();
mService.buildChargingBatteryVoltage(System.currentTimeMillis());
if (!mService.mSeparateNetwork && (!mService.mMntnMode)) {
mService.startMaster(true);
}
@ -1092,44 +1083,6 @@ public class MpMasterService extends Service {
return signalLevel;
}
public static String getBatteryVoltage() {
int val = 0;
for (int idx = 0; idx < 3; idx++) {
val = MpMasterService.getInt(117);
if (val > 0) {
return Integer.toString(val / 1000) + "." + Integer.toString((val % 1000) / 100);
}
}
return "";
}
private void buildChargingBatteryVoltage(long ts) {
batterySingleThread = SingletonThread.getInstance();
batterySingleThread.execute(new Runnable() {
@Override
public void run() {
logger.info("电压线程开始");
int val = 0;
for (int idx = 0; idx < 3; idx++) {
logger.info("电压测试第" + idx + "次开始读取");
val = MpMasterService.getInt(112);
logger.info("电压测试第" + idx + "次读取结束 " + val);
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);
@ -1140,18 +1093,6 @@ public class MpMasterService extends Service {
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();
@ -1547,6 +1488,8 @@ public class MpMasterService extends Service {
public native static int[] getStats(long ts);
public native static long[] getBatteryInfo();
public native static String getSystemProperty(String key);
public native static void rebootDevice();

Loading…
Cancel
Save