Merge branch 'ping' into 1.0-pre12
authorStricted <info@stricted.net>
Thu, 12 Jan 2017 04:25:44 +0000 (05:25 +0100)
committerStricted <info@stricted.net>
Thu, 12 Jan 2017 04:25:44 +0000 (05:25 +0100)
SpeedportHybridControl.Implementations/util.cs
SpeedportHybridControl/MainWindow.xaml.cs

index a3c814e65564f317a801092fc0ee9d82df0a097d..4c807bbcae054159f6a20a4500d2a0a9cbcac13d 100644 (file)
@@ -2,8 +2,13 @@
 using Newtonsoft.Json.Linq;
 using System;
 using System.Linq;
+using System.Net;
+using System.Net.NetworkInformation;
+using System.Net.Sockets;
 using System.Security.Cryptography;
 using System.Text;
+using System.Threading;
+using System.Windows;
 using System.Windows.Media;
 using System.Xml;
 
@@ -238,5 +243,53 @@ namespace SpeedportHybridControl.Implementations
 
             return false;
         }
+
+               public static bool checkLteModul ()
+               {
+                       Ping ping = new Ping();
+                       try
+                       {
+                               PingReply reply = ping.Send("172.10.10.1", 2);
+
+                               if (reply.Status == IPStatus.Success)
+                               {
+                                       return true;
+                               }
+#if DEBUG
+                               else
+                               {
+                                       LogManager.WriteToLog("unable to reach LTE Modul");
+                               }
+#endif
+                       }
+                       catch (PingException) {
+#if DEBUG
+                               LogManager.WriteToLog("unable to reach LTE Modul");
+#endif
+                       }
+
+                       return false;
+               }
+
+               public static void sendCommandToLteModul (string Command)
+               {
+                       if (checkLteModul().Equals(true))
+                       {
+                               try
+                               {
+                                       Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
+                                       IPAddress serverAddr = IPAddress.Parse("172.10.10.1");
+                                       IPEndPoint endPoint = new IPEndPoint(serverAddr, 1280);
+                                       byte[] cmd = Encoding.ASCII.GetBytes(Command);
+                                       sock.SendTo(cmd, endPoint);
+                                       sock.Close();
+                               }
+                               catch (Exception)
+                               {
+                                       new Thread(() => { MessageBox.Show("couldn't send Command to LTE Modul", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error); }).Start();
+                                       LogManager.WriteToLog("couldn't send Command to LTE Modul");
+                               }
+                       }
+               }
     }
 }
index 65183cf4ca15e78ded4d0da8163863a84ed2989b..f88e7745cd5c14021bbc5e86d05e9f3165b73152 100644 (file)
@@ -1,4 +1,6 @@
-using System.Windows;
+using SpeedportHybridControl.Implementations;
+using System.Threading;
+using System.Windows;
 
 namespace SpeedportHybridControl
 {
@@ -10,6 +12,16 @@ namespace SpeedportHybridControl
         public MainWindow()
         {
             InitializeComponent();
-        }
+                       /*
+                       if (util.checkLteModul())
+                       {
+                               MessageBox.Show("ABC", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
+                       }
+                       else
+                       {
+                               MessageBox.Show("DEF", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Error);
+                       }
+                       */
+               }
     }
 }