diff --git a/static/discovery.js b/static/discovery.js index 5f68096..7c1ded4 100644 --- a/static/discovery.js +++ b/static/discovery.js @@ -12,6 +12,14 @@ class SimplifiedProtocolDiscovery { } bindDiscoveryEvents() { + // Discovery scan button + const startScanBtn = document.getElementById('start-discovery-scan'); + if (startScanBtn) { + startScanBtn.addEventListener('click', () => { + this.startDiscoveryScan(); + }); + } + // Auto-fill signal form from discovery document.addEventListener('click', (e) => { if (e.target.classList.contains('use-discovered-endpoint')) { @@ -123,6 +131,45 @@ class SimplifiedProtocolDiscovery { } } + // Start discovery scan + async startDiscoveryScan() { + console.log('Starting discovery scan...'); + + // Update UI + const startBtn = document.getElementById('start-discovery-scan'); + const stopBtn = document.getElementById('stop-discovery-scan'); + const statusDiv = document.getElementById('discovery-status'); + + if (startBtn) startBtn.disabled = true; + if (stopBtn) stopBtn.disabled = false; + if (statusDiv) { + statusDiv.innerHTML = '
Discovery scan in progress...
'; + } + + try { + // Run discovery + const results = await this.discoverAndSuggestSignals(); + + // Update status + if (statusDiv) { + statusDiv.innerHTML = `
Discovery complete. Found ${results.length} devices.
`; + } + + this.showNotification(`Discovery complete. Found ${results.length} devices.`, 'success'); + + } catch (error) { + console.error('Discovery scan failed:', error); + if (statusDiv) { + statusDiv.innerHTML = '
Discovery scan failed
'; + } + this.showNotification('Discovery scan failed', 'error'); + } finally { + // Reset UI + if (startBtn) startBtn.disabled = false; + if (stopBtn) stopBtn.disabled = true; + } + } + // Advanced discovery features async discoverAndSuggestSignals(networkRange = '192.168.1.0/24') { console.log(`Starting discovery scan on ${networkRange}`); @@ -187,8 +234,13 @@ class SimplifiedProtocolDiscovery { } displayDiscoveryResults(suggestedSignals) { + console.log('Displaying discovery results:', suggestedSignals); const resultsContainer = document.getElementById('discovery-results'); - if (!resultsContainer) return; + if (!resultsContainer) { + console.error('Discovery results container not found!'); + this.showNotification('Discovery results container not found', 'error'); + return; + } resultsContainer.innerHTML = '

Discovery Results

'; diff --git a/static/protocol_mapping.js b/static/protocol_mapping.js index 72eafc8..a55fd82 100644 --- a/static/protocol_mapping.js +++ b/static/protocol_mapping.js @@ -257,6 +257,7 @@ function autoPopulateSignalForm(discoveryData) { console.log('Auto-populating signal form with:', discoveryData); // First, open the "Add New Signal" modal + console.log('Opening Add Signal modal...'); showAddSignalModal(); // Wait for modal to be fully loaded and visible diff --git a/test_discovery_integration.html b/test_discovery_integration.html new file mode 100644 index 0000000..f99a125 --- /dev/null +++ b/test_discovery_integration.html @@ -0,0 +1,223 @@ + + + + + + Discovery Integration Test + + + +
+

Discovery Integration Test

+ +
+

Test 1: Check if Functions are Available

+ +
+
+ +
+

Test 2: Simulate Discovery Results

+ +
+
+ +
+

Test 3: Test Auto-Population

+ +
+
+ +
+

Test 4: Test API Endpoints

+ +
+
+
+ + + + \ No newline at end of file