device.cs
来自「zwave 无线通讯协议 PC controller 控制器源码」· CS 代码 · 共 186 行
CS
186 行
////////////////////////////////////////////////////////////////////////////////////////////////
//
// #######
// # ## #### ##### ##### ## ## #####
// ## ## ## ## ## ## ## ## ##
// ## # ###### ## ## #### ## ## ####
// ## ## ## ## ## ## ##### ##
// ####### #### ## ## ##### ## #####
// #####
// Z-Wave, the wireless language.
//
// Copyright Zensys A/S, 2003
//
// All Rights Reserved
//
// Description: This source file includes functions for accepting different types.
//
// Author: Jette Christensen
//
// Last Changed By: $Author: jch $
// Revision: $Revision: 1.2 $
// Last Changed: $Date: 2006/03/29 13:55:50 $
//
//////////////////////////////////////////////////////////////////////////////////////////////
using System;
using Zensys.ZCmdClass;
using ZWaveCmdClass;
using System.Text;
using System.Globalization;
namespace ZWavePCController
{
/// <summary>
/// This class contains all data that is not GUI
/// </summary>
///
public class Device
{
/// <summary>
/// Verify if the nodetype is recognized and accepted.
/// </summary>
/// <param name="nodeType"></param>
/// <returns>true if node is accepted</returns>
public bool IsAcceptedNodeType(GenericType nodeType)
{
return ((nodeType == GenericType.GENERIC_TYPE_REPEATER_SLAVE) ||
(nodeType == GenericType.GENERIC_TYPE_SWITCH_BINARY) ||
(nodeType == GenericType.GENERIC_TYPE_SWITCH_MULTILEVEL) ||
(nodeType == GenericType.GENERIC_TYPE_SENSOR_BINARY) ||
(nodeType == GenericType.GENERIC_TYPE_SENSOR_MULTILEVEL) ||
(nodeType == GenericType.GENERIC_TYPE_METER_PULSE) ||
(nodeType == GenericType.GENERIC_TYPE_ENTRY_CONTROL) ||
(nodeType == GenericType.GENERIC_TYPE_NON_INTEROPERABLE) ||
(nodeType == GenericType.GENERIC_TYPE_SEMI_INTEROPERABLE) ||
(nodeType == GenericType.GENERIC_TYPE_SWITCH_REMOTE) ||
(nodeType == GenericType.GENERIC_TYPE_SWITCH_TOGGLE));
}
/// <summary>
/// Verify if the controller is recognized and accepted
/// </summary>
/// <param name="nodeType"></param>
/// <returns>true if node is accepted</returns>
public bool IsAcceptedControllerType(GenericType nodeType)
{
return (nodeType == GenericType.GENERIC_TYPE_STATIC_CONTROLLER || nodeType == GenericType.GENERIC_TYPE_GENERIC_CONTROLLER) || (nodeType == GenericType.GENERIC_TYPE_REPEATER_SLAVE) || (nodeType == GenericType.GENERIC_TYPE_THERMOSTAT);
}
/// <summary>
/// Verify if node is a sensor
/// </summary>
/// <param name="nodeType"></param>
/// <returns>true if nodetype is a sensor</returns>
public bool IsAcceptedSensorType(GenericType nodeType)
{
return (nodeType == GenericType.GENERIC_TYPE_SENSOR_BINARY) ||
(nodeType == GenericType.GENERIC_TYPE_SENSOR_MULTILEVEL);
}
/// <summary>
/// Verify if node is a switch
/// </summary>
/// <param name="nodeType"></param>
/// <returns>true if nodetype is a swich</returns>
public bool IsAcceptedSwitchType(GenericType nodeType)
{
return (nodeType == GenericType.GENERIC_TYPE_SWITCH_BINARY) ||
(nodeType == GenericType.GENERIC_TYPE_SWITCH_MULTILEVEL);
}
/// <summary>
/// Converts basic device class to a textstring
/// </summary>
/// <param name="basic"></param>
/// <returns>Basic Device Class as a string</returns>
public string WriteBasicDeviceClass(byte basic)
{
switch((DeviceClass)basic)
{
case DeviceClass.BASIC_TYPE_CONTROLLER:
return "Controller";
case DeviceClass.BASIC_TYPE_STATIC_CONTROLLER:
return "Static Controller";
case DeviceClass.BASIC_TYPE_SLAVE:
return "Slave";
case DeviceClass.BASIC_TYPE_ROUTING_SLAVE:
return "Routing Slave";
default:
return basic.ToString(CultureInfo.CurrentCulture);
}
}
/// <summary>
/// Takes the input string and changes _ to space and lowers all but chars after space:
/// PORTABLE_CONTROLLER => Portable Controller
/// </summary>
/// <param name="cmd">string to humanize</param>
/// <returns></returns>
public string ToHumanString(string cmd)
{
if (cmd == null)
{
throw new ArgumentNullException("cmd");
}
StringBuilder cmdName = new StringBuilder();
//string cmdName = "";
bool toUpper = true;
foreach(char c in cmd)
{
if(c == '_')
{
toUpper = true;
cmdName = cmdName.Append(" ");
}
else
{
if(toUpper)
{
cmdName = cmdName.Append(c.ToString().ToUpper(CultureInfo.CurrentCulture));
toUpper = false;
}
else
{
cmdName = cmdName.Append(c.ToString().ToLower(CultureInfo.CurrentCulture));
}
}
}//foreach
return cmdName.ToString();
}
/// <summary>
/// Converts generic device class to a textstring
/// </summary>
/// <param name="nodeType"></param>
/// <returns>Generic Device Class as a string</returns>
public string WriteGenericDeviceClass(GenericType nodeType)
{
string cmd = nodeType.ToString().Substring("GENERIC_TYPE_".Length);
return ToHumanString(cmd);
}
/// <summary>
/// Converts Specific Device Class to a textstring
/// </summary>
/// <param name="generic"></param>
/// <param name="specific"></param>
/// <returns>Specific Device Class as a string</returns>
public string WriteSpecificDeviceClass(byte generic,byte specific)
{
string temp = DeviceTypes.GetSpecificDeviceTypeString(generic,specific).Substring("SPECIFIC_TYPE_".Length);
return ToHumanString(temp);
}
/// <summary>
/// Converts node type parameter to a textstring
/// </summary>
/// <param name="cmdclass"></param>
/// <returns>Node Type Parameter as a string</returns>
public string WriteNodeTypeParameters(byte cmdClass)
{
string temp = ((cmdClass)cmdClass).ToString().Substring("COMMAND_CLASS_".Length);
return ToHumanString(temp);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?