-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
80 lines (65 loc) · 1.77 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Package main creates subprocesses, a pipeline to pass stdout from RTL-SDR to
// stdin of multimon-ng. Then, stdout from multimon-ng is decoded and handled by
// packet handlers.
package main
import (
"fmt"
"io"
"os"
"os/signal"
"syscall"
"github.com/cceremuga/ionosphere/services/config"
"github.com/cceremuga/ionosphere/services/handler"
"github.com/cceremuga/ionosphere/services/log"
"github.com/cceremuga/ionosphere/services/packet"
"github.com/cceremuga/ionosphere/subprocesses/multimon"
"github.com/cceremuga/ionosphere/subprocesses/rtlfm"
"github.com/cceremuga/ionosphere/tasks/beacon"
"github.com/fatih/color"
)
const logo = `
____ __
/ _/__ ___ ___ ___ ___ / / ___ _______
_/ // _ \/ _ \/ _ \(_-</ _ \/ _ \/ -_) __/ -_)
/___/\___/_//_/\___/___/ .__/_//_/\__/_/ \__/
/_/
`
func main() {
color.Cyan(logo)
log.Debug("Ionosphere initializing.")
c := config.Load()
// Pipe io from rtl_fm to multimon-ng
rtl := rtlfm.Build(&c.Rtl)
mult := multimon.Build(&c.Multimon)
r, w := io.Pipe()
rtl.Stdout = w
mult.Stdin = r
// Start handlers, then subprocesses.
handler.Start()
rtlfm.Start(rtl)
multimon.Start(mult, packet.Decode)
beacon.Start(&c.Beacon)
// Listen for exit signals, set up for a clean exit.
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan,
syscall.SIGINT,
syscall.SIGKILL,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
s := <-sigchan
log.Debug(fmt.Sprintf("Signal (%s) caught, terminating processes.", s))
w.Close()
rtl.Process.Kill()
mult.Process.Kill()
log.Debug("Ionosphere exiting!")
os.Exit(0)
}()
log.Debug("Listening for packets.")
// Perform a clean exit if one of the subprocesses terms early.
go func() {
rtl.Wait()
w.Close()
}()
mult.Wait()
}