Files
AiQ_GUI/Camera/Router.cs

92 lines
3.2 KiB
C#
Raw Permalink Normal View History

2025-09-02 15:32:24 +01:00
using Renci.SshNet;
namespace AiQ_GUI
{
internal class Router
{
const string RouterUsername = "router";
const string RouterPassword = "MAV999";
public static RouterInfo GetRouterInfo()
{
RouterInfo Router = new();
try
{
using SshClient client = new("192.168.1.1", RouterUsername, RouterPassword);
client.Connect();
Router.Strength = Convert.ToInt16(client.RunCommand("uci -P /var/state/ get mobile.dev_info1.strength").Result);
Router.SimStatus = client.RunCommand("uci -P /var/state/ get mobile.dev_info1.simstatus").Result;
Router.Port3Status = client.RunCommand("swconfig dev switch0 port 3 get link").Result;
Router.Port4Status = client.RunCommand("swconfig dev switch0 port 4 get link").Result;
SshCommand? pingCmd = client.RunCommand("ping -c 2 -W 2 8.8.8.8"); // Run ping and check exit status
Router.GoodPing = pingCmd.ExitStatus == 0;
client.Disconnect();
return Router;
}
catch
{
MainForm.Instance.AddToActionsList("Is the router on the network? Has the MAV Config file been applied?");
}
return null;
}
public static bool CheckRouter(RouterInfo Router)
{
if (Router == null)
return false;
bool PassTest = true;
double Strength = Math.Round((Router.Strength / 31.0) * 100.0, 2); // Strength is out of 31, so we convert it to a percentage
if (Strength < 25.0)
{
MainForm.Instance.AddToActionsList($"Router signal strength is {Strength} which is below 25%. Please check the router connection.");
PassTest = false;
}
if (!Router.SimStatus.Contains("SIM Ready"))
{
MainForm.Instance.AddToActionsList($"SIM card is not ready. {Router.SimStatus} Please check the SIM card status.");
PassTest = false;
}
if (!Router.Port3Status.Contains("port:3 link:up speed:100baseT full-duplex"))
{
MainForm.Instance.AddToActionsList($"Port 3 is not connected properly. {Router.Port3Status} Please check the connection.");
PassTest = false;
}
if (!Router.Port4Status.Contains("port:4 link:up speed:100baseT full-duplex"))
{
MainForm.Instance.AddToActionsList($"Port 4 is not connected properly. {Router.Port4Status} Please check the connection.");
PassTest = false;
}
if (!Router.GoodPing)
{
MainForm.Instance.AddToActionsList("Router could not ping 8.8.8.8. Please check the online connection.");
PassTest = false;
}
return PassTest;
}
}
class RouterInfo
{
public int Strength { get; set; } = 0;
public string SimStatus { get; set; } = string.Empty;
public string Port3Status { get; set; } = string.Empty;
public string Port4Status { get; set; } = string.Empty;
public bool GoodPing { get; set; } = false;
}
}