private void handleClient(TcpClient socket) { String rawData; String data; NetworkStream ns = socket.GetStream(); StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns); sw.WriteLine("@CONNECTION@OK@"); sw.Flush(); Gps dispositive = new Gps(); while (true) { try { // do things rawData = sr.ReadLine(); Console.WriteLine("Raw data: " + rawData); // debug data = hexaToString(rawData); Console.WriteLine("String data: " + data); // debug String[] rippedMessage = data.Split('@'); // rawdata = imei@timestamp@lng@lat@speed@satellites@altitude@angle@in7(encendido/apagado)@in25(batería) dispositive.Imei = rippedMessage[1]; // response @OK@direction@velocidad@altitud@batería String response = "OK"; String direction = geoReverse(rippedMessage[2], rippedMessage[3]); response += "@" + direction; response += "@" + rippedMessage[4]; response += "@" + rippedMessage[6]; float battery = float.Parse(rippedMessage[9]) / 1000; response += "@" + battery.ToString(); sw.WriteLine(response); sw.Flush(); } catch (Exception err) { Console.WriteLine(err.ToString()); break; } } ns.Close(); socket.Close(); // finish }
private void handleClient(TcpClient socket) { String rawData; String data; NetworkStream ns = socket.GetStream(); StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns); sw.WriteLine("@CONNECTION@OK@"); sw.Flush(); Gps dispositive = new Gps(); while (true) { try { // do things rawData = sr.ReadLine(); Console.WriteLine("Raw data: " + rawData); // debug data = hexaToString(rawData); Console.WriteLine("String data: " + data); // debug String[] rippedMessage = data.Split('@'); dispositive.Imei = rippedMessage[0]; dispositive.CurrentTimestamp = Int32.Parse(rippedMessage[1]); dispositive.CurrentLng = float.Parse(rippedMessage[2]); dispositive.CurrentLat = float.Parse(rippedMessage[3]); dispositive.CurrentSpeed = float.Parse(rippedMessage[4]); dispositive.CurrentSatellites = Int32.Parse(rippedMessage[5]); dispositive.CurrentAltitude = Int32.Parse(rippedMessage[6]); dispositive.CurrentAngle = float.Parse(rippedMessage[7]); if (rippedMessage[8] == "0") { dispositive.CurrentOn = false; } else { dispositive.CurrentOn = true; } dispositive.Battery = float.Parse(rippedMessage[9]); // response @OK@direction@velocidad@altitud@batería updateDispositive(dispositive); double shortDistance = getShortDistance(dispositive); String response = "OK"; String direction = geoReverse(rippedMessage[2], rippedMessage[3]); response += "@" + direction; response += "@" + rippedMessage[4]; response += "@" + rippedMessage[6]; float battery = float.Parse(rippedMessage[9]) / 1000; response += "@" + battery.ToString(); response += "@" + shortDistance.ToString(); sw.WriteLine(response); sw.Flush(); } catch (Exception err) { Console.WriteLine(err.ToString()); break; } } ns.Close(); socket.Close(); // finish }
private double getShortDistance(Gps dispositive) { Console.WriteLine(dispositives.Count); if (dispositives.Count > 2) { double minDistance = double.MaxValue; foreach (Gps disp in dispositives) { double distance = DistanceTo(dispositive.CurrentLat, dispositive.CurrentLng, disp.CurrentLat, disp.CurrentLng); if (distance<minDistance) { minDistance = distance; } } return minDistance; } else { return 0; } }
private void updateDispositive(Gps dispositive) { Boolean inList = false; for (int i = 0; i < dispositives.Count; i++) { if (dispositives[i].Imei == dispositive.Imei) { inList = true; dispositives[i] = dispositive; break; } } if (!inList) { dispositives.Add(dispositive); } }
private int getShortDistance(Gps dispositive) { if (dispositives.Count > 1) { foreach (Gps disp in dispositives) { DistanceTo(dispositive.CurrentLat, dispositive.CurrentLng, disp.CurrentLat, disp.CurrentLng); } return 0; } else { return 0; } }
private Boolean getShortDistance(Gps dispositive) { if (dispositives.Count > 1) { foreach (Gps disp in dispositives) { DistanceTo(dispositive.CurrentLat, dispositive.CurrentLng, disp.CurrentLat, disp.CurrentLng); } } else { return null; } }
private void getShortDistance(Gps dispositive) { foreach (Gps disp in dispositives) { distanceTo(dispositive.CurrentLat, dispositive.CurrentLng, disp.CurrentLat, disp.CurrentLng); } }
private void getShortDistance(Gps dispositive) { }
private double getShortDistance(Gps dispositive) { if (dispositives.Count > 1) { double minDistance = double.MaxValue; foreach (Gps disp in dispositives) { DistanceTo(dispositive.CurrentLat, dispositive.CurrentLng, disp.CurrentLat, disp.CurrentLng); } return 0; } else { return 0; } }
private void getShortDistance(Gps dispositive) { foreach (Gps disp in dispositives) { } }