Пример #1
0
        public static bool SetMulti(Controller controller, byte nodeId, byte endpoint, bool value)
        {
            Common.logger.Info("Multi for node {0}: {1} {2}", nodeId, endpoint, value);
            var cmd = new COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CMD_ENCAP();

            cmd.properties1.sourceEndPoint      = endpoint;
            cmd.properties2.destinationEndPoint = endpoint;
            cmd.commandClass = 32;
            cmd.command      = 1;
            cmd.parameter    = value ? new byte[] { 255 } : new byte[] { 0 };

            var setBasic = controller.SendData(nodeId, cmd, txOptions);

            return(setBasic.TransmitStatus == TransmitStatuses.CompleteOk);
        }
Пример #2
0
 private byte[] EncapData(byte[] data, byte destinationEndPoint)
 {
     if (destinationEndPoint > 0)
     {
         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 i = 2; i < data.Length; i++)
         {
             multiChannelCmd.parameter.Add(data[i]);
         }
         multiChannelCmd.properties1.res                 = 0;
         multiChannelCmd.properties1.sourceEndPoint      = 0;
         multiChannelCmd.properties2.bitAddress          = 0;
         multiChannelCmd.properties2.destinationEndPoint = destinationEndPoint;
         data = multiChannelCmd;
     }
     return(data);
 }
Пример #3
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
                                { }
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        public override ActionBase SubstituteActionInternal(ApiOperation action)
        {
            ActionBase ret = null;

            if (IsActive)
            {
                var sendDataAction = action as SendDataOperation;
                if (sendDataAction != null && sendDataAction.IsFollowup)
                {
                    if (IsSupervisionSupported(sendDataAction.NodeId))
                    {
                        if (sendDataAction.Data.Length >= 2 && (sendDataAction.Data[0] != COMMAND_CLASS_SUPERVISION.ID || sendDataAction.Data[1] != COMMAND_CLASS_SUPERVISION.SUPERVISION_GET.ID))
                        {
                            if (sendDataAction.Data[0] == COMMAND_CLASS_MULTI_CHANNEL_V4.ID && sendDataAction.Data[1] == COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CMD_ENCAP.ID)
                            {
                                COMMAND_CLASS_MULTI_CHANNEL_V4.MULTI_CHANNEL_CMD_ENCAP multiChannelCommand = sendDataAction.Data;
                                List <byte> innerdata = new List <byte>();
                                innerdata.Add(multiChannelCommand.commandClass);
                                innerdata.Add(multiChannelCommand.command);
                                if (multiChannelCommand.parameter != null)
                                {
                                    innerdata.AddRange(multiChannelCommand.parameter);
                                }
                                var supervisionGetCmd = new COMMAND_CLASS_SUPERVISION.SUPERVISION_GET()
                                {
                                    properties1 = new COMMAND_CLASS_SUPERVISION.SUPERVISION_GET.Tproperties1()
                                    {
                                        sessionId = _sessionId++
                                    },
                                    encapsulatedCommandLength = (byte)innerdata.Count,
                                    encapsulatedCommand       = innerdata.ToArray()
                                };
                                byte[] supervisionGetCmdData = supervisionGetCmd;
                                multiChannelCommand.commandClass = supervisionGetCmdData[0];
                                multiChannelCommand.command      = supervisionGetCmdData[1];
                                if (supervisionGetCmdData.Length > 2)
                                {
                                    var tmp = new byte[supervisionGetCmdData.Length - 2];
                                    Array.Copy(supervisionGetCmdData, 2, tmp, 0, tmp.Length);
                                    multiChannelCommand.parameter = tmp;
                                }
                                sendDataAction.Data = multiChannelCommand;
                                ret = sendDataAction;
                            }
                            else
                            {
                                var substitutedData = new COMMAND_CLASS_SUPERVISION.SUPERVISION_GET()
                                {
                                    properties1 = new COMMAND_CLASS_SUPERVISION.SUPERVISION_GET.Tproperties1()
                                    {
                                        sessionId = _sessionId++
                                    },
                                    encapsulatedCommandLength = (byte)sendDataAction.Data.Length,
                                    encapsulatedCommand       = sendDataAction.Data
                                };
                                sendDataAction.Data = substitutedData;
                                ret = sendDataAction;
                            }
                        }
                    }
                }
            }
            return(ret);
        }