コード例 #1
0
 private Command CreateTransportCommand(Command command)
 {
     // addressing an enpoint?
     if (_endpointID != 0)
     {
         // yes, so wrap command in a encapsulated multi channel command
         command = MultiChannelCommand.Encapsulate(0, _endpointID, command);
     }
     // additional CRC16 checksum required?
     if (Node.UseCrc16Checksum)
     {
         // yes, so wrap command in a encapsulated CRC16 endcap command
         command = Crc16Command.Encapsulate(command);
     }
     return(command);
 }
コード例 #2
0
ファイル: CommandTests.cs プロジェクト: roblans/ZWave4Net-v2
        public void MultiEncapDecap()
        {
            var crc16Command = Crc16Command.Encapsulate(MultiChannelCommand.Encapsulate(0, 1, new Command(CommandClass.Basic, 0x02)));

            Assert.AreEqual(crc16Command.CommandClass, CommandClass.Crc16Encap);
            Assert.AreEqual(crc16Command.CommandID, 0x01);

            var multiChannelCommand = (MultiChannelCommand)crc16Command.Decapsulate();

            Assert.AreEqual(multiChannelCommand.SourceEndpointID, 0);
            Assert.AreEqual(multiChannelCommand.TargetEndpointID, 1);
            Assert.AreEqual(multiChannelCommand.CommandClass, CommandClass.MultiChannel);
            Assert.AreEqual(multiChannelCommand.CommandID, 0x0D);

            var basicCommand = multiChannelCommand.Decapsulate();

            Assert.AreEqual(basicCommand.CommandClass, CommandClass.Basic);
            Assert.AreEqual(basicCommand.CommandID, 0x02);

            var commands = Encapsulation.Flatten(crc16Command).ToArray();

            Assert.AreEqual(commands.Length, 3);

            crc16Command = (Crc16Command)commands[0];
            Assert.AreEqual(crc16Command.CommandClass, CommandClass.Crc16Encap);
            Assert.AreEqual(crc16Command.CommandID, 0x01);

            multiChannelCommand = (MultiChannelCommand)commands[1];
            Assert.AreEqual(multiChannelCommand.SourceEndpointID, 0);
            Assert.AreEqual(multiChannelCommand.TargetEndpointID, 1);
            Assert.AreEqual(multiChannelCommand.CommandClass, CommandClass.MultiChannel);
            Assert.AreEqual(multiChannelCommand.CommandID, 0x0D);

            basicCommand = commands[2];
            Assert.AreEqual(basicCommand.CommandClass, CommandClass.Basic);
            Assert.AreEqual(basicCommand.CommandID, 0x02);
        }