Browse Source

feta:增加获取设备版本信息接口

develop
白凤吉 2 months ago
parent
commit
48c617125c
  1. 34
      app/src/main/java/com/iflytop/profilometer/api/system/SystemApi.java
  2. 8
      app/src/main/java/com/iflytop/profilometer/api/system/SystemRoutes.kt
  3. 2
      app/src/main/java/com/iflytop/profilometer/common/result/Result.java
  4. 13
      app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceDriver.java
  5. 10
      app/src/main/java/com/iflytop/profilometer/model/bo/DeviceInfo.java
  6. 43
      app/src/main/java/com/iflytop/profilometer/model/vo/DeviceInfoVO.java

34
app/src/main/java/com/iflytop/profilometer/api/system/SystemApi.java

@ -1,6 +1,8 @@
package com.iflytop.profilometer.api.system;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import com.iflytop.profilometer.common.constant.LogTag;
@ -11,7 +13,9 @@ import com.iflytop.profilometer.core.bluetooth.BleDeviceDriver;
import com.iflytop.profilometer.core.bluetooth.BleManager;
import com.iflytop.profilometer.core.system.SystemService;
import com.iflytop.profilometer.dao.SystemConfigDao;
import com.iflytop.profilometer.model.bo.DeviceInfo;
import com.iflytop.profilometer.model.entity.SystemConfig;
import com.iflytop.profilometer.model.vo.DeviceInfoVO;
import com.iflytop.profilometer.model.vo.SystemConfigVO;
/**
@ -24,6 +28,30 @@ public class SystemApi {
this.context = context.getApplicationContext();
}
public String getInfo() {
DeviceInfoVO deviceInfoVO = new DeviceInfoVO();
try {
PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
String versionName = info.versionName;
deviceInfoVO.setAppVersion(versionName);
} catch (PackageManager.NameNotFoundException e) {
Log.e(LogTag.PROFILOMENTER, "获取软件版本号出错", e);
}
try {
if (BleManager.getInstance().isConnected()) {
BleDeviceDriver bleDeviceDriver = SystemService.getInstance().getBleDeviceDriver();
DeviceInfo deviceInfo = bleDeviceDriver.getDeviceInfo();
deviceInfoVO.setSn(deviceInfo.sn.toString());
deviceInfoVO.setSfwVersion(deviceInfo.sfw_version.toString());
deviceInfoVO.setHfwVersion(deviceInfo.hfw_version.toString());
}
} catch (Exception e) {
Log.e(LogTag.PROFILOMENTER, "获取设备信息出错", e);
}
return Result.success(deviceInfoVO);
}
public String config() {
SystemConfigDao systemConfigDao = new SystemConfigDao(context);
SystemConfig serverConfig = systemConfigDao.getSystemConfigByKey(SystemConfigType.SERVER);
@ -46,8 +74,7 @@ public class SystemApi {
systemConfigVO.setStandbyMinutes(standbyMinutesByDevice / 60 / 1000);
}
} catch (Exception e) {
e.printStackTrace();
Log.e(LogTag.PROFILOMENTER, "获取设备自动待机时间出错");
Log.e(LogTag.PROFILOMENTER, "获取设备自动待机时间出错", e);
}
return Result.success(systemConfigVO);
}
@ -84,8 +111,7 @@ public class SystemApi {
bleDeviceDriver.setStandbyInactiveTime(standbyMinutes * 60 * 1000);
}
} catch (Exception e) {
e.printStackTrace();
Log.e(LogTag.PROFILOMENTER, "保存设备自动待机时间出错");
Log.e(LogTag.PROFILOMENTER, "保存设备自动待机时间出错", e);
}
return Result.success();
}

8
app/src/main/java/com/iflytop/profilometer/api/system/SystemRoutes.kt

@ -13,6 +13,14 @@ fun Routing.systemRoutes(context: Context) {
val api = SystemApi(context)
/**
*
*/
post("/api/system/info") {
val jsonResponse = api.getInfo()
call.respondText(jsonResponse, ContentType.Application.Json)
}
/**
*
*/
post("/api/system/config") {

2
app/src/main/java/com/iflytop/profilometer/common/result/Result.java

@ -18,7 +18,7 @@ public final class Result {
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("success", true);
resultMap.put("data", data);
JSONConfig jsonConfig = JSONConfig.create().setDateFormat("yyyy-MM-dd HH:mm:ss");
JSONConfig jsonConfig = JSONConfig.create().setDateFormat("yyyy-MM-dd HH:mm:ss").setIgnoreNullValue(false);
return JSONUtil.toJsonStr(resultMap, jsonConfig);
}

13
app/src/main/java/com/iflytop/profilometer/core/bluetooth/BleDeviceDriver.java

@ -4,7 +4,10 @@ import com.iflytop.profilometer.core.migration.channel.BleDeviceUartChannel;
import com.iflytop.profilometer.core.migration.config.AppConstantConfig;
import com.iflytop.profilometer.core.migration.factory.TPMIPacketFactory;
import com.iflytop.profilometer.core.migration.type.DeviceAppearance;
import com.iflytop.profilometer.core.migration.type.DeviceSN;
import com.iflytop.profilometer.core.migration.type.Version;
import com.iflytop.profilometer.core.migration.type.protocol.TPMIPacket;
import com.iflytop.profilometer.model.bo.DeviceInfo;
import com.iflytop.profilometer.model.bo.RailProfileMeasureTaskState;
public class BleDeviceDriver {
@ -105,4 +108,14 @@ public class BleDeviceDriver {
time = rx.getDataAsInt(0);
return time;
}
public DeviceInfo getDeviceInfo(){
var packet = TPMIPacketFactory.buildGetDeviceInfoCmd();
var rx = uartChannel.sendCommand(packet, CMD_OVERTIME);
var info = new DeviceInfo();
info.sn = new DeviceSN(rx.getDataAsInt(0));
info.sfw_version = new Version(rx.getDataAsInt(1));
info.hfw_version = new Version(rx.getDataAsInt(2));
return info;
}
}

10
app/src/main/java/com/iflytop/profilometer/model/bo/DeviceInfo.java

@ -0,0 +1,10 @@
package com.iflytop.profilometer.model.bo;
import com.iflytop.profilometer.core.migration.type.DeviceSN;
import com.iflytop.profilometer.core.migration.type.Version;
public class DeviceInfo {
public DeviceSN sn;
public Version sfw_version;
public Version hfw_version;
}

43
app/src/main/java/com/iflytop/profilometer/model/vo/DeviceInfoVO.java

@ -0,0 +1,43 @@
package com.iflytop.profilometer.model.vo;
import com.iflytop.profilometer.core.migration.type.DeviceSN;
import com.iflytop.profilometer.core.migration.type.Version;
public class DeviceInfoVO {
private String sn = null;
private String appVersion = null;
private String sfwVersion = null;
private String hfwVersion = null;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getAppVersion() {
return appVersion;
}
public void setAppVersion(String appVersion) {
this.appVersion = appVersion;
}
public String getSfwVersion() {
return sfwVersion;
}
public void setSfwVersion(String sfwVersion) {
this.sfwVersion = sfwVersion;
}
public String getHfwVersion() {
return hfwVersion;
}
public void setHfwVersion(String hfwVersion) {
this.hfwVersion = hfwVersion;
}
}
Loading…
Cancel
Save