b083890e96
Integrated comprehensive device attribution system into GigLez:
1. Simple Device Matcher (src/matcher/simple_matcher.py):
- Frequency-based device categorization (315/433/868/915 MHz)
- Protocol-specific identification (Princeton, EV1527, Oregon Scientific, etc.)
- Modulation + frequency matching (OOK/FSK/ASK)
- Confidence scoring (0.4-0.95 range)
- 50+ device types covered
2. API Integration (src/api/main_simple.py):
- Device matching in upload pipeline
- Added device fields: device_name, device_category, match_confidence, match_method, device_description
- Top 5 alternative matches stored per capture
- New endpoint: GET /api/v1/captures/{id} for detail view
3. Frontend Implementation:
- Detail modal with comprehensive device information
- Device identification section with confidence bars
- Alternative matches display
- Signal, location, and metadata sections
- Keyboard (ESC) and click-outside modal closing
4. UI Enhancements (static/css/main.css):
- Modal overlay with backdrop blur
- Animated modal slide-in
- Confidence visualization (green/yellow/red bars)
- Responsive detail grid layout
- Device match cards with categories
5. JavaScript Integration:
- detail-modal.js: Comprehensive detail view renderer
- Updated map.js and search.js to use detail modal
- Removed placeholder functions
6. Utilities:
- scripts/rematch_captures.py: Re-run matcher on existing data
- Successfully re-matched 20 existing captures
Device Categories Supported:
- Consumer RF (remotes, sensors)
- Automotive (key fobs, TPMS)
- Home Automation (garage/gate openers, blinds)
- Sensors (weather stations, temperature)
- Security (door/window sensors, alarms)
- IoT (smart meters, LoRa devices)
- Industrial (SCADA, telemetry, RFID)
Match Methods:
- Protocol matching (highest confidence: 0.7-0.95)
- Frequency matching (0.4-0.7)
- Modulation + frequency matching (0.5-0.7)
Frontend now displays:
- Device name and category on map markers
- Confidence percentage
- Detailed device information modal
- Alternative device matches
- Match method explanation
All existing captures successfully identified with 60-70% confidence.
204 lines
5.8 KiB
JavaScript
204 lines
5.8 KiB
JavaScript
// GigLez - Map Visualization
|
|
|
|
let map;
|
|
let markerLayer;
|
|
let markerClusterGroup;
|
|
let capturesData = [];
|
|
|
|
// Frequency color mapping
|
|
const FREQUENCY_COLORS = {
|
|
315: '#10b981', // Green
|
|
433: '#3b82f6', // Blue
|
|
868: '#f59e0b', // Orange
|
|
915: '#ef4444', // Red
|
|
default: '#6b7280' // Gray
|
|
};
|
|
|
|
// Initialize map
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
initMap();
|
|
loadCaptures();
|
|
setupMapControls();
|
|
});
|
|
|
|
function initMap() {
|
|
// Create map centered on US
|
|
map = L.map('map').setView([39.8283, -98.5795], 4);
|
|
|
|
// Add OpenStreetMap tiles
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
maxZoom: 19
|
|
}).addTo(map);
|
|
|
|
// Create marker cluster group
|
|
markerClusterGroup = L.markerClusterGroup({
|
|
maxClusterRadius: 50,
|
|
spiderfyOnMaxZoom: true,
|
|
showCoverageOnHover: false,
|
|
zoomToBoundsOnClick: true
|
|
});
|
|
|
|
// Create regular marker layer
|
|
markerLayer = L.layerGroup();
|
|
|
|
// Add cluster group by default
|
|
map.addLayer(markerClusterGroup);
|
|
|
|
// Export map to window for access from other modules
|
|
window.map = map;
|
|
}
|
|
|
|
function setupMapControls() {
|
|
// Cluster toggle
|
|
document.getElementById('cluster-toggle').addEventListener('change', (e) => {
|
|
if (e.target.checked) {
|
|
map.removeLayer(markerLayer);
|
|
map.addLayer(markerClusterGroup);
|
|
} else {
|
|
map.removeLayer(markerClusterGroup);
|
|
map.addLayer(markerLayer);
|
|
}
|
|
renderMarkers();
|
|
});
|
|
|
|
// Frequency filter
|
|
document.getElementById('frequency-filter').addEventListener('change', () => {
|
|
renderMarkers();
|
|
});
|
|
|
|
// Heatmap toggle (placeholder)
|
|
document.getElementById('heatmap-toggle').addEventListener('change', (e) => {
|
|
if (e.target.checked) {
|
|
alert('Heatmap view coming soon!');
|
|
e.target.checked = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
async function loadCaptures() {
|
|
try {
|
|
const response = await fetch('/api/v1/query/captures?limit=1000');
|
|
|
|
if (!response.ok) {
|
|
console.error('Failed to load captures');
|
|
return;
|
|
}
|
|
|
|
const data = await response.json();
|
|
capturesData = data.captures || [];
|
|
|
|
renderMarkers();
|
|
updateStats();
|
|
|
|
} catch (error) {
|
|
console.error('Error loading captures:', error);
|
|
}
|
|
}
|
|
|
|
function renderMarkers() {
|
|
// Clear existing markers
|
|
markerClusterGroup.clearLayers();
|
|
markerLayer.clearLayers();
|
|
|
|
// Get frequency filter
|
|
const frequencyFilter = document.getElementById('frequency-filter').value;
|
|
|
|
// Filter captures
|
|
let filtered = capturesData;
|
|
|
|
if (frequencyFilter) {
|
|
const targetFreq = parseInt(frequencyFilter) * 1e6;
|
|
filtered = capturesData.filter(c => {
|
|
const freq = c.frequency / 1e6;
|
|
return Math.abs(freq - parseInt(frequencyFilter)) < 50;
|
|
});
|
|
}
|
|
|
|
// Create markers
|
|
filtered.forEach(capture => {
|
|
const marker = createMarker(capture);
|
|
|
|
// Add to both layers (only one will be visible)
|
|
markerClusterGroup.addLayer(marker);
|
|
markerLayer.addLayer(marker);
|
|
});
|
|
|
|
// Update count
|
|
document.getElementById('total-captures').textContent = filtered.length;
|
|
}
|
|
|
|
function createMarker(capture) {
|
|
// Determine color based on frequency
|
|
const freqMHz = Math.round(capture.frequency / 1e6);
|
|
let color = FREQUENCY_COLORS.default;
|
|
|
|
for (const [freq, col] of Object.entries(FREQUENCY_COLORS)) {
|
|
if (freq === 'default') continue;
|
|
if (Math.abs(freqMHz - parseInt(freq)) < 50) {
|
|
color = col;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Create custom icon
|
|
const icon = L.divIcon({
|
|
className: 'custom-marker',
|
|
html: `<div style="background-color: ${color}; width: 12px; height: 12px; border-radius: 50%; border: 2px solid white; box-shadow: 0 0 4px rgba(0,0,0,0.3);"></div>`,
|
|
iconSize: [12, 12],
|
|
iconAnchor: [6, 6]
|
|
});
|
|
|
|
// Create marker
|
|
const marker = L.marker([capture.latitude, capture.longitude], { icon });
|
|
|
|
// Create popup
|
|
const popupContent = createPopupContent(capture);
|
|
marker.bindPopup(popupContent);
|
|
|
|
return marker;
|
|
}
|
|
|
|
function createPopupContent(capture) {
|
|
const freqMHz = (capture.frequency / 1e6).toFixed(2);
|
|
const date = new Date(capture.captured_at).toLocaleDateString();
|
|
|
|
let deviceInfo = 'Unknown Device';
|
|
if (capture.device_name) {
|
|
deviceInfo = `<strong>${capture.device_name}</strong>`;
|
|
if (capture.match_confidence) {
|
|
deviceInfo += ` (${(capture.match_confidence * 100).toFixed(0)}% confidence)`;
|
|
}
|
|
}
|
|
|
|
return `
|
|
<div class="marker-popup">
|
|
<h4>${deviceInfo}</h4>
|
|
<p><strong>Frequency:</strong> ${freqMHz} MHz</p>
|
|
<p><strong>Protocol:</strong> ${capture.protocol || 'RAW'}</p>
|
|
<p><strong>Captured:</strong> ${date}</p>
|
|
<p><strong>Location:</strong> ${capture.latitude.toFixed(6)}, ${capture.longitude.toFixed(6)}</p>
|
|
${capture.accuracy ? `<p><strong>Accuracy:</strong> ±${capture.accuracy.toFixed(1)}m</p>` : ''}
|
|
<button onclick="viewCaptureDetails(${capture.id})" class="btn btn-primary" style="margin-top: 0.5rem;">
|
|
View Details
|
|
</button>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
function updateStats() {
|
|
// Total captures
|
|
document.getElementById('total-captures').textContent = capturesData.length;
|
|
|
|
// Unique devices
|
|
const uniqueDevices = new Set(
|
|
capturesData
|
|
.filter(c => c.device_name)
|
|
.map(c => c.device_name)
|
|
).size;
|
|
document.getElementById('unique-devices').textContent = uniqueDevices;
|
|
}
|
|
|
|
// Export for external use
|
|
window.reloadMapData = loadCaptures;
|