Niklas 1 year ago
commit
1f5cc164ce

BIN
lib/darcula.jar View File


+ 80
- 0
pom.xml View File

@@ -0,0 +1,80 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>de.gurkengewuerz</groupId>
8
+    <artifactId>serialinterface</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+
11
+    <dependencies>
12
+        <dependency>
13
+            <groupId>org.rxtx</groupId>
14
+            <artifactId>rxtx</artifactId>
15
+            <version>2.1.7</version>
16
+        </dependency>
17
+        <dependency>
18
+            <groupId>org.json</groupId>
19
+            <artifactId>json</artifactId>
20
+            <version>20160810</version>
21
+        </dependency>
22
+        <dependency>
23
+            <groupId>org.tinylog</groupId>
24
+            <artifactId>tinylog</artifactId>
25
+            <version>1.3.2</version>
26
+        </dependency>
27
+        <dependency>
28
+            <groupId>com.intellij</groupId>
29
+            <artifactId>forms_rt</artifactId>
30
+            <version>7.0.3</version>
31
+        </dependency>
32
+        <dependency>
33
+            <groupId>com.bulenkov</groupId>
34
+            <artifactId>darcula</artifactId>
35
+            <version>1.0.0</version>
36
+            <scope>system</scope>
37
+            <systemPath>${project.basedir}/lib/darcula.jar</systemPath>
38
+        </dependency>
39
+    </dependencies>
40
+
41
+    <build>
42
+        <plugins>
43
+            <plugin>
44
+                <artifactId>maven-compiler-plugin</artifactId>
45
+                <version>3.5.1</version>
46
+                <configuration>
47
+                    <source>1.8</source>
48
+                    <target>1.8</target>
49
+                </configuration>
50
+            </plugin>
51
+            <plugin>
52
+                <artifactId>maven-assembly-plugin</artifactId>
53
+                <version>2.6</version>
54
+                <configuration>
55
+                    <appendAssemblyId>false</appendAssemblyId>
56
+                    <finalName>${project.artifactId}</finalName>
57
+                    <descriptorRefs>
58
+                        <descriptorRef>
59
+                            jar-with-dependencies
60
+                        </descriptorRef>
61
+                    </descriptorRefs>
62
+                    <archive>
63
+                        <manifest>
64
+                            <mainClass>${project.groupId}.${project.artifactId}.SerialInterface</mainClass>
65
+                        </manifest>
66
+                    </archive>
67
+                </configuration>
68
+                <executions>
69
+                    <execution>
70
+                        <id>assamble</id>
71
+                        <goals>
72
+                            <goal>single</goal>
73
+                        </goals>
74
+                        <phase>package</phase>
75
+                    </execution>
76
+                </executions>
77
+            </plugin>
78
+        </plugins>
79
+    </build>
80
+</project>

+ 140
- 0
src/main/java/de/gurkengewuerz/serialinterface/DashboardStatus.java View File

@@ -0,0 +1,140 @@
1
+package de.gurkengewuerz.serialinterface;
2
+
3
+import org.json.JSONObject;
4
+import org.pmw.tinylog.Logger;
5
+
6
+import java.nio.charset.StandardCharsets;
7
+import java.util.Arrays;
8
+
9
+/**
10
+ * Created by gurkengewuerz.de on 08.01.2018.
11
+ */
12
+public class DashboardStatus {
13
+
14
+    private int fuel = 100;
15
+    private int rpm = 0;
16
+    private int kmh = 0;
17
+    private boolean backlight = true;
18
+    private boolean fogbeam = false;
19
+    private boolean highbeam = false;
20
+    private boolean handbrake = false;
21
+    private boolean abs = false;
22
+    private boolean oil_pressure = false;
23
+    private boolean tire_pressure = false;
24
+    private boolean kupplung = false;
25
+    private boolean trunk = false;
26
+    private boolean l_turn_signal = false;
27
+    private boolean r_turn_signal = false;
28
+    private boolean offroad = false;
29
+    private boolean water_temp = false;
30
+    private boolean seat_belt = false;
31
+    private boolean battery = false;
32
+    private boolean check_lamp = false;
33
+    private boolean doors = false;
34
+
35
+    public void setFuel(int fuel) {
36
+        this.fuel = fuel;
37
+    }
38
+
39
+    public void setRpm(int rpm) {
40
+        this.rpm = rpm;
41
+    }
42
+
43
+    public void setKmh(int kmh) {
44
+        this.kmh = kmh;
45
+    }
46
+
47
+    public void setBacklight(boolean backlight) {
48
+        this.backlight = backlight;
49
+    }
50
+
51
+    public void setFogbeam(boolean fogbeam) {
52
+        this.fogbeam = fogbeam;
53
+    }
54
+
55
+    public void setHighbeam(boolean highbeam) {
56
+        this.highbeam = highbeam;
57
+    }
58
+
59
+    public void setHandbrake(boolean handbrake) {
60
+        this.handbrake = handbrake;
61
+    }
62
+
63
+    public void setAbs(boolean abs) {
64
+        this.abs = abs;
65
+    }
66
+
67
+    public void setOil_pressure(boolean oil_pressure) {
68
+        this.oil_pressure = oil_pressure;
69
+    }
70
+
71
+    public void setTire_pressure(boolean tire_pressure) {
72
+        this.tire_pressure = tire_pressure;
73
+    }
74
+
75
+    public void setKupplung(boolean kupplung) {
76
+        this.kupplung = kupplung;
77
+    }
78
+
79
+    public void setTrunk(boolean trunk) {
80
+        this.trunk = trunk;
81
+    }
82
+
83
+    public void setL_turn_signal(boolean l_turn_signal) {
84
+        this.l_turn_signal = l_turn_signal;
85
+    }
86
+
87
+    public void setR_turn_signal(boolean r_turn_signal) {
88
+        this.r_turn_signal = r_turn_signal;
89
+    }
90
+
91
+    public void setOffroad(boolean offroad) {
92
+        this.offroad = offroad;
93
+    }
94
+
95
+    public void setWater_temp(boolean water_temp) {
96
+        this.water_temp = water_temp;
97
+    }
98
+
99
+    public void setSeat_belt(boolean seat_belt) {
100
+        this.seat_belt = seat_belt;
101
+    }
102
+
103
+    public void setBattery(boolean battery) {
104
+        this.battery = battery;
105
+    }
106
+
107
+    public void setCheck_lamp(boolean check_lamp) {
108
+        this.check_lamp = check_lamp;
109
+    }
110
+
111
+    public void setDoors(boolean doors) {
112
+        this.doors = doors;
113
+    }
114
+
115
+    public String generateJSON() {
116
+        JSONObject obj = new JSONObject();
117
+        obj.put("kmh", kmh);
118
+        obj.put("rpm", rpm);
119
+        obj.put("fuel", fuel);
120
+        obj.put("backlight", backlight);
121
+        obj.put("l_turn_signal", l_turn_signal);
122
+        obj.put("r_turn_signal", r_turn_signal);
123
+        obj.put("offroad", offroad);
124
+        obj.put("water_temp", water_temp);
125
+        obj.put("seat_belt", seat_belt);
126
+        obj.put("battery", battery);
127
+        obj.put("check_lamp", check_lamp);
128
+        obj.put("doors", doors);
129
+        obj.put("fogbeam", fogbeam);
130
+        obj.put("highbeam", highbeam);
131
+        obj.put("handbrake", handbrake);
132
+        obj.put("abs", abs);
133
+        obj.put("oil_pressure", oil_pressure);
134
+        obj.put("tire_pressure", tire_pressure);
135
+        obj.put("kupplung", kupplung);
136
+        obj.put("trunk", trunk);
137
+
138
+        return obj.toString();
139
+    }
140
+}

+ 390
- 0
src/main/java/de/gurkengewuerz/serialinterface/SerialGUI.form View File

@@ -0,0 +1,390 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.gurkengewuerz.serialinterface.SerialGUI">
3
+  <grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4
+    <margin top="0" left="0" bottom="0" right="0"/>
5
+    <constraints>
6
+      <xy x="20" y="20" width="1066" height="465"/>
7
+    </constraints>
8
+    <properties/>
9
+    <border type="none"/>
10
+    <children>
11
+      <tabbedpane id="b373f" binding="tabbedPane1" default-binding="true">
12
+        <constraints>
13
+          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
14
+            <preferred-size width="200" height="200"/>
15
+          </grid>
16
+        </constraints>
17
+        <properties>
18
+          <toolTipText value="Settings Panel"/>
19
+        </properties>
20
+        <border type="none"/>
21
+        <children>
22
+          <grid id="67de2" layout-manager="GridLayoutManager" row-count="2" column-count="8" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
23
+            <margin top="0" left="0" bottom="0" right="0"/>
24
+            <constraints>
25
+              <tabbedpane title="Settings"/>
26
+            </constraints>
27
+            <properties/>
28
+            <border type="none"/>
29
+            <children>
30
+              <grid id="b360f" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
31
+                <margin top="0" left="0" bottom="0" right="0"/>
32
+                <constraints>
33
+                  <grid row="0" column="4" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
34
+                </constraints>
35
+                <properties/>
36
+                <border type="none"/>
37
+                <children>
38
+                  <component id="3979f" class="javax.swing.JLabel">
39
+                    <constraints>
40
+                      <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
41
+                    </constraints>
42
+                    <properties>
43
+                      <text value="Listen on:"/>
44
+                    </properties>
45
+                  </component>
46
+                  <component id="7841" class="javax.swing.JTextField" binding="a0000TextField" default-binding="true">
47
+                    <constraints>
48
+                      <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
49
+                        <preferred-size width="150" height="-1"/>
50
+                      </grid>
51
+                    </constraints>
52
+                    <properties>
53
+                      <text value="0.0.0.0"/>
54
+                    </properties>
55
+                  </component>
56
+                  <component id="13719" class="javax.swing.JLabel">
57
+                    <constraints>
58
+                      <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
59
+                    </constraints>
60
+                    <properties>
61
+                      <text value="Port:"/>
62
+                    </properties>
63
+                  </component>
64
+                  <component id="e23ad" class="javax.swing.JTextField" binding="a8652TextField" default-binding="true">
65
+                    <constraints>
66
+                      <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
67
+                        <preferred-size width="150" height="-1"/>
68
+                      </grid>
69
+                    </constraints>
70
+                    <properties>
71
+                      <text value="8652"/>
72
+                    </properties>
73
+                  </component>
74
+                  <grid id="7504f" binding="simulatorPanel" layout-manager="GridLayoutManager" row-count="9" column-count="7" same-size-horizontally="true" same-size-vertically="true" hgap="-1" vgap="-1">
75
+                    <margin top="0" left="0" bottom="0" right="0"/>
76
+                    <constraints>
77
+                      <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
78
+                    </constraints>
79
+                    <properties/>
80
+                    <border type="none"/>
81
+                    <children>
82
+                      <component id="e13cd" class="javax.swing.JSpinner" binding="fuelSpinner">
83
+                        <constraints>
84
+                          <grid row="0" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
85
+                        </constraints>
86
+                        <properties>
87
+                          <toolTipText value="Set Fuel"/>
88
+                        </properties>
89
+                      </component>
90
+                      <component id="7a85" class="javax.swing.JLabel">
91
+                        <constraints>
92
+                          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
93
+                        </constraints>
94
+                        <properties>
95
+                          <text value="Fuellevel"/>
96
+                        </properties>
97
+                      </component>
98
+                      <component id="d70a1" class="javax.swing.JCheckBox" binding="fogBeamCheckBox" default-binding="true">
99
+                        <constraints>
100
+                          <grid row="1" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
101
+                        </constraints>
102
+                        <properties>
103
+                          <text value="Fog Beam"/>
104
+                        </properties>
105
+                      </component>
106
+                      <component id="e6f32" class="javax.swing.JCheckBox" binding="backlightCheckBox" default-binding="true">
107
+                        <constraints>
108
+                          <grid row="0" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
109
+                        </constraints>
110
+                        <properties>
111
+                          <selected value="true"/>
112
+                          <text value="Backlight"/>
113
+                        </properties>
114
+                      </component>
115
+                      <component id="ef69f" class="javax.swing.JButton" binding="updateButton" default-binding="true">
116
+                        <constraints>
117
+                          <grid row="0" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
118
+                        </constraints>
119
+                        <properties>
120
+                          <text value="Update"/>
121
+                        </properties>
122
+                      </component>
123
+                      <component id="cc497" class="javax.swing.JCheckBox" binding="waterTempCheckBox" default-binding="true">
124
+                        <constraints>
125
+                          <grid row="4" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
126
+                        </constraints>
127
+                        <properties>
128
+                          <text value="Water Temp."/>
129
+                        </properties>
130
+                      </component>
131
+                      <component id="cf2eb" class="javax.swing.JCheckBox" binding="highBeamCheckBox" default-binding="true">
132
+                        <constraints>
133
+                          <grid row="2" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
134
+                        </constraints>
135
+                        <properties>
136
+                          <text value="High Beam"/>
137
+                        </properties>
138
+                      </component>
139
+                      <component id="23b21" class="javax.swing.JCheckBox" binding="handbrakeCheckBox" default-binding="true">
140
+                        <constraints>
141
+                          <grid row="3" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
142
+                        </constraints>
143
+                        <properties>
144
+                          <text value="Handbrake"/>
145
+                        </properties>
146
+                      </component>
147
+                      <component id="5abb7" class="javax.swing.JCheckBox" binding="ABSCheckBox" default-binding="true">
148
+                        <constraints>
149
+                          <grid row="4" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
150
+                        </constraints>
151
+                        <properties>
152
+                          <text value="ABS"/>
153
+                        </properties>
154
+                      </component>
155
+                      <component id="cf12a" class="javax.swing.JCheckBox" binding="oilPressureCheckBox" default-binding="true">
156
+                        <constraints>
157
+                          <grid row="5" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
158
+                        </constraints>
159
+                        <properties>
160
+                          <text value="Oil Pressure"/>
161
+                        </properties>
162
+                      </component>
163
+                      <component id="ad835" class="javax.swing.JCheckBox" binding="tirePressureCheckBox" default-binding="true">
164
+                        <constraints>
165
+                          <grid row="6" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
166
+                        </constraints>
167
+                        <properties>
168
+                          <text value="Tire Pressure"/>
169
+                        </properties>
170
+                      </component>
171
+                      <component id="16ce3" class="javax.swing.JCheckBox" binding="lTurnSignalCheckBox" default-binding="true">
172
+                        <constraints>
173
+                          <grid row="1" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
174
+                        </constraints>
175
+                        <properties>
176
+                          <enabled value="true"/>
177
+                          <selected value="false"/>
178
+                          <text value="l. turn signal"/>
179
+                        </properties>
180
+                      </component>
181
+                      <component id="410e9" class="javax.swing.JCheckBox" binding="rTurnSignalCheckBox" default-binding="true">
182
+                        <constraints>
183
+                          <grid row="2" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
184
+                        </constraints>
185
+                        <properties>
186
+                          <text value="r. turn signal"/>
187
+                        </properties>
188
+                      </component>
189
+                      <component id="5857" class="javax.swing.JCheckBox" binding="offroadCheckBox" default-binding="true">
190
+                        <constraints>
191
+                          <grid row="3" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
192
+                        </constraints>
193
+                        <properties>
194
+                          <text value="Offroad"/>
195
+                        </properties>
196
+                      </component>
197
+                      <component id="d1169" class="javax.swing.JCheckBox" binding="seatBeltCheckBox" default-binding="true">
198
+                        <constraints>
199
+                          <grid row="5" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
200
+                        </constraints>
201
+                        <properties>
202
+                          <text value="Seat Belt"/>
203
+                        </properties>
204
+                      </component>
205
+                      <component id="4d16a" class="javax.swing.JCheckBox" binding="lowVoltageCheckBox" default-binding="true">
206
+                        <constraints>
207
+                          <grid row="6" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
208
+                        </constraints>
209
+                        <properties>
210
+                          <text value="Low Voltage"/>
211
+                        </properties>
212
+                      </component>
213
+                      <component id="6991a" class="javax.swing.JCheckBox" binding="checkLampCheckBox" default-binding="true">
214
+                        <constraints>
215
+                          <grid row="7" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
216
+                        </constraints>
217
+                        <properties>
218
+                          <text value="&quot;Check Lamp&quot;"/>
219
+                        </properties>
220
+                      </component>
221
+                      <component id="57cab" class="javax.swing.JCheckBox" binding="kupplungCheckBox" default-binding="true">
222
+                        <constraints>
223
+                          <grid row="7" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
224
+                        </constraints>
225
+                        <properties>
226
+                          <text value="&quot;Kupplung&quot;"/>
227
+                        </properties>
228
+                      </component>
229
+                      <component id="2486d" class="javax.swing.JCheckBox" binding="openDoorsCheckBox" default-binding="true">
230
+                        <constraints>
231
+                          <grid row="8" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
232
+                        </constraints>
233
+                        <properties>
234
+                          <text value="Open Doors"/>
235
+                        </properties>
236
+                      </component>
237
+                      <component id="c7825" class="javax.swing.JCheckBox" binding="openTrunkCheckBox" default-binding="true">
238
+                        <constraints>
239
+                          <grid row="8" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
240
+                        </constraints>
241
+                        <properties>
242
+                          <text value="Open Trunk"/>
243
+                        </properties>
244
+                      </component>
245
+                      <grid id="f8ce8" layout-manager="GridLayoutManager" row-count="3" column-count="8" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
246
+                        <margin top="0" left="0" bottom="0" right="0"/>
247
+                        <constraints>
248
+                          <grid row="1" column="0" row-span="8" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
249
+                        </constraints>
250
+                        <properties/>
251
+                        <border type="none"/>
252
+                        <children>
253
+                          <component id="99554" class="javax.swing.JSlider" binding="kmhSlider">
254
+                            <constraints>
255
+                              <grid row="0" column="4" row-span="3" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
256
+                            </constraints>
257
+                            <properties>
258
+                              <inverted value="false"/>
259
+                              <maximum value="240"/>
260
+                              <orientation value="1"/>
261
+                              <paintLabels value="true"/>
262
+                              <paintTicks value="false"/>
263
+                              <paintTrack value="true"/>
264
+                              <snapToTicks value="true"/>
265
+                              <value value="0"/>
266
+                            </properties>
267
+                          </component>
268
+                          <component id="28e81" class="javax.swing.JSlider" binding="rpmSlider">
269
+                            <constraints>
270
+                              <grid row="0" column="0" row-span="3" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
271
+                            </constraints>
272
+                            <properties>
273
+                              <inverted value="false"/>
274
+                              <maximum value="8000"/>
275
+                              <minorTickSpacing value="100"/>
276
+                              <orientation value="1"/>
277
+                              <paintLabels value="true"/>
278
+                              <paintTicks value="false"/>
279
+                              <paintTrack value="true"/>
280
+                              <snapToTicks value="true"/>
281
+                              <value value="0"/>
282
+                              <valueIsAdjusting value="false"/>
283
+                            </properties>
284
+                          </component>
285
+                          <component id="95218" class="javax.swing.JLabel" binding="rpmCounter">
286
+                            <constraints>
287
+                              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
288
+                            </constraints>
289
+                            <properties>
290
+                              <font size="14" style="1"/>
291
+                              <text value="RPM: 0"/>
292
+                            </properties>
293
+                          </component>
294
+                          <component id="fb0c5" class="javax.swing.JLabel" binding="kmhCounter">
295
+                            <constraints>
296
+                              <grid row="0" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
297
+                            </constraints>
298
+                            <properties>
299
+                              <font size="14" style="1"/>
300
+                              <text value="0 km/h"/>
301
+                            </properties>
302
+                          </component>
303
+                        </children>
304
+                      </grid>
305
+                    </children>
306
+                  </grid>
307
+                </children>
308
+              </grid>
309
+              <component id="cb8a0" class="javax.swing.JButton" binding="connectButton" default-binding="true">
310
+                <constraints>
311
+                  <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
312
+                </constraints>
313
+                <properties>
314
+                  <text value="Connect"/>
315
+                </properties>
316
+              </component>
317
+              <component id="c6619" class="javax.swing.JList" binding="comPorts">
318
+                <constraints>
319
+                  <grid row="0" column="0" row-span="1" col-span="4" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
320
+                    <preferred-size width="150" height="50"/>
321
+                  </grid>
322
+                </constraints>
323
+                <properties/>
324
+              </component>
325
+              <component id="b0c47" class="javax.swing.JButton" binding="startServerButton" default-binding="true">
326
+                <constraints>
327
+                  <grid row="1" column="7" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
328
+                </constraints>
329
+                <properties>
330
+                  <enabled value="false"/>
331
+                  <text value="Start Server"/>
332
+                </properties>
333
+              </component>
334
+              <component id="7b84a" class="javax.swing.JButton" binding="refreshButton" default-binding="true">
335
+                <constraints>
336
+                  <grid row="1" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
337
+                </constraints>
338
+                <properties>
339
+                  <font/>
340
+                  <text value="Refresh"/>
341
+                </properties>
342
+              </component>
343
+            </children>
344
+          </grid>
345
+          <grid id="df335" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
346
+            <margin top="0" left="0" bottom="0" right="0"/>
347
+            <constraints>
348
+              <tabbedpane title="Debug"/>
349
+            </constraints>
350
+            <properties/>
351
+            <border type="none"/>
352
+            <children>
353
+              <component id="80b21" class="javax.swing.JButton" binding="sendButton" default-binding="true">
354
+                <constraints>
355
+                  <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
356
+                </constraints>
357
+                <properties>
358
+                  <text value="Send"/>
359
+                </properties>
360
+              </component>
361
+              <component id="2aae1" class="javax.swing.JTextField" binding="txText">
362
+                <constraints>
363
+                  <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
364
+                    <preferred-size width="150" height="-1"/>
365
+                  </grid>
366
+                </constraints>
367
+                <properties/>
368
+              </component>
369
+              <scrollpane id="995bd">
370
+                <constraints>
371
+                  <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
372
+                </constraints>
373
+                <properties/>
374
+                <border type="none"/>
375
+                <children>
376
+                  <component id="3d0a5" class="javax.swing.JTextArea" binding="debugArea">
377
+                    <constraints/>
378
+                    <properties>
379
+                      <wrapStyleWord value="true"/>
380
+                    </properties>
381
+                  </component>
382
+                </children>
383
+              </scrollpane>
384
+            </children>
385
+          </grid>
386
+        </children>
387
+      </tabbedpane>
388
+    </children>
389
+  </grid>
390
+</form>

+ 290
- 0
src/main/java/de/gurkengewuerz/serialinterface/SerialGUI.java View File

@@ -0,0 +1,290 @@
1
+package de.gurkengewuerz.serialinterface;
2
+
3
+import gnu.io.CommPortIdentifier;
4
+import gnu.io.SerialPort;
5
+import gnu.io.SerialPortEvent;
6
+import org.pmw.tinylog.Logger;
7
+
8
+import javax.swing.*;
9
+import java.awt.event.ActionEvent;
10
+import java.awt.event.ActionListener;
11
+import java.io.BufferedReader;
12
+import java.io.IOException;
13
+import java.io.InputStreamReader;
14
+import java.io.OutputStream;
15
+import java.util.ArrayList;
16
+import java.util.Hashtable;
17
+import java.util.concurrent.Executors;
18
+import java.util.concurrent.ScheduledExecutorService;
19
+import java.util.concurrent.TimeUnit;
20
+
21
+/**
22
+ * Created by gurkengewuerz.de on 08.01.2018.
23
+ */
24
+public class SerialGUI {
25
+    private JTabbedPane tabbedPane1;
26
+    private JButton refreshButton;
27
+    private JTextField a0000TextField;
28
+    private JTextArea debugArea;
29
+    private JButton sendButton;
30
+    private JTextField txText;
31
+    private JTextField a8652TextField;
32
+    private JButton connectButton;
33
+    private JButton startServerButton;
34
+    public JPanel mainPanel;
35
+    private JList comPorts;
36
+    private JSlider kmhSlider;
37
+    private JSpinner fuelSpinner;
38
+    private JSlider rpmSlider;
39
+    private JCheckBox rTurnSignalCheckBox;
40
+    private JCheckBox lTurnSignalCheckBox;
41
+    private JCheckBox handbrakeCheckBox;
42
+    private JCheckBox fogBeamCheckBox;
43
+    private JCheckBox highBeamCheckBox;
44
+    private JCheckBox seatBeltCheckBox;
45
+    private JCheckBox lowVoltageCheckBox;
46
+    private JCheckBox waterTempCheckBox;
47
+    private JCheckBox ABSCheckBox;
48
+    private JCheckBox tirePressureCheckBox;
49
+    private JCheckBox backlightCheckBox;
50
+    private JButton updateButton;
51
+    private JCheckBox offroadCheckBox;
52
+    private JCheckBox oilPressureCheckBox;
53
+    private JCheckBox openDoorsCheckBox;
54
+    private JCheckBox kupplungCheckBox;
55
+    private JCheckBox checkLampCheckBox;
56
+    private JCheckBox openTrunkCheckBox;
57
+    private JLabel rpmCounter;
58
+    private JLabel kmhCounter;
59
+    private JPanel simulatorPanel;
60
+
61
+    private SerialPort serialPort;
62
+    private BufferedReader input;
63
+    private OutputStream output;
64
+    private static final int TIME_OUT = 2000;
65
+    private static final int BAUDRATE = 115200; // ~ 14 kByte pro Sekunde
66
+    private DashboardStatus status;
67
+    private ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
68
+
69
+    /*
70
+    TODO: Klasse für Ansteuerung
71
+    TODO: WebServer
72
+    TODO: Update Simulation Panel if Class for contol gets updated! (Live View)
73
+
74
+
75
+     */
76
+
77
+    public SerialGUI() {
78
+        status = new DashboardStatus();
79
+
80
+        Logger.info(String.join(",", listPorts()));
81
+        refreshPortList();
82
+
83
+        SpinnerModel sm = new SpinnerNumberModel(100, 0, 100, 5);
84
+        fuelSpinner.setModel(sm);
85
+
86
+        Hashtable labelsKMH = new Hashtable();
87
+        labelsKMH.put(0, new JLabel("0 km/h"));
88
+        labelsKMH.put(40, new JLabel("40 km/h"));
89
+        labelsKMH.put(80, new JLabel("80 km/h"));
90
+        labelsKMH.put(120, new JLabel("120 km/h"));
91
+        labelsKMH.put(160, new JLabel("160 km/h"));
92
+        labelsKMH.put(200, new JLabel("200 km/h"));
93
+        labelsKMH.put(240, new JLabel("240 km/h"));
94
+        kmhSlider.setLabelTable(labelsKMH);
95
+
96
+        kmhSlider.addChangeListener(evt -> {
97
+            JSlider slider = (JSlider) evt.getSource();
98
+            if (!slider.getValueIsAdjusting()) {
99
+                int value = slider.getValue();
100
+                kmhCounter.setText(value + " km/h");
101
+            }
102
+        });
103
+
104
+        Hashtable labelsRPM = new Hashtable();
105
+        labelsRPM.put(0, new JLabel("0"));
106
+        labelsRPM.put(1000, new JLabel("1k"));
107
+        labelsRPM.put(2000, new JLabel("2k"));
108
+        labelsRPM.put(3000, new JLabel("3k"));
109
+        labelsRPM.put(4000, new JLabel("4k"));
110
+        labelsRPM.put(5000, new JLabel("5k"));
111
+        labelsRPM.put(6000, new JLabel("6k"));
112
+        labelsRPM.put(7000, new JLabel("7k"));
113
+        labelsRPM.put(8000, new JLabel("8k"));
114
+        rpmSlider.setLabelTable(labelsRPM);
115
+
116
+        rpmSlider.addChangeListener(evt -> {
117
+            JSlider slider = (JSlider) evt.getSource();
118
+            if (!slider.getValueIsAdjusting()) {
119
+                int value = slider.getValue();
120
+                rpmCounter.setText("RPM: " + value);
121
+            }
122
+        });
123
+
124
+        refreshButton.addActionListener(e -> {
125
+            refreshPortList();
126
+            comPorts.grabFocus();
127
+        });
128
+
129
+        connectButton.addActionListener(new ActionListener() {
130
+            @Override
131
+            public void actionPerformed(ActionEvent e) {
132
+                if (serialPort == null) {
133
+                    try {
134
+                        if (comPorts.getSelectedIndex() < 0) {
135
+                            errorBox("Please select a COM Port!", "No port selected");
136
+                            return;
137
+                        }
138
+
139
+                        CommPortIdentifier portId = getPortIDbyString((String) comPorts.getSelectedValue());
140
+                        if (portId == null) {
141
+                            errorBox("An invalid port is selected!\nIs the port still connected?", "Invalid port selected");
142
+                            refreshPortList();
143
+                            return;
144
+                        }
145
+
146
+                        // open serial port, and use class name for the appName.
147
+                        serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);
148
+
149
+                        // set port parameters
150
+                        serialPort.setSerialPortParams(BAUDRATE,
151
+                                SerialPort.DATABITS_8,
152
+                                SerialPort.STOPBITS_1,
153
+                                SerialPort.PARITY_NONE);
154
+
155
+                        // open the streams
156
+                        input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
157
+                        output = serialPort.getOutputStream();
158
+
159
+                        ses.scheduleAtFixedRate(() -> write(status.generateJSON()), 5 * 1000, 10, TimeUnit.MILLISECONDS);
160
+
161
+
162
+                        // add event listeners
163
+                        serialPort.addEventListener(oEvent -> {
164
+                            if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
165
+                                try {
166
+                                    String inputLine = input.readLine();
167
+                                    debugArea.append(inputLine + "\n");
168
+                                    debugArea.setCaretPosition(debugArea.getDocument().getLength());
169
+
170
+
171
+                                } catch (Exception ex) {
172
+                                    //Logger.error(ex);
173
+                                }
174
+                            }
175
+                        });
176
+                        serialPort.notifyOnDataAvailable(true);
177
+
178
+                        refreshButton.setEnabled(false);
179
+                        comPorts.setEnabled(false);
180
+                        startServerButton.setEnabled(true);
181
+                        connectButton.setText("Disconnect");
182
+                    } catch (Exception ex) {
183
+                        Logger.error(ex);
184
+                    }
185
+                } else {
186
+                    close();
187
+                    serialPort = null;
188
+
189
+                    refreshButton.setEnabled(true);
190
+                    comPorts.setEnabled(true);
191
+                    startServerButton.setEnabled(false);
192
+                    connectButton.setText("Connect");
193
+                    ses.shutdown();
194
+
195
+                    // TODO: Stop Server
196
+                }
197
+            }
198
+        });
199
+
200
+        sendButton.addActionListener(e -> {
201
+            write(txText.getText());
202
+            txText.setText("");
203
+        });
204
+
205
+        updateButton.addActionListener(e -> {
206
+            status.setRpm(rpmSlider.getValue());
207
+            status.setKmh(kmhSlider.getValue());
208
+            status.setFuel((Integer) fuelSpinner.getValue());
209
+            status.setFogbeam(fogBeamCheckBox.isSelected());
210
+            status.setHighbeam(highBeamCheckBox.isSelected());
211
+            status.setHandbrake(handbrakeCheckBox.isSelected());
212
+            status.setAbs(ABSCheckBox.isSelected());
213
+            status.setOil_pressure(oilPressureCheckBox.isSelected());
214
+            status.setTire_pressure(tirePressureCheckBox.isSelected());
215
+            status.setKupplung(kupplungCheckBox.isSelected());
216
+            status.setTrunk(openTrunkCheckBox.isSelected());
217
+            status.setBacklight(backlightCheckBox.isSelected());
218
+            status.setL_turn_signal(lTurnSignalCheckBox.isSelected());
219
+            status.setR_turn_signal(rTurnSignalCheckBox.isSelected());
220
+            status.setOffroad(offroadCheckBox.isSelected());
221
+            status.setWater_temp(waterTempCheckBox.isSelected());
222
+            status.setSeat_belt(seatBeltCheckBox.isSelected());
223
+            status.setBattery(lowVoltageCheckBox.isSelected());
224
+            status.setCheck_lamp(checkLampCheckBox.isSelected());
225
+            status.setDoors(openDoorsCheckBox.isSelected());
226
+            Logger.info(status.generateJSON());
227
+            Logger.info(status.generateJSON().getBytes().length);
228
+        });
229
+    }
230
+
231
+    public void write(String payload) {
232
+        if (serialPort != null) {
233
+            try {
234
+                output.write(payload.getBytes());
235
+                output.flush();
236
+            } catch (IOException e) {
237
+                Logger.error(e);
238
+            }
239
+        }
240
+    }
241
+
242
+    public synchronized void close() {
243
+        if (serialPort != null) {
244
+            serialPort.removeEventListener();
245
+            serialPort.close();
246
+        }
247
+    }
248
+
249
+    private void refreshPortList() {
250
+        DefaultListModel<String> model = new DefaultListModel<>();
251
+        comPorts.setModel(model);
252
+
253
+        listPorts().forEach(model::addElement);
254
+    }
255
+
256
+    private CommPortIdentifier getPortIDbyString(String port) {
257
+        CommPortIdentifier portID = null;
258
+
259
+        java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
260
+        while (portEnum.hasMoreElements()) {
261
+            CommPortIdentifier portIdentifier = portEnum.nextElement();
262
+            if (portIdentifier.getName().equals(port)) {
263
+                portID = portIdentifier;
264
+                break;
265
+            }
266
+        }
267
+
268
+        return portID;
269
+    }
270
+
271
+    private ArrayList<String> listPorts() {
272
+        ArrayList<String> ports = new ArrayList<>();
273
+        java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
274
+        while (portEnum.hasMoreElements()) {
275
+            CommPortIdentifier portIdentifier = portEnum.nextElement();
276
+            if (portIdentifier.getPortType() == CommPortIdentifier.PORT_SERIAL) ports.add(portIdentifier.getName());
277
+        }
278
+
279
+        return ports;
280
+    }
281
+
282
+
283
+    public static void infoBox(String infoMessage, String titleBar) {
284
+        JOptionPane.showMessageDialog(null, infoMessage, "INFO: " + titleBar, JOptionPane.INFORMATION_MESSAGE);
285
+    }
286
+
287
+    public static void errorBox(String errorMessage, String titleBar) {
288
+        JOptionPane.showMessageDialog(null, errorMessage, "ERROR: " + titleBar, JOptionPane.ERROR_MESSAGE);
289
+    }
290
+}

+ 37
- 0
src/main/java/de/gurkengewuerz/serialinterface/SerialInterface.java View File

@@ -0,0 +1,37 @@
1
+package de.gurkengewuerz.serialinterface;
2
+
3
+import com.bulenkov.darcula.DarculaLaf;
4
+
5
+import javax.swing.*;
6
+import java.awt.event.WindowAdapter;
7
+import java.awt.event.WindowEvent;
8
+
9
+/**
10
+ * Created by gurkengewuerz.de on 08.01.2018.
11
+ */
12
+public class SerialInterface {
13
+
14
+    public static void main(String... args) {
15
+        try {
16
+            UIManager.setLookAndFeel(new DarculaLaf());
17
+        } catch (UnsupportedLookAndFeelException e) {
18
+            e.printStackTrace();
19
+        }
20
+
21
+
22
+        JFrame frame = new JFrame("Serial Interface Manager");
23
+        SerialGUI gui = new SerialGUI();
24
+        frame.setContentPane(gui.mainPanel);
25
+
26
+        frame.addWindowListener(new WindowAdapter() {
27
+            @Override
28
+            public void windowClosing(WindowEvent e) {
29
+                gui.close();
30
+                frame.dispose();
31
+            }
32
+        });
33
+
34
+        frame.pack();
35
+        frame.setVisible(true);
36
+    }
37
+}

Loading…
Cancel
Save