zensysupnplightdevice.cs

来自「zwave 无线通讯协议 PC controller 控制器源码」· CS 代码 · 共 185 行

CS
185
字号
//////////////////////////////////////////////////////////////////////////////////////////////// 
//
//          #######
//          #   ##    ####   #####    #####  ##  ##   #####
//             ##    ##  ##  ##  ##  ##      ##  ##  ##
//            ##  #  ######  ##  ##   ####   ##  ##   ####
//           ##  ##  ##      ##  ##      ##   #####      ##
//          #######   ####   ##  ##  #####       ##  #####
//                                           #####
//          Z-Wave, the wireless language.
//
//          Copyright Zensys A/S, 2003,2004
//
//          All Rights Reserved
//
//          Description:   This source file is the main sourcefile for the
//                         ZensysUPnPLightDevice class, which implements a light device in UPnP
//
//                         Source is based on source code generated by Intel DeviceBuilder Tool
//
//                         Intel's UPnP .NET Framework Device Stack, Device Module
//                         Intel StackBuilder Build#1.0.1200.32486
//
//          Author:   Johann Sigfredsson
//
//          Last Changed By:  $Author: jch $
//          Revision:         $Revision: 1.2 $
//          Last Changed:     $Date: 2006/04/24 13:00:38 $
//
//////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Runtime.Remoting;
using Intel.UPNP;
using MicroStack;
using Zensys.ZWave.Communication;
using Zensys.ZWave.Logging;

namespace Zensys
{
	/// <summary>
	/// Summary description for ZensysUPnPLightDevice.
	/// </summary>
	public class ZensysUPnPLightDevice : ZensysUPnPDevice
	{
    public enum funcIDTypes : byte
    {
      GetStatus,
      SetTarget,
      GetLoadLevelStatus,
      GetMinLevel,
      SetLoadLevelTarget,
    }

    public event BridgeEvent_SubscriberHandler bridgeSubscriberEvent;

    private DimmingService dimmingService;
    private SwitchPower switchPowerService;
    private System.Boolean _targetStatus;
    private byte _loadLevelTarget;

    public System.Boolean Status {get {return switchPowerService.Evented_Status;} set {switchPowerService.Evented_Status = value;}}
    public System.Boolean TargetStatus {get {return _targetStatus;} set {_targetStatus = value;}}
    public byte LoadLevelTarget {get {return _loadLevelTarget;} set {_loadLevelTarget = value;}}
    public byte LoadLevelStatus {get {return dimmingService.Evented_LoadLevelStatus;} set {dimmingService.Evented_LoadLevelStatus = value;}}

    public ZensysUPnPLightDevice(ZWaveDeviceTypes devType, string name, byte Id, ZWaveLogging log)
    {
      ZensysUPnPDownDeviceInit(ZensysUPnPDevice.UPnPDeviceTypes.BinaryLight, devType, Id, log);
      device = UPnPDevice.CreateRootDevice(1800, 1.0, "\\");
      if (name.Length > 0)
      {
        Device.FriendlyName = name;
      }
      else
      {
        Device.FriendlyName = "LightXXX";
      }
			Device.Manufacturer = "Zensys";
			Device.ManufacturerURL = "http://www.zen-sys.com";
			Device.ModelName = "Light";
      Device.ModelName = ((deviceZWaveType == ZWaveDeviceTypes.SWITCH_BINARY) ? "Binary " : "Dimmable ") + Device.ModelName;
			Device.ModelDescription = "Zensys Light";
			Device.ModelNumber = "00001";
      /* For now we emit the device XML when the presentation page is requested */
      //device.PresentationURL = "web";
      Device.HasPresentation = true;
			Device.StandardDeviceType = "BinaryLight";
			MicroStack.SwitchPower SwitchPower = new MicroStack.SwitchPower();
			SwitchPower.External_GetStatus = new MicroStack.SwitchPower.Delegate_GetStatus(SwitchPower_GetStatus);
			SwitchPower.External_SetTarget = new MicroStack.SwitchPower.Delegate_SetTarget(SwitchPower_SetTarget);
			Device.AddService(SwitchPower);
      switchPowerService = SwitchPower;
      // Setting the initial value of evented variable
      switchPowerService.Evented_Status = false;

      if (deviceZWaveType == ZWaveDeviceTypes.SWITCH_MULTILEVEL)
      {
        MicroStack.DimmingService DimmingService = new MicroStack.DimmingService();
        DimmingService.External_GetLoadLevelStatus = new MicroStack.DimmingService.Delegate_GetLoadLevelStatus(DimmingService_GetLoadLevelStatus);
        DimmingService.External_GetMinLevel = new MicroStack.DimmingService.Delegate_GetMinLevel(DimmingService_GetMinLevel);
        DimmingService.External_SetLoadLevelTarget = new MicroStack.DimmingService.Delegate_SetLoadLevelTarget(DimmingService_SetLoadLevelTarget);
        Device.AddService(DimmingService);
        dimmingService = DimmingService;
        // Setting the initial value of evented variable
        dimmingService.Evented_LoadLevelStatus = 0;
      }
      Log.Write("UPnP device " + Device.FriendlyName + " created");
    }
		

    public override void Start()
		{
      base.Start();
      Log.Write("UPnP device " + Device.FriendlyName + " started");
    }
		

		public override void Stop()
		{
      base.Stop();
      Log.Write("UPnP device " + Device.FriendlyName + " stopped");
    }


		public void SwitchPower_GetStatus(out System.Boolean ResultStatus)
		{
			ResultStatus = Status;
      if (bridgeSubscriberEvent != null)
      {
        bridgeSubscriberEvent(this, (byte)ZensysUPnPLightDevice.funcIDTypes.GetStatus);
      }
      Log.Write("device " + Device.FriendlyName + " SwitchPower_GetStatus(" + ") = " + Status.ToString());
    }

		public void SwitchPower_SetTarget(System.Boolean newTargetValue)
		{
      TargetStatus = newTargetValue;
      Log.Write("device " + Device.FriendlyName + " SwitchPower_SetTarget(" + _targetStatus.ToString() + ")");

      if (bridgeSubscriberEvent != null)
      {
        bridgeSubscriberEvent(this, (byte)ZensysUPnPLightDevice.funcIDTypes.SetTarget);
      }
    }
		
		public void DimmingService_GetLoadLevelStatus(out System.Byte RetLoadLevelStatus)
		{
			RetLoadLevelStatus = LoadLevelStatus;
      if (bridgeSubscriberEvent != null)
      {
        bridgeSubscriberEvent(this, (byte)ZensysUPnPLightDevice.funcIDTypes.GetLoadLevelStatus);
      }
      Log.Write("device " + Device.FriendlyName + " DimmingService_GetLoadLevelStatus(" + ") = " + LoadLevelStatus.ToString());
    }
		
		public void DimmingService_GetMinLevel(out System.Byte MinLevel)
		{
			MinLevel = 0;
      if (bridgeSubscriberEvent != null)
      {
        bridgeSubscriberEvent(this, (byte)ZensysUPnPLightDevice.funcIDTypes.GetMinLevel);
      }
      Log.Write("device " + Device.FriendlyName + " DimmingService_GetMinLevel(" + ") = " + MinLevel.ToString());
    }
		
		public void DimmingService_SetLoadLevelTarget(System.Byte NewLoadLevelTarget)
		{
      LoadLevelTarget = NewLoadLevelTarget;

      if (bridgeSubscriberEvent != null)
      {
        bridgeSubscriberEvent(this, (byte)ZensysUPnPLightDevice.funcIDTypes.SetLoadLevelTarget);
      }
      Log.Write("device " + Device.FriendlyName + " DimmingService_SetLoadLevelTarget(" + _loadLevelTarget.ToString() + ")");
    }

    public override string ToString()
    {
      return "BinaryLight";
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?