zwaveupnpbridgeform.cs

来自「zwave 无线通讯协议 PC controller 控制器源码」· CS 代码 · 共 1,362 行 · 第 1/5 页

CS
1,362
字号
//////////////////////////////////////////////////////////////////////////////////////////////// 
//
//          #######
//          #   ##    ####   #####    #####  ##  ##   #####
//             ##    ##  ##  ##  ##  ##      ##  ##  ##
//            ##  #  ######  ##  ##   ####   ##  ##   ####
//           ##  ##  ##      ##  ##      ##   #####      ##
//          #######   ####   ##  ##  #####       ##  #####
//                                           #####
//          Z-Wave, the wireless language.
//
//          Copyright Zensys A/S, 2003,2004
//
//          All Rights Reserved
//
//          Description:   This source file is the main sourcefile for the ZWaveBridge
//
//          Author:   Johann Sigfredsson
//
//          Last Changed By:  $Author: jrm $
//          Revision:         $Revision: 1.6 $
//          Last Changed:     $Date: 2007/03/19 09:35:43 $
//
//////////////////////////////////////////////////////////////////////////////////////////////

#region using directives
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Zensys.ZWave.Communication;
using System.Threading;
using System.Diagnostics;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security; // CodeAccessPermission
using System.Security.Permissions;  // RegistryPermission
using System.Resources;
using Microsoft.Win32; //Microsoft.Win32.RegistryKey
using ZWaveCmdClass;
using Zensys.ZWave.Logging;
using Zensys.ZCmdClass;
//using System.Net;
//using System.Runtime.Remoting;
//using MicroStack;
#endregion using directives

namespace Zensys
{
    /// <summary>
    /// Summary description for ZWaveBridgeForm.
    /// </summary>
    public class ZWaveBridgeForm : System.Windows.Forms.Form
    {
        /// <summary>
        /// Summary description for TreeViewCmds.
        /// </summary>
        public enum TreeViewCmds
        {
            include,
            exclude,
            GetCurrentConnectionIDs,
            GetPositionInfo,
            LastChange,
        }

        #region Windows.Forms Fields
        private System.ComponentModel.IContainer components;
        private System.Windows.Forms.Button buttonExit;
        private System.Windows.Forms.CheckBox checkBoxAutoScroll;
        private System.Windows.Forms.ListView listViewDeviceList;
        private System.Windows.Forms.ListView listViewLog;
        private System.Windows.Forms.ColumnHeader columnHeaderTime;
        private System.Windows.Forms.ColumnHeader columnHeaderLogText;
        private System.Windows.Forms.ColumnHeader columnHeaderNodeID;
        private System.Windows.Forms.ColumnHeader columnHeaderDevice;
        private System.Windows.Forms.ColumnHeader columnHeaderUPnPDevice;
        private System.Windows.Forms.ColumnHeader columnHeaderUPnPFriendlyName;
        private System.Windows.Forms.NotifyIcon notifyIcon;
        private System.Windows.Forms.MenuItem menuItem1;
        private System.Windows.Forms.MenuItem menuItem2;
        private System.Windows.Forms.MenuItem menuItem3;
        private System.Windows.Forms.ContextMenu trayContextMenu;
        private System.Windows.Forms.TreeView treeViewRenderer;
        private System.Windows.Forms.TabControl tabControlZensysBridge;
        private System.Windows.Forms.TabPage tabPageUPnPAvRendererCP;
        private System.Windows.Forms.Button buttonPlay;
        private System.Windows.Forms.Button buttonStop;
        private System.Windows.Forms.Button buttonPrev;
        private System.Windows.Forms.Button buttonNext;
        private System.Windows.Forms.Label labelStatus;
        private System.Windows.Forms.Label labelStatusText;
        private System.Windows.Forms.Label labelStateText;
        private System.Windows.Forms.Label labelState;
        private System.Windows.Forms.Button buttonReScan;
        private System.Windows.Forms.TabPage tabPageZWaveNodes;
        private System.Windows.Forms.Label labelTitleText;
        private System.Windows.Forms.Label labelTitle;
        private System.Windows.Forms.ListView listViewZWaveNodes;
        private System.Windows.Forms.ColumnHeader columnHeaderNode;
        private System.Windows.Forms.ColumnHeader columnHeaderZWaveDeviceType;
        private System.Windows.Forms.TabPage tabPageUPnPDeviceScanner;
        private System.Windows.Forms.Button buttonDeviceScannerReScan;
        private System.Windows.Forms.TreeView treeViewDeviceScanner;
        private System.Windows.Forms.ImageList imageList1;
        private System.Windows.Forms.ColumnHeader ColumnHeaderStatus;
        private System.Windows.Forms.TabPage tabPageUPnPBridgedDev;
        private System.Windows.Forms.ContextMenu contextBridgedDeviceMenu;
        private System.Windows.Forms.ContextMenu contextMenuZWaveNodes;
        private System.Windows.Forms.MenuItem menuItemBridge;
        private System.Windows.Forms.ColumnHeader columnHeaderBridgeStatus;
        private System.Windows.Forms.MenuItem menuItemStop;
        private System.Windows.Forms.ContextMenu contextMenuDeviceScanner;
        private System.Windows.Forms.MenuItem menuItemRemoveUPnPDevice;
        private System.Windows.Forms.MenuItem menuItemRescanUPnP;
        private System.Windows.Forms.Button buttonOn;
        private System.Windows.Forms.Button buttonResetNode;
        private System.Windows.Forms.Button buttonAddNode;
        private System.Windows.Forms.Button buttonOff;
        private System.Windows.Forms.Label labelZWaveStatus;
        private System.Windows.Forms.Label labelZWaveStatusText;
        private System.Windows.Forms.Button buttonResetController;
        private System.Windows.Forms.CheckBox checkBoxAutoBridge;
        private System.Windows.Forms.ColumnHeader columnHeaderStreamDirection;
        #endregion Windows.Forms Fields

        public delegate void Complete(ref byte txStatus);
        public delegate void updateTreeViewRendererDelegate(TreeViewCmds cmd, ZensysUPnPAvRendererDevice rendererDev, object arg);
        public delegate void updateTreeViewScannerDelegate(TreeViewCmds cmd, Intel.UPNP.UPnPDevice device);
        public static IApplicationLayer applicationLayer;
        public static byte controllerNode;
        private ResourceManager resourceFormManager = new ResourceManager("ZWaveUPnPBridge.Properties.Resources", typeof(ZWaveBridgeForm).Assembly);

        private Mutex mutexRenderer = new Mutex();
        private Mutex mutexScanner = new Mutex();
        private updateTreeViewRendererDelegate updateTreeViewUPnPRenderer;
        private updateTreeViewScannerDelegate updateTreeViewScanner;
        private ZensysUPnPDevice device = null;
        private ArrayList UPnPdownDeviceList = new ArrayList();
        private ArrayList UPnPupDeviceList = new ArrayList();
        private System.Boolean autoScroll = true;

        private ZWaveLogging mainLog;
        private ZensysUPnPAvRendererCPDevice AVdevice;
        private ZensysUPnPDeviceScanner DevScanner;
        private ZensysUPnPLightCPDevice lightDevice;
        private UPnPEditForm editUPnPname = new UPnPEditForm();
        private UPnPtoZWaveForm bridgeUPnP2ZWave = new UPnPtoZWaveForm();
        private Hashtable ZWaveNodes = new Hashtable();
        private Queue GroupSendQueue = new Queue(5);
        private ArrayList nodeGetList = new ArrayList();


        private System.Windows.Forms.Button buttonSendInfo;

        private System.Windows.Forms.Button buttonAbort;
        private System.Windows.Forms.TabPage tabPageUPnPBinaryLightCP;
        private System.Windows.Forms.ListView listViewUPnPBinaryLight;
        private System.Windows.Forms.ColumnHeader columnHeaderUPnPName;
        private System.Windows.Forms.Button buttonGetReport;
        private System.Windows.Forms.ToolTip toolTipApp;
        private System.Windows.Forms.ContextMenu contextMenuUPnPBinaryLightCP;
        private System.Windows.Forms.MenuItem menuItemBridgeUPnPdevice;
        private System.Windows.Forms.MenuItem menuItemToggleLight;
        private System.Windows.Forms.Button buttonHide;
        private System.Windows.Forms.GroupBox groupBoxVirtualNode;
        private System.Windows.Forms.GroupBox groupBoxController;
        private System.Windows.Forms.Button buttonNewNode;
        private System.Windows.Forms.Button buttonReceiveReplication;
        private System.Windows.Forms.Label labelNodeID;
        private System.Windows.Forms.Label labelHomeIDText;
        private System.Windows.Forms.Label labelHomeID;
        private System.Windows.Forms.Label labelNodeIDText;
        private System.Windows.Forms.GroupBox groupBoxNodes;
        private System.Windows.Forms.Button buttonPause;
        private Queue SendQueue = new Queue(5);
        private System.Windows.Forms.ContextMenu contextMenuUPnPRendererCP;
        private System.Windows.Forms.Label labelSUCIDText;
        private System.Windows.Forms.Label labelSUCID;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.CheckBox checkBoxComDebug;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.StatusBar statusBarMain;
        private System.Windows.Forms.StatusBarPanel statusBarPanelVersion;
        private System.Windows.Forms.StatusBarPanel statusBarPanelLogLines;
        private System.Windows.Forms.StatusBarPanel statusBarPanelBridgedDevicesCount;
        private System.Windows.Forms.StatusBarPanel statusBarPanelUpTime;
        private System.Windows.Forms.Timer timerAppUpTime;
        private System.Windows.Forms.ColumnHeader columnHeaderVirtualNode;
        private System.Windows.Forms.Button buttonRequestUpdate;
        private System.Windows.Forms.Button buttonDelVirtualNode;
        private System.Windows.Forms.Button buttonCreateVirtualNode;
        private System.Windows.Forms.Button buttonRequestNeighborUpdate;
        private System.Threading.Timer sendInfoTimer = null;

        private const int ZW_SUC_FUNC_BASIC_SUC = 0x00;
        private const int ZW_SUC_FUNC_NODEID_SERVER = 0x01;
        private const int ZW_MAX_NODES = 232;
        private const byte NODE_BROADCAST = 0xFF;
        private const byte UPDATE_STATE_SUC_ID = 0x10;

        private string[] requestedPort = null;
        private DateTime StartUpTime;
        private TimeSpan timesp = new TimeSpan(0);
        //   private ZW_DataPacket dataPacket;

        private static string _portName = null;
        private string[] portNames;
        private VersionInfoType vit;
        private Thread formThread;
        private int homeId;
        private bool slaveController;
        private Node[] nodes;
        private byte SUC;
        private int baud = 115200;
        private Library lib;
        private String ver;

        public class ZWaveNode
        {
            private byte nodeId;
            private bool virtNode;
            private byte type;
            private object dev;

            public ZWaveNode(byte node, byte type, object device, bool virtualNode)
            {
                this.nodeId = node;
                this.type = type;
                this.dev = device;
                this.virtNode = virtualNode;
            }

            public byte NodeId
            {
                get { return nodeId; }
            }

            public byte Type
            {
                get { return type; }
                set { type = value; }
            }

            public object Dev
            {
                get { return dev; }
                set { dev = value; }
            }

            public ZensysBridgedDevice DevBridge
            {
                get { return dev as ZensysBridgedDevice; }
                set { dev = value as object; }
            }

            public ZensysUPnPDevice DevUPnP
            {
                get { return dev as ZensysUPnPDevice; }
                set { dev = value as object; }
            }
        }


        [Serializable]
        struct ZensysDeviceStorage
        {
            public byte nodeId;
            public string friendlyName;

⌨️ 快捷键说明

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