コード例 #1
0
        /// <summary>
        /// This will send a request for sensor initialization to the SensorNetworkServer, where the
        /// SensorNetworkServer will then respond with sensor initialization.
        /// </summary>
        /// <returns>The sensor initialization byte array.</returns>
        private byte[] RequestAndAcquireSensorInitialization()
        {
            // Start the server that will expect the Sensor Configuration
            Server.Start();

            // Wait for the SensorNetworkClient to send the initialization
            TcpClient localClient;

            byte[] receivedInit = new byte[SensorNetworkConstants.SensorNetworkSensorCount];

            // Once this line is passed, we have connected and received the initialization
            localClient = Server.AcceptTcpClient();
            logger.Info($"{Utilities.GetTimeStamp()}: Simulation Sensor Network received Sensor Initialization");
            ServerStream = localClient.GetStream();
            ServerStream.Read(receivedInit, 0, receivedInit.Length);

            // We will now dispose of the Server/Stream components because that is the only time we are using it
            ServerStream.Close();
            ServerStream.Dispose();
            Server.Stop();

            return(receivedInit);
        }
コード例 #2
0
 /// <summary>
 /// This is used to start the simulation Sensor Network. Calling this is equivalent to powering off the Teensy.
 /// </summary>
 public void EndSimulationSensorNetwork()
 {
     if (CurrentlyRunning)
     {
         CurrentlyRunning = false;
         if (Client != null)
         {
             Client.Dispose();
         }
         if (ClientStream != null)
         {
             ClientStream.Close();
             ClientStream.Dispose();
         }
         Server.Stop();
         if (ServerStream != null)
         {
             ServerStream.Close();
             ServerStream.Dispose();
         }
         SimulationSensorMonitoringThread.Join();
     }
 }