48
48
import org .apache .commons .cli .DefaultParser ;
49
49
50
50
import de .ibapl .fhz4j .api .Adapter ;
51
- import de .ibapl .fhz4j .api .FhzAdapter ;
52
- import de .ibapl .fhz4j .api .FhzDataListener ;
53
51
import de .ibapl .fhz4j .api .Protocol ;
54
52
import de .ibapl .fhz4j .cul .CulAdapter ;
55
- import de .ibapl .fhz4j .parser . cul .CulMessage ;
53
+ import de .ibapl .fhz4j .cul .CulMessage ;
56
54
import de .ibapl .fhz4j .protocol .em .EmMessage ;
57
55
import de .ibapl .fhz4j .protocol .evohome .EvoHomeMessage ;
58
56
import de .ibapl .fhz4j .protocol .fht .FhtMessage ;
64
62
import de .ibapl .spsw .logging .LoggingSerialPortSocket ;
65
63
import de .ibapl .spsw .logging .TimeStampLogging ;
66
64
import de .ibapl .spsw .ser2net .Ser2NetProvider ;
65
+ import de .ibapl .fhz4j .api .FhzHandler ;
66
+ import de .ibapl .fhz4j .cul .CulMessageListener ;
67
67
68
68
/**
69
69
* DOCUMENT ME!
70
70
*
71
71
* @author Arne Plöse
72
72
*/
73
73
public class Main {
74
- public final static String FHZ_CONSOLE = "fhz-console" ;
74
+
75
+ public final static String FHZ_CONSOLE = "fhz-console" ;
75
76
76
77
private static final Logger LOG = Logger .getLogger (FHZ_CONSOLE );
77
78
78
- private class FhzListener implements FhzDataListener {
79
-
80
- FhzAdapter fhzAdapter ;
79
+ private class FhzListener implements CulMessageListener {
80
+
81
+ FhzHandler fhzAdapter ;
81
82
82
83
@ Override
83
84
public void fhtDataParsed (FhtMessage fhtMessage ) {
84
85
printTimeStamp ();
85
86
System .out .println (fhtMessage .toString ());
86
87
//Just testing
87
88
if (true ) {
88
- return ;
89
+ return ;
89
90
}
90
-
91
+
91
92
if (DEVICES_HOME_CODE .add (fhtMessage .housecode )) {
92
93
try {
93
94
if (fhzAdapter != null ) {
94
- fhzAdapter .writeFhtTimeAndDate (fhtMessage .housecode , LocalDateTime .now ());
95
- fhzAdapter .initFhtReporting (fhtMessage .housecode );
95
+ fhzAdapter .writeFhtTimeAndDate (fhtMessage .housecode , LocalDateTime .now ());
96
+ fhzAdapter .initFhtReporting (fhtMessage .housecode );
96
97
}
97
98
} catch (Throwable t ) {
98
99
//no-op
@@ -148,17 +149,23 @@ public void failed(Throwable t) {
148
149
}
149
150
}
150
151
151
- @ Override
152
- public void culMessageParsed (CulMessage culMessage ) {
152
+ @ Override
153
+ public void culMessageParsed (CulMessage culMessage ) {
153
154
printTimeStamp ();
154
155
System .err .println (": CUL " + culMessage );
155
- }
156
+ }
156
157
157
- @ Override
158
- public void evoHomeParsed (EvoHomeMessage evoHomeMsg ) {
158
+ @ Override
159
+ public void evoHomeParsed (EvoHomeMessage evoHomeMsg ) {
159
160
printTimeStamp ();
160
161
System .out .println (evoHomeMsg .toString ());
161
- }
162
+ }
163
+
164
+ @ Override
165
+ public void signalStrength (float signalStrength ) {
166
+ printTimeStamp ();
167
+ System .out .append ("Signal strength: " ).println (signalStrength );
168
+ }
162
169
163
170
}
164
171
@@ -192,17 +199,17 @@ public static void main(String[] args) throws FileNotFoundException, IOException
192
199
optg .addOption (opt );
193
200
194
201
options .addOptionGroup (optg );
195
-
196
- opt = new Option (null , "enable-fhz " , false , "enable receive of fhz messages" );
202
+
203
+ opt = new Option (null , "enable-fht " , false , "enable receive of fht messages" );
197
204
options .addOption (opt );
198
205
199
206
opt = new Option (null , "enable-evo-home" , false , "enable receive of evo home messages" );
200
207
options .addOption (opt );
201
208
202
- opt = new Option ("s" , "scan" , false , "scan for serial ports" );
203
-
209
+ opt = new Option ("s" , "scan" , false , "scan for serial ports" );
210
+
204
211
options .addOption (opt );
205
-
212
+
206
213
opt = null ;
207
214
optg = null ;
208
215
@@ -217,25 +224,24 @@ public static void main(String[] args) throws FileNotFoundException, IOException
217
224
return ;
218
225
}
219
226
220
- if (cmd .hasOption ("help" ) || args .length == 0 ) {
227
+ if (cmd .hasOption ("help" ) || args .length == 0 ) {
221
228
printHelp (options );
222
229
223
230
return ;
224
231
}
225
232
ServiceLoader <SerialPortSocketFactory > sl = ServiceLoader .load (SerialPortSocketFactory .class );
226
233
Iterator <SerialPortSocketFactory > i = sl .iterator ();
227
234
if (!i .hasNext ()) {
228
- throw new RuntimeException ("No provider for SerialPortSocketFactory found, pleas add one to you class path " );
235
+ throw new RuntimeException ("No provider for SerialPortSocketFactory found, pleas add one to you class path " );
229
236
}
230
237
final SerialPortSocketFactory serialPortSocketFactory = i .next ();
231
238
232
-
233
239
if (cmd .hasOption ("scan" )) {
234
240
System .out .println ("Java Properties:" );
235
241
System .getProperties ().forEach ((Object key , Object value ) -> {
236
242
System .out .printf ("\t \" %s\" = \" %s\" \n " , key , value );
237
243
});
238
-
244
+
239
245
final List <String > ports = serialPortSocketFactory .getPortNames (false );
240
246
System .out .println ("Serial ports available" );
241
247
for (String port : ports ) {
@@ -246,15 +252,15 @@ public static void main(String[] args) throws FileNotFoundException, IOException
246
252
}
247
253
248
254
Set <Protocol > protocols = EnumSet .noneOf (Protocol .class );
249
- if (cmd .hasOption ("enable-fhz " )) {
250
- protocols .add (Protocol .FHZ );
255
+ if (cmd .hasOption ("enable-fht " )) {
256
+ protocols .add (Protocol .FHT );
251
257
}
252
-
258
+
253
259
if (cmd .hasOption ("enable-evo-home" )) {
254
- protocols .add (Protocol .EVO_HOME );
260
+ protocols .add (Protocol .EVO_HOME );
255
261
}
256
-
257
- final File logFile = File .createTempFile ("cul_" , ".txt" , Paths .get ("." ).toFile ());
262
+
263
+ final File logFile = File .createTempFile ("cul_" , ".txt" , Paths .get ("." ).toFile ());
258
264
259
265
if (cmd .hasOption ("ser2net" )) {
260
266
new Main ().runSer2Net (cmd .getOptionValue ("ser2net" ), protocols , logFile );
@@ -263,19 +269,19 @@ public static void main(String[] args) throws FileNotFoundException, IOException
263
269
if (cmd .hasOption ("port" )) {
264
270
new Main ().runLocalPort (cmd .getOptionValue ("port" ), protocols , logFile );
265
271
}
266
-
272
+
267
273
}
268
274
269
275
private final Set <Short > DEVICES_HOME_CODE = new HashSet <>();
270
276
271
277
public void runSer2Net (String ser2net , Set <Protocol > protocols , File logFile ) {
272
278
try {
273
279
LOG .info ("LOG File: " + logFile .getAbsolutePath ());
274
- String [] split = ser2net .split (":" );
280
+ String [] split = ser2net .split (":" );
275
281
SerialPortSocket serialPort = LoggingSerialPortSocket .wrapWithAsciiOutputStream (new Ser2NetProvider (split [0 ], Integer .valueOf (split [1 ])), new FileOutputStream (logFile ), false , TimeStampLogging .NONE );
276
282
run (serialPort , protocols );
277
283
} catch (Exception ex ) {
278
- throw new RuntimeException (ex );
284
+ throw new RuntimeException (ex );
279
285
}
280
286
}
281
287
@@ -284,71 +290,73 @@ public void runLocalPort(String port, Set<Protocol> protocols, File logFile) {
284
290
ServiceLoader <SerialPortSocketFactory > sl = ServiceLoader .load (SerialPortSocketFactory .class );
285
291
Iterator <SerialPortSocketFactory > i = sl .iterator ();
286
292
if (!i .hasNext ()) {
287
- throw new RuntimeException ("No provider for SerialPortSocketFactory found, pleas add one to you class path " );
293
+ throw new RuntimeException ("No provider for SerialPortSocketFactory found, pleas add one to you class path " );
288
294
}
289
295
final SerialPortSocketFactory serialPortSocketFactory = i .next ();
290
296
291
297
LOG .info ("LOG File: " + logFile .getAbsolutePath ());
292
298
SerialPortSocket serialPort = LoggingSerialPortSocket .wrapWithAsciiOutputStream (serialPortSocketFactory .createSerialPortSocket (port ), new FileOutputStream (logFile ), false , TimeStampLogging .UTC );
293
299
run (serialPort , protocols );
294
300
} catch (Exception ex ) {
295
- throw new RuntimeException (ex );
301
+ throw new RuntimeException (ex );
296
302
}
297
303
}
298
-
304
+
299
305
public void run (SerialPortSocket serialPortSocket , Set <Protocol > protocols ) throws Exception {
300
306
final FhzListener listener = new FhzListener ();
301
- try (CulAdapter culAddapter = (CulAdapter )FhzAdapter .open (serialPortSocket , listener )) {
307
+ try ( CulAdapter culAddapter = new CulAdapter (serialPortSocket , listener )) {
308
+ culAddapter .open ();
302
309
listener .fhzAdapter = culAddapter ;
303
- try {
304
310
try {
305
- Thread .sleep (100 );
306
- } catch (InterruptedException ex ) {
307
- LOG .log (Level .SEVERE , null , ex );
308
- }
309
- if (protocols .contains (Protocol .FHZ )) {
310
- culAddapter .initFhz ((short ) 0001 );
311
- culAddapter .initFhtReporting ((short )302 );
311
+ try {
312
+ Thread .sleep (100 );
313
+ } catch (InterruptedException ex ) {
314
+ LOG .log (Level .SEVERE , null , ex );
315
+ }
316
+ if (protocols .contains (Protocol .FHT )) {
317
+ culAddapter .initFhz ((short ) 0001 );
318
+ culAddapter .initFhtReporting ((short ) 302 );
312
319
// fhzAddapter.writeFhtTimeAndDate((short) 302, LocalDateTime.now());
313
320
// fhzAddapter.writeFhtCycle((short) 302, DayOfWeek.MONDAY, LocalTime.of(5, 0), LocalTime.of(8, 30), null, null);
314
321
// fhzAddapter.writeFht((short)302, FhtProperty.DESIRED_TEMP, 24.0f);
315
322
// fhzAddapter.writeFhtModeManu((short)302);
316
323
// fhzAddapter.writeFhtModeHoliday((short) 302, 16.0f, LocalDate.now().plusMonths(2).plusDays(4));
324
+ }
325
+ if (protocols .contains (Protocol .EVO_HOME )) {
326
+ culAddapter .initEvoHome ();
327
+ }
328
+
329
+ } catch (IOException ex ) {
330
+ LOG .log (Level .SEVERE , ex .getMessage (), ex );
331
+ throw new RuntimeException ("Can't init fhzAdapter" + ex );
317
332
}
318
- if (protocols .contains (Protocol .EVO_HOME )) {
319
- culAddapter .initEvoHome ();
320
- }
333
+ try {
334
+ char c ;
335
+ do {
336
+ c = (char ) System .in .read ();
337
+
338
+ switch (c ) {
339
+ case 'q' :
340
+ System .out .print ("Bye will close down!" );
341
+ break ;
342
+ case 'r' :
343
+ culAddapter .initFhtReporting (DEVICES_HOME_CODE );
344
+ break ;
345
+ default :
346
+ }
347
+ } while (c != 'q' );
321
348
322
- } catch (IOException ex ) {
323
- LOG .log (Level .SEVERE , ex .getMessage (), ex );
324
- throw new RuntimeException ("Can't init fhzAdapter" + ex );
325
- }
326
- try {
327
- char c ;
328
- do {
329
- c = (char ) System .in .read ();
330
-
331
- switch (c ) {
332
- case 'q' :
333
- System .out .print ("Bye will close down!" );
334
- break ;
335
- case 'r' :
336
- culAddapter .initFhtReporting (DEVICES_HOME_CODE );
337
- break ;
338
- default :
339
- }
340
- } while (c != 'q' );
349
+ } catch (IOException ex ) {
350
+ LOG .log (Level .SEVERE , null , ex );
351
+ }
352
+ System .out .println ("CLOSE" );
341
353
342
- } catch (IOException ex ) {
343
- LOG .log (Level .SEVERE , null , ex );
344
354
}
345
- System .out .println ("CLOSE" );
346
-
347
- }
348
355
}
356
+
349
357
private static void printHelp (Options opts ) {
350
358
HelpFormatter formatter = new HelpFormatter ();
351
359
formatter .setWidth (300 );
352
- formatter .printHelp ("openv4j-memory-image " , opts );
360
+ formatter .printHelp ("java -jar fhz4j-console-{VERSION}-jar-with-dependencies.jar " , opts );
353
361
}
354
362
}
0 commit comments