Example #1
0
        private IdpResponseCode OnEnumerateNodesCommand(UInt16 source, UInt16 address, OutgoingTransaction outgoing)
        {
            if (_unenumeratedNodes.Count != 0)
            {
                var node = _unenumeratedNodes.First();

                node.Address = address;
                //node.SetEnumerated();

                if (MarkEnumerated(node))
                {
                    outgoing.Write(true);
                    outgoing.WithResponseCode(IdpResponseCode.OK);

                    SendRequest(address, source, outgoing);

                    return(IdpResponseCode.Deferred);
                }
                else
                {
                    node.Address = UnassignedAddress;

                    outgoing.Write(false);

                    return(IdpResponseCode.InvalidParameters);
                }
            }
            else
            {
                outgoing.Write(false);
            }

            return(IdpResponseCode.OK);
        }
Example #2
0
        public IdpPacket ProcessPayload(UInt16 nodeAddress, IdpPacket packet)
        {
            var incoming = new IncomingTransaction(packet);
            var outgoing = new OutgoingTransaction(0xA000, incoming.TransactionId, IdpCommandFlags.None);

            if (_commandHandlers.ContainsKey(incoming.CommandId))
            {
                outgoing.Write((byte)IdpResponseCode.OK);
                outgoing.Write(incoming.CommandId);

                var responseCode = _commandHandlers[incoming.CommandId](incoming, outgoing);

                if (incoming.Flags.HasFlag(IdpCommandFlags.ResponseExpected))
                {
                    outgoing.WithResponseCode(responseCode);

                    return(outgoing.ToPacket(nodeAddress, packet.Source));
                }
            }
            else
            {
                outgoing.Write((byte)IdpResponseCode.UnknownCommand);
                outgoing.Write(incoming.CommandId);

                return(outgoing.ToPacket(nodeAddress, packet.Source));
            }

            return(null);
        }