91
MainForm.cs
91
MainForm.cs
@@ -14,10 +14,10 @@ namespace robospot_camera_finder
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private BindingList<Camera> allCameras = new();
|
||||
private BindingList<Camera> all_cameras = new();
|
||||
|
||||
public static string CAM_USERNAME = "admin";
|
||||
public static string CAM_PASSWORD = "RoboSpot10";
|
||||
public static string cam_username = "admin";
|
||||
public static string cam_password = "RoboSpot10";
|
||||
|
||||
// UDP discovery constants
|
||||
private const int SEND_PORT = 7701;
|
||||
@@ -34,19 +34,19 @@ namespace robospot_camera_finder
|
||||
{
|
||||
public Camera(string name, string ip, string location, string serial)
|
||||
{
|
||||
cameraName = name;
|
||||
cameraIP = ip;
|
||||
cameraLocation = location;
|
||||
cameraSerial = serial;
|
||||
camera_name = name;
|
||||
camera_ip = ip;
|
||||
camera_location = location;
|
||||
camera_serial = serial;
|
||||
}
|
||||
|
||||
public string cameraName { get; set; }
|
||||
public string camera_name { get; set; }
|
||||
|
||||
public string cameraIP { get; set; }
|
||||
public string camera_ip { get; set; }
|
||||
|
||||
public string cameraLocation { get; set; }
|
||||
public string camera_location { get; set; }
|
||||
|
||||
public string cameraSerial { get; set; }
|
||||
public string camera_serial { get; set; }
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
@@ -98,26 +98,26 @@ namespace robospot_camera_finder
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
bool gotProperIP = false;
|
||||
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
|
||||
bool got_proper_ip = false;
|
||||
foreach (var net_interface in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
IPInterfaceProperties interfaceProperties = networkInterface.GetIPProperties();
|
||||
foreach (UnicastIPAddressInformation interfaceUnicastAddr in interfaceProperties.UnicastAddresses)
|
||||
IPInterfaceProperties prop = net_interface.GetIPProperties();
|
||||
foreach (var ip in prop.UnicastAddresses)
|
||||
{
|
||||
if (interfaceUnicastAddr.Address.ToString().StartsWith("10."))
|
||||
if (ip.Address.ToString().StartsWith("10."))
|
||||
{
|
||||
if (interfaceUnicastAddr.IPv4Mask.ToString() == "255.0.0.0")
|
||||
if (ip.IPv4Mask.ToString() == "255.0.0.0")
|
||||
{
|
||||
gotProperIP = true;
|
||||
got_proper_ip = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!gotProperIP)
|
||||
if (!got_proper_ip)
|
||||
{
|
||||
DialogResult openNetworkSettings = MessageBox.Show("No Ethernet interface on the 10.0.0.0/8 subnet found. Cameras might not be detected. Do you want to open network settings ?", "Wrong IP configuration", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
|
||||
DialogResult open_netsettings = MessageBox.Show("No Ethernet interface on the 10.0.0.0/8 subnet found. Cameras might not be detected. Do you want to open network settings ?", "Wrong IP configuration", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
|
||||
|
||||
if (openNetworkSettings == DialogResult.Yes)
|
||||
if (open_netsettings == DialogResult.Yes)
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo("NCPA.cpl");
|
||||
startInfo.UseShellExecute = true;
|
||||
@@ -127,15 +127,15 @@ namespace robospot_camera_finder
|
||||
|
||||
}
|
||||
|
||||
lbMain.DataSource = allCameras;
|
||||
lbMain.DisplayMember = "cameraName";
|
||||
lbMain.ValueMember = "cameraIP";
|
||||
lbMain.DataSource = all_cameras;
|
||||
lbMain.DisplayMember = "camera_name";
|
||||
lbMain.ValueMember = "camera_ip";
|
||||
|
||||
// Initialize UDP clients
|
||||
InitializeUdpClients();
|
||||
|
||||
// Discover cameras
|
||||
DiscoverCameras();
|
||||
discover_cameras();
|
||||
}
|
||||
|
||||
private void InitializeUdpClients()
|
||||
@@ -153,24 +153,24 @@ namespace robospot_camera_finder
|
||||
}
|
||||
}
|
||||
|
||||
private void AddCamera(Camera newCamera)
|
||||
private void add_camera(Camera new_camera)
|
||||
{
|
||||
if (allCameras.Count == 0)
|
||||
if (all_cameras.Count == 0)
|
||||
{
|
||||
allCameras.Add(newCamera);
|
||||
all_cameras.Add(new_camera);
|
||||
}
|
||||
else
|
||||
{
|
||||
Camera searchCamera = allCameras.FirstOrDefault(cam => cam.cameraSerial == newCamera.cameraSerial);
|
||||
Camera find_cam = all_cameras.FirstOrDefault(cam => cam.camera_serial == new_camera.camera_serial);
|
||||
|
||||
if (searchCamera != null)
|
||||
if (find_cam != null)
|
||||
{
|
||||
int i = allCameras.IndexOf(searchCamera);
|
||||
allCameras[i] = newCamera;
|
||||
int i = all_cameras.IndexOf(find_cam);
|
||||
all_cameras[i] = new_camera;
|
||||
}
|
||||
else
|
||||
{
|
||||
allCameras.Add(newCamera);
|
||||
all_cameras.Add(new_camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,7 @@ namespace robospot_camera_finder
|
||||
if (lbMain.SelectedItem != null)
|
||||
{
|
||||
toolStripStatusLabel.Text = "Loading camera...";
|
||||
Camera camera = allCameras.FirstOrDefault<Camera>(cam => cam.cameraIP.ToString() == lbMain.SelectedValue.ToString());
|
||||
Camera camera = all_cameras.FirstOrDefault<Camera>(cam => cam.camera_ip.ToString() == lbMain.SelectedValue.ToString());
|
||||
Form viewer = new StreamViewer(lbMain.GetItemText(lbMain.SelectedItem), lbMain.SelectedValue.ToString(), camera, this);
|
||||
viewer.Show();
|
||||
toolStripStatusLabel.Text = "";
|
||||
@@ -198,21 +198,18 @@ namespace robospot_camera_finder
|
||||
{
|
||||
json = File.ReadAllText(openFile.FileName);
|
||||
|
||||
List<Camera>? camerasInFile = JsonSerializer.Deserialize<List<Camera>>(json);
|
||||
List<Camera> cameras_in_file = JsonSerializer.Deserialize<List<Camera>>(json);
|
||||
|
||||
if (camerasInFile is List<Camera>)
|
||||
foreach (Camera new_camera in cameras_in_file)
|
||||
{
|
||||
foreach (Camera camera in camerasInFile)
|
||||
{
|
||||
AddCamera(camera);
|
||||
}
|
||||
add_camera(new_camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
string json = JsonSerializer.Serialize<BindingList<Camera>>(allCameras, new JsonSerializerOptions
|
||||
string json = JsonSerializer.Serialize<BindingList<Camera>>(all_cameras, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
@@ -228,14 +225,14 @@ namespace robospot_camera_finder
|
||||
|
||||
private void manualAddToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
ManualIPForm manualForm = new ManualIPForm();
|
||||
Manual_IP_Form manualForm = new Manual_IP_Form();
|
||||
|
||||
if (manualForm.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
string ipAddress = manualForm.ipAddress;
|
||||
|
||||
Camera cameraToAdd = new Camera("Camera " + ipAddress, ipAddress, "", ipAddress.Replace(".", ""));
|
||||
AddCamera(cameraToAdd);
|
||||
Camera camera_to_add = new Camera("Camera " + ipAddress, ipAddress, "", "");
|
||||
add_camera(camera_to_add);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,7 +426,7 @@ namespace robospot_camera_finder
|
||||
// Add camera to list (must be done on UI thread)
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
AddCamera(discoveredCamera);
|
||||
add_camera(discoveredCamera);
|
||||
toolStripStatusLabel.Text = $"Found camera: {cameraName} ({cameraIP})";
|
||||
}));
|
||||
}
|
||||
@@ -445,7 +442,7 @@ namespace robospot_camera_finder
|
||||
}
|
||||
|
||||
// Main discovery method
|
||||
private async void DiscoverCameras()
|
||||
private async void discover_cameras()
|
||||
{
|
||||
if (isDiscovering)
|
||||
{
|
||||
@@ -489,7 +486,7 @@ namespace robospot_camera_finder
|
||||
finally
|
||||
{
|
||||
isDiscovering = false;
|
||||
toolStripStatusLabel.Text = $"Discovery complete. Found {allCameras.Count} cameras.";
|
||||
toolStripStatusLabel.Text = $"Discovery complete. Found {all_cameras.Count} cameras.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace robospot_camera_finder
|
||||
{
|
||||
partial class ManualIPForm
|
||||
partial class Manual_IP_Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@@ -10,12 +10,12 @@ using System.Windows.Forms;
|
||||
|
||||
namespace robospot_camera_finder
|
||||
{
|
||||
public partial class ManualIPForm : Form
|
||||
public partial class Manual_IP_Form : Form
|
||||
{
|
||||
|
||||
public string ipAddress { get; set; }
|
||||
|
||||
public ManualIPForm()
|
||||
public Manual_IP_Form()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace robospot_camera_finder
|
||||
private void updateZoomSlider()
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + cam_ip + "/stw-cgi/ptzcontrol.cgi?msubmenu=query&action=view&Query=Zoom");
|
||||
request.Credentials = new NetworkCredential(MainForm.CAM_USERNAME, MainForm.CAM_PASSWORD);
|
||||
request.Credentials = new NetworkCredential(MainForm.cam_username, MainForm.cam_password);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
string text;
|
||||
using (var sr = new StreamReader(response.GetResponseStream())) { text = sr.ReadToEnd(); }
|
||||
@@ -64,7 +64,7 @@ namespace robospot_camera_finder
|
||||
}
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + cam_ip + "/stw-cgi/ptzcontrol.cgi?msubmenu=absolute&action=control&ZoomPulse=" + zoom_pulse);
|
||||
request.Credentials = new NetworkCredential(MainForm.CAM_USERNAME, MainForm.CAM_PASSWORD);
|
||||
request.Credentials = new NetworkCredential(MainForm.cam_username, MainForm.cam_password);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace robospot_camera_finder
|
||||
private void sendZoomValueManual(string zoom_value)
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + cam_ip + "/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&NormalizedSpeed=True&action=control&Channel=0&Zoom=" + zoom_value);
|
||||
request.Credentials = new NetworkCredential(MainForm.CAM_USERNAME, MainForm.CAM_PASSWORD);
|
||||
request.Credentials = new NetworkCredential(MainForm.cam_username, MainForm.cam_password);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user