-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetLED.java
More file actions
95 lines (81 loc) · 3.1 KB
/
setLED.java
File metadata and controls
95 lines (81 loc) · 3.1 KB
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
// Set LED for Lodi, GNU GPL
//
// Call: java setLED <ip-address of LoDi SC> <node> <status> # set Status - see API NodeStatusSend
// java setLED <ip-address of LoDi SC> <hh:mm> # set Time - see API TimeSet
// java setLED <ip-address of LoDi SC> F<factor> # set Time Factor - see API TimeSpeedSet
//
// API documentation LoDi
// 1. https://www.lokstoredigital.de/service/ger%C3%A4te-api/allgemeines/
// 2. https://www.lokstoredigital.de/service/ger%C3%A4te-api/lodi-shift-commander/
//
// Status:
// 0: Beleuchtung aus
// 1: Licht-Kurve 1
// 2: Licht-Kurve 2
// 3: Licht-Kurve 3
// 8: Blitz
// 9: Doppelblitz
// 10: zufälliges Blitzen
// 11: Wolkenzug
import java.net.*;
import java.io.*;
public class setLED {
public static void main( String[] args ) throws IOException {
String host = args[0];
InetAddress address = InetAddress.getByName(host);
final int port = 11092;
byte[] timeSet = { (byte)0x20, (byte)0x77, (byte)0x42,
(byte)0x00, (byte)0x00 };
byte[] timeSpeedSet = { (byte)0x20, (byte)0x76, (byte)0x42,
(byte)0x00 };
byte[] nodeStatusSend = { (byte)0x20, (byte)0x6C, (byte)0x42,
(byte)0x01, (byte)0x00, (byte)0x00 };
final int receiveSize = 4096;
DatagramSocket socket = new DatagramSocket();
DatagramPacket packetReceive = new DatagramPacket( new byte[receiveSize], receiveSize );
DatagramPacket packetSend;
if ( args[1].indexOf(':') != -1 ) {
int hh = Integer.parseInt(args[1].substring(0,2));
int mm = Integer.parseInt(args[1].substring(3,5));
int units = hh * 1800 + mm * 30;
byte high = (byte)(units / 256);
byte low = (byte)(units % 256);
timeSet[3] = high;
timeSet[4] = low;
packetSend = new DatagramPacket(timeSet, timeSet.length, address, port);
}
else if ( args[1].indexOf("F") != -1 ) {
int len = args[1].length();
byte factor = (byte)Integer.parseInt(args[1].substring(1,len));
timeSpeedSet[3] = factor;
packetSend = new DatagramPacket(timeSpeedSet, timeSpeedSet.length, address, port);
}
else {
byte node = (byte)Integer.parseInt(args[1]);
byte status = (byte)Integer.parseInt(args[2]);
nodeStatusSend[4] = node;
nodeStatusSend[5] = status;
packetSend = new DatagramPacket(nodeStatusSend, nodeStatusSend.length, address, port);
}
int len = packetSend.getLength();
byte[] data = packetSend.getData();
for ( int i=0; i<len; i++ ) {
System.out.printf( "%02X ", data[i] );
}
System.out.println();
socket.send(packetSend);
socket.setSoTimeout(1000); // in millisecounds
try {
socket.receive( packetReceive );
len = packetReceive.getLength();
data = packetReceive.getData();
for ( int i=0; i<len; i++ ) {
System.out.printf( "%02X ", data[i] );
}
System.out.println();
}
catch (SocketTimeoutException e) {
System.out.println( "Timeout during receive" );
}
} // main
} // public class setLED