优化运维功能

serial
Matthew 1 year ago
parent 8c4f7faee1
commit e57843cdb0

@ -8,7 +8,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>

@ -54,9 +54,7 @@ public class MainActivity extends AppCompatActivity {
public static final int MSG_WHAT_LOG_OBSERVER = MicroPhotoService.MSG_WHAT_MAX + 10;
// Used to load the 'microphoto' library on application startup.
static {
System.loadLibrary("microphoto");
}
public static final int MAX_LOG_LINES = 480;
public static final int MIN_LOG_LINES = 120;

@ -26,6 +26,7 @@ android {
externalNativeBuild {
cmake {
abiFilters 'arm64-v8a'
cppFlags ''
}
}
}
@ -39,6 +40,25 @@ android {
jniDebuggable true
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.18.1'
}
}
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
@ -53,10 +73,6 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
@ -75,7 +91,6 @@ android {
keyPassword 'XyMpApp'
}
}
}
dependencies {

@ -0,0 +1,49 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.18.1)
# Declares and names the project.
project("mpmaster")
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
mpmaster
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
mpmaster.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
mpmaster
# Links the target library to the log library
# included in the NDK.
${log-lib} )

@ -0,0 +1,54 @@
// Write C++ code here.
//
// Do not forget to dynamically load the C++ library into your application.
//
// For instance,
//
// In MainActivity.java:
// static {
// System.loadLibrary("mpmaster");
// }
//
// Or, in MainActivity.kt:
// companion object {
// init {
// System.loadLibrary("mpmaster")
// }
// }
#include <jni.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define IOT_PARAM_WRITE 0xAE
#define IOT_PARAM_READ 0xAF
#define MAX_STRING_LEN 32
typedef struct
{
int cmd;
int value;
int result;
long value2;
char str[MAX_STRING_LEN];
}IOT_PARAM;
extern "C" JNIEXPORT jint JNICALL
Java_com_xypower_mpmaster_MpMasterService_getInt(JNIEnv* env, jclass cls, jint cmd) {
int fd = open("/dev/mtkgpioctrl", O_RDONLY);
// LOGE("get_int fd=%d,cmd=%d\r\n",fd, cmd);
if( fd > 0 )
{
IOT_PARAM param;
param.cmd = cmd;
ioctl(fd, IOT_PARAM_READ, &param);
#ifdef _DEBUG
ALOGI("getInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
#endif
close(fd);
return param.value;
}
return -1;
}

@ -64,6 +64,7 @@ public class AppMaster {
public static final String CMD_UPDATE_CONFIG = "upd_cfg";
public static final String CMD_PULL_FILE = "pull_files";
public static final String CMD_PUSH_FILE = "push_file";
public static final String CMD_DELETE_FILE = "del_file";
public static final String CMD_HOT_SPOT = "yw_cmd_hot_spot";
public static final String CMD_ENABLE_GPS = "yw_cmd_enable_gps";
public static final String CMD_ENABLE_OTG = "yw_cmd_enable_otg";
@ -270,13 +271,12 @@ public class AppMaster {
} catch (Exception e) {
e.printStackTrace();
}
}
private String getBatteryVoltage() {
int val = 0;
for (int idx = 0; idx < 3; idx++) {
val = SysApi.getBatteryVoltage();
val = MpMasterService.getInt(115);
if (val > 0) {
return Integer.toString(val / 1000) + "." + Integer.toString((val % 1000) / 100);
}
@ -288,7 +288,7 @@ public class AppMaster {
private String getChargingBatteryVoltage() {
int val = 0;
for (int idx = 0; idx < 3; idx++) {
val = SysApi.getChargingBusVoltage();
val = MpMasterService.getInt(112);
if (val > 0) {
return Integer.toString(val / 1000) + "." + Integer.toString((val % 1000) / 100);
}
@ -366,7 +366,6 @@ public class AppMaster {
private void processCmd(long cid, JSONObject jsonObject) {
String cmd = jsonObject.optString("cmd", "");
if (TextUtils.equals(cmd, CMD_REBOOT_DEV)) {
SysApi.reboot(mService.getApplicationContext());
} else if (TextUtils.equals(cmd, CMD_UPLOAD_LOGS)) {
@ -455,6 +454,46 @@ public class AppMaster {
} else if (TextUtils.equals(cmd, CMD_ENABLE_OTG)) {
int enable = jsonObject.optInt("enable", 1);
SysApi.setOtgState((enable != 0));
} else if (TextUtils.equals(cmd, CMD_PULL_FILE)) {
pullFiles(jsonObject);
} else if (TextUtils.equals(cmd, CMD_DELETE_FILE)) {
String path = jsonObject.optString("path", null);
deleteFile(path);
}
}
private void pullFiles(JSONObject jsonObject) {
try {
JSONArray jsonPaths = jsonObject.optJSONArray("paths");
if (jsonPaths != null && jsonPaths.length() > 0) {
// String[] path = jsonObject.optString("path", null);
List<String> paths = new ArrayList<>();
for (int idx = 0; idx < jsonPaths.length(); idx++) {
String path = jsonPaths.optString(idx);
if (path != null) {
paths.add(path);
}
}
String url = jsonObject.optString("url", null);
if (url != null && !paths.isEmpty()) {
uploadFiles(url, paths);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void deleteFile(String path) {
try {
File file = new File(path);
if (file.exists() && file.isFile()) {
file.delete();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
@ -608,8 +647,7 @@ public class AppMaster {
return;
}
// ZipUtils
// ZipUtils.ZipFiles(logDir, file);
ZipUtils.ZipFiles(paths, file);
if (!file.exists()) {
return;

@ -176,4 +176,6 @@ public class MainActivity extends AppCompatActivity {
return super.onKeyDown(keyCode, event);
}
}

@ -47,8 +47,13 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
public class MpMasterService extends Service {
static {
System.loadLibrary("mpmaster");
}
public static final String TAG = "MpMaster";
public final static int MSG_WHAT_SENDING_HB = 40;
@ -59,6 +64,8 @@ public class MpMasterService extends Service {
public static final String ACTION_STOP = "com.xypower.mpmaster.ACT_STOP";
public static final String ACTION_MAIN = "com.xypower.mpmaster.ACT_MAIN";
public static final String ACTION_UPD_OTA = "com.xy.otaupdateresult";
private static final String ACTION_UPDATE_CONFIGS = "com.xypower.mpmaster.ACT_UPD_CFG";
private static final String ACTION_HEARTBEAT = "com.xypower.mpmaster.ACT_HB";
@ -148,6 +155,7 @@ public class MpMasterService extends Service {
// intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY);
intentFilter.addAction(ACTION_MSG_BROADCAST);
intentFilter.addAction(ACTION_UPDATE_CONFIGS);
intentFilter.addAction(ACTION_UPD_OTA);
registerReceiver(mAlarmReceiver, intentFilter);
}
@ -241,6 +249,7 @@ public class MpMasterService extends Service {
}
if ((ts - modifiedTimeOfDb) > mTimeOfMpAppAlive) {
// greater than 30m
// Logger.
MicroPhotoContext.restartMpApp(context);
mTimeToStartMpApp = ts;
}
@ -345,6 +354,8 @@ public class MpMasterService extends Service {
} else {
mService.loadConfig();
}
} else if (TextUtils.equals(ACTION_UPD_OTA, action)) {
}
}
}
@ -721,6 +732,7 @@ public class MpMasterService extends Service {
}
public native static int getInt(int cmd);
////////////////////////GPS////////////////////

Loading…
Cancel
Save