| | |
| | | // 割草机长度,单位米 |
| | | private String mowingSafetyDistance; |
| | | // 割草安全距离,单位米 |
| | | |
| | | private String movement_speed = "-1"; // 运动速度 km/h |
| | | // 大灯状态:0关闭,1开启 |
| | | private String headlight_status = "-1"; |
| | | // 割草机开关状态:0熄火,1开启 |
| | | private String mower_switch_status = "-1"; |
| | | private static final double METERS_PER_DEGREE_LAT = 111320.0d; |
| | | |
| | | |
| | |
| | | if (mowerWidth != null) properties.setProperty("mowerWidth", mowerWidth); |
| | | if (mowerLength != null) properties.setProperty("mowerLength", mowerLength); |
| | | if (mowingSafetyDistance != null) properties.setProperty("mowingSafetyDistance", mowingSafetyDistance); |
| | | if (movement_speed != null) properties.setProperty("movement_speed", movement_speed); |
| | | if (headlight_status != null) properties.setProperty("headlight_status", headlight_status); |
| | | if (mower_switch_status != null) properties.setProperty("mower_switch_status", mower_switch_status); |
| | | |
| | | // 保存到文件 |
| | | try (FileOutputStream output = new FileOutputStream("device.properties"); |
| | |
| | | target.mowerWidth = properties.getProperty("mowerWidth", "-1"); |
| | | target.mowerLength = properties.getProperty("mowerLength", "-1"); |
| | | target.mowingSafetyDistance = properties.getProperty("mowingSafetyDistance", "-1"); |
| | | target.movement_speed = properties.getProperty("movement_speed", "-1"); |
| | | target.headlight_status = properties.getProperty("headlight_status", "-1"); |
| | | target.mower_switch_status = properties.getProperty("mower_switch_status", "-1"); |
| | | } |
| | | |
| | | private void applyDefaults(Device target) { |
| | |
| | | target.mowerWidth = "-1"; |
| | | target.mowerLength = "-1"; |
| | | target.mowingSafetyDistance = "-1"; |
| | | target.movement_speed = "-1"; |
| | | target.headlight_status = "-1"; |
| | | target.mower_switch_status = "-1"; |
| | | } |
| | | |
| | | public static synchronized Device initializeActiveDevice(String mowerId) { // 根据设备ID初始化活跃设备 |
| | |
| | | case "mowingSafetyDistance": |
| | | this.mowingSafetyDistance = value; |
| | | return true; |
| | | case "movement_speed": |
| | | this.movement_speed = value; |
| | | return true; |
| | | case "headlight_status": |
| | | this.headlight_status = value; |
| | | return true; |
| | | case "mower_switch_status": |
| | | this.mower_switch_status = value; |
| | | return true; |
| | | default: |
| | | System.err.println("未知字段: " + fieldName); |
| | | return false; |
| | |
| | | this.mowingSafetyDistance = mowingSafetyDistance; |
| | | } |
| | | |
| | | public String getMovement_speed() { // 获取运动速度 |
| | | return movement_speed; |
| | | } |
| | | |
| | | public void setMovement_speed(String movement_speed) { // 设置运动速度 |
| | | this.movement_speed = movement_speed; |
| | | } |
| | | |
| | | public String getHeadlight_status() { // 获取大灯状态 |
| | | return headlight_status; |
| | | } |
| | | |
| | | public void setHeadlight_status(String headlight_status) { // 设置大灯状态 |
| | | this.headlight_status = headlight_status; |
| | | } |
| | | |
| | | public String getMower_switch_status() { // 获取割草机开关状态 |
| | | return mower_switch_status; |
| | | } |
| | | |
| | | public void setMower_switch_status(String mower_switch_status) { // 设置割草机开关状态 |
| | | this.mower_switch_status = mower_switch_status; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { // 输出对象信息 |
| | | return "Device{" + |
| | |
| | | ", mowerWidth='" + mowerWidth + '\'' + |
| | | ", mowerLength='" + mowerLength + '\'' + |
| | | ", mowingSafetyDistance='" + mowingSafetyDistance + '\'' + |
| | | ", movement_speed='" + movement_speed + '\'' + |
| | | ", headlight_status='" + headlight_status + '\'' + |
| | | ", mower_switch_status='" + mower_switch_status + '\'' + |
| | | '}'; |
| | | } |
| | | } |