This repository has been archived by the owner on May 7, 2020. It is now read-only.
/
SerialConfigOptionProvider.java
53 lines (46 loc) · 1.8 KB
/
SerialConfigOptionProvider.java
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
/**
* Copyright (c) 2014-2017 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.config.serial.internal;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import org.eclipse.smarthome.config.core.ConfigOptionProvider;
import org.eclipse.smarthome.config.core.ParameterOption;
import org.osgi.service.component.annotations.Component;
import gnu.io.CommPortIdentifier;
/**
* This service provides serial port names as options for configuration parameters.
*
* @author Kai Kreuzer - Initial contribution and API
*
*/
@Component
public class SerialConfigOptionProvider implements ConfigOptionProvider {
@Override
public Collection<ParameterOption> getParameterOptions(URI uri, String param, String context, Locale locale) {
List<ParameterOption> options = new ArrayList<>();
if ("serial-port".equals(context)) {
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier id = portList.nextElement();
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
options.add(new ParameterOption(id.getName(), id.getName()));
}
}
}
return options;
}
@Override
public Collection<ParameterOption> getParameterOptions(URI uri, String param, Locale locale) {
return null;
}
}