Exemplo n.º 1
0
        private void setConfigurationThread()
        {
            StmConfig config = null;

            this.Invoke(new Action(() => { config = createConfiguration(); }));
            try
            {
                config = stmConnection.updateConfiguration(config);
            }
            catch (Exception ex)
            {
                try
                {
                    config = stmConnection.updateConfiguration(config);
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                    return;
                }
            }
            if (InvokeRequired)
            {
                this.Invoke(new Action(() => { parseConfiguration(config); }));
            }
        }
        public StmConnection(IPAddress stmConfigAddress, int udpStreamingPort)
        {
            LastConfiguration     = new StmConfig();
            this.stmConfigAddress = stmConfigAddress;

            pcHost    = new IPEndPoint(IPAddress.Any, udpStreamingPort);
            udpClient = new UdpClient(udpStreamingPort, AddressFamily.InterNetwork);

            receiveTask = Task.Run(() => receiveByUdpAsync());
        }
        public StmConfig updateConfiguration(StmConfig stmConfig)
        {
            WebClient client = new WebClient();

            byte[] response       = client.UploadData("http://" + stmConfigAddress.ToString() + "/config", "PUT", Encoding.ASCII.GetBytes(stmConfig.toString()));
            String responseString = System.Text.Encoding.UTF8.GetString(response);

            LastConfiguration = StmConfig.parse(responseString);
            return(LastConfiguration);
        }
Exemplo n.º 4
0
 private void parseConfiguration(StmConfig configuration)
 {
     lock (locker)
     {
         endpointTextBox.Text    = configuration.UdpEndpointIP;
         portTextBox.Text        = configuration.UdpEndpointPort.ToString();
         windowTypeComboBox.Text = configuration.WindowType;
         freqTextBox.Text        = configuration.SamplingFrequency.ToString();
         delayTextBox.Text       = configuration.AmplitudeSamplingDelay.ToString();
     }
 }
        public async Task <StmConfig> getConfiguration()
        {
            HttpClient client = new HttpClient();

            client.Timeout = TimeSpan.FromSeconds(2);
            HttpResponseMessage responseMsg = await client.GetAsync("http://" + stmConfigAddress.ToString() + "/config");

            responseMsg.EnsureSuccessStatusCode();
            string responseString = await responseMsg.Content.ReadAsStringAsync();

            client.Dispose();

            LastConfiguration = StmConfig.parse(responseString);
            return(LastConfiguration);
        }
Exemplo n.º 6
0
        private StmConfig createConfiguration()
        {
            StmConfig configuration = new StmConfig();

            lock (locker)
            {
                try
                {
                    IPAddress address = IPAddress.Parse(endpointTextBox.Text);
                    configuration.UdpEndpointIP = address.ToString();
                    endpointTextBox.Text        = address.ToString();
                }
                catch (Exception)
                {
                    endpointTextBox.Text        = stmConnection.LastConfiguration.UdpEndpointIP;
                    configuration.UdpEndpointIP = stmConnection.LastConfiguration.UdpEndpointIP;
                }

                try
                {
                    int port = Int32.Parse(portTextBox.Text);
                    if (port < 0 || port > 65535)
                    {
                        throw new Exception();
                    }
                    configuration.UdpEndpointPort = port;
                }
                catch (Exception)
                {
                    portTextBox.Text = stmConnection.LastConfiguration.UdpEndpointPort.ToString();
                    configuration.UdpEndpointPort = stmConnection.LastConfiguration.UdpEndpointPort;
                }

                try
                {
                    int frequency = Int32.Parse(freqTextBox.Text);
                    if (frequency < 0 || frequency > 192000)
                    {
                        throw new Exception();
                    }
                    configuration.SamplingFrequency = frequency;
                }
                catch (Exception)
                {
                    freqTextBox.Text = stmConnection.LastConfiguration.SamplingFrequency.ToString();
                    configuration.SamplingFrequency = stmConnection.LastConfiguration.SamplingFrequency;
                }

                try
                {
                    int samplpingDelay = Int32.Parse(delayTextBox.Text);
                    if (samplpingDelay <= 0 || samplpingDelay > 10000)
                    {
                        throw new Exception();
                    }
                    configuration.AmplitudeSamplingDelay = samplpingDelay;
                }
                catch (Exception)
                {
                    delayTextBox.Text = stmConnection.LastConfiguration.AmplitudeSamplingDelay.ToString();
                    configuration.AmplitudeSamplingDelay = stmConnection.LastConfiguration.AmplitudeSamplingDelay;
                }

                try
                {
                    string windowType = "";
                    if (!windowTypeDictionary.TryGetValue(windowTypeComboBox.Text, out windowType))
                    {
                        throw new Exception();
                    }

                    configuration.WindowType = windowType;
                }
                catch (Exception)
                {
                    configuration.WindowType = stmConnection.LastConfiguration.WindowType;
                    windowTypeComboBox.Text  = windowTypeDictionary.FirstOrDefault(x => x.Value == stmConnection.LastConfiguration.WindowType).Key;
                }
            }
            return(configuration);
        }