| | |
| | | import baseStation.BaseStation; |
| | | import set.Setsys; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStreamWriter; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.Locale; |
| | | import java.util.Properties; |
| | | |
| | |
| | | // 差分时间 |
| | | private String selfCheckStatus = "-1"; |
| | | // 割草机自检状态 |
| | | private String mowerStartStatus = "-1"; |
| | | // 割草机启动状态:1开启,0熄火,-1未知 |
| | | private String mowerLightStatus = "-1"; |
| | | // 割草机灯开关状态:1开启,0关闭,-1未知 |
| | | private String mowerBladeHeight = "-1"; |
| | | // 割草机刀盘高度:-1未知 |
| | | |
| | | private static final double METERS_PER_DEGREE_LAT = 111320.0d; |
| | | |
| | |
| | | applyDefaults(gecaoji); |
| | | } |
| | | |
| | | /** |
| | | * 保存所有属性到device.properties文件 |
| | | */ |
| | | public void saveToProperties() { |
| | | Properties properties = new Properties(); |
| | | |
| | | // 加载现有属性(保留其他属性) |
| | | try (FileInputStream input = new FileInputStream("device.properties")) { |
| | | properties.load(input); |
| | | } catch (IOException e) { |
| | | // 如果文件不存在,继续创建新文件 |
| | | } |
| | | |
| | | // 设置所有设备属性 |
| | | if (mowerName != null) properties.setProperty("mowerName", mowerName); |
| | | if (mowerModel != null) properties.setProperty("mowerModel", mowerModel); |
| | | if (mowerNumber != null) properties.setProperty("mowerNumber", mowerNumber); |
| | | if (mowingWidth != null) properties.setProperty("mowingWidth", mowingWidth); |
| | | if (mowingHeight != null) properties.setProperty("mowingHeight", mowingHeight); |
| | | if (baseStationNumber != null) properties.setProperty("baseStationNumber", baseStationNumber); |
| | | if (baseStationCardNumber != null) properties.setProperty("baseStationCardNumber", baseStationCardNumber); |
| | | if (baseStationCoordinates != null) properties.setProperty("baseStationCoordinates", baseStationCoordinates); |
| | | if (deviceCardnumber != null) properties.setProperty("deviceCardnumber", deviceCardnumber); |
| | | if (createTime != null) properties.setProperty("createTime", createTime); |
| | | if (GupdateTime != null) properties.setProperty("GupdateTime", GupdateTime); |
| | | if (BupdateTime != null) properties.setProperty("BupdateTime", BupdateTime); |
| | | if (realtimeLatitude != null) properties.setProperty("realtimeLatitude", realtimeLatitude); |
| | | if (realtimeLongitude != null) properties.setProperty("realtimeLongitude", realtimeLongitude); |
| | | if (realtimeAltitude != null) properties.setProperty("realtimeAltitude", realtimeAltitude); |
| | | if (realtimeX != null) properties.setProperty("realtimeX", realtimeX); |
| | | if (realtimeY != null) properties.setProperty("realtimeY", realtimeY); |
| | | if (realtimeSpeed != null) properties.setProperty("realtimeSpeed", realtimeSpeed); |
| | | if (heading != null) properties.setProperty("heading", heading); |
| | | if (pitch != null) properties.setProperty("pitch", pitch); |
| | | if (battery != null) properties.setProperty("battery", battery); |
| | | if (positioningStatus != null) properties.setProperty("positioningStatus", positioningStatus); |
| | | if (satelliteCount != null) properties.setProperty("satelliteCount", satelliteCount); |
| | | if (differentialAge != null) properties.setProperty("differentialAge", differentialAge); |
| | | if (selfCheckStatus != null) properties.setProperty("selfCheckStatus", selfCheckStatus); |
| | | if (mowerStartStatus != null) properties.setProperty("mowerStartStatus", mowerStartStatus); |
| | | if (mowerLightStatus != null) properties.setProperty("mowerLightStatus", mowerLightStatus); |
| | | if (mowerBladeHeight != null) properties.setProperty("mowerBladeHeight", mowerBladeHeight); |
| | | |
| | | // 保存到文件 |
| | | try (FileOutputStream output = new FileOutputStream("device.properties"); |
| | | OutputStreamWriter writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) { |
| | | properties.store(writer, "Updated device properties"); |
| | | } catch (IOException ex) { |
| | | System.err.println("无法保存 device.properties: " + ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private void loadPropertiesInto(Device target, Properties properties) { |
| | | if (target == null) { |
| | | return; |
| | |
| | | target.positioningStatus = properties.getProperty("positioningStatus", "-1"); |
| | | target.satelliteCount = properties.getProperty("satelliteCount", "-1"); |
| | | target.differentialAge = properties.getProperty("differentialAge", "-1"); |
| | | target.selfCheckStatus = properties.getProperty("selfCheckStatus", "-1"); |
| | | target.selfCheckStatus = properties.getProperty("selfCheckStatus", "-1"); |
| | | target.mowerStartStatus = properties.getProperty("mowerStartStatus", "-1"); |
| | | target.mowerLightStatus = properties.getProperty("mowerLightStatus", "-1"); |
| | | target.mowerBladeHeight = properties.getProperty("mowerBladeHeight", "-1"); |
| | | } |
| | | |
| | | private void applyDefaults(Device target) { |
| | |
| | | target.positioningStatus = "-1"; |
| | | target.satelliteCount = "-1"; |
| | | target.differentialAge = "-1"; |
| | | target.selfCheckStatus = "-1"; |
| | | target.selfCheckStatus = "-1"; |
| | | target.mowerStartStatus = "-1"; |
| | | target.mowerLightStatus = "-1"; |
| | | target.mowerBladeHeight = "-1"; |
| | | } |
| | | |
| | | public static synchronized Device initializeActiveDevice(String mowerId) { // 根据设备ID初始化活跃设备 |
| | |
| | | case "selfCheckStatus": |
| | | this.selfCheckStatus = value; |
| | | return true; |
| | | case "mowerStartStatus": |
| | | this.mowerStartStatus = value; |
| | | return true; |
| | | case "mowerLightStatus": |
| | | this.mowerLightStatus = value; |
| | | return true; |
| | | case "mowerBladeHeight": |
| | | this.mowerBladeHeight = value; |
| | | return true; |
| | | default: |
| | | System.err.println("未知字段: " + fieldName); |
| | | return false; |
| | |
| | | this.selfCheckStatus = selfCheckStatus; |
| | | } |
| | | |
| | | public String getMowerStartStatus() { // 获取割草机启动状态 |
| | | return mowerStartStatus; |
| | | } |
| | | |
| | | public void setMowerStartStatus(String mowerStartStatus) { // 设置割草机启动状态 |
| | | this.mowerStartStatus = mowerStartStatus; |
| | | } |
| | | |
| | | public String getMowerLightStatus() { // 获取割草机灯开关状态 |
| | | return mowerLightStatus; |
| | | } |
| | | |
| | | public void setMowerLightStatus(String mowerLightStatus) { // 设置割草机灯开关状态 |
| | | this.mowerLightStatus = mowerLightStatus; |
| | | } |
| | | |
| | | public String getMowerBladeHeight() { // 获取割草机刀盘高度 |
| | | return mowerBladeHeight; |
| | | } |
| | | |
| | | public void setMowerBladeHeight(String mowerBladeHeight) { // 设置割草机刀盘高度 |
| | | this.mowerBladeHeight = mowerBladeHeight; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { // 输出对象信息 |
| | | return "Device{" + |
| | |
| | | ", satelliteCount='" + satelliteCount + '\'' + |
| | | ", differentialAge='" + differentialAge + '\'' + |
| | | ", selfCheckStatus='" + selfCheckStatus + '\'' + |
| | | ", mowerStartStatus='" + mowerStartStatus + '\'' + |
| | | ", mowerLightStatus='" + mowerLightStatus + '\'' + |
| | | ", mowerBladeHeight='" + mowerBladeHeight + '\'' + |
| | | '}'; |
| | | } |
| | | } |