Beispiel #1
0
        public void Should_encode_szx()
        {
            var szx1 = BlockOption.EncodeSzx(16);
            var szx2 = BlockOption.EncodeSzx(1024);

            Assert.AreEqual(0, szx1);
            Assert.AreEqual(6, szx2);
        }
Beispiel #2
0
        public void Should_construct_block2_option()
        {
            var option = new BlockOption(OptionNumber.Block2, 2, 0, BlockOption.EncodeSzx(32));

            Assert.AreEqual(33, ByteConverter.GetInt(option.Value));
            Assert.AreEqual(2, option.Num);
            Assert.AreEqual(0, option.M);
            Assert.AreEqual(32, BlockOption.DecodeSzx(option.Szx));
        }
Beispiel #3
0
        public void Should_construct_block1_option()
        {
            var option = new BlockOption(OptionNumber.Block1, 3, 1, BlockOption.EncodeSzx(128));

            Assert.AreEqual(59, ByteConverter.GetInt(option.Value));
            Assert.AreEqual(3, option.Num);
            Assert.AreEqual(1, option.M);
            Assert.AreEqual(128, BlockOption.DecodeSzx(option.Szx));
        }
Beispiel #4
0
        public static Response Simple_atomic_blockwise_put_response(int num)
        {
            var m        = num < 2 ? 1 : 0;
            var response = new Response(MessageType.Acknowledgement, CodeRegistry.Changed)
            {
                Id = 1234, Token = ByteConverter.GetBytes(0x17)
            };

            response.AddOption(new BlockOption(OptionNumber.Block1, num, m, BlockOption.EncodeSzx(128)));
            return(response);
        }
Beispiel #5
0
        public TransferLayer(ILayer lowerLayer, int blockSize)
            : base(lowerLayer)
        {
            _tokenManager = new TokenManager();
            _incomplete   = new Dictionary <string, Message>();

            if (blockSize > 0)
            {
                _szx = BlockOption.EncodeSzx(blockSize);
            }
        }
Beispiel #6
0
        // example 2 (figure 3): Blockwise GET with early negotiation
        public static Request Blockwise_get_with_early_negotiation(int num)
        {
            var id      = 1234 + num;
            var uri     = new Uri("coap://server/status");
            var request = new Request(CodeRegistry.Get, true)
            {
                Id = id, Uri = uri
            };

            request.AddOption(new BlockOption(OptionNumber.Block2, num, 0, BlockOption.EncodeSzx(64)));
            return(request);
        }
Beispiel #7
0
        public static Response Simple_blockwise_get_block(int num)
        {
            var id    = 1234 + num;
            var m     = num < 2 ? 1 : 0;
            var block = new Response(MessageType.Acknowledgement, CodeRegistry.Content)
            {
                Id = id, Payload = new byte[128]
            };

            block.AddOption(new BlockOption(OptionNumber.Block2, num, m, BlockOption.EncodeSzx(128)));
            return(block);
        }