示例#1
0
        //TODO:
        //MULTI_CHANNEL_END_POINT_FIND
        //MULTI_INSTANCE_CMD_ENCAP
        //MULTI_INSTANCE_GET
        protected override void OnHandledInternal(DataReceivedUnit ou)
        {
            ou.SetNextActionItems();
            byte nodeId = ReceivedAchData.SrcNodeId;

            byte[] command          = ReceivedAchData.Command;
            var    scheme           = (SecuritySchemes)ReceivedAchData.SecurityScheme;
            bool   isSuportedScheme = IsSupportedScheme(_network, command, scheme);

            if (command != null && command.Length > 1 && isSuportedScheme)
            {
                if (command[1] == COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_END_POINT_GET.ID)
                {
                    var cmd = (COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_END_POINT_GET)command;
                    var rpt = new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_END_POINT_REPORT()
                    {
                        properties1 = new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_END_POINT_REPORT.Tproperties1()
                        {
                            res1      = 0x00,
                            identical = 0x01,
                            dynamic   = 0x00,
                        },
                        properties2 = new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_END_POINT_REPORT.Tproperties2()
                        {
                            individualEndPoints = END_POINTS_COUNT,
                            res2 = 0x00
                        },
                        properties3 = new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_END_POINT_REPORT.Tproperties3()
                        {
                        }
                    };
                    var sendData = new SendDataExOperation(nodeId, rpt, TxOptions, scheme);
                    ou.SetNextActionItems(sendData);
                }
                else if (command[1] == COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CAPABILITY_GET.ID)
                {
                    var cmd = (COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CAPABILITY_GET)command;
                    if (cmd.properties1.endPoint > 0 &&
                        cmd.properties1.endPoint <= END_POINTS_COUNT)
                    {
                        var rpt = new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CAPABILITY_REPORT()
                        {
                            genericDeviceClass  = GENERIC_DEVICE_CLASS,
                            specificDeviceClass = SPECIFIC_DEVICE_CLASS,
                            properties1         =
                            {
                                dynamic  = 0,
                                endPoint = cmd.properties1.endPoint
                            },
                            commandClass = GetCapability(cmd.properties1.endPoint)
                        };
                        var sendData = new SendDataExOperation(nodeId, rpt, TxOptions, scheme);
                        ou.SetNextActionItems(sendData);
                    }
                }
                else if (command[1] == COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_AGGREGATED_MEMBERS_GET.ID)
                {
                    var cmd = (COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_AGGREGATED_MEMBERS_GET)command;
                    if (cmd.properties1.aggregatedEndPoint > 0 &&
                        cmd.properties1.aggregatedEndPoint <= END_POINTS_COUNT)
                    {
                        var rpt = new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_AGGREGATED_MEMBERS_REPORT()
                        {
                            properties1 =
                            {
                                aggregatedEndPoint = cmd.properties1.aggregatedEndPoint,
                                res                = 0
                            },
                            numberOfBitMasks = 0x01
                        };
                        rpt.aggregatedMembersBitMask.Add(0x03);
                        var sendData = new SendDataExOperation(nodeId, rpt, TxOptions, scheme);
                        ou.SetNextActionItems(sendData);
                    }
                }
                else if (command[1] == COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CMD_ENCAP.ID)
                {
                    var data = UnboxAndGetResponce(command);
                    if (data != null && data.Length > 0)
                    {
                        var sendData = new SendDataExOperation(nodeId, data, TxOptions, scheme);
                        ou.SetNextActionItems(sendData);
                    }
                }
            }
        }
示例#2
0
        protected override void OnCompletedInternal(ActionCompletedUnit ou)
        {
            var result = ou.Action.Result;

            if (result is RequestNodeInfoResult)
            {
                RequestNodeInfoResult res = (RequestNodeInfoResult)result;
                if (res)
                {
                    if (_nodeInfo.Result)
                    {
                        _nodeInfoSecondAttempt.Token.SetCancelled();
                    }
                    else if (_nodeInfoSecondAttempt.Result)
                    {
                        isFirstFailed = true;
                        SpecificResult.RequestNodeInfo = _nodeInfoSecondAttempt.SpecificResult;
                    }

                    if ((res.CommandClasses == null || !res.CommandClasses.Contains(COMMAND_CLASS_MULTI_CHANNEL_V4.ID)) &&
                        (res.SecureCommandClasses == null || !res.SecureCommandClasses.Contains(COMMAND_CLASS_MULTI_CHANNEL_V4.ID)))
                    {
                        _requestEndPoints.Token.SetCancelled();
                        _requestEndPointsCapabilities.Token.SetCancelled();
                    }
                }
                else if (isFirstFailed)
                {
                    _requestEndPoints.Token.SetCancelled();
                    _requestEndPointsCapabilities.Token.SetCancelled();
                }
            }
            else if (result is RequestDataResult)
            {
                RequestDataResult res = (RequestDataResult)result;
                if (res && res.Command != null && res.Command.Length > 1 && res.Command[0] == COMMAND_CLASS_MULTI_CHANNEL_V4.ID)
                {
                    if (res.Command[1] == COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_END_POINT_REPORT.ID)
                    {
                        COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_END_POINT_REPORT epReport = res.Command;
                        _isIdentical = epReport.properties1.identical == 0x01;
                        _endPoints   = epReport.properties2.individualEndPoints;
                        var count = _isIdentical ? 1 : _endPoints;
                        if ((count > 0 && count < 0xFF))
                        {
                            var tmpList = new List <ActionBase>();
                            for (int i = 0; i < count; i++)
                            {
                                COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CAPABILITY_GET cGet = new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CAPABILITY_GET();
                                cGet.properties1.res      = 0x00;
                                cGet.properties1.endPoint = (byte)(i + 1);
                                var requestCapability = new RequestDataOperation(0, res.NodeId,
                                                                                 cGet, _txOptions,
                                                                                 new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CAPABILITY_REPORT(), 2, 5000);
                                tmpList.Add(requestCapability);

                                if (_network != null && _network.HasSecurityScheme(res.NodeId, SecuritySchemeSet.ALL))
                                {
                                    byte[] data = null;
                                    if (_network.HasSecurityScheme(res.NodeId, SecuritySchemeSet.ALLS2))
                                    {
                                        data = new COMMAND_CLASS_SECURITY_2.SECURITY_2_COMMANDS_SUPPORTED_GET();
                                    }
                                    else if (_network.HasSecurityScheme(res.NodeId, SecuritySchemes.S0))
                                    {
                                        data = new COMMAND_CLASS_SECURITY.SECURITY_COMMANDS_SUPPORTED_GET();
                                    }

                                    COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CMD_ENCAP multiChannelCmd = new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CMD_ENCAP();
                                    multiChannelCmd.commandClass = data[0];
                                    multiChannelCmd.command      = data[1];
                                    multiChannelCmd.parameter    = new List <byte>();
                                    for (int j = 2; j < data.Length; j++)
                                    {
                                        multiChannelCmd.parameter.Add(data[j]);
                                    }
                                    multiChannelCmd.properties1.res                 = 0;
                                    multiChannelCmd.properties1.sourceEndPoint      = 0;
                                    multiChannelCmd.properties2.bitAddress          = 0;
                                    multiChannelCmd.properties2.destinationEndPoint = (byte)(i + 1);
                                    data = multiChannelCmd;

                                    var requestSupported = new RequestDataOperation(0, res.NodeId,
                                                                                    multiChannelCmd, _txOptions,
                                                                                    new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CMD_ENCAP(), 2, 5000);
                                    tmpList.Add(requestSupported);
                                }
                            }

                            _requestEndPointsCapabilities.AddActions(tmpList.ToArray());
                        }
                        SpecificResult.RequestEndPoints = res;
                    }
                }
            }
            else if (result.InnerResults != null && result.InnerResults.Count > 0)
            {
                SpecificResult.RequestEndPointCapabilities = new List <RequestDataResult>();
                foreach (var item in result.InnerResults)
                {
                    if (item is RequestDataResult)
                    {
                        RequestDataResult res = (RequestDataResult)item;
                        if (res && res.Command != null && res.Command.Length > 1 && res.Command[0] == COMMAND_CLASS_MULTI_CHANNEL_V4.ID)
                        {
                            if (res.Command[1] == COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CAPABILITY_REPORT.ID)
                            {
                                COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CAPABILITY_REPORT cmd = res.Command;
                                if (_isIdentical)
                                {
                                    SpecificResult.RequestEndPointCapabilities.Clear();
                                    for (int i = 0; i < _endPoints; i++)
                                    {
                                        SpecificResult.RequestEndPointCapabilities.Add(res);
                                    }
                                }
                                else
                                {
                                    SpecificResult.RequestEndPointCapabilities.Add(res);
                                }
                            }
                            else if (res.Command[1] == COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CMD_ENCAP.ID)
                            {
                                try
                                {
                                    byte[] secureCC = null;
                                    COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CMD_ENCAP cmd = res.Command;
                                    if (cmd.commandClass == COMMAND_CLASS_SECURITY.ID && cmd.command == COMMAND_CLASS_SECURITY.SECURITY_COMMANDS_SUPPORTED_REPORT.ID)
                                    {
                                        COMMAND_CLASS_SECURITY.SECURITY_COMMANDS_SUPPORTED_REPORT supportedS0 = new[] { cmd.commandClass, cmd.command }.Concat(cmd.parameter).ToArray();
                                        secureCC = supportedS0.commandClassSupport.TakeWhile(x => x != 0xEF).ToArray();
                                    }
                                    else if (cmd.commandClass == COMMAND_CLASS_SECURITY_2.ID && cmd.command == COMMAND_CLASS_SECURITY_2.SECURITY_2_COMMANDS_SUPPORTED_REPORT.ID)
                                    {
                                        COMMAND_CLASS_SECURITY_2.SECURITY_2_COMMANDS_SUPPORTED_REPORT supportedS2 = new[] { cmd.commandClass, cmd.command }.Concat(cmd.parameter).ToArray();
                                        secureCC = supportedS2.commandClass.TakeWhile(x => x != 0xEF).ToArray();
                                    }
                                    if (_isIdentical)
                                    {
                                        for (int i = 0; i < _endPoints; i++)
                                        {
                                            _network.SetSecureCommandClasses(new NodeTag(NodeId, (byte)(i + 1)), secureCC);
                                        }
                                    }
                                    else
                                    {
                                        _network.SetSecureCommandClasses(new NodeTag(NodeId, cmd.properties1.sourceEndPoint), secureCC);
                                    }
                                }
                                catch
                                { }
                            }
                        }
                    }
                }
            }
        }