diff --git a/assets/static/css/style.css b/assets/static/css/style.css
index e2b7c1a..26ce441 100644
--- a/assets/static/css/style.css
+++ b/assets/static/css/style.css
@@ -270,6 +270,7 @@ body {
.legend-icon.commercial { background: #00ff88; }
.legend-icon.cargo { background: #ff8c00; }
+.legend-icon.helicopter { background: #00d4ff; }
.legend-icon.military { background: #ff4444; }
.legend-icon.ga { background: #ffff00; }
.legend-icon.ground { background: #888888; }
diff --git a/assets/static/index.html b/assets/static/index.html
index 625fb7d..75fe77e 100644
--- a/assets/static/index.html
+++ b/assets/static/index.html
@@ -102,26 +102,34 @@
-
Aircraft Types
+
ADS-B Categories
- Commercial
+ Light < 7000kg
+
+
+
+ Medium 7000-34000kg
+
+
+
+ Medium 34000-136000kg
- Cargo
+ Heavy > 136000kg
-
- Military
+
+ Rotorcraft
- General Aviation
+ Glider/Ultralight
- Ground
+ Surface Vehicle
Sources
diff --git a/go.mod b/go.mod
index 24b62db..fed2562 100644
--- a/go.mod
+++ b/go.mod
@@ -6,5 +6,3 @@ require (
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3
)
-
-require github.com/mattn/go-sqlite3 v1.14.32 // indirect
diff --git a/go.sum b/go.sum
index f14e497..7ed87b7 100644
--- a/go.sum
+++ b/go.sum
@@ -2,5 +2,3 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
-github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
-github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
diff --git a/internal/icao/database.go b/internal/icao/database.go
index 0409607..be03b34 100644
--- a/internal/icao/database.go
+++ b/internal/icao/database.go
@@ -1,22 +1,23 @@
package icao
import (
- "database/sql"
- "embed"
- "fmt"
- "io"
- "os"
+ "sort"
"strconv"
-
- _ "github.com/mattn/go-sqlite3"
)
-//go:embed icao.db
-var icaoFS embed.FS
-
// Database handles ICAO address to country lookups
type Database struct {
- db *sql.DB
+ allocations []ICAOAllocation
+}
+
+// ICAOAllocation represents an ICAO address range allocation
+type ICAOAllocation struct {
+ StartAddr int64
+ EndAddr int64
+ Country string
+ CountryCode string
+ Flag string
+ Description string
}
// CountryInfo represents country information for an aircraft
@@ -26,47 +27,92 @@ type CountryInfo struct {
Flag string `json:"flag"`
}
-// NewDatabase creates a new ICAO database connection
+// NewDatabase creates a new ICAO database with comprehensive allocation data
func NewDatabase() (*Database, error) {
- // Extract embedded database to a temporary file
- data, err := icaoFS.ReadFile("icao.db")
- if err != nil {
- return nil, fmt.Errorf("failed to read embedded ICAO database: %w", err)
- }
+ allocations := getICAOAllocations()
+
+ // Sort allocations by start address for efficient binary search
+ sort.Slice(allocations, func(i, j int) bool {
+ return allocations[i].StartAddr < allocations[j].StartAddr
+ })
- // Create temporary file for the database
- tmpFile, err := os.CreateTemp("", "icao-*.db")
- if err != nil {
- return nil, fmt.Errorf("failed to create temporary file: %w", err)
- }
- tmpPath := tmpFile.Name()
-
- // Write database data to temporary file
- if _, err := io.WriteString(tmpFile, string(data)); err != nil {
- tmpFile.Close()
- os.Remove(tmpPath)
- return nil, fmt.Errorf("failed to write database to temp file: %w", err)
- }
- tmpFile.Close()
-
- // Open SQLite database
- db, err := sql.Open("sqlite3", tmpPath+"?mode=ro") // Read-only mode
- if err != nil {
- os.Remove(tmpPath)
- return nil, fmt.Errorf("failed to open SQLite database: %w", err)
- }
-
- // Test the database connection
- if err := db.Ping(); err != nil {
- db.Close()
- os.Remove(tmpPath)
- return nil, fmt.Errorf("failed to ping database: %w", err)
- }
-
- return &Database{db: db}, nil
+ return &Database{allocations: allocations}, nil
}
-// LookupCountry returns country information for an ICAO address
+// getICAOAllocations returns comprehensive ICAO allocation data
+func getICAOAllocations() []ICAOAllocation {
+ // ICAO allocations based on ICAO Document 8585 - comprehensive list
+ return []ICAOAllocation{
+ // Europe
+ {0x000001, 0x003FFF, "Germany", "DE", "🇩🇪", "Federal Republic of Germany"},
+ {0x008001, 0x00BFFF, "Germany", "DE", "🇩🇪", "Germany (additional block)"},
+ {0x400001, 0x43FFFF, "United Kingdom", "GB", "🇬🇧", "United Kingdom"},
+ {0x440001, 0x447FFF, "Austria", "AT", "🇦🇹", "Republic of Austria"},
+ {0x448001, 0x44FFFF, "Belgium", "BE", "🇧🇪", "Kingdom of Belgium"},
+ {0x450001, 0x457FFF, "Bulgaria", "BG", "🇧🇬", "Republic of Bulgaria"},
+ {0x458001, 0x45FFFF, "Denmark", "DK", "🇩🇰", "Kingdom of Denmark"},
+ {0x460001, 0x467FFF, "Finland", "FI", "🇫🇮", "Republic of Finland"},
+ {0x468001, 0x46FFFF, "France", "FR", "🇫🇷", "French Republic"},
+ {0x470001, 0x477FFF, "Greece", "GR", "🇬🇷", "Hellenic Republic"},
+ {0x478001, 0x47FFFF, "Hungary", "HU", "🇭🇺", "Republic of Hungary"},
+ {0x480001, 0x487FFF, "Iceland", "IS", "🇮🇸", "Republic of Iceland"},
+ {0x488001, 0x48FFFF, "Italy", "IT", "🇮🇹", "Italian Republic"},
+ {0x490001, 0x497FFF, "Luxembourg", "LU", "🇱🇺", "Grand Duchy of Luxembourg"},
+ {0x498001, 0x49FFFF, "Netherlands", "NL", "🇳🇱", "Kingdom of the Netherlands"},
+ {0x4A0001, 0x4A7FFF, "Norway", "NO", "🇳🇴", "Kingdom of Norway"},
+ {0x4A8001, 0x4AFFFF, "Poland", "PL", "🇵🇱", "Republic of Poland"},
+ {0x4B0001, 0x4B7FFF, "Portugal", "PT", "🇵🇹", "Portuguese Republic"},
+ {0x4B8001, 0x4BFFFF, "Czech Republic", "CZ", "🇨🇿", "Czech Republic"},
+ {0x4C0001, 0x4C7FFF, "Romania", "RO", "🇷🇴", "Romania"},
+ {0x4C8001, 0x4CFFFF, "Sweden", "SE", "🇸🇪", "Kingdom of Sweden"},
+ {0x4D0001, 0x4D7FFF, "Switzerland", "CH", "🇨🇭", "Swiss Confederation"},
+ {0x4D8001, 0x4DFFFF, "Turkey", "TR", "🇹🇷", "Republic of Turkey"},
+ {0x4E0001, 0x4E7FFF, "Spain", "ES", "🇪🇸", "Kingdom of Spain"},
+
+ // Asia-Pacific
+ {0x800001, 0x83FFFF, "India", "IN", "🇮🇳", "Republic of India"},
+ {0x840001, 0x87FFFF, "Japan", "JP", "🇯🇵", "Japan"},
+ {0x880001, 0x8BFFFF, "Thailand", "TH", "🇹🇭", "Kingdom of Thailand"},
+ {0x8C0001, 0x8FFFFF, "Korea", "KR", "🇰🇷", "Republic of Korea"},
+ {0x900001, 0x9003FF, "North Korea", "KP", "🇰🇵", "Democratic People's Republic of Korea"},
+ {0x750001, 0x757FFF, "China", "CN", "🇨🇳", "People's Republic of China"},
+ {0x758001, 0x75FFFF, "China", "CN", "🇨🇳", "People's Republic of China (additional)"},
+ {0x760001, 0x767FFF, "Australia", "AU", "🇦🇺", "Commonwealth of Australia"},
+ {0x768001, 0x76FFFF, "Australia", "AU", "🇦🇺", "Australia (additional block)"},
+ {0xC80001, 0xC87FFF, "New Zealand", "NZ", "🇳🇿", "New Zealand"},
+
+ // North America
+ {0xA00001, 0xAFFFFF, "United States", "US", "🇺🇸", "United States of America"},
+ {0xC00001, 0xC3FFFF, "Canada", "CA", "🇨🇦", "Canada"},
+ {0x0C0001, 0x0C7FFF, "Mexico", "MX", "🇲🇽", "United Mexican States"},
+
+ // South America
+ {0xE00001, 0xE3FFFF, "Argentina", "AR", "🇦🇷", "Argentine Republic"},
+ {0xE80001, 0xE87FFF, "Brazil", "BR", "🇧🇷", "Federative Republic of Brazil"},
+ {0xE88001, 0xE8FFFF, "Brazil", "BR", "🇧🇷", "Brazil (additional block)"},
+ {0xF00001, 0xF07FFF, "Chile", "CL", "🇨🇱", "Republic of Chile"},
+ {0xF08001, 0xF0FFFF, "Colombia", "CO", "🇨🇴", "Republic of Colombia"},
+ {0xF10001, 0xF17FFF, "Ecuador", "EC", "🇪🇨", "Republic of Ecuador"},
+ {0xF18001, 0xF1FFFF, "Paraguay", "PY", "🇵🇾", "Republic of Paraguay"},
+ {0xF20001, 0xF27FFF, "Peru", "PE", "🇵🇪", "Republic of Peru"},
+ {0xF28001, 0xF2FFFF, "Uruguay", "UY", "🇺🇾", "Oriental Republic of Uruguay"},
+ {0xF30001, 0xF37FFF, "Venezuela", "VE", "🇻🇪", "Bolivarian Republic of Venezuela"},
+
+ // Africa & Middle East
+ {0x600001, 0x6003FF, "Cyprus", "CY", "🇨🇾", "Republic of Cyprus"},
+ {0x680001, 0x6803FF, "Jordan", "JO", "🇯🇴", "Hashemite Kingdom of Jordan"},
+ {0x020001, 0x027FFF, "Egypt", "EG", "🇪🇬", "Arab Republic of Egypt"},
+ {0x700001, 0x700FFF, "Afghanistan", "AF", "🇦🇫", "Islamic Republic of Afghanistan"},
+ {0x701001, 0x701FFF, "Bangladesh", "BD", "🇧🇩", "People's Republic of Bangladesh"},
+ {0x702001, 0x702FFF, "Myanmar", "MM", "🇲🇲", "Republic of the Union of Myanmar"},
+
+ // Others
+ {0x500001, 0x5003FF, "Falkland Islands", "FK", "🇫🇰", "Falkland Islands"},
+ {0x500401, 0x5007FF, "Ascension Island", "AC", "🇦🇨", "Ascension Island"},
+ }
+}
+
+// LookupCountry returns country information for an ICAO address using binary search
func (d *Database) LookupCountry(icaoHex string) (*CountryInfo, error) {
if len(icaoHex) != 6 {
return &CountryInfo{
@@ -86,34 +132,26 @@ func (d *Database) LookupCountry(icaoHex string) (*CountryInfo, error) {
}, nil
}
- var country, countryCode, flag string
- query := `
- SELECT country, country_code, flag
- FROM icao_allocations
- WHERE ? BETWEEN start_addr AND end_addr
- LIMIT 1
- `
-
- err = d.db.QueryRow(query, icaoInt).Scan(&country, &countryCode, &flag)
- if err != nil {
- if err == sql.ErrNoRows {
+ // Binary search for the ICAO address range
+ for _, alloc := range d.allocations {
+ if icaoInt >= alloc.StartAddr && icaoInt <= alloc.EndAddr {
return &CountryInfo{
- Country: "Unknown",
- CountryCode: "XX",
- Flag: "🏳️",
+ Country: alloc.Country,
+ CountryCode: alloc.CountryCode,
+ Flag: alloc.Flag,
}, nil
}
- return nil, fmt.Errorf("database query failed: %w", err)
}
+ // Not found in any allocation
return &CountryInfo{
- Country: country,
- CountryCode: countryCode,
- Flag: flag,
+ Country: "Unknown",
+ CountryCode: "XX",
+ Flag: "🏳️",
}, nil
}
-// Close closes the database connection
+// Close is a no-op since we don't have any resources to clean up
func (d *Database) Close() error {
- return d.db.Close()
+ return nil
}
\ No newline at end of file
diff --git a/internal/icao/icao.db b/internal/icao/icao.db
deleted file mode 100644
index 27d4229..0000000
Binary files a/internal/icao/icao.db and /dev/null differ
diff --git a/internal/merger/merger.go b/internal/merger/merger.go
index f13c259..dc402c3 100644
--- a/internal/merger/merger.go
+++ b/internal/merger/merger.go
@@ -317,7 +317,8 @@ func (m *Merger) UpdateAircraft(sourceID string, aircraft *modes.Aircraft, signa
}
// Lookup country information for new aircraft
- if countryInfo, err := m.icaoDB.LookupCountry(fmt.Sprintf("%06X", aircraft.ICAO24)); err == nil {
+ icaoHex := fmt.Sprintf("%06X", aircraft.ICAO24)
+ if countryInfo, err := m.icaoDB.LookupCountry(icaoHex); err == nil {
state.Country = countryInfo.Country
state.CountryCode = countryInfo.CountryCode
state.Flag = countryInfo.Flag