kopia lustrzana https://github.com/cyoung/stratux
Fixes #102.
START,Thu Nov 12 19:25:38 +0000 UTC 2015,Thu Nov 12 19:25:38 +0000 UTC 2015 UNPAUSE,71289772 2739899291,Found 2 device(s): 2740283977,0: Realtek, RTL2838UHIDIR, SN: stratux:978 2740438248,1: Realtek, RTL2838UHIDIR, SN: 00000001 (currently selected) 2740605904,Found Rafael Micro R820T tuner 2740683299,Max available gain is: 49.60 2740807935,Setting gain to: 49.60 2740880330,Exact sample rate is: 2000000.052982 Hz 2740943976,Gain reported by device: 49.60pull/112/head^2
rodzic
3745a805b7
commit
7f50242867
|
@ -31,6 +31,7 @@ const (
|
|||
esReplayLog = "/var/log/stratux-es.log"
|
||||
gpsReplayLog = "/var/log/stratux-gps.log"
|
||||
ahrsReplayLog = "/var/log/stratux-ahrs.log"
|
||||
dump1090ReplayLog = "/var/log/stratux-dump1090.log"
|
||||
|
||||
UPLINK_BLOCK_DATA_BITS = 576
|
||||
UPLINK_BLOCK_BITS = (UPLINK_BLOCK_DATA_BITS + 160)
|
||||
|
@ -51,10 +52,11 @@ const (
|
|||
MSGTYPE_BASIC_REPORT = 0x1E
|
||||
MSGTYPE_LONG_REPORT = 0x1F
|
||||
|
||||
MSGCLASS_UAT = 0
|
||||
MSGCLASS_ES = 1
|
||||
MSGCLASS_GPS = 3
|
||||
MSGCLASS_AHRS = 4
|
||||
MSGCLASS_UAT = 0
|
||||
MSGCLASS_ES = 1
|
||||
MSGCLASS_GPS = 3
|
||||
MSGCLASS_AHRS = 4
|
||||
MSGCLASS_DUMP1090 = 5
|
||||
|
||||
LON_LAT_RESOLUTION = float32(180.0 / 8388608.0)
|
||||
TRACK_RESOLUTION = float32(360.0 / 256.0)
|
||||
|
@ -74,6 +76,7 @@ var uatReplayfp *os.File
|
|||
var esReplayfp *os.File
|
||||
var gpsReplayfp *os.File
|
||||
var ahrsReplayfp *os.File
|
||||
var dump1090Replayfp *os.File
|
||||
|
||||
type msg struct {
|
||||
MessageClass uint
|
||||
|
@ -469,6 +472,23 @@ func updateStatus() {
|
|||
globalStatus.Uptime = time.Since(timeStarted).Nanoseconds() / 1000000
|
||||
}
|
||||
|
||||
type ReplayWriter struct {
|
||||
fp *os.File
|
||||
}
|
||||
|
||||
func (r ReplayWriter) Write(p []byte) (n int, err error) {
|
||||
//TODO.
|
||||
return r.fp.Write(p)
|
||||
}
|
||||
|
||||
func (r ReplayWriter) Close() error {
|
||||
return r.fp.Close()
|
||||
}
|
||||
|
||||
func makeReplayLogEntry(msg string) string {
|
||||
return fmt.Sprintf("%d,%s\n", time.Since(timeStarted).Nanoseconds(), msg)
|
||||
}
|
||||
|
||||
func replayLog(msg string, msgclass int) {
|
||||
if !globalSettings.ReplayLog { // Logging disabled.
|
||||
return
|
||||
|
@ -487,9 +507,12 @@ func replayLog(msg string, msgclass int) {
|
|||
fp = gpsReplayfp
|
||||
case MSGCLASS_AHRS:
|
||||
fp = ahrsReplayfp
|
||||
case MSGCLASS_DUMP1090:
|
||||
fp = dump1090Replayfp
|
||||
}
|
||||
if fp != nil {
|
||||
fmt.Fprintf(fp, "%d,%s\n", time.Since(timeStarted).Nanoseconds(), msg)
|
||||
s := makeReplayLogEntry(msg)
|
||||
fp.Write([]byte(s))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -799,6 +822,10 @@ func replayMark(active bool) {
|
|||
ahrsReplayfp.Write([]byte(t))
|
||||
}
|
||||
|
||||
if dump1090Replayfp != nil {
|
||||
dump1090Replayfp.Write([]byte(t))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func openReplay(fn string) (*os.File, error) {
|
||||
|
@ -884,6 +911,13 @@ func main() {
|
|||
ahrsReplayfp = ahrsfp
|
||||
defer ahrsReplayfp.Close()
|
||||
}
|
||||
// Dump1090 replay log.
|
||||
if dump1090fp, err := openReplay(dump1090ReplayLog); err != nil {
|
||||
globalSettings.ReplayLog = false
|
||||
} else {
|
||||
dump1090Replayfp = dump1090fp
|
||||
defer dump1090Replayfp.Close()
|
||||
}
|
||||
|
||||
// Mark the files (whether we're logging or not).
|
||||
replayMark(globalSettings.ReplayLog)
|
||||
|
|
30
main/sdr.go
30
main/sdr.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
|
@ -34,20 +35,42 @@ var es_wg *sync.WaitGroup = &sync.WaitGroup{}
|
|||
|
||||
var maxSignalStrength int
|
||||
|
||||
func readToChan(fp io.ReadCloser, ch chan []byte) {
|
||||
for {
|
||||
buf := make([]byte, 1024)
|
||||
n, err := fp.Read(buf)
|
||||
if n > 0 {
|
||||
ch <- buf[:n]
|
||||
} else if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ES) read() {
|
||||
defer es_wg.Done()
|
||||
log.Println("Entered ES read() ...")
|
||||
cmd := exec.Command("/usr/bin/dump1090", "--net", "--device-index", strconv.Itoa(e.indexID))
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
stderr, _ := cmd.StderrPipe()
|
||||
|
||||
outputChan := make(chan []byte, 1024)
|
||||
|
||||
go readToChan(stdout, outputChan)
|
||||
go readToChan(stderr, outputChan)
|
||||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
log.Printf("Error executing /usr/bin/dump1090: %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
log.Println("Executed /usr/bin/dump1090 successfully...")
|
||||
|
||||
for {
|
||||
select {
|
||||
default:
|
||||
time.Sleep(1 * time.Second)
|
||||
case buf := <-outputChan:
|
||||
replayLog(string(buf), MSGCLASS_DUMP1090)
|
||||
|
||||
case <-es_shutdown:
|
||||
log.Println("ES read(): shutdown msg received, calling cmd.Process.Kill() ...")
|
||||
err := cmd.Process.Kill()
|
||||
|
@ -58,6 +81,9 @@ func (e *ES) read() {
|
|||
log.Println("\t kill successful...")
|
||||
}
|
||||
return
|
||||
default:
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue