Beispiel #1
0
        private void treeResources_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            CoApGet get = new CoApGet();

            get.IpAddress  = lstDevices.SelectedItem.ToString();
            get.ServerPort = Convert.ToInt32(cboPort.Text);
            get.URI        = treeResources.SelectedNode.Text;
            if (NetworkInterface.Instance.UsingFSU)
            {
                byte[]        payload        = get.ToBytes();
                TestStatus    result         = new TestStatus();
                TestManager   m_test_manager = new TestManager();
                BasicReporter r = new BasicReporter(result);
                m_test_manager.TestReporter = r;

                CoApFsuCommand cmd = new CoApFsuCommand();
                cmd.CoApPayload           = get.ToBytes();
                FsuFacade.UseSecurePort   = false;
                FsuFacade.UseNullHeader   = false;
                FsuFacade.RequiresUserPIN = false;
                FileLogger.Write(String.Format("FsuFacade.UseSecurePort={0}", FsuFacade.UseSecurePort));
                FileLogger.Write(String.Format("FsuFacade.UseNullHeader={0}", FsuFacade.UseNullHeader));
                FileLogger.Write(String.Format("FsuFacade.RequiresUserPIN={0}", FsuFacade.RequiresUserPIN));
                CattEng.Test test = cmd.ToTest(lstDevices.SelectedItem.ToString());//);SSNUtils.MiscTypes.fsu_ip_address);

                m_test_manager.Add(test);
                while (!m_test_manager.Empty)
                {
                    Console.WriteLine("Sleeping");
                    Thread.Sleep(50);
                }

                CoApFsuTest     t           = (CoApFsuTest)r.TestResult;
                CoApFsuResponse resp        = (CoApFsuResponse)r.TestResult.ResponseResult.response;
                byte[]          respPayload = resp.Payload;
                //CoAPResponse cr = new CoAPResponse();
                //cr.FromByteStream(respPayload);
                //CoAPPayload p = cr.Payload;
                get.SetGetResult(resp.Payload);//(p.ToStream(0));
            }
            else
            {
                get.Send();
            }
            txtResult.Text = get.Response.ToString();
            Cursor.Current = Cursors.Default;
        }
Beispiel #2
0
        /// <summary>
        /// Handle GET request
        /// </summary>
        /// <param name="sender">the object generating the click</param>
        /// <param name="e">click-related arguments</param>
        private void btnGet_Click(object sender, EventArgs e)
        {
            // Set the wait cursor.
            Cursor.Current = Cursors.WaitCursor;

            // Hide any previous results
            pnlResults.Visible = false;
            lblResult.Visible  = false;

            CoApGet get = (CoApGet)NetworkInterface.Instance.ResourceGetter;

            // Use the device property for the target location.
            get.IpAddress = txtDevice.Text;

            // Use the pre-defined CoAP port number.
            get.ServerPort = GatewaySettings.Instance.CoApPort;

            // Use the resource property for the target resource.
            get.URI = txtURI.Text;

            // Send the request!
            get.Send();

            // Parse out the GET response.
            try
            {
                txtResult.Text = get.Response.ToString();
                if (get.Response.Payload.Value != null)
                {
                    if (get.Response.Payload.Value.Length != 0)
                    {
                        txtResult.Text += HdkUtils.BytesToHexView(get.Response.Payload.Value);
                    }
                }
            }
            catch
            {
                txtResult.Text = "Unable to retreive response from resource";
            }

            // Finally, make the results visible.
            pnlResults.Visible = true;
            lblResult.Visible  = true;

            // Reset the wait cursor.
            Cursor.Current = Cursors.Default;
        }