Skip to content

Commit

Permalink
Filter skipping feature
Browse files Browse the repository at this point in the history
  • Loading branch information
varnav committed Jun 7, 2023
1 parent 6083092 commit 28ac0ba
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
```
```

## See also

http://jasonplayne.com:8080/ - raw packet decoder
57 changes: 36 additions & 21 deletions dumpsbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -54,35 +74,30 @@ 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)
}
_, err = writer.WriteString(line)
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
}

0 comments on commit 28ac0ba

Please sign in to comment.