Пример #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
        public void Crc16EncapCommandSerialize()
        {
            // SDS12657-12-Z-Wave-Command-Class-Specification-A-M.pdf | 4.41.1 CRC-16 Encapsulated Command
            // 4.41.2 Example
            // CRC - 16 Encapsulation Command Class = 0x56
            // CRC - 16 Encapsulation Command = 0x01
            // Basic Command Class = 0x20
            // Basic Get Command = 0x02
            // CRC1 = 0x4D
            // CRC2 = 0x26

            var command = Crc16Command.Encapsulate(new Command(CommandClass.Basic, 0x02));
            var payload = command.Serialize().ToArray();

            Assert.AreEqual(payload[0], (byte)CommandClass.Crc16Encap);
            Assert.AreEqual(payload[1], 0x01);
            Assert.AreEqual(payload[2], (byte)CommandClass.Basic);
            Assert.AreEqual(payload[3], 0x02);
            Assert.AreEqual(payload[4], 0x4D);
            Assert.AreEqual(payload[5], 0x26);
        }
Пример #3
0
        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);
        }