Exemplo n.º 1
0
        public override ActionBase SubstituteActionInternal(ApiOperation action)
        {
            ActionBase ret = null;

            if (IsActive && (action is SendDataOperation || action is SendDataExOperation) &&
                action.SubstituteSettings.HasFlag(SubstituteFlags.UseCrc16Encap))
            {
                byte[] data = null;
                if (action is SendDataOperation)
                {
                    data = ((SendDataOperation)action).Data;
                }
                else
                {
                    data = ((SendDataExOperation)action).Data;
                }
                if (data.Length > 1)
                {
                    if (data[0] != COMMAND_CLASS_CRC_16_ENCAP.ID)
                    {
                        var substitutedData = new COMMAND_CLASS_CRC_16_ENCAP.CRC_16_ENCAP();
                        substitutedData.commandClass = data[0];
                        substitutedData.command      = data[1];
                        substitutedData.data         = new List <byte>();

                        for (int i = 2; i < data.Length; i++)
                        {
                            substitutedData.data.Add(data[i]);
                        }

                        substitutedData.checksum = new byte[] { 0, 0 };
                        byte[] tmp = substitutedData;
                        ushort crc = Utils.Tools.ZW_CreateCrc16(null, 0, tmp, (byte)(tmp.Length - 2));
                        substitutedData.checksum = new[] { (byte)(crc >> 8), (byte)crc };

                        data = substitutedData;
                        if (action is SendDataOperation)
                        {
                            ((SendDataOperation)action).Data = data;
                        }
                        else
                        {
                            ((SendDataExOperation)action).Data = data;
                        }
                        ret = action;
                    }
                }
            }
            return(ret);
        }
Exemplo n.º 2
0
        public ActionBase SubstituteAction(ActionBase action)
        {
            ActionBase ret = null;

            ApiOperation apiAction = action as ApiOperation;

            if (apiAction != null)
            {
                Action <IActionItem> completedCallback = action.CompletedCallback;
                ActionToken          token             = action.Token;
                ActionResult         result            = action.Result;
                ActionBase           parent            = action.ParentAction;
                int actionId = action.Id;

                ret = SubstituteActionInternal(apiAction);

                if (ret != null)
                {
                    ret.Id           = actionId;
                    ret.ParentAction = parent;
                    ret.Token        = token;
                    if (ret.CompletedCallback == null)
                    {
                        ret.CompletedCallback = completedCallback;
                    }
                    else
                    {
                        var newCompletedCallback = ret.CompletedCallback;
                        ret.CompletedCallback = (x) =>
                        {
                            newCompletedCallback(x);
                            completedCallback(x);
                        };
                    }
                }
            }
            return(ret);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public virtual ActionBase SubstituteActionInternal(ApiOperation action)
        {
            ActionBase ret = null;

            return(ret);
        }