Skip to content

Commit 26f2963

Browse files
committed
Version release
Basic functionality implemented
1 parent 90b89ef commit 26f2963

File tree

3 files changed

+198
-4
lines changed

3 files changed

+198
-4
lines changed

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ dependencies {
2626
jar {
2727
manifest {
2828
name = "OpenMUC Gogo Console Commands"
29-
version = "0.1.0"
29+
version = "1.0.0"
3030
symbolicName = "org.openmucextensions.console";
31-
// instruction 'Bundle-Activator', 'org.openmucextensions.console.Activator'
3231
instruction 'Bundle-ClassPath', '.'
3332
instruction 'Import-Package', '*'
3433
instruction 'Export-Package', ''

src/main/java/org/openmucextensions/console/ConsoleCommands.java

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
package org.openmucextensions.console;
22

3+
import java.util.Date;
34
import java.util.List;
45

56
import org.apache.felix.service.command.Descriptor;
7+
import org.openmuc.framework.config.ChannelConfig;
8+
import org.openmuc.framework.config.ChannelScanInfo;
69
import org.openmuc.framework.config.ConfigService;
10+
import org.openmuc.framework.config.DeviceConfig;
11+
import org.openmuc.framework.config.DeviceScanInfo;
12+
import org.openmuc.framework.config.DriverConfig;
13+
import org.openmuc.framework.config.RootConfig;
14+
import org.openmuc.framework.data.BooleanValue;
15+
import org.openmuc.framework.data.ByteArrayValue;
16+
import org.openmuc.framework.data.ByteValue;
17+
import org.openmuc.framework.data.DoubleValue;
18+
import org.openmuc.framework.data.FloatValue;
19+
import org.openmuc.framework.data.IntValue;
20+
import org.openmuc.framework.data.LongValue;
21+
import org.openmuc.framework.data.Record;
22+
import org.openmuc.framework.data.ShortValue;
23+
import org.openmuc.framework.data.StringValue;
24+
import org.openmuc.framework.dataaccess.Channel;
725
import org.openmuc.framework.dataaccess.DataAccessService;
826
import org.osgi.service.component.ComponentContext;
927
import org.slf4j.Logger;
@@ -46,11 +64,182 @@ public void drivers() {
4664

4765
List<String> drivers = configService.getIdsOfRunningDrivers();
4866

67+
printLine();
4968
for (String driver : drivers) {
5069
System.out.println(driver);
5170
}
5271

5372
System.out.println(drivers.size() + " driver(s) found");
5473
}
5574

75+
@Descriptor("scans for devices with a specific driver")
76+
public void scanForDevices(@Descriptor("the driver id") String driverId, @Descriptor("the driver-specific settings for device scan") String settings) {
77+
78+
try {
79+
System.out.println("Scanning for devices...");
80+
List<DeviceScanInfo> infos = configService.scanForDevices(driverId, settings);
81+
82+
printLine();
83+
for (DeviceScanInfo deviceScanInfo : infos) {
84+
System.out.println("id: " + deviceScanInfo.getId() + " address: " + deviceScanInfo.getDeviceAddress() + " description: " + deviceScanInfo.getDescription());
85+
}
86+
87+
System.out.println(infos.size() + " device(s) found");
88+
89+
} catch (Exception e) {
90+
System.out.println("Error while scanning for devices: " + e.getMessage());
91+
}
92+
93+
}
94+
95+
@Descriptor("scans for devices with a specific driver")
96+
public void scanForDevices(@Descriptor("the driver id") String driverId) {
97+
scanForDevices(driverId, null);
98+
}
99+
100+
@Descriptor("scans for channels of a specific device")
101+
public void scanForChannels(@Descriptor("the device id") String deviceId, @Descriptor("the driver-specific settings for channel scan") String settings) {
102+
103+
try {
104+
List<ChannelScanInfo> infos = configService.scanForChannels(deviceId, settings);
105+
106+
printLine();
107+
for (ChannelScanInfo channelScanInfo : infos) {
108+
System.out.println("address: " + channelScanInfo.getChannelAddress() + ", description: " + channelScanInfo.getDescription());
109+
}
110+
111+
System.out.println(infos.size() + " channel(s) found");
112+
} catch (Exception e) {
113+
System.out.println("Error while scanning for channels: " + e.getMessage());
114+
}
115+
116+
}
117+
118+
@Descriptor("scans for channels of a specific device")
119+
public void scanForChannels(@Descriptor("the device id") String deviceId) {
120+
scanForChannels(deviceId, null);
121+
}
122+
123+
@Descriptor("shows the actual OpenMUC configuration")
124+
public void config() {
125+
126+
RootConfig rootConfig = configService.getConfig();
127+
128+
printLine();
129+
130+
if(rootConfig.getDrivers().size() > 0) {
131+
for (DriverConfig driverConfig : rootConfig.getDrivers()) {
132+
133+
System.out.println("driver: " + driverConfig.getId());
134+
System.out.println("");
135+
136+
for (DeviceConfig deviceConfig : driverConfig.getDevices()) {
137+
System.out.println("device: " + deviceConfig.getId() + " (" + deviceConfig.getDescription() + ")");
138+
System.out.println("");
139+
140+
for (ChannelConfig channelConfig : deviceConfig.getChannels()) {
141+
System.out.println("channel: " + channelConfig.getId() + " (" + channelConfig.getDescription() + "), address: " + channelConfig.getChannelAddress());
142+
}
143+
}
144+
145+
printLine();
146+
}
147+
} else {
148+
System.out.println("The actual OpenMUC configuration is empty");
149+
}
150+
151+
}
152+
153+
@Descriptor("shows a list of all configured channel ids")
154+
public void channels() {
155+
156+
List<String> channels = dataAccessService.getAllIds();
157+
158+
printLine();
159+
for (String channel : channels) {
160+
System.out.println(channel);
161+
}
162+
163+
System.out.println(channels.size() + " channel(s) found");
164+
}
165+
166+
@Descriptor("reads the value of the specified channel")
167+
public void read(@Descriptor("channel id to read") String channelId) {
168+
169+
Channel channel = dataAccessService.getChannel(channelId);
170+
171+
if(channel != null) {
172+
Record record = channel.read();
173+
174+
printLine();
175+
if(record != null) System.out.println("timestamp: " + new Date(record.getTimestamp()).toString() + ", value: " + record.getValue());
176+
} else {
177+
System.out.println("Channel " + channelId + " not found");
178+
}
179+
}
180+
181+
@Descriptor("writes the value of the specified channel")
182+
public void write(@Descriptor("the channel id") String channelId, @Descriptor("the value to write") String value) {
183+
184+
Channel channel = dataAccessService.getChannel(channelId);
185+
186+
if(channel != null) {
187+
188+
switch (channel.getValueType()) {
189+
case INTEGER:
190+
Integer intVal = Integer.parseInt(value);
191+
channel.write(new IntValue(intVal.intValue()));
192+
break;
193+
194+
case BOOLEAN:
195+
Boolean boolVal = Boolean.parseBoolean(value);
196+
channel.write(new BooleanValue(boolVal.booleanValue()));
197+
break;
198+
199+
case BYTE:
200+
Byte byteVal = Byte.parseByte(value);
201+
channel.write(new ByteValue(byteVal));
202+
break;
203+
204+
case BYTE_ARRAY:
205+
channel.write(new ByteArrayValue(value.getBytes()));
206+
break;
207+
208+
case DOUBLE:
209+
Double doubleVal = Double.parseDouble(value);
210+
channel.write(new DoubleValue(doubleVal.doubleValue()));
211+
break;
212+
213+
case FLOAT:
214+
Float floatVal = Float.parseFloat(value);
215+
channel.write(new FloatValue(floatVal.floatValue()));
216+
break;
217+
218+
case LONG:
219+
Long longVal = Long.parseLong(value);
220+
channel.write(new LongValue(longVal.longValue()));
221+
break;
222+
223+
case SHORT:
224+
Short shortVal = Short.parseShort(value);
225+
channel.write(new ShortValue(shortVal.shortValue()));
226+
break;
227+
228+
default:
229+
channel.write(new StringValue(value));
230+
break;
231+
}
232+
233+
read(channelId);
234+
235+
} else {
236+
System.out.println("Channel " + channelId + " not found");
237+
}
238+
239+
}
240+
241+
private void printLine() {
242+
System.out.println("--------------------");
243+
}
244+
56245
}

src/main/resources/OSGI-INF/components.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.openmucextensions.console" immediate="true">
33
<implementation class="org.openmucextensions.console.ConsoleCommands"/>
44
<property name="osgi.command.scope" type="String" value="openmuc"/>
5-
<property name="osgi.command.function" value="drivers">
6-
5+
<property name="osgi.command.function">
6+
drivers
7+
scanForDevices
8+
config
9+
scanForChannels
10+
channels
11+
read
12+
write
713
</property>
814
<service>
915
<provide interface="org.openmucextensions.console.ConsoleCommands"/>

0 commit comments

Comments
 (0)