Ejemplo n.º 1
0
        public bool LoadLidarConfigFromFile()
        {
            bool              Succeeded = false;
            List <string>     sendData  = new List <string>();
            List <string>     ackData   = new List <string>();
            string            path      = AppDomain.CurrentDomain.BaseDirectory + @"\Lidar\LidarConfig.txt";
            ProgressBarDialog form      =
                new ProgressBarDialog("טוען את המערכת", "מבצע איתחול לחיישן Lidar...");
            Thread thread = new Thread(() => {
                if (File.Exists(path))
                {
                    var reader = new StreamReader(path);
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        if (line.Contains("SEND"))
                        {
                            var lst     = line.Split('\t');
                            string send = lst.Last().Replace("<STX>", ((char)2).ToString())
                                          .Replace("<ETX>", ((char)3).ToString())
                                          .Replace("{resolution}", LidarTelegram.Resolution)
                                          .Replace("{start angle}", LidarTelegram.StartAngle)
                                          .Replace("{stop angle}", LidarTelegram.StopAngle);
                            line            = reader.ReadLine();
                            lst             = line.Split('\t');
                            string received = lst.Last().Replace("<STX>", ((char)2).ToString())
                                              .Replace("<ETX>", ((char)3).ToString())
                                              .Replace("{resolution}", LidarTelegram.Resolution)
                                              .Replace("{start angle}", LidarTelegram.StartAngle)
                                              .Replace("{stop angle}", LidarTelegram.StopAngle);
                            sendData.Add(send);
                            ackData.Add(received);
                        }
                    }
                    for (int i = 0; i < sendData.Count; i++)
                    {
                        //Succeeded = socket.SendWithAck(sendData[i], ackData[i]);
                        Succeeded = socket.Send(sendData[i]);
                        if (!Succeeded)
                        {
                            break;
                        }
                        form.updateProgressBar(100 / sendData.Count);
                    }
                    form.Invoke(new Action(() => form.Close()));
                }
                else
                {
                    Console.WriteLine("File not Exists");
                }
            });

            thread.IsBackground = true;
            thread.Start();
            form.ShowDialog();
            return(Succeeded);
        }
Ejemplo n.º 2
0
 // If needed sending the scan results to serial port & server
 private void PastResultsOn(string data)
 {
     // send data to controller
     if (serialPort != null && serialPort.IsOpen)
     {
         new Thread(() => {
             if (config.getSerialDataType() == Configuration.DataType[0])
             {
                 serialPort.Write(data);
             }
             else if (config.getSerialDataType() == Configuration.DataType[1])
             {
                 foreach (var it in obstacle.Select((x, i) => new { Value = x, Index = i }))
                 {
                     StringBuilder str = new StringBuilder("מסד: " + (it.Index + 1).ToString() + ",");
                     if (gps != null)
                     {
                         str.Append("קורדינטות: " + it.Value.GetLocation(gps) + ",");
                     }
                     str.Append("זווית: " + it.Value.GetAngle() + ",");
                     str.Append("צד" + it.Value.GetSideDistance() + ",");
                     str.Append("מרחק" + it.Value.GetFrontDistance() + ",");
                     str.Append("גובה מתחת לחיישן" + it.Value.GetHeight() + ",");
                     str.AppendLine("רמת התראה" + it.Value.GetAleatLevel() + ".");
                     serialPort.Write(str.ToString());
                 }
             }
         }).Start();
     }
     // send data to server
     if (sendSocket != null)
     {
         new Thread(() => {
             string serverData = data;
             if (gps != null)
             {
                 serverData += " Location " + gps.getLocation().ToString();
             }
             if (gps != null)
             {
                 serverData += " Azimuth " + gps.getAzimuth();
             }
             if (serverStatus.Text == "מחובר")
             {
                 sendSocket.Send(serverData, false);
             }
         }).Start();
     }
 }
Ejemplo n.º 3
0
 // Create Socket Connection with the server.
 // And send to the server configuration for correct display
 private void configServerConnection()
 {
     try {
         bool   isSucceeded           = false;
         int    vehicleWidth          = config.getVehicleWidth();
         int    height                = config.getSensorHeightSetup();
         int    setUpAngle            = config.getAngleSetup();
         float  resolution            = config.getResolution();
         int    startAngle            = config.getStartAngle();
         int    stopAngle             = config.getStopAngle();
         int    sideL                 = config.getSideLowAlert();
         int    sideH                 = config.getSideHighAlert();
         int    FrontL                = config.getFrontLowAlert();
         int    FrontH                = config.getFrontHighAlert();
         int    HoleL                 = config.getHoleLowAlert();
         int    HoleH                 = config.getHoleHighAlert();
         int    minimumHeightDetected = config.getMinimumHeightDetected();
         string srvConfig             = "Config " + vehicleWidth + " " + height + " " +
                                        setUpAngle + " " + resolution + " " + startAngle + " " +
                                        stopAngle + " " + sideL + " " + sideH + " " + FrontL + " " +
                                        FrontH + " " + HoleL + " " + HoleH + " " + minimumHeightDetected;
         IPAddress server = IPAddress.Parse(config.getServerIp());
         IPAddress my     = LocalIP.GetLocalIP(LOCAL_IP_TYPE.INTERNET);
         if (my == null || server == null)
         {
             throw new ProtocolViolationException();
         }
         sendSocket  = new SocketSync(my, server, serverPort, ServerTimeOut);
         isSucceeded = sendSocket.Connect();
         if (isSucceeded)
         {
             isSucceeded = sendSocket.Send(srvConfig, false);
         }
         ServerTimeOut(!isSucceeded);
     } catch (Exception e) {
         Console.WriteLine(e);
     }
 }