张世豪
4 天以前 6700283f9103a45bc087838ebf3eeeeb9022dd98
src/gecaoji/Device.java
@@ -83,6 +83,12 @@
    // 割草机灯开关状态:1开启,0关闭,-1未知
    private String mowerBladeHeight = "-1";
    // 割草机刀盘高度:-1未知
    private String mowerWidth;
    // 割草机宽度,单位米
    private String mowerLength;
    // 割草机长度,单位米
    private String mowingSafetyDistance;
    // 割草安全距离,单位米
    private static final double METERS_PER_DEGREE_LAT = 111320.0d;
    
@@ -155,6 +161,9 @@
        if (mowerStartStatus != null) properties.setProperty("mowerStartStatus", mowerStartStatus);
        if (mowerLightStatus != null) properties.setProperty("mowerLightStatus", mowerLightStatus);
        if (mowerBladeHeight != null) properties.setProperty("mowerBladeHeight", mowerBladeHeight);
        if (mowerWidth != null) properties.setProperty("mowerWidth", mowerWidth);
        if (mowerLength != null) properties.setProperty("mowerLength", mowerLength);
        if (mowingSafetyDistance != null) properties.setProperty("mowingSafetyDistance", mowingSafetyDistance);
        
        // 保存到文件
        try (FileOutputStream output = new FileOutputStream("device.properties");
@@ -198,6 +207,9 @@
        target.mowerStartStatus = properties.getProperty("mowerStartStatus", "-1");
        target.mowerLightStatus = properties.getProperty("mowerLightStatus", "-1");
        target.mowerBladeHeight = properties.getProperty("mowerBladeHeight", "-1");
        target.mowerWidth = properties.getProperty("mowerWidth", "-1");
        target.mowerLength = properties.getProperty("mowerLength", "-1");
        target.mowingSafetyDistance = properties.getProperty("mowingSafetyDistance", "-1");
    }
    private void applyDefaults(Device target) {
@@ -233,6 +245,9 @@
        target.mowerStartStatus = "-1";
        target.mowerLightStatus = "-1";
        target.mowerBladeHeight = "-1";
        target.mowerWidth = "-1";
        target.mowerLength = "-1";
        target.mowingSafetyDistance = "-1";
    }
    public static synchronized Device initializeActiveDevice(String mowerId) { // 根据设备ID初始化活跃设备
@@ -343,6 +358,15 @@
            case "mowerBladeHeight":
                this.mowerBladeHeight = value;
                return true;
            case "mowerWidth":
                this.mowerWidth = value;
                return true;
            case "mowerLength":
                this.mowerLength = value;
                return true;
            case "mowingSafetyDistance":
                this.mowingSafetyDistance = value;
                return true;
            default:
                System.err.println("未知字段: " + fieldName);
                return false;
@@ -835,6 +859,30 @@
        this.mowerBladeHeight = mowerBladeHeight;
    }
    public String getMowerWidth() { // 获取割草机宽度
        return mowerWidth;
    }
    public void setMowerWidth(String mowerWidth) { // 设置割草机宽度
        this.mowerWidth = mowerWidth;
    }
    public String getMowerLength() { // 获取割草机长度
        return mowerLength;
    }
    public void setMowerLength(String mowerLength) { // 设置割草机长度
        this.mowerLength = mowerLength;
    }
    public String getMowingSafetyDistance() { // 获取割草安全距离
        return mowingSafetyDistance;
    }
    public void setMowingSafetyDistance(String mowingSafetyDistance) { // 设置割草安全距离
        this.mowingSafetyDistance = mowingSafetyDistance;
    }
    @Override
    public String toString() { // 输出对象信息
        return "Device{" +
@@ -866,6 +914,9 @@
                ", mowerStartStatus='" + mowerStartStatus + '\'' +
                ", mowerLightStatus='" + mowerLightStatus + '\'' +
                ", mowerBladeHeight='" + mowerBladeHeight + '\'' +
                ", mowerWidth='" + mowerWidth + '\'' +
                ", mowerLength='" + mowerLength + '\'' +
                ", mowingSafetyDistance='" + mowingSafetyDistance + '\'' +
                '}';
    }
}