コード例 #1
0
        /// <summary>
        /// Converts the initialization from the config file to bytes and then sends it to the Sensor Network.
        /// </summary>
        public bool SendSensorInitialization()
        {
            bool success = false;
            var  init    = SensorNetworkConfig.GetSensorInitAsBytes();

            try
            {
                // Set up TCP client
                InitializationClient = new TcpClient(IPAddress, Port);
                NetworkStream stream = InitializationClient.GetStream();

                // Send initialization
                stream.Write(init, 0, init.Length);

                stream.Flush();
                stream.Close();
                stream.Dispose();
                InitializationClient.Close();
                InitializationClient.Dispose();

                success = true; // Successfully sent the message without any errors
            }

            // Reaching this exception will set the SensorNetworkServer's status to InitializationSendingFailed
            catch (SocketException)
            {
                logger.Info(Utilities.GetTimeStamp() + $": There was an error sending data to the Sensor Network at {IPAddress}:{Port}; " +
                            $"the address:port may be busy or no server was found. Please verify the address:port is available and restart the " +
                            $"Control Room software.");
            }

            return(success);
        }
コード例 #2
0
        public void TestGetSensorInitAsBytes_AllTrue_AllBytesOne()
        {
            SensorNetworkConfig config = new SensorNetworkConfig(5);

            var bytes = config.GetSensorInitAsBytes();

            // All bytes in the array should be 1
            Assert.IsTrue(bytes.All(singleByte => singleByte == 1));
        }
コード例 #3
0
        public void TestGetSensorInitAsBytes_AllTrue_AllBytesZero()
        {
            SensorNetworkConfig config = new SensorNetworkConfig(5);

            config.ElevationTemp1Init              = false;
            config.AzimuthTemp1Init                = false;
            config.ElevationAccelerometerInit      = false;
            config.AzimuthAccelerometerInit        = false;
            config.CounterbalanceAccelerometerInit = false;
            config.ElevationEncoderInit            = false;
            config.AzimuthEncoderInit              = false;

            var bytes = config.GetSensorInitAsBytes();

            // All bytes in the array should be 0
            Assert.IsTrue(bytes.All(singleByte => singleByte == 0));
        }