Example #1
0
        public void BuildUp()
        {
            //byte array to store 32 acceleration data points
            blobData = new List <byte>();
            azBlob   = new AzimuthAccelerationBlob();
            cbBlob   = new CounterbalanceAccelerationBlob();
            elBlob   = new ElevationAccelerationBlob();
            azAcc    = Acceleration.Generate(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), 1, 2, 3, SensorLocationEnum.AZ_MOTOR);
            cbAcc    = Acceleration.Generate(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), 1, 2, 3, SensorLocationEnum.COUNTERBALANCE);
            elAcc    = Acceleration.Generate(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), 1, 2, 3, SensorLocationEnum.EL_MOTOR);

            //version
            blobData.Add(1);

            //FIFO Size
            blobData.Add(32);

            //SampleFrequency
            byte[] frequency = BitConverter.GetBytes(800);
            blobData.Add(frequency[0]);
            blobData.Add(frequency[1]);

            //GRange
            blobData.Add(1);

            //full resolution
            blobData.Add(BitConverter.GetBytes(true)[0]);

            //label
            char label = 't';

            blobData.Add(BitConverter.GetBytes(label)[0]);


            //time
            byte[] time = BitConverter.GetBytes(azAcc.TimeCaptured);

            for (int i = 0; i < 8; i++)
            {
                blobData.Add(time[i]);
            }

            //acc x
            byte[] accX = BitConverter.GetBytes(azAcc.x);

            for (int i = 0; i < 2; i++)
            {
                blobData.Add(accX[i]);
            }
            //acc x
            byte[] accY = BitConverter.GetBytes(azAcc.y);

            for (int i = 0; i < 2; i++)
            {
                blobData.Add(accY[i]);
            }

            //acc z
            byte[] accZ = BitConverter.GetBytes(azAcc.z);
            for (int i = 0; i < 2; i++)
            {
                blobData.Add(accZ[i]);
            }


            // write 31 data points without time
            for (int size = 0; size < 31; size++)
            {
                //label
                label = 'a';
                blobData.Add(BitConverter.GetBytes(label)[0]);

                //acc x
                for (int i = 0; i < 2; i++)
                {
                    blobData.Add(accX[i]);
                }
                //acc y
                for (int i = 0; i < 2; i++)
                {
                    blobData.Add(accY[i]);
                }

                //acc z
                for (int i = 0; i < 2; i++)
                {
                    blobData.Add(accZ[i]);
                }
            }

            //save the three blobs

            azBlob.BlobList = blobData;
            cbBlob.BlobList = blobData;
            elBlob.BlobList = blobData;


            // create the three comparison acceleration arrays
            azAccArr = new Acceleration[32];
            cbAccArr = new Acceleration[32];
            elAccArr = new Acceleration[32];

            for (int i = 0; i < 32; i++)
            {
                azAccArr[i] = azAcc;
                cbAccArr[i] = cbAcc;
                elAccArr[i] = elAcc;
            }
        }
Example #2
0
        /// <summary>
        /// Constructor used to set the values needed to initialize the components of the class. It will not start waiting for data until
        /// StartSensorMonitoringRoutine() is called.
        ///
        /// The reason the client IP address is a string and not an IPAddress is because none of the TCPClient class's
        /// constructors take an IPAddress. :(
        /// </summary>
        /// <param name="serverIPAddress">This is the IP address the SensorNetworkServer is "listening" to.</param>
        /// <param name="serverPort">This is the port the SensorNetworkServer is "listening" to.</param>
        /// <param name="clientIPAddress">This is the IP address of the SensorNetwork that we will be sending the sensor initialization to.</param>
        /// <param name="clientPort">This is the port of the SensorNetwork that we will be sending the sensor initialization to.</param>
        /// <param name="telescopeId">The Radio Telescope that the SensorNetworkConfig will apply to.</param>
        /// <param name="isSimulation">Tells the SensorNetworkServer if it should initialize the SimulationSensorNetwork,
        /// or if it is connecting to the production hardware (or maybe an outside simulation).</param>
        public SensorNetworkServer(IPAddress serverIPAddress, int serverPort, string clientIPAddress, int clientPort, int telescopeId, bool isSimulation)
        {
            // Initialize main parts of the Sensor Network
            Server = new TcpListener(serverIPAddress, serverPort);
            InitializationClient = new SensorNetworkClient(clientIPAddress, clientPort, telescopeId);

            // Sensor data initialization
            CurrentElevationMotorTemp    = new Temperature[1];
            CurrentElevationMotorTemp[0] = new Temperature();

            CurrentAzimuthMotorTemp    = new Temperature[1];
            CurrentAzimuthMotorTemp[0] = new Temperature();

            CurrentAbsoluteOrientation = new Orientation();

            CurrentElevationMotorAccl    = new Acceleration[1];
            CurrentElevationMotorAccl[0] = new Acceleration();

            CurrentAzimuthMotorAccl    = new Acceleration[1];
            CurrentAzimuthMotorAccl[0] = new Acceleration();

            CurrentCounterbalanceAccl    = new Acceleration[1];
            CurrentCounterbalanceAccl[0] = new Acceleration();

            AbsoluteOrientationOffset = new Orientation();

            // Sensor error initialization
            SensorStatuses = new SensorStatuses();
            SensorStatuses.AzimuthAbsoluteEncoderStatus      = SensorNetworkSensorStatus.Okay;
            SensorStatuses.ElevationAbsoluteEncoderStatus    = SensorNetworkSensorStatus.Okay;
            SensorStatuses.AzimuthTemperature1Status         = SensorNetworkSensorStatus.Okay;
            SensorStatuses.AzimuthTemperature2Status         = SensorNetworkSensorStatus.Okay;
            SensorStatuses.ElevationTemperature1Status       = SensorNetworkSensorStatus.Okay;
            SensorStatuses.ElevationTemperature2Status       = SensorNetworkSensorStatus.Okay;
            SensorStatuses.AzimuthAccelerometerStatus        = SensorNetworkSensorStatus.Okay;
            SensorStatuses.ElevationAccelerometerStatus      = SensorNetworkSensorStatus.Okay;
            SensorStatuses.CounterbalanceAccelerometerStatus = SensorNetworkSensorStatus.Okay;

            // Initialize threads and additional processes, if applicable
            SensorMonitoringThread      = new Thread(() => { SensorMonitoringRoutine(); });
            SensorMonitoringThread.Name = "SensorMonitorThread";

            // We only want to run the internal simulation if the user selected to run the Simulated Sensor Network
            if (isSimulation)
            {
                SimulationSensorNetwork = new SimulationSensorNetwork(serverIPAddress.ToString(), serverPort, IPAddress.Parse(clientIPAddress), clientPort);
            }
            else
            {
                SimulationSensorNetwork = null;
            }

            // Initialize the timeout timer but don't start it yet
            Timeout           = new System.Timers.Timer();
            Timeout.Elapsed  += TimedOut; // TimedOut is the function at the bottom that executes when this elapses
            Timeout.AutoReset = false;

            AzimuthAccBlob        = new AzimuthAccelerationBlob();
            ElevationAccBlob      = new ElevationAccelerationBlob();
            CounterbalanceAccBlob = new CounterbalanceAccelerationBlob();
        }