예제 #1
0
        public ZclOnOffClusterTest()
        {
            var node     = new ZigBeeNode();
            var endpoint = new ZigBeeEndpoint(node, 0);

            _cluster = new ZclOnOffCluster(endpoint);
        }
예제 #2
0
        /// <summary>
        /// Get the simple descriptor for an endpoint and create the <see cref="ZigBeeEndpoint">
        ///
        /// <param name="endpointId">the endpoint id to request</param>
        /// <returns>the newly created <see cref="ZigBeeEndpoint"> for the endpoint, or null on error</returns>
        /// </summary>
        private async Task <ZigBeeEndpoint> GetSimpleDescriptor(byte endpointId)
        {
            SimpleDescriptorRequest simpleDescriptorRequest = new SimpleDescriptorRequest();

            simpleDescriptorRequest.DestinationAddress = new ZigBeeEndpointAddress((ushort)Node.NetworkAddress);
            simpleDescriptorRequest.NwkAddrOfInterest  = Node.NetworkAddress;
            simpleDescriptorRequest.Endpoint           = endpointId;

            CommandResult response = await NetworkManager.SendTransaction(simpleDescriptorRequest, simpleDescriptorRequest);

            SimpleDescriptorResponse simpleDescriptorResponse = (SimpleDescriptorResponse)response.Response;

            Log.Debug("{IeeeAddress}: Node SVC Discovery: SimpleDescriptorResponse returned {Response}", Node.IeeeAddress, simpleDescriptorResponse);

            if (simpleDescriptorResponse == null)
            {
                return(null);
            }

            if (simpleDescriptorResponse.Status == ZdoStatus.SUCCESS)
            {
                ZigBeeEndpoint   endpoint         = new ZigBeeEndpoint(Node, endpointId);
                SimpleDescriptor simpleDescriptor = simpleDescriptorResponse.SimpleDescriptor;

                endpoint.ProfileId     = simpleDescriptor.ProfileId;
                endpoint.DeviceId      = simpleDescriptor.DeviceId;
                endpoint.DeviceVersion = simpleDescriptor.DeviceVersion;
                endpoint.SetInputClusterIds(simpleDescriptor.InputClusterList.Select(id => id).ToList());
                endpoint.SetOutputClusterIds(simpleDescriptor.OutputClusterList.Select(id => id).ToList());

                return(endpoint);
            }

            return(null);
        }
예제 #3
0
        public ZclCluster(ZigBeeEndpoint zigbeeEndpoint, ushort clusterId, string clusterName)
        {
            _attributes = InitializeAttributes();

            this._zigbeeEndpoint = zigbeeEndpoint;
            this._clusterId      = clusterId;
            this._clusterName    = clusterName;
            this._normalizer     = new ZclAttributeNormalizer();
        }
예제 #4
0
        /// <summary>
        /// Get the active endpoints for a node
        ///
        /// <returns>true if the message was processed ok</returns>
        /// </summary>
        private async Task <bool> RequestActiveEndpoints()
        {
            ActiveEndpointsRequest activeEndpointsRequest = new ActiveEndpointsRequest();

            activeEndpointsRequest.DestinationAddress = new ZigBeeEndpointAddress((ushort)Node.NetworkAddress);
            activeEndpointsRequest.NwkAddrOfInterest  = Node.NetworkAddress;

            CommandResult response = await NetworkManager.SendTransaction(activeEndpointsRequest, activeEndpointsRequest);

            ActiveEndpointsResponse activeEndpointsResponse = (ActiveEndpointsResponse)response.Response;

            Log.Debug("{IeeeAddress}: Node SVC Discovery: ActiveEndpointsResponse returned {Response}", Node.IeeeAddress, response);

            if (activeEndpointsResponse == null)
            {
                return(false);
            }

            // Get the simple descriptors for all endpoints
            List <ZigBeeEndpoint> endpoints = new List <ZigBeeEndpoint>();

            foreach (byte endpointId in activeEndpointsResponse.ActiveEpList)
            {
                ZigBeeEndpoint endpoint = await GetSimpleDescriptor(endpointId);

                if (endpoint == null)
                {
                    return(false);
                }

                endpoints.Add(endpoint);
            }

            // All endpoints have been received, so add them to the node
            foreach (ZigBeeEndpoint endpoint in endpoints)
            {
                _updatedNode.AddEndpoint(endpoint);
            }

            return(true);
        }
 /// <summary>
 /// Default constructor to create a On / Off Switch Configuration cluster.
 ///
 /// <param name="zigbeeEndpoint"> the ZigBeeEndpoint this cluster is contained within </param>
 /// </summary>
 public ZclOnOffSwitchConfigurationCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #6
0
 /// <summary>
 /// Default constructor to create a Thermostat User Interface Configuration cluster.
 ///
 /// <param name="zigbeeEndpoint"> the ZigBeeEndpoint this cluster is contained within </param>
 /// </summary>
 public ZclThermostatUserInterfaceConfigurationCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #7
0
 /// <summary>
 /// Default constructor to create a General cluster.
 ///
 /// @param zigbeeEndpoint the {@link ZigBeeEndpoint}
 /// </summary>
 public ZclGeneralCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
 /**
  * Default constructor to create a Analog Input (BACnet Extended) cluster.
  *
  * @param zigbeeEndpoint the {@link ZigBeeEndpoint}
  */
 public ZclAnalogInputBACnetExtendedCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #9
0
 /// <summary>
 /// Default constructor to create a Multistate Output (Basic) cluster.
 ///
 /// <param name ="zigbeeEndpoint">The ZigBeeEndpoint</param>
 /// </summary>
 public ZclMultistateOutputBasicCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #10
0
 /// <summary>
 /// Default constructor to create a Device Temperature Configuration cluster.
 ///
 /// <param name ="zigbeeEndpoint">The ZigBeeEndpoint</param>
 /// </summary>
 public ZclDeviceTemperatureConfigurationCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #11
0
        static void Main(string[] args)
        {
            _nodes = new List <ZigBeeNode>();

            // Configure Serilog
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console()
                         .CreateLogger();
            try
            {
                TransportConfig transportOptions = new TransportConfig();

                Console.Write("Please enter your COM Port: ");

                var port = Console.ReadLine();

                ZigBeeSerialPort zigbeePort = new ZigBeeSerialPort(port);

                IZigBeeTransportTransmit dongle = new ZigBeeDongleTiCc2531(zigbeePort);

                ZigBeeNetworkManager networkManager = new ZigBeeNetworkManager(dongle);

                ZigBeeDiscoveryExtension discoveryExtension = new ZigBeeDiscoveryExtension();
                discoveryExtension.setUpdatePeriod(60);
                networkManager.AddExtension(discoveryExtension);

                // Initialise the network
                networkManager.Initialize();

                networkManager.AddCommandListener(new ConsoleCommandListener());
                networkManager.AddNetworkNodeListener(new ConsoleNetworkNodeListener());

                Log.Logger.Information("PAN ID: {PanId}", networkManager.ZigBeePanId);
                Log.Logger.Information("Extended PAN ID: {ExtendenPanId}", networkManager.ZigBeeExtendedPanId);
                Log.Logger.Information("Channel: {Channel}", networkManager.ZigbeeChannel);

                byte channel = 11;

                byte pan = 1;

                ExtendedPanId extendedPan = new ExtendedPanId();

                ZigBeeKey nwkKey = ZigBeeKey.CreateRandom();

                ZigBeeKey linkKey = new ZigBeeKey(new byte[] { 0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, 0x6C, 0x69, 0x61,
                                                               0x6E, 0x63, 0x65, 0x30, 0x39 });


                Console.WriteLine("*** Resetting network");
                Console.WriteLine("  * Channel                = " + channel);
                Console.WriteLine("  * PAN ID                 = " + pan);
                Console.WriteLine("  * Extended PAN ID        = " + extendedPan);
                Console.WriteLine("  * Link Key               = " + linkKey);

                networkManager.SetZigBeeChannel((ZigBeeChannel)channel);
                networkManager.SetZigBeePanId(pan);
                networkManager.SetZigBeeExtendedPanId(extendedPan);
                networkManager.SetZigBeeNetworkKey(nwkKey);
                networkManager.SetZigBeeLinkKey(linkKey);

                transportOptions.AddOption(TransportConfigOption.TRUST_CENTRE_LINK_KEY, new ZigBeeKey(new byte[] { 0x5A, 0x69,
                                                                                                                   0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, 0x6C, 0x69, 0x61, 0x6E, 0x63, 0x65, 0x30, 0x39 }));

                dongle.UpdateTransportConfig(transportOptions);

                networkManager.AddSupportedCluster(0x06);

                ZigBeeStatus startupSucceded = networkManager.Startup(false);

                if (startupSucceded == ZigBeeStatus.SUCCESS)
                {
                    Log.Logger.Information("ZigBee console starting up ... [OK]");
                }
                else
                {
                    Log.Logger.Information("ZigBee console starting up ... [FAIL]");
                    return;
                }

                ZigBeeNode coord = networkManager.GetNode(0);

                coord.PermitJoin(true);

                Console.WriteLine("Joining enabled...");

                string cmd = Console.ReadLine();

                while (cmd != "exit")
                {
                    if (cmd == "toggle")
                    {
                        Console.WriteLine("Destination Address: ");
                        string nwkAddr = Console.ReadLine();

                        if (ushort.TryParse(nwkAddr, out ushort addr))
                        {
                            var node = networkManager.GetNode(addr);

                            if (node != null)
                            {
                                ZigBeeEndpoint ep = new ZigBeeEndpoint(node, 0);
                                node.AddEndpoint(ep);

                                ZclOnOffCluster onOff = new ZclOnOffCluster(node.GetEndpoint(0));

                                onOff.ToggleCommand();
                            }
                        }
                    }

                    cmd = Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
 /// <summary>
 /// Default constructor to create a Appliance Events and Alerts cluster.
 ///
 /// <param name ="zigbeeEndpoint">The ZigBeeEndpoint</param>
 /// </summary>
 public ZclApplianceEventsAndAlertsCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #13
0
 /**
  * Default constructor to create a Pump Configuration and Control cluster.
  *
  * @param zigbeeEndpoint the {@link ZigBeeEndpoint}
  */
 public ZclPumpConfigurationAndControlCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #14
0
 /**
  * Default constructor to create a Thermostat cluster.
  *
  * @param zigbeeEndpoint the {@link ZigBeeEndpoint}
  */
 public ZclThermostatCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #15
0
 /**
  * Default constructor to create a Binary Value (BACnet Extended) cluster.
  *
  * @param zigbeeEndpoint the {@link ZigBeeEndpoint}
  */
 public ZclBinaryValueBACnetExtendedCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
 /// <summary>
 /// Default constructor to create a Appliance Statistics cluster.
 ///
 /// <param name ="zigbeeEndpoint">The ZigBeeEndpoint</param>
 /// </summary>
 public ZclApplianceStatisticsCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
 /// <summary>
 /// Default constructor to create a Key Establishment cluster.
 ///
 /// <param name ="zigbeeEndpoint">The ZigBeeEndpoint</param>
 /// </summary>
 public ZclKeyEstablishmentCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
 /// <summary>
 /// Default constructor to create a BACnet Protocol Tunnel cluster.
 ///
 /// <param name ="zigbeeEndpoint">The ZigBeeEndpoint</param>
 /// </summary>
 public ZclBACnetProtocolTunnelCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #19
0
 /// <summary>
 /// Default constructor to create a Pressure Measurement cluster.
 ///
 /// <param name="zigbeeEndpoint"> the ZigBeeEndpoint this cluster is contained within </param>
 /// </summary>
 public ZclPressureMeasurementCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #20
0
 /// <summary>
 /// Default constructor to create a Analog Value (BACnet Regular) cluster.
 ///
 /// @param zigbeeEndpoint the {@link ZigBeeEndpoint}
 /// </summary>
 public ZclAnalogValueBACnetRegularCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #21
0
 /// <summary>
 /// Default constructor to create a Diagnostics cluster.
 ///
 /// <param name ="zigbeeEndpoint">The ZigBeeEndpoint</param>
 /// </summary>
 public ZclDiagnosticsCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #22
0
 /**
  * Default constructor to create a Electrical Measurement cluster.
  *
  * @param zigbeeEndpoint the {@link ZigBeeEndpoint}
  */
 public ZclElectricalMeasurementCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #23
0
 /// <summary>
 /// Default constructor to create a Door Lock cluster.
 ///
 /// <param name ="zigbeeEndpoint">The ZigBeeEndpoint</param>
 /// </summary>
 public ZclDoorLockCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #24
0
 /// <summary>
 /// Default constructor to create a Occupancy sensing cluster.
 ///
 /// @param zigbeeEndpoint the {@link ZigBeeEndpoint}
 /// </summary>
 public ZclOccupancySensingCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #25
0
 /**
  * Default constructor to create a Multistate Input (BACnet Regular) cluster.
  *
  * @param zigbeeEndpoint the {@link ZigBeeEndpoint}
  */
 public ZclMultistateInputBACnetRegularCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
 /// <summary>
 /// Default constructor to create a Relative humidity measurement cluster.
 ///
 /// <param name ="zigbeeEndpoint">The ZigBeeEndpoint</param>
 /// </summary>
 public ZclRelativeHumidityMeasurementCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #27
0
 /// <summary>
 /// Default constructor to create a Basic cluster.
 ///
 /// @param zigbeeEndpoint the {@link ZigBeeEndpoint}
 /// </summary>
 public ZclBasicCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #28
0
 /// <summary>
 /// Default constructor to create a Fan Control cluster.
 ///
 /// <param name="zigbeeEndpoint"> the ZigBeeEndpoint this cluster is contained within </param>
 /// </summary>
 public ZclFanControlCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
예제 #29
0
 /// <summary>
 /// Default constructor to create a IAS Zone cluster.
 ///
 /// <param name="zigbeeEndpoint"> the ZigBeeEndpoint this cluster is contained within </param>
 /// </summary>
 public ZclIasZoneCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }
 /**
  * Default constructor to create a Illuminance level sensing cluster.
  *
  * @param zigbeeEndpoint the {@link ZigBeeEndpoint}
  */
 public ZclIlluminanceLevelSensingCluster(ZigBeeEndpoint zigbeeEndpoint)
     : base(zigbeeEndpoint, CLUSTER_ID, CLUSTER_NAME)
 {
 }