on demand discovery

This commit is contained in:
2025-06-01 12:07:19 +02:00
parent 606b92fd32
commit c0f6277265
2 changed files with 32 additions and 29 deletions

31
MainForm.Designer.cs generated
View File

@@ -35,12 +35,12 @@
toolStripStatusDisco = new ToolStripStatusLabel();
menuStrip1 = new MenuStrip();
discoveryToolStripMenuItem = new ToolStripMenuItem();
discoverToolStripMenuItem = new ToolStripMenuItem();
toolStripSeparator2 = new ToolStripSeparator();
manualAddToolStripMenuItem = new ToolStripMenuItem();
toolStripSeparator1 = new ToolStripSeparator();
saveToolStripMenuItem = new ToolStripMenuItem();
loadToolStripMenuItem = new ToolStripMenuItem();
toolStripSeparator2 = new ToolStripSeparator();
discoverToolStripMenuItem = new ToolStripMenuItem();
statusStripMain.SuspendLayout();
menuStrip1.SuspendLayout();
SuspendLayout();
@@ -49,7 +49,6 @@
//
lbMain.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
lbMain.FormattingEnabled = true;
lbMain.ItemHeight = 15;
lbMain.Location = new Point(12, 23);
lbMain.Name = "lbMain";
lbMain.Size = new Size(776, 394);
@@ -73,8 +72,7 @@
// toolStripStatusDisco
//
toolStripStatusDisco.Name = "toolStripStatusDisco";
toolStripStatusDisco.Size = new Size(111, 17);
toolStripStatusDisco.Text = "";
toolStripStatusDisco.Size = new Size(0, 17);
//
// menuStrip1
//
@@ -92,6 +90,18 @@
discoveryToolStripMenuItem.Size = new Size(70, 20);
discoveryToolStripMenuItem.Text = "Discovery";
//
// discoverToolStripMenuItem
//
discoverToolStripMenuItem.Name = "discoverToolStripMenuItem";
discoverToolStripMenuItem.Size = new Size(180, 22);
discoverToolStripMenuItem.Text = "Discover cameras";
discoverToolStripMenuItem.Click += discoverToolStripMenuItem_Click;
//
// toolStripSeparator2
//
toolStripSeparator2.Name = "toolStripSeparator2";
toolStripSeparator2.Size = new Size(177, 6);
//
// manualAddToolStripMenuItem
//
manualAddToolStripMenuItem.Name = "manualAddToolStripMenuItem";
@@ -118,17 +128,6 @@
loadToolStripMenuItem.Text = "Load";
loadToolStripMenuItem.Click += loadToolStripMenuItem_Click;
//
// toolStripSeparator2
//
toolStripSeparator2.Name = "toolStripSeparator2";
toolStripSeparator2.Size = new Size(177, 6);
//
// discoverToolStripMenuItem
//
discoverToolStripMenuItem.Name = "discoverToolStripMenuItem";
discoverToolStripMenuItem.Size = new Size(180, 22);
discoverToolStripMenuItem.Text = "Discover cameras";
//
// MainForm
//
AutoScaleDimensions = new SizeF(7F, 15F);

View File

@@ -14,8 +14,8 @@ namespace robospot_camera_finder
{
public partial class MainForm : Form
{
public string VERSION = "1.1.0";
// Version
public string VERSION = "1.2.0";
// Main list containing all cameras
private BindingList<Camera> all_cameras = new();
@@ -39,23 +39,21 @@ namespace robospot_camera_finder
// Camera class
public class Camera
{
public Camera(string name, string ip, string location, string serial)
public Camera(string name, string ip, string id)
{
camera_name = name;
camera_ip = ip;
camera_location = location;
camera_serial = serial;
camera_id = id;
}
public string camera_name { get; set; }
public string camera_ip { get; set; }
public string camera_location { get; set; }
public string camera_serial { get; set; }
public string camera_id { get; set; }
}
// Discovery packet struc
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DataPacketIPv4
{
@@ -164,7 +162,7 @@ namespace robospot_camera_finder
}
// Add cameras to the main list
private void add_camera(Camera new_camera)
private void AddCamera(Camera new_camera)
{
if (all_cameras.Count == 0)
{
@@ -172,7 +170,7 @@ namespace robospot_camera_finder
}
else
{
Camera find_cam = all_cameras.FirstOrDefault(cam => cam.camera_serial == new_camera.camera_serial);
Camera find_cam = all_cameras.FirstOrDefault(cam => cam.camera_id == new_camera.camera_id);
if (find_cam != null)
{
@@ -369,8 +367,7 @@ namespace robospot_camera_finder
Camera discoveredCamera = new Camera(
$"{deviceName} - ({cameraIP})",
cameraIP,
$"MAC: {macAddress}",
packetId // Using packet_id as serial for uniqueness
packetId
);
// Add camera to list (must be done on UI thread)
@@ -412,6 +409,7 @@ namespace robospot_camera_finder
isDiscovering = true;
toolStripStatusLabel.Text = "Discovering cameras...";
discoverToolStripMenuItem.Enabled = false;
try
{
@@ -437,6 +435,7 @@ namespace robospot_camera_finder
{
isDiscovering = false;
toolStripStatusLabel.Text = $"Discovery complete. Found {all_cameras.Count} cameras.";
discoverToolStripMenuItem.Enabled = true;
}
}
@@ -496,8 +495,8 @@ namespace robospot_camera_finder
{
string ipAddress = manualForm.ipAddress;
Camera camera_to_add = new Camera("Camera " + ipAddress, ipAddress, "", "CAM_FINDER_" + DateTime.Now.Ticks.ToString());
add_camera(camera_to_add);
Camera camera_to_add = new Camera("Camera " + ipAddress, ipAddress, ipAddress);
AddCamera(camera_to_add);
}
}
@@ -515,5 +514,10 @@ namespace robospot_camera_finder
base.OnFormClosing(e);
}
private void discoverToolStripMenuItem_Click(object sender, EventArgs e)
{
DiscoverCameras();
}
}
}