示例#1
0
 private void tT()
 {
     if (InvokeRequired)
     {
         Invoke(new MethodInvoker(tT));
     }
     else
     {
         if (this.Text == "Radar Client")
         {
             this.Text = "Radar Client +";
         }
         else
         {
             this.Text = "Radar Client";
         }
         byte[] data;
         if (RadarRequest.SendMRM_SCAN_INFO(out data, _radar.Scans[scanIndex]))
         {
             _async.Send(data);
         }
         if ((++scanIndex) >= _radar.Scans.Count)
         {
             scanIndex = 0;
         }
     }
 }
示例#2
0
 private void radar_ScanReceived(object sender, MRM_SCAN_INFO ts)
 {
     byte[] b;
     if (RadarRequest.SendMRM_SCAN_INFO(out b, ts))
     {
         _async.Send(b);
     }
     //string s = "Scan " + m.MessageID.ToString() + " of length " + m.ScanData.Count.ToString() + " was received";
     //_async.Send(Encoding.Default.GetBytes(s));
     try
     {
         if (wr != null)
         {
             wr.Write(System.DateTime.Now.Ticks + ", MrmFullScanInfo, " + ts.MessageID + ", " + ts.SourceID + ", " + ts.Timestamp + ", ");
             wr.Write(ts.Reserved1 + ", " + ts.Reserved2 + ", " + ts.Reserved3 + ", " + ts.Reserved4 + ", " + ts.ScanStartPS + ", " + ts.ScanStopPS + ", " + ts.ScanStepBins + ", ");
             wr.Write("1, " + ts.AntennaID + ", " + ts.Reserved5 + ", " + ts.NumberOfSamplesTotal);
             foreach (int az in ts.ScanData)
             {
                 wr.Write(", " + az);
             }
             wr.Write('\n');
         }
     }
     catch (ObjectDisposedException e)
     {
         System.Diagnostics.Debug.WriteLine(e);
     }
 }
示例#3
0
        private void radar_ControlReceived(object sender, string s)
        {
            byte[] prefix = new byte[4];
            prefix[0] = prefix[1] = 0xA5;
            RadarRequest.FromUshort((ushort)s.Length, prefix, 2);
            string str = Encoding.Default.GetString(prefix) + s;

            _async.Send(Encoding.Default.GetBytes(str));
        }
示例#4
0
        private void readPort()
        {
            try
            {
                MRM_SCAN_INFO v = new MRM_SCAN_INFO();
                v.ScanData = new List <int>();
                while (KeepReading)
                {
                    while (KeepReading && _port.BytesToRead < 4)
                    {
                        ;
                    }
                    byte[] s = new byte[4];
                    int    k = _port.Read(s, 0, 4);
                    if (k == 4)
                    {
                        int numBytes = 0;
                        if (s[0] == 0xA5 && s[1] == 0xA5)
                        {
                            numBytes = 256 * s[2] + s[3];
                            while (KeepReading && _port.BytesToRead < numBytes)
                            {
                                ;
                            }
                            byte[] r = new byte[numBytes];
                            k = _port.Read(r, 0, numBytes);

                            ushort code = (ushort)((r[0] << 8) + r[1]);
                            if (code == 0xF201)
                            {
                                MRM_SCAN_INFO t;
                                if (RadarRequest.ReceiveMRM_SCAN_INFO(Encoding.Default.GetString(r, 2, r.Length - 2), out t))
                                {
                                    System.Diagnostics.Debug.WriteLine(t.MessageID + " " + t.MessageIndex);
                                    foreach (int i in t.ScanData)
                                    {
                                        v.ScanData.Add(i);
                                    }
                                    if (t.MessageIndex == t.NumberOfMessagesTotal - 1)
                                    {
                                        v.MessageID                = t.MessageID;
                                        v.SourceID                 = t.SourceID;
                                        v.Timestamp                = t.Timestamp;
                                        v.Reserved1                = t.Reserved1;
                                        v.Reserved2                = t.Reserved2;
                                        v.Reserved3                = t.Reserved3;
                                        v.Reserved4                = t.Reserved4;
                                        v.ScanStartPS              = t.ScanStartPS;
                                        v.ScanStopPS               = t.ScanStopPS;
                                        v.ScanStepBins             = t.ScanStepBins;
                                        v.ScanType                 = t.ScanType;
                                        v.Reserved5                = t.Reserved5;
                                        v.AntennaID                = t.AntennaID;
                                        v.OperationalMode          = t.OperationalMode;
                                        v.NumberOfSamplesInMessage = t.NumberOfSamplesInMessage;
                                        v.NumberOfSamplesTotal     = t.NumberOfSamplesTotal;
                                        v.MessageIndex             = t.MessageIndex;
                                        v.NumberOfMessagesTotal    = t.NumberOfMessagesTotal;
                                        //string path = "C:\\Users\\Dustin\\Radar Data\\Radar Scans\\test.csv";
                                        //if (!System.IO.File.Exists(path)) System.IO.File.Create(path);
                                        //using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path, true))
                                        //{
                                        //    sw.Write(v.Timestamp + ", MrmFullScanInfo, " + v.MessageID + ", " + v.SourceID + ", " + v.Timestamp + ", ");
                                        //    sw.Write(v.Reserved1 + ", " + v.Reserved2 + ", " + v.Reserved3 + ", " + v.Reserved4 + ", " + v.ScanStartPS + ", " + v.ScanStopPS + ", " + v.ScanStepBins + ", ");
                                        //    sw.Write("1, " + v.AntennaID + ", " + v.Reserved5 + ", " + v.NumberOfSamplesTotal);
                                        //    foreach (int a in v.ScanData)
                                        //        sw.Write(", " + a);
                                        //    sw.Write('\n');
                                        //    sw.Close();

                                        //}
                                        if (ScanReceived != null)
                                        {
                                            ScanReceived(this, v);
                                        }
                                        v          = new MRM_SCAN_INFO();
                                        v.ScanData = new List <int>();
                                    }
                                }
                            }
                            else
                            {
                                if (this.CommandReceived != null)
                                {
                                    this.CommandReceived(this, Encoding.Default.GetString(r));
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }