association.cs

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

CS
173
字号
//////////////////////////////////////////////////////////////////////////////////////////////// 
//
//          #######
//          #   ##    ####   #####    #####  ##  ##   #####
//             ##    ##  ##  ##  ##  ##      ##  ##  ##
//            ##  #  ######  ##  ##   ####   ##  ##   ####
//           ##  ##  ##      ##  ##      ##   #####      ##
//          #######   ####   ##  ##  #####       ##  #####
//                                           #####
//          Z-Wave, the wireless language.
//
//          Copyright Zensys A/S, 2003
//
//          All Rights Reserved
//
//          Description:   This source file includes functions for external EEPROM
//
//
//          Last Changed By:  $Author: jch $
//          Revision:         $Revision: 1.2 $
//          Last Changed:     $Date: 2006/03/29 13:55:53 $
//
//////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using Zensys.ZWave.Communication;

namespace ZWavePCController
{
	/// <summary>
	/// Summary description for Association.
	/// </summary>
	public class Association
	{
    public static Hashtable AssociationTable = new Hashtable();
		public Association()
		{
		}

    public struct AssociationItem
    {
      public ArrayList Members;
    }
  
    /// <summary>
    /// Get the number of groupings supported for this nodeId
    /// </summary>
    /// <param name="nodeId"></param>
    /// <returns>number of groupings supported</returns>
    public byte SupportedGroupings(byte nodeId)
    {
      if(AssociationTable.ContainsKey(nodeId))
      {
        AssociationItem item = (AssociationItem)AssociationTable[nodeId];          
        return (byte)item.Members.Count;
      }
      return 0;
    }

    public byte[] GetGroupings(byte nodeId)
    {
      if(SupportedGroupings(nodeId)!=0)
      {
        AssociationItem item = (AssociationItem)AssociationTable[nodeId];                    
        byte[] temp = new byte[item.Members.Count];
        for(byte i = 1;i<=temp.Length;i++)
        {
          temp[i-1] = i;
        }
        return temp;
      }
      return null;
    }


    /// <summary>
    /// Set the number of supported groupings for a given nodeId
    /// </summary>
    /// <param name="nodeId"></param>
    /// <param name="groupings"></param>
    public void SetGroupings(byte nodeId, byte groupings)
    {
      AssociationItem item = new AssociationItem();
      item.Members = new ArrayList();
      byte[] temp = null;
      for(int i = 0;i<groupings;i++)
      {
        item.Members.Add(temp);
      }
      if(AssociationTable.ContainsKey(nodeId))
      {
        AssociationTable[nodeId] = item;
      }
      else
      {
        AssociationTable.Add(nodeId,item);
      }
    }

    /// <summary>
    /// Get the nodeIDs for a given group
    /// </summary>
    /// <param name="nodeId">nodeId</param>
    /// <param name="groupNo">groupNumber to get</param>
    /// <returns>array of nodeids or null if group does not exist</returns>
    public byte[] GetNodes(byte nodeId,byte groupNo)
    {
      if(AssociationTable.ContainsKey(nodeId))
      {
        AssociationItem item = (AssociationItem)AssociationTable[nodeId];
        if(item.Members.Count>=groupNo)
        {
          byte[] temp = (byte[])item.Members[groupNo-1];
          return temp;
        }
      }
      return null;
    }
    /// <summary>
    /// Adds a group to the AssociationTable
    /// </summary>
    /// <param name="nodeId">nodeId to add association grouping for</param>
    /// <param name="groupNumber">group number to add</param>
    /// <param name="group">Array of NodeIds</param>
    public void AddGroup(byte nodeId,byte groupNumber,byte[] group)
    {
      if(!AssociationTable.ContainsKey(nodeId))
      {
        AssociationItem temp = new AssociationItem();
        temp.Members = new ArrayList(groupNumber); 
        byte[] tmp = null;
        temp.Members.Add(tmp);
        if (temp.Members.Count >= groupNumber)
        {
          temp.Members[groupNumber-1] = group;
        }
        AssociationTable.Add(nodeId,temp);
      }
      else
      {
        AssociationItem temp = (AssociationItem)AssociationTable[nodeId];
        if(temp.Members.Count>=groupNumber)
        {
          temp.Members[groupNumber-1] = group;
        }
        else
        {
          ArrayList newRange = new ArrayList(temp.Members.Count-groupNumber);
          temp.Members.AddRange(newRange);
          temp.Members[groupNumber-1] = group;
        }
        AssociationTable[nodeId] = temp;
      }
    }
 

    public void RemoveGroup(byte nodeId,byte groupNumber)
    {
      if(AssociationTable.ContainsKey(nodeId))
      {
        AssociationItem temp = (AssociationItem)AssociationTable[nodeId];
        if(temp.Members.Count>groupNumber)
        {
          temp.Members[groupNumber] = null;
          AssociationTable[nodeId] = temp;
        }
      }
    }


  }
}

⌨️ 快捷键说明

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