Commit 88abd45e authored by Vlado Altmann's avatar Vlado Altmann
Browse files

initial commit (not tested)

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/xmlpull.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-core.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-core-javadoc.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-core-sources.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-device.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-device-javadoc.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-device-sources.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-example.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-example-javadoc.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-example-sources.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-gpio-extension.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-gpio-extension-javadoc.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-gpio-extension-sources.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-service.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-service-javadoc.jar"/>
<classpathentry kind="lib" path="D:/Arbeit/Development/Java/3rdparty/pi4j/pi4j-service-sources.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/jmeds2.0-beta10"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LightBulb2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
package com.pi.lightbulb.client;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import org.ws4d.java.authorization.AuthorizationException;
import org.ws4d.java.client.DefaultClient;
import org.ws4d.java.client.SearchManager;
import org.ws4d.java.communication.CommunicationException;
import org.ws4d.java.communication.CommunicationManagerRegistry;
import org.ws4d.java.communication.DPWSProtocolVersion;
import org.ws4d.java.configuration.DPWSProperties;
import org.ws4d.java.configuration.DispatchingProperties;
import org.ws4d.java.constants.DPWS2006.DPWSConstants2006;
import org.ws4d.java.dispatch.DefaultServiceReference;
import org.ws4d.java.security.CredentialInfo;
import org.ws4d.java.security.SecurityKey;
import org.ws4d.java.service.DefaultService;
import org.ws4d.java.service.Device;
import org.ws4d.java.service.InvocationException;
import org.ws4d.java.service.Operation;
import org.ws4d.java.service.Service;
import org.ws4d.java.service.parameter.ParameterValue;
import org.ws4d.java.service.reference.DeviceReference;
import org.ws4d.java.types.HelloData;
import org.ws4d.java.types.QName;
import org.ws4d.java.types.QNameSet;
import org.ws4d.java.types.SearchParameter;
import org.ws4d.java.util.Log;
import com.pi.lightbulb.device.BulbGPIOListener;
import com.pi.lightbulb.gpio.DefaultClientGPIO;
import com.pi.lightbulb.gpio.GpioListener;
public class LightBulbClient extends DefaultClientGPIO {
public final static String NAMESPACE = "http://www.demo.com/bbsr";
public final static String DEVICE = "Sensor";
public final static String SERVICE = "SensorInterface";
boolean bound = false;
private Service service;
private Timer timer;
private class Task extends TimerTask
{
private LightBulbClient client;
public Task(LightBulbClient airCondClient)
{
client = airCondClient;
}
@Override
public void run()
{
System.out.println("Refresh");
client.updateTemperature();
}
}
@Override
public synchronized void deviceFound(DeviceReference devRef, SearchParameter search, String comManId) {
QNameSet types = devRef.getDiscoveryData().getTypes();
org.ws4d.java.structures.Iterator i = types.iterator();
// System.out.println("Found Device: " + devRef.toString());
while (i.hasNext() && service == null)
{
QName qname = (QName) i.next();
if (qname.getLocalPart().equals(DEVICE))
{
System.out.println("Device: " + qname.getLocalPart());
try {
Device device = devRef.getDevice();
QNameSet serviceTypes = new QNameSet();
serviceTypes.add(new QName(SERVICE, NAMESPACE));
org.ws4d.java.structures.Iterator serviceIterator = device.getServiceReferences(serviceTypes, SecurityKey.EMPTY_KEY);
DefaultServiceReference serviceRef = (DefaultServiceReference) serviceIterator.next();
service = serviceRef.getService();
// System.out.println("ServiceId: " + service.toString());
bound = true;
BulbGPIOListener.getInstance().pulse(500);
Task task = new Task(this);
timer = new Timer();
timer.schedule(task, 5000, 5000);
updateTemperature();
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AuthorizationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
@Override
public void helloReceived(HelloData helloData)
{
Log.info("Hello received");
BulbGPIOListener.getInstance().pulse(500);
if (GpioListener.getInstance().areButtonsHighDelayed(DispatchingProperties.getInstance().getResponseWaitTime() / 1000))
{
Log.info("Hello accepted");
DeviceReference devRef = getDeviceReference(helloData);
deviceFound(devRef, null, CommunicationManagerRegistry.getPreferredCommunicationManagerID());
}
else Log.info("Hello rejected");
}
@Override
public void searchKnownDevices()
{
Log.info("Searching for devices...");
SearchParameter search = new SearchParameter();
QNameSet qnameSet = new QNameSet();
qnameSet.add(new QName(DEVICE, NAMESPACE));
search.setDeviceTypes(qnameSet, CommunicationManagerRegistry.getPreferredCommunicationManagerID());
SearchManager.searchDevice(search, this, null);
}
public void registerKnownHello()
{
SearchParameter search = new SearchParameter();
QNameSet qnameSet = new QNameSet();
qnameSet.add(new QName(DEVICE, NAMESPACE));
search.setDeviceTypes(qnameSet, CommunicationManagerRegistry.getPreferredCommunicationManagerID());
this.registerHelloListening(search);
}
@Override
public void resetPairing()
{
bound = false;
if (timer != null)
{
timer.cancel();
}
service = null;
BulbGPIOListener.getInstance().pulse(1000);
}
public void updateTemperature()
{
// we are looking for an Operation by its name
Operation op = service.getOperation(null, "LightAction", null, null);
ParameterValue input = op.createInputValue();
ParameterValue result;
try {
result = op.invoke(input, CredentialInfo.EMPTY_CREDENTIAL_INFO);
System.out.println("Response from the LightAction: " + result.toString());
double light = Double.parseDouble(result.toString());
if (light < 80)
{
BulbGPIOListener.getInstance().setBulbStateOn();
}
else
{
BulbGPIOListener.getInstance().setBulbStateOff();
}
} catch (AuthorizationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// public static void main(String[] args)
// {
// Log.setLogLevel(Log.DEBUG_LEVEL_INFO);
// DPWSProperties properties = DPWSProperties.getInstance();
// properties.addSupportedDPWSVersion(new DPWSProtocolVersion(DPWSConstants2006.DPWS_VERSION2006));
//
// JMEDSFramework.start(args);
//
// AirCondClient client = new AirCondClient();
// client.searchKnownDevices();
//
// }
}
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://www.ws4d.org/Configuration"
xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xmlns:tns="http://www.ws4d.org/Configuration"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<wsdl:types>
<xs:schema targetNamespace="http://www.ws4d.org/Configuration">
<xs:import namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing"
schemaLocation="addressing.xsd" />
<xs:simpleType name="RoleType">
<xs:restriction base="xs:string">
<xs:enumeration value="Service" />
<xs:enumeration value="Client" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="DataType">
<xs:restriction base="xs:string">
<xs:enumeration value="Integer" />
<xs:enumeration value="UnsignedInteger" />
<xs:enumeration value="Time" />
<xs:enumeration value="Date" />
<xs:enumeration value="Boolean" />
<xs:enumeration value="Float" />
<xs:enumeration value="String" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="OperatorType">
<xs:restriction base="xs:string">
<xs:enumeration value="Equal" />
<xs:enumeration value="NotEqual" />
<xs:enumeration value="Greater" />
<xs:enumeration value="GreaterOrEqual" />
<xs:enumeration value="Less" />
<xs:enumeration value="LessOrEqual" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="LogicOperationType">
<xs:restriction base="xs:string">
<xs:enumeration value="AND" />
<xs:enumeration value="OR" />
<xs:enumeration value="NAND" />
<xs:enumeration value="NOR" />
<xs:enumeration value="XOR" />
<xs:enumeration value="XNOR" />
</xs:restriction>
</xs:simpleType>
<!-- Workaround for a broken QName support in JMEDS -->
<xs:complexType name="EndpointReferenceType">
<xs:sequence>
<xs:element name="Address" type="xs:anyURI" />
<xs:element name="Device" type="tns:DeviceType" />
<xs:element name="PortType" type="tns:InterfaceType"
minOccurs="0" />
<xs:element name="ServiceId" type="xs:anyURI"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="InterfaceType">
<xs:sequence>
<xs:element name="LocalName" type="xs:NCName" />
<xs:element name="Namespace" type="xs:anyURI" />
<!-- <xs:element name="Type" type="xs:QName" /> -->
<xs:element name="Role" type="tns:RoleType" minOccurs="0" />
<!-- <xs:element name="RuleSupport" type="xs:boolean" minOccurs="0"/> -->
</xs:sequence>
<xs:attribute name="ruleSupport" type="xs:boolean" use="optional"/>
</xs:complexType>
<xs:complexType name="DeviceType">
<xs:sequence>
<xs:element name="LocalName" type="xs:NCName" />
<xs:element name="Namespace" type="xs:anyURI" />
<!-- <xs:element name="Type" type="xs:QName" /> -->
</xs:sequence>
</xs:complexType>
<xs:complexType name="ServiceType">
<xs:sequence>
<xs:element ref="tns:EndpointReference" />
</xs:sequence>
<xs:attribute name="id" type="xs:int" use="optional" />
</xs:complexType>
<xs:complexType name="DisconnectServiceType">
<xs:choice>
<xs:element ref="tns:EndpointReference" />
<xs:element name="Id" type="xs:int" />
</xs:choice>
</xs:complexType>
<xs:complexType name="InterfacesType">
<xs:sequence>
<xs:element name="Interface" minOccurs="0" maxOccurs="unbounded"
type="tns:InterfaceType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ServicesType">
<xs:sequence>
<xs:element name="Service" minOccurs="0" maxOccurs="unbounded"
type="tns:ServiceType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ParameterDescriptionType">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Type" type="tns:DataType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConditionType">
<xs:sequence>
<xs:element name="Parameter" type="xs:string" />
<xs:element name="Operator" type="tns:OperatorType" />
<xs:element name="Value" type="xs:anySimpleType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConditionsType">
<xs:sequence>
<xs:element name="Condition" type="tns:ConditionType" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ParameterType">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Value" type="xs:anySimpleType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ParametersType">
<xs:sequence>
<xs:element name="Parameter" type="tns:ParameterType"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConfigurationParametersType">
<xs:sequence>
<xs:element name="Parameter" type="tns:ParameterDescriptionType"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="RuleActionType">
<xs:sequence>
<xs:element name="Operation" type="xs:string" />
<xs:element name="Parameters" type="tns:ParametersType" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="RuleType">
<xs:sequence>
<xs:element name="Conditions" type="tns:ConditionsType" />
<xs:element name="Connection" type="tns:LogicOperationType" />
<xs:element name="Action" type="tns:RuleActionType" />
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="optional" />
<xs:attribute name="id" type="xs:int" use="optional" />
</xs:complexType>
<xs:complexType name="RulesType">
<xs:sequence>
<xs:element name="Rule" minOccurs="0" maxOccurs="unbounded"
type="tns:RuleType" />
</xs:sequence>
</xs:complexType>
<xs:element name="Interfaces" type="tns:InterfacesType" />
<xs:element name="Service" type="tns:DisconnectServiceType" />
<xs:element name="Services" type="tns:ServicesType" />
<xs:element name="EndpointReference" type="tns:EndpointReferenceType" />
<xs:element name="Rules" type="tns:RulesType" />
<xs:element name="Rule" type="tns:RuleType" />
<xs:element name="Parameters" type="tns:ConfigurationParametersType" />
<xs:element name="Id" type="xs:int" />
</xs:schema>
</wsdl:types>
<wsdl:message name="GetSupportedInterfacesRequest" />
<wsdl:message name="GetSupportedInterfacesResponse">
<wsdl:part element="tns:Interfaces" name="parameters" />
</wsdl:message>
<wsdl:message name="ConnectServiceRequest">
<wsdl:part element="tns:EndpointReference" name="parameters" />
</wsdl:message>
<wsdl:message name="GetConnectedServicesRequest" />
<wsdl:message name="GetConnectedServicesResponse">
<wsdl:part element="tns:Services" name="parameters" />
</wsdl:message>
<wsdl:message name="DisconnectServiceRequest">
<wsdl:part element="tns:Service" name="parameters" />
</wsdl:message>
<wsdl:message name="GetRuleParametersRequest" />
<wsdl:message name="GetRuleParametersResponse">
<wsdl:part element="tns:Parameters" name="parameters" />
</wsdl:message>
<wsdl:message name="GetRulesRequest" />
<wsdl:message name="GetRulesResponse">
<wsdl:part element="tns:Rules" name="parameters" />
</wsdl:message>
<wsdl:message name="SetRuleRequest">
<wsdl:part element="tns:Rule" name="parameters" />
</wsdl:message>
<wsdl:message name="DeleteRuleRequest">
<wsdl:part element="tns:Id" name="parameters" />
</wsdl:message>
<wsdl:portType name="ConfigurationInterface"
e:EventSource="true">
<wsdl:operation name="GetSupportedInterfaces">
<wsdl:input message="tns:GetSupportedInterfacesRequest"
name="GetSupportedInterfacesRequest" wsam:Action="http://www.ws4d.org/Configuration/GetSupportedInterfaces" />
<wsdl:output message="tns:GetSupportedInterfacesResponse"
name="GetSupportedInterfacesResponse"
wsam:Action="http://www.ws4d.org/Configuration/GetSupportedInterfacesResponse" />
</wsdl:operation>
<wsdl:operation name="ConnectService">
<wsdl:input message="tns:ConnectServiceRequest" name="ConnectServiceRequest"
wsam:Action="http://www.ws4d.org/Configuration/ConnectService" />
</wsdl:operation>
<wsdl:operation name="GetConnectedServices">
<wsdl:input message="tns:GetConnectedServicesRequest"
name="GetConnectedServicesRequest" wsam:Action="http://www.ws4d.org/Configuration/GetConnectedServices" />
<wsdl:output message="tns:GetConnectedServicesResponse"
name="GetConnectedServicesResponse"
wsam:Action="http://www.ws4d.org/Configuration/GetConnectedServicesResponse" />
</wsdl:operation>
<wsdl:operation name="DisconnectService">
<wsdl:input message="tns:DisconnectServiceRequest" name="DisconnectServiceRequest"
wsam:Action="http://www.ws4d.org/Configuration/DisconnectService" />
</wsdl:operation>
<wsdl:operation name="GetRuleParameters">
<wsdl:input message="tns:GetRuleParametersRequest" name="GetRuleParameters"
wsam:Action="http://www.ws4d.org/Configuration/GetRuleParameters" />
<wsdl:output message="tns:GetRuleParametersResponse"
name="GetRuleParametersResponse" wsam:Action="http://www.ws4d.org/Configuration/GetRuleParametersResponse" />
</wsdl:operation>
<wsdl:operation name="GetRules">
<wsdl:input message="tns:GetRulesRequest" name="GetRulesRequest"
wsam:Action="http://www.ws4d.org/Configuration/GetRules" />
<wsdl:output message="tns:GetRulesResponse" name="GetRulesResponse"
wsam:Action="http://www.ws4d.org/Configuration/GetRulesResponse" />
</wsdl:operation>
<wsdl:operation name="SetRule">
<wsdl:input message="tns:SetRuleRequest" name="SetRuleRequest"
wsam:Action="http://www.ws4d.org/Configuration/SetRule" />
</wsdl:operation>
<wsdl:operation name="DeleteRule">
<wsdl:input message="tns:DeleteRuleRequest" name="DeleteRuleRequest"
wsam:Action="http://www.ws4d.org/Configuration/DeleteRule" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ConfigurationBinding" type="tns:ConfigurationInterface">
<wsoap12:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetSupportedInterfaces">
<wsoap12:operation
soapAction="http://www.ws4d.org/Configuration/GetSupportedInterfaces" />
<wsdl:input>
<wsoap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<wsoap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ConnectService">
<wsoap12:operation soapAction="http://www.ws4d.org/Configuration/ConnectService" />
<wsdl:input>
<wsoap12:body use="literal" />
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="GetConnectedServices">
<wsoap12:operation
soapAction="http://www.ws4d.org/Configuration/GetConnectedServices" />
<wsdl:input>
<wsoap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<wsoap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="DisconnectService">
<wsoap12:operation
soapAction="http://www.ws4d.org/Configuration/DisconnectService" />
<wsdl:input>
<wsoap12:body use="literal" />
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="GetRuleParameters">
<wsoap12:operation
soapAction="http://www.ws4d.org/Configuration/GetRuleParameters" />
<wsdl:input>
<wsoap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<wsoap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetRules">
<wsoap12:operation soapAction="http://www.ws4d.org/Configuration/GetRules" />
<wsdl:input>