Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribution - code snippet for Australian aircraft (traffic.go) #736

Closed
armeniki opened this issue Aug 14, 2018 · 10 comments
Closed

Contribution - code snippet for Australian aircraft (traffic.go) #736

armeniki opened this issue Aug 14, 2018 · 10 comments

Comments

@armeniki
Copy link

armeniki commented Aug 14, 2018

Hi everyone,

I wanted to firstly say thanks for everyone involved with this project!

Secondly, I wanted to contribute a bit of code below, which will enable Australian users to decode the ICAO Mode S HEX into Australian "VH-xxx" tail numbers. This code is in the icao2reg function in the file traffic.go located in the main folder.

I have compiled this successfully and tested it on the latest version (1.4r5) with GoLang v1.10.3.

Cheers,
Armen

func icao2reg(icao_addr uint32) (string, bool) {
	// Initialize local variables
	base34alphabet := string("ABCDEFGHJKLMNPQRSTUVWXYZ0123456789")
	nationalOffset := uint32(0xA00001) // default is US
	tail := ""
	nation := ""

	// Determine nationality
	if (icao_addr >= 0xA00001) && (icao_addr <= 0xAFFFFF) {
		nation = "US"
	} else if (icao_addr >= 0xC00001) && (icao_addr <= 0xC3FFFF) {
		nation = "CA"
	} else if (icao_addr >= 0x7C0000) && (icao_addr <= 0x7FFFFF) {
		nation = "AU"
	} else {
		//TODO: future national decoding.
		return "OTHER", false
	}

	if nation == "CA" { // Canada decoding
		// First, discard addresses that are not assigned to aircraft on the civil registry
		if icao_addr > 0xC0CDF8 {
			//fmt.Printf("%X is a Canada aircraft, but not a CF-, CG-, or CI- registration.\n", icao_addr)
			return "CA-MIL", false
		}

		nationalOffset := uint32(0xC00001)
		serial := int32(icao_addr - nationalOffset)

		// Fifth letter
		e := serial % 26

		// Fourth letter
		d := (serial / 26) % 26

		// Third letter
		c := (serial / 676) % 26 // 676 == 26*26

		// Second letter
		b := (serial / 17576) % 26 // 17576 == 26*26*26

		b_str := "FGI"

		//fmt.Printf("B = %d, C = %d, D = %d, E = %d\n",b,c,d,e)
		tail = fmt.Sprintf("C-%c%c%c%c", b_str[b], c+65, d+65, e+65)
	}


	if nation == "AU" { // Australia decoding

		nationalOffset := uint32(0x7C0000)
		offset := (icao_addr - nationalOffset)
		i1 := offset/1296
		offset2 := offset % 1296
		i2 := offset2/36
		offset3 := offset2 % 36
		i3 := offset3
	
		var a_char, b_char, c_char string

		a_char = fmt.Sprintf("%c", i1+65)
		b_char = fmt.Sprintf("%c", i2+65)
		c_char = fmt.Sprintf("%c", i3+65)

		if i1<0 || i1>25 || i2<0 || i2>25 || i3<0 || i3>25 {
			return "OTHER", false
		}
			
		tail = "VH-" + a_char + b_char + c_char
	}


	if nation == "US" { // FAA decoding
		// First, discard addresses that are not assigned to aircraft on the civil registry
		if icao_addr > 0xADF7C7 {
			//fmt.Printf("%X is a US aircraft, but not on the civil registry.\n", icao_addr)
			return "US-MIL", false
		}

		serial := int32(icao_addr - nationalOffset)
		// First digit
		a := (serial / 101711) + 1

		// Second digit
		a_remainder := serial % 101711
		b := ((a_remainder + 9510) / 10111) - 1

		// Third digit
		b_remainder := (a_remainder + 9510) % 10111
		c := ((b_remainder + 350) / 951) - 1

		// This next bit is more convoluted. First, figure out if we're using the "short" method of
		// decoding the last two digits (two letters, one letter and one blank, or two blanks).
		// This will be the case if digit "B" or "C" are calculated as negative, or if c_remainder
		// is less than 601.

		c_remainder := (b_remainder + 350) % 951
		var d, e int32

		if (b >= 0) && (c >= 0) && (c_remainder > 600) { // alphanumeric decoding method
			d = 24 + (c_remainder-601)/35
			e = (c_remainder - 601) % 35

		} else { // two-letter decoding method
			if (b < 0) || (c < 0) {
				c_remainder -= 350 // otherwise "  " == 350, "A " == 351, "AA" == 352, etc.
			}

			d = (c_remainder - 1) / 25
			e = (c_remainder - 1) % 25

			if e < 0 {
				d -= 1
				e += 25
			}
		}

		a_char := fmt.Sprintf("%d", a)
		var b_char, c_char, d_char, e_char string

		if b >= 0 {
			b_char = fmt.Sprintf("%d", b)
		}

		if b >= 0 && c >= 0 {
			c_char = fmt.Sprintf("%d", c)
		}

		if d > -1 {
			d_char = string(base34alphabet[d])
			if e > 0 {
				e_char = string(base34alphabet[e-1])
			}
		}

		tail = "N" + a_char + b_char + c_char + d_char + e_char

	}

	return tail, true
}

@jamieqld
Copy link

Thanks for the great code.
Im new to this, would you know how I can get a version that only uses a single 1090 radio for version (1.4r5)
The one I have from the main page is dual radio.

@armeniki
Copy link
Author

armeniki commented Aug 14, 2018

Hi jamieqld, thank you!

You don't need a specific version to use only the 1090ES. If you only want to use your SDR for 1090, just plug it in and edit the config file accordingly. You can disable/enable which bands appear on the main page so when you restart, you'll only see 1090ES data displayed on the main page.

@jamieqld
Copy link

@armeniki ,
Im a real noob at this.
I have Stratux working on my Pi3 sd card. I have also download the source code, however I have been looking all day for the Config file so I can edit it, with no luck.

Would you be able to help me find/edit the config file. Please guide me as a noob.

Thanks
jamie

@armeniki
Copy link
Author

Hi Jamie, the configuration file is located here:

/etc/stratux.conf

Change the UAT_Enabled setting to false, reboot and you'll be all set.

@jamieqld
Copy link

Do I have to SSH into it.
I have a usb keyboard and mouse connected to the pi, and when i do a ls i dont see those files

@Helno
Copy link
Collaborator

Helno commented Aug 14, 2018

@jamieqld You do not actually have to edit any files.

You can change this in the web interface in either the settings tab or if you do not see a slider there for it you can click on the version number repeatedly on the main page and the developer tab will appear. There are sliders to enable or disable 978 1090 along with GPS AHRS and BARO.

@jamieqld
Copy link

jamieqld commented Aug 14, 2018

Thanks Helno, I was able to get that to work. I was able to turn off radio 978 as not needed here is Australia.

edit update
At command prompt cd /etc
ls
/etc/stratux.conf
all good now.

I know im a noob at this, but very keen to learn.

jamie
VH-XJL

@kdknigga
Copy link
Contributor

kdknigga commented Aug 15, 2018 via email

@cyoung
Copy link
Owner

cyoung commented Aug 15, 2018

The file doesn't exist if the system is running on defaults. Once you change a setting, a stratux.conf file is generated.

@cyoung
Copy link
Owner

cyoung commented Aug 15, 2018

@armeniki - thanks! This is going in master now and you should see it integrated into the latest on the builds site soon (http://updates.stratux.me/builds/).

cyoung added a commit that referenced this issue Aug 15, 2018
@cyoung cyoung closed this as completed Aug 15, 2018
tobo07 added a commit to tobo07/stratux that referenced this issue Aug 17, 2018
* Remove old AHRS replay tools. Add protocol tools.

* Typo and path fix.

* Change IP Stratux IP address and DHCP range.

* Update install and auto-start scripts.

* Update make clean.

* Add missing files from update scripts.

* Update goflying.

* Update goflying.

* Add alias for 192.168.10.1 for normal webui access.

* Adapt `ffMonitor()` to ahrs_approx - only send the FF AHRS packets when FF is detected.

* Add dhcpd.conf and interfaces files to .sh update.

* Remove sqlite log and stratux.log on update.

* Install dhcpd.conf and interfaces file.

* stratux.log cleanup.

* Remove unused 'CPULoad' status variable.

* Typo fix.

* Move to cyoung/goflying, 'stratux_master' branch.

* Update goflying.

* Update goflying.

* Change goflying version.

* Merge branch 'master' into ahrs_dev_protocolfun

# Conflicts:
#	selfupdate/makeupdate.sh
#	selfupdate/update_footer.sh

* Cleanup.

* Add Merlin auto-detect.

* Clean up log output.

* Update oled package to new 'luma' package name.

Fixes cyoung#672.

* Change luma usage.

cyoung#672.

* Use estimate vAcc = 2*hAcc instead of reported vAcc.

Fixes cyoung#666.

* Turn off PPS output (green LED on GPYes).

cyoung#659.

* Add NightMode to turn off ACT LED.

cyoung#659.

* Remove socket listener from fancontrol. Replace with http server. Serve status in JSON format.

* Update system uptime warning format.

* update readme.md

added additional jet tests.

* Turn off wireless power management, from D. DeMartini.

* Add logrotate conf. Keep two days of logs. Run logrotate on boot.

* Add some AHRS and maintenance web calls to documents.

* Change deleted AvSquirrel/dump1090 submodule to mirror at stratux/dump1090

* Remove old libimu.so references in selfupdate.

* Create function that tracks critical system errors and issues them only once.

cyoung#692

* Use addSingleSystemErrorf() instead of tracking error prints individually.

cyoung#692.

* Change error prints to use addSingleSystemErrorf().

cyoung#692

* Clean up unused imports.

cyoung#692

* Upgrade golang version in CircleCI from 1.6 to 1.9.2.

* Clean gopath on each CircleCI build.

* Install mercurial on CircleCI.

* Remove "test" directory from go get in gen_gdl90 make.

* Cleanup.

cyoung#692

* Remove test build from CircleCI config.

* Change CircleCI to test to build master.

* Remove unnecessary debug print.

* Delete /var/log/stratux* on update.

* Simplify "Settings" page.

Only display "Hardware" and "Diagnostic" settings when in developer mode.

* Make PPM setting a developer option.

cyoung#79.

* Roll back changes.

* Use "N" or "C" regs derived from Mode-S identifier, or default to "Stratux".

* RPi3B+ setup.

* Add new ForeFlight AHRS and ID GDL90 messages.

* Change ForeFlight support note in README.

* Update ForeFlight version to 10+ for AHRS support.

* gen_gdl90 gracefulShutdown() on system shutdown or reboot request.

* Clean up obsolete dangerzone includes.

* Fan control failsafe temp.

cyoung#663

* Fix gdl90 AHRSGyroHeading reporting.

* Comment out ublox8 Glonass / Galileo code.

* Increase suggested wait time on updates.

* Add info to main status help page.

Fixes cyoung#728.

* Adds AU tail number decoding from ICAO addr.

Contribution by @armeniki. cyoung#736.
tobo07 added a commit to tobo07/stratux that referenced this issue Aug 19, 2018
* Remove old AHRS replay tools. Add protocol tools.

* Typo and path fix.

* Change IP Stratux IP address and DHCP range.

* Update install and auto-start scripts.

* Update make clean.

* Add missing files from update scripts.

* Update goflying.

* Update goflying.

* Add alias for 192.168.10.1 for normal webui access.

* Adapt `ffMonitor()` to ahrs_approx - only send the FF AHRS packets when FF is detected.

* Add dhcpd.conf and interfaces files to .sh update.

* Remove sqlite log and stratux.log on update.

* Install dhcpd.conf and interfaces file.

* stratux.log cleanup.

* Remove unused 'CPULoad' status variable.

* Typo fix.

* Move to cyoung/goflying, 'stratux_master' branch.

* Update goflying.

* Update goflying.

* Change goflying version.

* Merge branch 'master' into ahrs_dev_protocolfun

# Conflicts:
#	selfupdate/makeupdate.sh
#	selfupdate/update_footer.sh

* Cleanup.

* Add Merlin auto-detect.

* Clean up log output.

* Update oled package to new 'luma' package name.

Fixes cyoung#672.

* Change luma usage.

cyoung#672.

* Use estimate vAcc = 2*hAcc instead of reported vAcc.

Fixes cyoung#666.

* Turn off PPS output (green LED on GPYes).

cyoung#659.

* Add NightMode to turn off ACT LED.

cyoung#659.

* Remove socket listener from fancontrol. Replace with http server. Serve status in JSON format.

* Update system uptime warning format.

* update readme.md

added additional jet tests.

* Turn off wireless power management, from D. DeMartini.

* Add logrotate conf. Keep two days of logs. Run logrotate on boot.

* Add some AHRS and maintenance web calls to documents.

* Change deleted AvSquirrel/dump1090 submodule to mirror at stratux/dump1090

* Remove old libimu.so references in selfupdate.

* Create function that tracks critical system errors and issues them only once.

cyoung#692

* Use addSingleSystemErrorf() instead of tracking error prints individually.

cyoung#692.

* Change error prints to use addSingleSystemErrorf().

cyoung#692

* Clean up unused imports.

cyoung#692

* Upgrade golang version in CircleCI from 1.6 to 1.9.2.

* Clean gopath on each CircleCI build.

* Install mercurial on CircleCI.

* Remove "test" directory from go get in gen_gdl90 make.

* Cleanup.

cyoung#692

* Remove test build from CircleCI config.

* Change CircleCI to test to build master.

* Remove unnecessary debug print.

* Delete /var/log/stratux* on update.

* Simplify "Settings" page.

Only display "Hardware" and "Diagnostic" settings when in developer mode.

* Make PPM setting a developer option.

cyoung#79.

* Roll back changes.

* Use "N" or "C" regs derived from Mode-S identifier, or default to "Stratux".

* RPi3B+ setup.

* Add new ForeFlight AHRS and ID GDL90 messages.

* Change ForeFlight support note in README.

* Update ForeFlight version to 10+ for AHRS support.

* gen_gdl90 gracefulShutdown() on system shutdown or reboot request.

* Clean up obsolete dangerzone includes.

* Fan control failsafe temp.

cyoung#663

* Fix gdl90 AHRSGyroHeading reporting.

* Comment out ublox8 Glonass / Galileo code.

* Increase suggested wait time on updates.

* Add info to main status help page.

Fixes cyoung#728.

* Adds AU tail number decoding from ICAO addr.

Contribution by @armeniki. cyoung#736.
tobo07 added a commit to tobo07/stratux that referenced this issue Sep 22, 2018
* Add info to main status help page.

Fixes cyoung#728.

* Adds AU tail number decoding from ICAO addr.

Contribution by @armeniki. cyoung#736.

* update readme

Remove line about dangerzone and added kwikEFIS to the list of apps that support Stratux

* Revert 0d93623.

* Add SoftRF udev rules and "ping" code hack (temporary).
tobo07 added a commit to tobo07/stratux that referenced this issue Sep 22, 2018
* Add info to main status help page.

Fixes cyoung#728.

* Adds AU tail number decoding from ICAO addr.

Contribution by @armeniki. cyoung#736.

* update readme

Remove line about dangerzone and added kwikEFIS to the list of apps that support Stratux

* Revert 0d93623.

* Add SoftRF udev rules and "ping" code hack (temporary).

* Update gen_gdl90.go

* Update flarm.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants