예제 #1
0
        public void TryGetState_WithInvalidPackageLength()
        {
            var state   = new byte[] { 1, 2, 4, 8, 16, 32, 64, 128 };
            var package = LightPiProtocol.CreatePackage(state);

            // Destroy the length of the package.
            Array.Resize(ref package, 9);

            byte[] returnState;
            var    hasSucceeded = LightPiProtocol.TryParsePackage(package, out returnState);

            Assert.IsFalse(hasSucceeded);
        }
예제 #2
0
        public void TryGetState_WithInvalidPackagePrefix()
        {
            var state   = new byte[] { 1, 2, 4, 8, 16, 32, 64, 128 };
            var package = LightPiProtocol.CreatePackage(state);

            // Destroy the prefix of the package.
            package[0] = 32;

            byte[] returnState;
            var    hasSucceeded = LightPiProtocol.TryParsePackage(package, out returnState);

            Assert.IsFalse(hasSucceeded);
        }
예제 #3
0
        public void TryGetState()
        {
            var state   = new byte[] { 1, 2, 4, 8, 16, 32, 64, 128 };
            var package = LightPiProtocol.CreatePackage(state);

            byte[] returnState;
            var    hasSucceeded = LightPiProtocol.TryParsePackage(package, out returnState);

            Assert.IsTrue(hasSucceeded);
            Assert.AreEqual(state.Length, returnState.Length);

            for (var i = 0; i < state.Length; i++)
            {
                Assert.AreEqual(state[i], returnState[i]);
            }
        }
예제 #4
0
        public CommitChangesResult CommitChanges()
        {
            lock (_syncRoot)
            {
                var state = GenerateState();
                if (!ForceCommits && _previousSentState.SequenceEqual(state))
                {
                    return(new CommitChangesResult(false, null));
                }

                _previousSentState = state;

                var package = LightPiProtocol.CreatePackage(state);
                _udpClient.Send(package, package.Length, _ipEndPoint);

                return(new CommitChangesResult(true, state));
            }
        }
예제 #5
0
        public void GeneratePackage()
        {
            var state   = new byte[] { 1, 2, 4, 8, 16, 32, 64, 128 };
            var package = LightPiProtocol.CreatePackage(state);

            Assert.AreEqual(LightPiProtocol.PackageLength, package.Length);

            // Check the prefix
            for (var i = 0; i < LightPiProtocol.PackagePrefixLength; i++)
            {
                Assert.AreEqual(package[i], LightPiProtocol.PackagePrefix[i], "Prefix is invalid.");
            }

            // Check the state
            for (var i = 0; i < state.Length; i++)
            {
                Assert.AreEqual(state[i], package[i + LightPiProtocol.PackagePrefixLength], "State is invalid.");
            }
        }
예제 #6
0
        public void GeneratePackage_WithInvalidState()
        {
            var state = new byte[] { 1, 2, 4, 8, 16 };

            LightPiProtocol.CreatePackage(state);
        }