张世豪
8 天以前 c57cb0cd9feb4495c89246b2faec6d5e45c23c30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
package gecaoji;
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;
 
/**
 * 设备信息类
 */
public class Device {
    static Device gecaoji=new Device();
    public static Device getGecaoji() {
        return gecaoji;
    }
 
    public static void setGecaoji(Device gecaoji) {
        Device.gecaoji = gecaoji;
    }
 
    static {
        String id=Setsys.getPropertyValue("mowerId");
        gecaoji.setMowerNumber(id);
    }
    // 用户标识
    private String mowerName;
    // 割草机名称
    private String mowerModel;
    // 割草机型号
    private String mowerNumber;
    // 割草机设备编号(唯一)
    private String mowingWidth;
    // 割草宽度,单位厘米
    private String mowingHeight;
    // 割草高度,单位厘米
    private String baseStationNumber;
    // 差分基站编号
    private String baseStationCardNumber;
    // 差分基站卡号
    private String baseStationCoordinates;
    // 差分基站坐标
    private String deviceCardnumber;
    // 设备卡号
    private String createTime;
    // 创建时间
    private String GupdateTime;
    // 割草机数据更新时间
    private String BupdateTime;
    // 基准站数据更新时间
    private String realtimeLatitude;
    // 实时纬度(度分)
    private String realtimeLongitude;
    // 实时经度(度分)
    private String realtimeAltitude;
    // 实时高程(米)
    private String realtimeX;
    // 实时X坐标(米)
    private String realtimeY;
    // 实时Y坐标(米)
    private String realtimeSpeed;
    // 实时速度
    private String heading;
    // 航向角
    private String pitch;
    // 俯仰角
    private String battery;
    // 实时电量
    private String positioningStatus;
    // 定位状态
    private String satelliteCount;
    // 卫星可数
    private String differentialAge;
    // 差分时间
    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;
    
 
    /**
     * 初始化方法 - 从device.properties文件加载数据
     */
    public void initFromProperties() { // 从属性文件初始化设备数据
        Properties properties = new Properties();
        try (FileInputStream input = new FileInputStream("device.properties")) {
            // 从根目录加载device.properties文件
            properties.load(input);
 
            loadPropertiesInto(this, properties);
            loadPropertiesInto(gecaoji, properties); // 保持共享实例同步
        } catch (IOException e) {
            // 如果文件不存在或读取失败,将所有属性设置为-1
            System.err.println("无法读取device.properties文件: " + e.getMessage());
            setDefaultValues();
        }
    }
 
    /**
     * 设置默认值-1
     */
    private void setDefaultValues() { // 设置默认字段值
        applyDefaults(this);
        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.mowerName = properties.getProperty("mowerName", "-1");
        target.mowerModel = properties.getProperty("mowerModel", "-1");
        target.mowerNumber = properties.getProperty("mowerNumber", "-1");
        target.mowingWidth = properties.getProperty("mowingWidth", "-1");
        target.mowingHeight = properties.getProperty("mowingHeight", "-1");
        target.baseStationNumber = properties.getProperty("baseStationNumber", "-1");
        target.baseStationCardNumber = properties.getProperty("baseStationCardNumber", "-1");
        target.baseStationCoordinates = properties.getProperty("baseStationCoordinates", "-1");
        target.deviceCardnumber = properties.getProperty("deviceCardnumber", "-1");
        target.createTime = properties.getProperty("createTime", "-1");
        target.GupdateTime = properties.getProperty("GupdateTime", "-1");
        target.BupdateTime = properties.getProperty("BupdateTime", "-1");
        target.realtimeLatitude = properties.getProperty("realtimeLatitude", "-1");
        target.realtimeLongitude = properties.getProperty("realtimeLongitude", "-1");
        target.realtimeAltitude = properties.getProperty("realtimeAltitude", "-1");
        target.realtimeX = properties.getProperty("realtimeX", "-1");
        target.realtimeY = properties.getProperty("realtimeY", "-1");
        target.realtimeSpeed = properties.getProperty("realtimeSpeed", "-1");
        target.heading = properties.getProperty("heading", "-1");
        target.pitch = properties.getProperty("pitch", "-1");
        target.battery = properties.getProperty("battery", "-1");
        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.mowerStartStatus = properties.getProperty("mowerStartStatus", "-1");
        target.mowerLightStatus = properties.getProperty("mowerLightStatus", "-1");
        target.mowerBladeHeight = properties.getProperty("mowerBladeHeight", "-1");
    }
 
    private void applyDefaults(Device target) {
        if (target == null) {
            return;
        }
 
        target.mowerName = "-1";
        target.mowerModel = "-1";
        target.mowerNumber = "-1";
        target.mowingWidth = "-1";
        target.mowingHeight = "-1";
        target.baseStationNumber = "-1";
        target.baseStationCardNumber = "-1";
        target.baseStationCoordinates = "-1";
        target.deviceCardnumber = "-1";
        target.createTime = "-1";
        target.GupdateTime = "-1";
        target.BupdateTime = "-1";
        target.realtimeLatitude = "-1";
        target.realtimeLongitude = "-1";
        target.realtimeAltitude = "-1";
        target.realtimeX = "-1";
        target.realtimeY = "-1";
        target.realtimeSpeed = "-1";
        target.heading = "-1";
        target.pitch = "-1";
        target.battery = "-1";
        target.positioningStatus = "-1";
        target.satelliteCount = "-1";
        target.differentialAge = "-1";
        target.selfCheckStatus = "-1";
        target.mowerStartStatus = "-1";
        target.mowerLightStatus = "-1";
        target.mowerBladeHeight = "-1";
    }
 
    public static synchronized Device initializeActiveDevice(String mowerId) { // 根据设备ID初始化活跃设备
        Device device = new Device();
        gecaoji = device;
        device.initFromProperties();
        if (!isInvalidValue(mowerId)) {
            device.setMowerNumber(mowerId.trim());
        }
        return device;
    }
 
    public static Device getActiveDevice() { // 获取当前活跃设备
        return gecaoji;
    }
 
   
 
    /**
     * 更新字段值
     * @param fieldName 字段名
     * @param value 新值
     * @return 是否更新成功
     */
    public boolean updateField(String fieldName, String value) { // 按字段更新属性值
        switch (fieldName) {
            case "mowerName":
                this.mowerName = value;
                return true;
            case "mowerModel":
                this.mowerModel = value;
                return true;
            case "mowerNumber":
                this.mowerNumber = value;
                return true;
            case "mowingWidth":
                this.mowingWidth = value;
                return true;
            case "mowingHeight":
                this.mowingHeight = value;
                return true;
            case "baseStationNumber":
                this.baseStationNumber = value;
                return true;
            case "baseStationCardNumber":
                this.baseStationCardNumber = value;
                return true;
            case "baseStationCoordinates":
                this.baseStationCoordinates = value;
                return true;
            case "deviceCardnumber":
                this.deviceCardnumber = value;
                return true;
            case "createTime":
                this.createTime = value;
                return true;
            case "GupdateTime":
                this.GupdateTime = value;
                return true;
            case "BupdateTime":
                this.BupdateTime = value;
                return true;
            case "realtimeLatitude":
                this.realtimeLatitude = value;
                return true;
            case "realtimeLongitude":
                this.realtimeLongitude = value;
                return true;
            case "realtimeAltitude":
                this.realtimeAltitude = value;
                return true;
            case "realtimeX":
                this.realtimeX = value;
                return true;
            case "realtimeY":
                this.realtimeY = value;
                return true;
            case "realtimeSpeed":
                this.realtimeSpeed = value;
                return true;
            case "heading":
                this.heading = value;
                return true;
            case "pitch":
                this.pitch = value;
                return true;
            case "battery":
                this.battery = value;
                return true;
            case "positioningStatus":
                this.positioningStatus = value;
                return true;
            case "satelliteCount":
                this.satelliteCount = value;
                return true;
            case "differentialAge":
                this.differentialAge = value;
                return true;
            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;
        }
    }
 
    public static synchronized void updateFromGNGGA(String gnggaData, String deviceId) { // 静态解析GNGGA数据更新设备
        Device device = gecaoji;
        if (device == null) {
            return;
        }
        device.applyGNGGAUpdate(gnggaData, deviceId);
    }
 
    public static synchronized void updateFromSerialGNGGA(String gnggaData) { // 串口数据更新路径(无需设备编号匹配)
        Device device = gecaoji;
        if (device == null) {
            return;
        }
        device.chuankouGNGGAUpdate(gnggaData);
    }
 
    private void applyGNGGAUpdate(String gnggaData, String deviceId) { // 执行GNGGA更新逻辑
        if (gnggaData == null) {
            return;
        }
 
        String trimmed = gnggaData.trim();
        if (trimmed.isEmpty() || !trimmed.startsWith("$GNGGA")) {
            return;
        }
 
        String[] fields = trimmed.split(",");
        if (fields.length < 21) {
            System.err.println("GNGGA字段数量不足: " + fields.length);
            return;
        }
 
        String sanitizedExpectedId = hasMeaningfulValue(deviceId) ? deviceId.trim() : null;
        String incomingDeviceId = sanitizeField(fields, 15);
        if (sanitizedExpectedId != null) {
            if (!hasMeaningfulValue(incomingDeviceId) || !sanitizedExpectedId.equals(incomingDeviceId)) {
                return;
            }
        }
        if (hasMeaningfulValue(incomingDeviceId) && !incomingDeviceId.equals(mowerNumber)) {
            mowerNumber = incomingDeviceId;
        }
 
        String latitudeValue = sanitizeField(fields, 2);
        String latitudeHemisphere = sanitizeField(fields, 3);
        String longitudeValue = sanitizeField(fields, 4);
        String longitudeHemisphere = sanitizeField(fields, 5);
 
        String combinedLatitude = combineCoordinate(latitudeValue, latitudeHemisphere);
        if (hasMeaningfulValue(combinedLatitude)) {
            realtimeLatitude = combinedLatitude;
        }
        String combinedLongitude = combineCoordinate(longitudeValue, longitudeHemisphere);
        if (hasMeaningfulValue(combinedLongitude)) {
            realtimeLongitude = combinedLongitude;
        }
 
        String altitudeValue = sanitizeField(fields, 9);
        if (hasMeaningfulValue(altitudeValue)) {
            realtimeAltitude = altitudeValue;
        }
 
        positioningStatus = defaultIfEmpty(sanitizeField(fields, 6));
        satelliteCount = defaultIfEmpty(sanitizeField(fields, 7));
        differentialAge = defaultIfEmpty(sanitizeField(fields, 13));
        battery = defaultIfEmpty(sanitizeField(fields, 16));
        pitch = defaultIfEmpty(sanitizeField(fields, 17));
        realtimeSpeed = defaultIfEmpty(sanitizeField(fields, 18));
        heading = defaultIfEmpty(sanitizeField(fields, 19));
        GupdateTime = String.valueOf(System.currentTimeMillis());
 
        updateRelativeCoordinates(latitudeValue, latitudeHemisphere, longitudeValue, longitudeHemisphere);
    }
    
    /**串口更新GNGGA数据*/
    private void chuankouGNGGAUpdate(String gnggaData) { // 执行GNGGA更新逻辑
        if (gnggaData == null) {
            return;
        }
 
        String trimmed = gnggaData.trim();
        if (trimmed.isEmpty() || !trimmed.startsWith("$GNGGA")) {
            return;
        }
 
        String[] fields = trimmed.split(",");
        if (fields.length < 15) {
            System.err.println("GNGGA字段数量不足: " + fields.length);
            return;
        }
 
        
        String latitudeValue = sanitizeField(fields, 2);
        String latitudeHemisphere = sanitizeField(fields, 3);
        String longitudeValue = sanitizeField(fields, 4);
        String longitudeHemisphere = sanitizeField(fields, 5);
 
        String combinedLatitude = combineCoordinate(latitudeValue, latitudeHemisphere);
        if (hasMeaningfulValue(combinedLatitude)) {
            realtimeLatitude = combinedLatitude;
        }
        String combinedLongitude = combineCoordinate(longitudeValue, longitudeHemisphere);
        if (hasMeaningfulValue(combinedLongitude)) {
            realtimeLongitude = combinedLongitude;
        }
 
        String altitudeValue = sanitizeField(fields, 9);
        if (hasMeaningfulValue(altitudeValue)) {
            realtimeAltitude = altitudeValue;
        }
 
        positioningStatus = defaultIfEmpty(sanitizeField(fields, 6));
        satelliteCount = defaultIfEmpty(sanitizeField(fields, 7));
        differentialAge = defaultIfEmpty(sanitizeField(fields, 13));       
        realtimeSpeed ="0";        
        GupdateTime = String.valueOf(System.currentTimeMillis());
 
        updateRelativeCoordinates(latitudeValue, latitudeHemisphere, longitudeValue, longitudeHemisphere);
    }
 
    private void updateRelativeCoordinates(String latValue, String latHemisphere,
                                           String lonValue, String lonHemisphere) { // 计算相对坐标
        if (!hasMeaningfulValue(latValue) || !hasMeaningfulValue(lonValue)
                || !hasMeaningfulValue(latHemisphere) || !hasMeaningfulValue(lonHemisphere)) {
            return;
        }
 
        double mowerLat = toDecimalDegrees(latValue, latHemisphere);
        double mowerLon = toDecimalDegrees(lonValue, lonHemisphere);
        if (Double.isNaN(mowerLat) || Double.isNaN(mowerLon)) {
            return;
        }
 
        double[] baseLatLon = resolveBaseStationLatLon();
        if (baseLatLon == null) {
            return;
        }
 
        double meanLatRad = Math.toRadians((baseLatLon[0] + mowerLat) / 2.0d);
        double deltaLatDeg = mowerLat - baseLatLon[0];
        double deltaLonDeg = mowerLon - baseLatLon[1];
 
        double metersPerLon = METERS_PER_DEGREE_LAT * Math.cos(meanLatRad);
        double eastMeters = deltaLonDeg * metersPerLon;
        double northMeters = deltaLatDeg * METERS_PER_DEGREE_LAT;
 
        if (Double.isFinite(eastMeters) && Double.isFinite(northMeters)) {
            realtimeX = formatMeters(eastMeters);
            realtimeY = formatMeters(northMeters);
        }
    }
 
    private double[] resolveBaseStationLatLon() { // 解析基站经纬度
        String coords = baseStationCoordinates;
        if (isInvalidValue(coords)) {
            BaseStation baseStation = new BaseStation();
            baseStation.load();
            coords = baseStation.getInstallationCoordinates();
            if (!isInvalidValue(coords)) {
                baseStationCoordinates = coords;
            }
        }
 
        if (isInvalidValue(coords)) {
            return null;
        }
 
        String[] parts = coords.split(",");
        if (parts.length < 4) {
            return null;
        }
 
        double baseLat = toDecimalDegrees(parts[0].trim(), parts[1].trim());
        double baseLon = toDecimalDegrees(parts[2].trim(), parts[3].trim());
        if (Double.isNaN(baseLat) || Double.isNaN(baseLon)) {
            return null;
        }
        return new double[]{baseLat, baseLon};
    }
 
    private double toDecimalDegrees(String value, String hemisphere) { // 经纬度转换为十进制度
        if (!hasMeaningfulValue(value)) {
            return Double.NaN;
        }
 
        try {
            double raw = Double.parseDouble(value);
            double degrees = Math.floor(raw / 100d);
            double minutes = raw - degrees * 100d;
            double decimal = degrees + minutes / 60d;
 
            if ("S".equalsIgnoreCase(hemisphere) || "W".equalsIgnoreCase(hemisphere)) {
                return -decimal;
            }
            return decimal;
        } catch (NumberFormatException ex) {
            return Double.NaN;
        }
    }
 
    private String combineCoordinate(String value, String hemisphere) { // 拼接坐标与方向标识
        if (!hasMeaningfulValue(value)) {
            return "-1";
        }
        if (hasMeaningfulValue(hemisphere)) {
            return value + "," + hemisphere;
        }
        return value;
    }
 
    private String sanitizeField(String[] fields, int index) { // 清洗字段数据
        if (fields == null || index < 0 || index >= fields.length) {
            return "";
        }
        String value = fields[index];
        return value == null ? "" : value.trim();
    }
 
    private String defaultIfEmpty(String value) { // 空值返还默认值
        return hasMeaningfulValue(value) ? value : "-1";
    }
 
    private static boolean hasMeaningfulValue(String value) { // 判断值是否有效
        return value != null && !value.trim().isEmpty() && !"-1".equals(value.trim());
    }
 
    private static boolean isInvalidValue(String value) { // 判断值是否无效
        return value == null || value.trim().isEmpty() || "-1".equals(value.trim());
    }
 
    private String formatMeters(double value) { // 格式化米制数值
        if (Double.isNaN(value) || Double.isInfinite(value)) {
            return "-1";
        }
        return String.format(Locale.US, "%.3f", value);
    }
 
    // Getter 和 Setter 方法
    public String getMowerName() { // 获取割草机名称
        return mowerName;
    }
 
    public void setMowerName(String mowerName) { // 设置割草机名称
        this.mowerName = mowerName;
    }
 
    public String getMowerModel() { // 获取割草机型号
        return mowerModel;
    }
 
    public void setMowerModel(String mowerModel) { // 设置割草机型号
        this.mowerModel = mowerModel;
    }
 
    public String getMowerNumber() { // 获取割草机编号
        return mowerNumber;
    }
 
    public void setMowerNumber(String mowerNumber) { // 设置割草机编号
        this.mowerNumber = mowerNumber;
    }
 
    public String getMowingWidth() { // 获取割草宽度
        return mowingWidth;
    }
 
    public void setMowingWidth(String mowingWidth) { // 设置割草宽度
        this.mowingWidth = mowingWidth;
    }
 
    public String getMowingHeight() { // 获取割草高度
        return mowingHeight;
    }
 
    public void setMowingHeight(String mowingHeight) { // 设置割草高度
        this.mowingHeight = mowingHeight;
    }
 
    public String getBaseStationNumber() { // 获取基站编号
        return baseStationNumber;
    }
 
    public void setBaseStationNumber(String baseStationNumber) { // 设置基站编号
        this.baseStationNumber = baseStationNumber;
    }
 
    public String getBaseStationCardNumber() { // 获取基站卡号
        return baseStationCardNumber;
    }
 
    public void setBaseStationCardNumber(String baseStationCardNumber) { // 设置基站卡号
        this.baseStationCardNumber = baseStationCardNumber;
    }
 
    public String getBaseStationCoordinates() { // 获取基站坐标
        return baseStationCoordinates;
    }
 
    public void setBaseStationCoordinates(String baseStationCoordinates) { // 设置基站坐标
        this.baseStationCoordinates = baseStationCoordinates;
    }
 
    public String getDeviceCardnumber() { // 获取设备卡号
        return deviceCardnumber;
    }
 
    public void setDeviceCardnumber(String deviceCardnumber) { // 设置设备卡号
        this.deviceCardnumber = deviceCardnumber;
    }
 
    public String getCreateTime() { // 获取创建时间
        return createTime;
    }
 
    public void setCreateTime(String createTime) { // 设置创建时间
        this.createTime = createTime;
    }
 
    public String getGupdateTime() { // 获取割草机更新时间
        return GupdateTime;
    }
 
    public void setGupdateTime(String gupdateTime) { // 设置割草机更新时间
        GupdateTime = gupdateTime;
    }
 
    public String getBupdateTime() { // 获取基站更新时间
        return BupdateTime;
    }
 
    public void setBupdateTime(String bupdateTime) { // 设置基站更新时间
        BupdateTime = bupdateTime;
    }
 
    public String getRealtimeLatitude() { // 获取实时纬度
        return realtimeLatitude;
    }
 
    public void setRealtimeLatitude(String realtimeLatitude) { // 设置实时纬度
        this.realtimeLatitude = realtimeLatitude;
    }
 
    public String getRealtimeLongitude() { // 获取实时经度
        return realtimeLongitude;
    }
 
    public void setRealtimeLongitude(String realtimeLongitude) { // 设置实时经度
        this.realtimeLongitude = realtimeLongitude;
    }
 
    public String getRealtimeAltitude() { // 获取实时高程
        return realtimeAltitude;
    }
 
    public void setRealtimeAltitude(String realtimeAltitude) { // 设置实时高程
        this.realtimeAltitude = realtimeAltitude;
    }
 
    public String getRealtimeX() { // 获取实时X坐标
        return realtimeX;
    }
 
    public void setRealtimeX(String realtimeX) { // 设置实时X坐标
        this.realtimeX = realtimeX;
    }
 
    public String getRealtimeY() { // 获取实时Y坐标
        return realtimeY;
    }
 
    public void setRealtimeY(String realtimeY) { // 设置实时Y坐标
        this.realtimeY = realtimeY;
    }
 
    public String getRealtimeSpeed() { // 获取实时速度
        return realtimeSpeed;
    }
 
    public void setRealtimeSpeed(String realtimeSpeed) { // 设置实时速度
        this.realtimeSpeed = realtimeSpeed;
    }
 
    public String getHeading() { // 获取航向角
        return heading;
    }
 
    public void setHeading(String heading) { // 设置航向角
        this.heading = heading;
    }
 
    public String getPitch() { // 获取俯仰角
        return pitch;
    }
 
    public void setPitch(String pitch) { // 设置俯仰角
        this.pitch = pitch;
    }
 
    public String getBattery() { // 获取实时电量
        return battery;
    }
 
    public void setBattery(String battery) { // 设置实时电量
        this.battery = battery;
    }
 
    public String getPositioningStatus() { // 获取定位状态
        return positioningStatus;
    }
 
    public void setPositioningStatus(String positioningStatus) { // 设置定位状态
        this.positioningStatus = positioningStatus;
    }
 
    public String getSatelliteCount() { // 获取卫星数量
        return satelliteCount;
    }
 
    public void setSatelliteCount(String satelliteCount) { // 设置卫星数量
        this.satelliteCount = satelliteCount;
    }
 
    public String getDifferentialAge() { // 获取差分时间
        return differentialAge;
    }
 
    public void setDifferentialAge(String differentialAge) { // 设置差分时间
        this.differentialAge = differentialAge;
    }
 
    public String getSelfCheckStatus() { // 获取自检状态
        return selfCheckStatus;
    }
 
    public void setSelfCheckStatus(String selfCheckStatus) { // 设置自检状态
        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{" +
                "mowerName='" + mowerName + '\'' +
                ", mowerModel='" + mowerModel + '\'' +
                ", mowerNumber='" + mowerNumber + '\'' +
                ", mowingWidth='" + mowingWidth + '\'' +
                ", mowingHeight='" + mowingHeight + '\'' +
                ", baseStationNumber='" + baseStationNumber + '\'' +
                ", baseStationCardNumber='" + baseStationCardNumber + '\'' +
                ", baseStationCoordinates='" + baseStationCoordinates + '\'' +
                ", deviceCardnumber='" + deviceCardnumber + '\'' +
                ", createTime='" + createTime + '\'' +
                ", GupdateTime='" + GupdateTime + '\'' +
                ", BupdateTime='" + BupdateTime + '\'' +
                ", realtimeLatitude='" + realtimeLatitude + '\'' +
                ", realtimeLongitude='" + realtimeLongitude + '\'' +
                ", realtimeAltitude='" + realtimeAltitude + '\'' +
                ", realtimeX='" + realtimeX + '\'' +
                ", realtimeY='" + realtimeY + '\'' +
                ", realtimeSpeed='" + realtimeSpeed + '\'' +
                ", heading='" + heading + '\'' +
                ", pitch='" + pitch + '\'' +
                ", battery='" + battery + '\'' +
                ", positioningStatus='" + positioningStatus + '\'' +
                ", satelliteCount='" + satelliteCount + '\'' +
                ", differentialAge='" + differentialAge + '\'' +
                ", selfCheckStatus='" + selfCheckStatus + '\'' +
                ", mowerStartStatus='" + mowerStartStatus + '\'' +
                ", mowerLightStatus='" + mowerLightStatus + '\'' +
                ", mowerBladeHeight='" + mowerBladeHeight + '\'' +
                '}';
    }
}