| | |
| | | package gecaoji; |
| | | import baseStation.BaseStation; |
| | | import set.Setsys; |
| | | import zhuye.MowerLocationData; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | |
| | | // 割草机灯开关状态: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; |
| | | |
| | |
| | | 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"); |
| | |
| | | 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) { |
| | |
| | | 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初始化活跃设备 |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | positioningStatus = defaultIfEmpty(sanitizeField(fields, 6)); |
| | | // 同步到绘制模块的数据源,保证往返绘制定时器能识别定位质量 |
| | | try { |
| | | MowerLocationData.updateProperty("positioningQuality", positioningStatus); |
| | | } catch (Throwable ignored) { |
| | | // 防御式:即使更新失败也不影响设备数据处理 |
| | | } |
| | | satelliteCount = defaultIfEmpty(sanitizeField(fields, 7)); |
| | | differentialAge = defaultIfEmpty(sanitizeField(fields, 13)); |
| | | battery = defaultIfEmpty(sanitizeField(fields, 16)); |
| | |
| | | } |
| | | |
| | | positioningStatus = defaultIfEmpty(sanitizeField(fields, 6)); |
| | | // 同步到绘制模块的数据源,保证往返绘制定时器能识别定位质量 |
| | | try { |
| | | MowerLocationData.updateProperty("positioningQuality", positioningStatus); |
| | | } catch (Throwable ignored) { |
| | | // 防御式:即使更新失败也不影响设备数据处理 |
| | | } |
| | | satelliteCount = defaultIfEmpty(sanitizeField(fields, 7)); |
| | | differentialAge = defaultIfEmpty(sanitizeField(fields, 13)); |
| | | realtimeSpeed ="0"; |
| | |
| | | if (Double.isFinite(eastMeters) && Double.isFinite(northMeters)) { |
| | | realtimeX = formatMeters(eastMeters); |
| | | realtimeY = formatMeters(northMeters); |
| | | |
| | | // 保存坐标到工具类 |
| | | lujing.SavaXyZuobiao.addCoordinate(eastMeters, northMeters); |
| | | } |
| | | } |
| | | |
| | |
| | | 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{" + |
| | |
| | | ", mowerStartStatus='" + mowerStartStatus + '\'' + |
| | | ", mowerLightStatus='" + mowerLightStatus + '\'' + |
| | | ", mowerBladeHeight='" + mowerBladeHeight + '\'' + |
| | | ", mowerWidth='" + mowerWidth + '\'' + |
| | | ", mowerLength='" + mowerLength + '\'' + |
| | | ", mowingSafetyDistance='" + mowingSafetyDistance + '\'' + |
| | | '}'; |
| | | } |
| | | } |