private void UpdateAdapters() { NetworkInterface[] adaptersArr = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adaptersArr) { String aId = adapter.Id; if (_adapters.ContainsKey(aId)) { var netInter = _adapters[aId]; netInter.NetInterface = adapter; netInter.ActualV4Statistics = adapter.GetIPStatistics(); _adapters[aId] = netInter; } else { var netInter = new AdapterInterface { NetInterface = adapter, ActualV4Statistics = adapter.GetIPStatistics() }; _adapters.Add(aId, netInter); } } }
public TurnOnOffDevice(string vendorName, string model, string version, string serialNumber, string description, ITurnOnOffModule module) : base(module.Name, vendorName, model, version, serialNumber, description) { Module = module; AdapterBusObject busObject = new AdapterBusObject("Guybrush"); Interface = new AdapterInterface("com.guybrush.devices.onoffcontrol"); var attr = new AdapterAttribute("Status", module.Status) { COVBehavior = SignalBehavior.Always, Access = E_ACCESS_TYPE.ACCESS_READ }; attr.Annotations.Add("com.guybrush.devices.onoffcontrol.status", "The device status"); Interface.Properties.Add(attr); List <IAdapterValue> inputs = new List <IAdapterValue>(1); inputs.Add(new AdapterValue("TargetStatus", false)); AdapterMethod method = new AdapterMethod("Switch", "Switches devices on or off.", ChangeStatus, inputs); Interface.Methods.Add(method); busObject.Interfaces.Add(Interface); BusObjects.Add(busObject); CreateEmitSignalChangedSignal(); Module.ValueChanged += Module_ValueChanged; }
// private AdapterInterface _interfaceRemoteControl; public MockBulbDevice(MockLightingServiceHandler handler) : base(handler.Name, "MockDevices Inc", "Mock Bulb", "1", handler.Id, "") { base.LightingServiceHandler = handler; Icon = new AdapterIcon(new System.Uri("ms-appx:///Icons/Light.png")); _interfaceOnOff = InterfaceCreators.CreateOnOffStatus(handler.LampState_OnOff); _interfaceOff = InterfaceCreators.CreateOffControl(()=> { handler.LampState_OnOff = false; }); _interfaceOn = InterfaceCreators.CreateOnControl(() => { handler.LampState_OnOff = true; }); _interfaceColor = InterfaceCreators.CreateColor(0d, 0d, (hue) => { handler.LampState_Hue = (UInt32)(hue / 360 * (UInt32.MaxValue - 1)); }, (saturation) => { handler.LampState_Saturation = (UInt32)(saturation * (UInt32.MaxValue - 1)); }); _interfaceBrightness = InterfaceCreators.CreateBrightness(0d, (brightness) => { handler.LampState_Brightness = (UInt32)(brightness * (UInt32.MaxValue - 1)); }); AdapterBusObject abo = new AdapterBusObject("org/alljoyn/SmartSpaces/Operation"); abo.Interfaces.Add(_interfaceOnOff); abo.Interfaces.Add(_interfaceOn); abo.Interfaces.Add(_interfaceOff); if (handler.LampDetails_Color) abo.Interfaces.Add(_interfaceColor); if (handler.LampDetails_Dimmable) abo.Interfaces.Add(_interfaceBrightness); base.CreateEmitSignalChangedSignal(); this.BusObjects.Add(abo); handler.PropertyChanged += Handler_PropertyChanged; handler.LampStateChanged += Handler_LampStateChanged; }
public ReaderDevice(string vendorName, string model, string version, string serialNumber, string description, IReaderModule module) : base(module.Name, vendorName, model, version, serialNumber, description) { Module = module; AdapterBusObject busObject = new AdapterBusObject("Guybrush"); Interface = new AdapterInterface("com.guybrush.devices.reader"); var attrValue = new AdapterAttribute("Value", module.Value) { COVBehavior = SignalBehavior.Always, Access = E_ACCESS_TYPE.ACCESS_READ }; attrValue.Annotations.Add("com.guybrush.devices.reader.value", "The device value"); Interface.Properties.Add(attrValue); var attrUnit = new AdapterAttribute("Unit", module.Unit) { COVBehavior = SignalBehavior.Always, Access = E_ACCESS_TYPE.ACCESS_READ }; attrUnit.Annotations.Add("com.guybrush.devices.reader.unit", "The device unit"); Interface.Properties.Add(attrUnit); busObject.Interfaces.Add(Interface); BusObjects.Add(busObject); CreateEmitSignalChangedSignal(); Module.ValueChanged += Module_ValueChanged; Module.UnitChanged += Module_UnitChanged; }
public MockCurrentHumidityDevice(string name, string id, double currentHumidity) : base(name, "MockDevices Inc", "Mock Humidity", "1", id, "") { Icon = new AdapterIcon(new System.Uri("ms-appx:///Icons/Humidity.png")); _iface = AllJoynSimulatorApp.Devices.InterfaceCreators.CreateHumidity(currentHumidity); BusObjects.Add(new AdapterBusObject("org.alljoyn.SmartSpaces.Environment")); BusObjects[0].Interfaces.Add(_iface); CreateEmitSignalChangedSignal(); _currentValue = currentHumidity; }
public SmarthomeAdapter(BridgeConfiguration configuration, ConditionManager conditionMgr) : base(configuration) { _conditionManager = conditionMgr; _abo = new AdapterBusObject("Guybrush"); AdapterInterface conditionInterface = new AdapterInterface("com.guybrush.station.conditions"); var addConInputParams = new List <AdapterValue>(); addConInputParams.Add(new AdapterValue("SourceDeviceType", -1)); addConInputParams.Add(new AdapterValue("SourceDevice", "")); addConInputParams.Add(new AdapterValue("TargetDevice", "")); addConInputParams.Add(new AdapterValue("RequiredValue", -1)); addConInputParams.Add(new AdapterValue("ConditionType", -1)); addConInputParams.Add(new AdapterValue("TargetValue", -1)); var addConOutParams = new List <AdapterValue>(); addConOutParams.Add(new AdapterValue("Response", "")); AdapterMethod addCondAttr = new AdapterMethod("AddCondition", "Calling this method will add new condition.", AddCondition, addConInputParams, addConOutParams); conditionInterface.Methods.Add(addCondAttr); var getCondOutParams = new List <AdapterValue>(); getCondOutParams.Add(new AdapterValue("SourceDeviceType", "")); getCondOutParams.Add(new AdapterValue("SourceDevice", "")); getCondOutParams.Add(new AdapterValue("TargetDevice", "")); getCondOutParams.Add(new AdapterValue("RequiredValue", "")); getCondOutParams.Add(new AdapterValue("ConditionType", "")); getCondOutParams.Add(new AdapterValue("TargetValue", "")); AdapterMethod getCondAttr = new AdapterMethod("GetConditions", "Calling this method returns list of conditions", GetConditions, null, getCondOutParams); conditionInterface.Methods.Add(getCondAttr); var removeCondInputParams = new List <AdapterValue>(); removeCondInputParams.Add(new AdapterValue("SourceDevice", "")); removeCondInputParams.Add(new AdapterValue("TargetDevice", "")); var removeConOutParams = new List <AdapterValue>(); removeConOutParams.Add(new AdapterValue("Response", "")); AdapterMethod removeCondAttr = new AdapterMethod("RemoveCondition", "Calling this method will remove a condition", RemoveCondition, removeCondInputParams, removeConOutParams); conditionInterface.Methods.Add(removeCondAttr); _abo.Interfaces.Add(conditionInterface); BusObjects.Add(_abo); }
/* <interface name="org.alljoyn.SmartSpaces.Operation.OffControl"> <annotation name="org.alljoyn.Bus.DocString.En" value="This interface provides the capability to switch off the device."/> <annotation name="org.alljoyn.Bus.Secure" value="true"/> <property name="Version" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The interface version."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> <method name="SwitchOff"> <annotation name="org.alljoyn.Bus.DocString.En" value="Switch off the device."/> </method> </interface: */ private AdapterInterface CreateOffInterface(bool currentValue) { var iface = new AdapterInterface("org.alljoyn.SmartSpaces.Operation.OffControl"); iface.Properties.Add(new AdapterAttribute("Version", (ushort)1) { COVBehavior = SignalBehavior.Never }); iface.Properties[0].Annotations.Add("org.alljoyn.Bus.DocString.En", "The interface version"); var m = new AdapterMethod("SwitchOff", "Switch off the device.", (sender, input, output) => { OnOff = false; }); iface.Methods.Add(m); return iface; }
/*<interface name="org.alljoyn.SmartSpaces.Environment.CurrentTemperature"> <annotation name="org.alljoyn.Bus.DocString.En" value="This interface provides capability to represent current temperature."/> <annotation name="org.alljoyn.Bus.Secure" value="true"/> <property name="Version" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The interface version."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> <property name="CurrentValue" type="d" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="Current temperature expressed in Celsius."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> <annotation name="org.alljoyn.Bus.Type.Units" value="degrees Celsius"/> </property> <property name="Precision" type="d" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The precision of the CurrentValue property. i.e. the number of degrees Celsius the actual power consumption must change before CurrentValue is updated."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> <annotation name="org.alljoyn.Bus.Type.Units" value="degrees Celsius"/> </property> <property name="UpdateMinTime" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The minimum time between updates of the CurrentValue property in milliseconds."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> <annotation name="org.alljoyn.Bus.Type.Units" value="milliseconds"/> </property> </interface>*/ public static AdapterInterface CreateTemperature(double currentValue) { AdapterInterface iface = new AdapterInterface("org.alljoyn.SmartSpaces.Environment.CurrentTemperature"); //iface.Annotations.Add("org.alljoyn.Bus.DocString.En", "This interface provides capability to represent current temperature."); //iface.Annotations.Add("org.alljoyn.Bus.Secure", "true"); iface.Properties.Add(new AdapterAttribute("Version", (ushort)1) { COVBehavior = SignalBehavior.Never }); iface.Properties.Add(new AdapterAttribute("CurrentValue", currentValue) { COVBehavior = SignalBehavior.Always }); iface.Properties[1].Annotations.Add("org.alljoyn.Bus.Type.Units", "degrees Celcius"); iface.Properties.Add(new AdapterAttribute("Precision", 0.1d) { COVBehavior = SignalBehavior.Always }); iface.Properties.Add(new AdapterAttribute("UpdateMinTime", (ushort)3000) { COVBehavior = SignalBehavior.Always }); return iface; }
/* <interface name="org.alljoyn.SmartSpaces.Environment.CurrentHumidity"> <annotation name="org.alljoyn.Bus.DocString.En" value="This interface provides capability to represent current relative humidity."/> <annotation name="org.alljoyn.Bus.Secure" value="true"/> <property name="Version" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The interface version"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> <property name="CurrentValue" type="y" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="Current relative humidity value"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> <annotation name="org.alljoyn.Bus.Type.Min" value="0"/> </property> <property name="MaxValue" type="y" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="Maximum value allowed for represented relative humidity"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> </property> </interface> */ public static AdapterInterface CreateHumidity(double currentValue) { var iface = new AdapterInterface("org.alljoyn.SmartSpaces.Environment.CurrentHumidity"); //iface.Annotations.Add("org.alljoyn.Bus.DocString.En", "This interface provides capability to represent current relative humidity."); //iface.Annotations.Add("org.alljoyn.Bus.Secure", "true"); iface.Properties.Add(new AdapterAttribute("Version", (ushort)1) { COVBehavior = SignalBehavior.Never }); iface.Properties[0].Annotations.Add("org.alljoyn.Bus.DocString.En", "The interface version"); iface.Properties.Add(new AdapterAttribute("CurrentValue", currentValue) { COVBehavior = SignalBehavior.Always }); iface.Properties[1].Annotations.Add("org.alljoyn.Bus.DocString.En", "Current relative humidity value"); iface.Properties[1].Annotations.Add("org.alljoyn.Bus.Type.Min", "0"); iface.Properties.Add(new AdapterAttribute("MaxValue", 100d) { COVBehavior = SignalBehavior.Always }); iface.Properties[2].Annotations.Add("org.alljoyn.Bus.DocString.En", "Maximum value allowed for represented relative humidity"); return iface; }
public MockOnOffSwitchDevice(string name, string id, bool isOn, Windows.UI.Core.CoreDispatcher dispatcher) : base(name, "MockDevices Inc", "Mock Switch", "1", id, "") { this.dispatcher = dispatcher; Icon = new AdapterIcon(new System.Uri("ms-appx:///Icons/Switch.png")); _interfaceOnOff = CreateOnOffInterface(isOn); _interfaceOn = CreateOnInterface(isOn); _interfaceOff = CreateOffInterface(!isOn); _interfaceRemoteControl = CreateRemoteControllabilityInterface(true); AdapterBusObject abo = new AdapterBusObject("org/alljoyn/SmartSpaces/Operation/Switch"); abo.Interfaces.Add(_interfaceOnOff); abo.Interfaces.Add(_interfaceOn); abo.Interfaces.Add(_interfaceOff); abo.Interfaces.Add(_interfaceRemoteControl); this.BusObjects.Add(abo); CreateEmitSignalChangedSignal(); _onOff = isOn; }
public DisplayDevice(string name, string vendorName, string model, string version, string serialNumber, string description, IDisplayModule module) : base(name, vendorName, model, version, serialNumber, description) { Module = module; AdapterBusObject busObject = new AdapterBusObject("Guybrush"); Interface = new AdapterInterface("com.guybrush.display"); var attr = new AdapterAttribute("Text", module.Text) { COVBehavior = SignalBehavior.Always, Access = E_ACCESS_TYPE.ACCESS_READ }; attr.Annotations.Add("com.guybrush.devices.display.text", "The device status"); Interface.Properties.Add(attr); busObject.Interfaces.Add(Interface); BusObjects.Add(busObject); CreateEmitSignalChangedSignal(); Module.TextChanged += Module_TextChanged; }
/* <interface name="org.alljoyn.SmartSpaces.Operation.RemoteControllability"> <annotation name="org.alljoyn.Bus.DocString.En" value="This interface provides a capability to monitor remote control enabled/disabled status."/> <annotation name="org.alljoyn.Bus.Secure" value="true"/> <property name="Version" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The interface version."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> <property name="IsControllable" type="b" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="Status of remote controllability; true if remote controllability enabled."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> </property> </interface> */ private static AdapterInterface CreateRemoteControllabilityInterface(bool currentValue) { var iface = new AdapterInterface("org.alljoyn.SmartSpaces.Operation.RemoteControllability"); iface.Properties.Add(new AdapterAttribute("Version", (ushort)1) { COVBehavior = SignalBehavior.Never }); iface.Properties[0].Annotations.Add("org.alljoyn.Bus.DocString.En", "The interface version"); iface.Properties.Add(new AdapterAttribute("IsControllable", currentValue) { COVBehavior = SignalBehavior.Always }); iface.Properties[1].Annotations.Add("org.alljoyn.Bus.DocString.En", "Status of remote controllability; true if remote controllability enabled."); return iface; }
/* </interface> <interface name="org.alljoyn.SmartSpaces.Operation.OnOffStatus"> <annotation name="org.alljoyn.Bus.DocString.En" value="This interface provides a capability to monitor the on/off status of device."/> <annotation name="org.alljoyn.Bus.Secure" value="true"/> <property name="Version" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The interface version."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> <property name="OnOff" type="b" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="Current on/off state of the appliance. If true, the device is on state."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> </property> </interface> */ private static AdapterInterface CreateOnOffInterface(bool currentValue) { var iface = new AdapterInterface("org.alljoyn.SmartSpaces.Operation.OnOffStatus"); iface.Properties.Add(new AdapterAttribute("Version", (ushort)1) { COVBehavior = SignalBehavior.Never }); iface.Properties[0].Annotations.Add("org.alljoyn.Bus.DocString.En", "The interface version"); iface.Properties.Add(new AdapterAttribute("OnOff", currentValue) { COVBehavior = SignalBehavior.Always }); iface.Properties[1].Annotations.Add("org.alljoyn.Bus.DocString.En", "Current on/off state of the appliance. If true, the device is on state."); return iface; }
/* <interface name="org.alljoyn.SmartSpaces.Operation.OnControl"> <annotation name="org.alljoyn.Bus.DocString.En" value="This interface provides capability to switch on the device."/> <annotation name="org.alljoyn.Bus.Secure" value="true"/> <property name="Version" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The interface version."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> <method name="SwitchOn"> <annotation name="org.alljoyn.Bus.DocString.En" value="Switch on the device."/> </method> </interface> */ public static AdapterInterface CreateOnControl(Action switchOnAction) { var iface = new AdapterInterface("org.alljoyn.SmartSpaces.Operation.OnControl"); iface.Properties.Add(new AdapterAttribute("Version", (ushort)1) { COVBehavior = SignalBehavior.Never }); iface.Properties[0].Annotations.Add("org.alljoyn.Bus.DocString.En", "The interface version"); var m = new AdapterMethod("SwitchOn", "Switch on the device.", (sender, input, output) => { switchOnAction(); }); iface.Methods.Add(m); return iface; }
/* <interface name="org.alljoyn.SmartSpaces.Operation.Color"> <annotation name="org.alljoyn.Bus.DocString.En" value="This interface provides capabilities to control and monitor color."/> <annotation name="org.alljoyn.Bus.Secure" value="true"/> <property name="Version" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The interface version."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> <property name="Hue" type="d" access="readwrite"> <annotation name="org.alljoyn.Bus.DocString.En" value="Hue of the device."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> <annotation name="org.alljoyn.Bus.Type.Min" value="0.0"/> <annotation name="org.alljoyn.Bus.Type.Max" value="360.0"/> </property> <property name="Saturation" type="d" access="readwrite"> <annotation name="org.alljoyn.Bus.DocString.En" value="Saturation of the device."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> <annotation name="org.alljoyn.Bus.Type.Min" value="0.0"/> <annotation name="org.alljoyn.Bus.Type.Max" value="1.0"/> </property> </interface> */ public static AdapterInterface CreateColor(double currentHue, double currentSaturation, Action<double> onHueChanged, Action<double> onSaturationChanged) { var iface = new AdapterInterface("org.alljoyn.SmartSpaces.Operation.Color"); iface.Properties.Add(new AdapterAttribute("Version", (ushort)1) { COVBehavior = SignalBehavior.Never }); iface.Properties[0].Annotations.Add("org.alljoyn.Bus.DocString.En", "The interface version"); iface.Properties.Add(new AdapterAttribute("Hue", currentHue, (value) => { if (!(value is double)) return AllJoynStatusCode.BUS_BAD_VALUE_TYPE; double hue = (double)value; if (hue < 0 || hue > 360) return AllJoynStatusCode.BUS_BAD_VALUE; onHueChanged(hue); return AllJoynStatusCode.Ok; }) { COVBehavior = SignalBehavior.Always }); iface.Properties[1].Annotations.Add("org.alljoyn.Bus.DocString.En", "Hue of the device."); iface.Properties[1].Annotations.Add("org.alljoyn.Bus.DocString.Min", "0.0"); iface.Properties[1].Annotations.Add("org.alljoyn.Bus.DocString.Max", "360.0."); iface.Properties.Add(new AdapterAttribute("Saturation", currentSaturation, (value) => { if (!(value is double)) return AllJoynStatusCode.BUS_BAD_VALUE_TYPE; double saturation = (double)value; if (saturation < 0 || saturation > 1) return AllJoynStatusCode.BUS_BAD_VALUE; onSaturationChanged(saturation); return AllJoynStatusCode.Ok; }) { COVBehavior = SignalBehavior.Always }); iface.Properties[2].Annotations.Add("org.alljoyn.Bus.DocString.En", "Saturation of the device."); iface.Properties[2].Annotations.Add("org.alljoyn.Bus.DocString.Min", "0.0"); iface.Properties[2].Annotations.Add("org.alljoyn.Bus.DocString.Max", "1.0."); return iface; }
/* <interface name="org.alljoyn.SmartSpaces.Operation.Brightness"> <annotation name="org.alljoyn.Bus.DocString.En" value="This interface provides capabilities to control and monitor brightness."/> <annotation name="org.alljoyn.Bus.Secure" value="true"/> <property name="Version" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The interface version."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> <property name="Brightness" type="d" access="readwrite"> <annotation name="org.alljoyn.Bus.DocString.En" value="Brightness of the device."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/> <annotation name="org.alljoyn.Bus.Type.Min" value="0.0"/> <annotation name="org.alljoyn.Bus.Type.Max" value="1.0"/> </property> </interface> */ public static AdapterInterface CreateBrightness(double currentValue, Action<double> onBrightnessChanged) { var iface = new AdapterInterface("org.alljoyn.SmartSpaces.Operation.Brightness"); iface.Properties.Add(new AdapterAttribute("Version", (ushort)1) { COVBehavior = SignalBehavior.Never }); iface.Properties[0].Annotations.Add("org.alljoyn.Bus.DocString.En", "The interface version"); iface.Properties.Add(new AdapterAttribute("Brightness", currentValue, (value) => { if (!(value is double)) return AllJoynStatusCode.BUS_BAD_VALUE_TYPE; double brightness = (double)value; if (brightness < 0 || brightness > 1) return AllJoynStatusCode.BUS_BAD_VALUE; onBrightnessChanged(brightness); return AllJoynStatusCode.Ok; }) { COVBehavior = SignalBehavior.Always }); iface.Properties[1].Annotations.Add("org.alljoyn.Bus.DocString.En", "Brightness of the device."); return iface; }