]> git.basschouten.com Git - openhab-addons.git/blob
1bc4b300e29f2a025ac7441cad79cca59af0e256
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.synopanalyzer.internal.synop;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link SynopMobile} is responsible for analyzing Mobile station
21  * specifics Synop messages
22  *
23  * @author Jonarzz - Initial contribution
24  */
25 @NonNullByDefault
26 public class SynopMobile extends Synop {
27     private float latitude;
28     private float longitude;
29
30     private int verticalQuadrantMultiplier;
31     private int horizontalQuadrantMultiplier;
32
33     public SynopMobile(List<String> stringArray) {
34         super(stringArray);
35
36         setLatitude();
37         setLongitudeAndQuadrant();
38     }
39
40     @Override
41     protected void setHorizontalVisibilityInt() {
42         String temp;
43         if (stringArray.size() < 6 || !isValidString((temp = stringArray.get(5)))) {
44             horizontalVisibilityInt = INITIAL_VALUE;
45             return;
46         }
47
48         try {
49             horizontalVisibilityInt = Integer.parseInt(temp.substring(3, 5));
50         } catch (NumberFormatException e) {
51             horizontalVisibilityInt = INITIAL_VALUE;
52         }
53     }
54
55     @Override
56     protected void setTemperatureString() {
57         String temp;
58         if (stringArray.size() < 8 || !isValidString((temp = stringArray.get(7)))) {
59             return;
60         }
61
62         temperatureString = temp.substring(1, 5);
63     }
64
65     @Override
66     protected void setWindString() {
67         String temp;
68         if (stringArray.size() < 7 || !isValidString((temp = stringArray.get(6)))) {
69             return;
70         }
71
72         windString = temp;
73     }
74
75     @Override
76     protected void setPressureString() {
77         return;
78     }
79
80     private void setLatitude() {
81         String temp;
82         if (stringArray.size() < 4 || !isValidString((temp = stringArray.get(3)))) {
83             return;
84         }
85
86         String latitudeString = temp.substring(2, 5);
87         int tempInt = 0;
88
89         try {
90             tempInt = Integer.parseInt(latitudeString);
91         } catch (NumberFormatException e) {
92             latitude = INITIAL_VALUE;
93             return;
94         }
95
96         latitude = (float) tempInt / 10;
97     }
98
99     private void setLongitudeAndQuadrant() {
100         String temp;
101         if (stringArray.size() < 5 || !isValidString((temp = stringArray.get(4)))) {
102             return;
103         }
104
105         setQuadrantMultipliers(temp.charAt(0));
106         setLongitude(temp.substring(1, 5));
107     }
108
109     private void setQuadrantMultipliers(char q) {
110         switch (q) {
111             case '1':
112                 verticalQuadrantMultiplier = 1;
113                 horizontalQuadrantMultiplier = 1;
114                 break;
115             case '3':
116                 verticalQuadrantMultiplier = -1;
117                 horizontalQuadrantMultiplier = 1;
118                 break;
119             case '5':
120                 verticalQuadrantMultiplier = -1;
121                 horizontalQuadrantMultiplier = -1;
122                 break;
123             case '7':
124                 verticalQuadrantMultiplier = 1;
125                 horizontalQuadrantMultiplier = -1;
126                 break;
127             default:
128                 verticalQuadrantMultiplier = 0;
129                 horizontalQuadrantMultiplier = 0;
130                 break;
131         }
132     }
133
134     private void setLongitude(String str) {
135         int tempInt = 0;
136
137         try {
138             tempInt = Integer.parseInt(str);
139         } catch (NumberFormatException e) {
140             longitude = INITIAL_VALUE;
141             return;
142         }
143
144         longitude = (float) tempInt / 10;
145     }
146
147     public float getLatitude() {
148         return latitude;
149     }
150
151     public float getLongitude() {
152         return longitude;
153     }
154
155     public int getVerticalQuadrantMultiplier() {
156         return verticalQuadrantMultiplier;
157     }
158
159     public int getHorizontalQuadrantMultiplier() {
160         return horizontalQuadrantMultiplier;
161     }
162 }