diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a872999..7c4d8c9 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -27,7 +27,7 @@ jobs: # working-directory: somedir # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 + args: dumpsbs.go --fast # Optional: show only new issues if it's a pull request. The default value is `false`. # only-new-issues: true diff --git a/README.md b/README.md index 3512caf..f3ca359 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,15 @@ # DumpSBS -Golang tool to connect to ADS-B receivers like [readsb](https://github.com/wiedehopf/readsb) or [dump1090](https://github.com/flightaware/dump1090) via [SBS protocol](http://woodair.net/sbs/article/barebones42_socket_data.htm) and dump data to files. +Golang tool to connect to ADS-B receivers like [readsb](https://github.com/wiedehopf/readsb) or [dump1090](https://github.com/flightaware/dump1090), or services like [ADS-B Hub](https://www.adsbhub.org/howtogetdata.php) via [SBS protocol](http://woodair.net/sbs/article/barebones42_socket_data.htm) and dump data to files. New file will be created hourly. -Add this to cron.daily to compress those files: +`netcat` can do basic dumping fine, but this tool also does filtering and dump file rotation + +Add this to `/etc/cron.hourly/` to compress those files: ```sh -find /opt/dumpsbs/logs -mtime +1 -name '*.csv' -exec xz -3 {} \; +#!/bin/sh +find /opt/dumpsbs/logs -mmin +90 -name '*.csv' -exec zstd -9 --rm {} \; ``` ```go @@ -33,4 +36,8 @@ type SBS struct { SPI int // Flag to indicate the transponder ident has been activated IsOnGround int // Flag to indicate the ground squat switch is active } -``` \ No newline at end of file +``` + +## See also + +http://jasonplayne.com:8080/ - raw packet decoder \ No newline at end of file diff --git a/dumpsbs.go b/dumpsbs.go index 9b6ba8a..76921ff 100644 --- a/dumpsbs.go +++ b/dumpsbs.go @@ -16,12 +16,28 @@ var ( f *os.File ) +func getCurrentFileName(outputDir string) string { + t := time.Now() + return outputDir + "/" + t.Format("20060102_15") + ".csv" +} + +func createWriter(filename string) (*os.File, *bufio.Writer) { + f, err := os.Create(filename) + if err != nil { + log.Fatal(err) + } + + writer := bufio.NewWriter(f) + return f, writer +} + func main() { // Command line arguments host := flag.String("host", "localhost:30003", "The host to connect to") outputDir := flag.String("output", ".", "The output directory") verbose := flag.Bool("v", false, "Print not just to file but also to STDOUT") vnf := flag.Bool("vnf", false, "Print filtered out data to STDOUT") + sf := flag.Bool("sf", false, "Skip filters") flag.Parse() // Connect to the TCP server @@ -32,6 +48,10 @@ func main() { println("Connected to", *host) defer conn.Close() + if *sf { + println("Skipping filters") + } + // Read data from the TCP connection reader := bufio.NewReader(conn) for { @@ -54,10 +74,7 @@ func main() { defer f.Close() } - // Write the data to the file if necessary values are found - linearr := strings.Split(line, ",") - // Field numbers, 12 equals 11 in array: http://woodair.net/sbs/article/barebones42_socket_data.htm - if len(line) > 10 && (len(linearr[11]) > 0 || len(linearr[17]) > 0 || len(linearr[10]) > 0) { // Data not empty, line is complete + if len(line) > 10 && *sf { // Skipping filters if *verbose { print(line) } @@ -65,24 +82,22 @@ func main() { if err != nil { log.Fatal(err) } - } else if *vnf { - print(line) + } else { // Not skipping filters + linearr := strings.Split(line, ",") + // Write the data to the file if necessary values are found + // Field numbers, 12 equals 11 in array: http://woodair.net/sbs/article/barebones42_socket_data.htm + if len(line) > 10 && (len(linearr[11]) > 0 || len(linearr[17]) > 0 || len(linearr[10]) > 0) { + if *verbose { + print(line) + } + _, err = writer.WriteString(line) + if err != nil { + log.Fatal(err) + } + } else if *vnf { + print(line) + } } writer.Flush() } } - -func getCurrentFileName(outputDir string) string { - t := time.Now() - return outputDir + "/" + t.Format("20060102_15") + ".txt" -} - -func createWriter(filename string) (*os.File, *bufio.Writer) { - f, err := os.Create(filename) - if err != nil { - log.Fatal(err) - } - - writer := bufio.NewWriter(f) - return f, writer -}