kopia lustrzana https://github.com/cyoung/stratux
commit
c4762633b0
|
@ -1,31 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"sync"
|
||||
"github.com/sevlyar/go-daemon"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ipadAddr = "192.168.10.255:49002"
|
||||
dump1090Addr = "127.0.0.1:30003"
|
||||
ipadAddr = "192.168.10.255:49002"
|
||||
dump1090Addr = "127.0.0.1:30003"
|
||||
maxDatagramSize = 8192
|
||||
)
|
||||
|
||||
|
||||
type PositionInfo struct {
|
||||
lat string
|
||||
lng string
|
||||
alt string
|
||||
hdg string
|
||||
vel string
|
||||
vr string
|
||||
tail string
|
||||
lat string
|
||||
lng string
|
||||
alt string
|
||||
hdg string
|
||||
vel string
|
||||
vr string
|
||||
tail string
|
||||
last_seen time.Time
|
||||
}
|
||||
|
||||
|
@ -140,4 +138,4 @@ func main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"strings"
|
||||
"encoding/hex"
|
||||
"log"
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
const (
|
||||
UPLINK_BLOCK_DATA_BITS = 576
|
||||
UPLINK_BLOCK_BITS = (UPLINK_BLOCK_DATA_BITS+160)
|
||||
UPLINK_BLOCK_DATA_BYTES = (UPLINK_BLOCK_DATA_BITS/8)
|
||||
UPLINK_BLOCK_BYTES = (UPLINK_BLOCK_BITS/8)
|
||||
UPLINK_BLOCK_DATA_BITS = 576
|
||||
UPLINK_BLOCK_BITS = (UPLINK_BLOCK_DATA_BITS + 160)
|
||||
UPLINK_BLOCK_DATA_BYTES = (UPLINK_BLOCK_DATA_BITS / 8)
|
||||
UPLINK_BLOCK_BYTES = (UPLINK_BLOCK_BITS / 8)
|
||||
|
||||
UPLINK_FRAME_BLOCKS = 6
|
||||
UPLINK_FRAME_DATA_BITS = (UPLINK_FRAME_BLOCKS * UPLINK_BLOCK_DATA_BITS)
|
||||
UPLINK_FRAME_BITS = (UPLINK_FRAME_BLOCKS * UPLINK_BLOCK_BITS)
|
||||
UPLINK_FRAME_DATA_BYTES = (UPLINK_FRAME_DATA_BITS/8)
|
||||
UPLINK_FRAME_BYTES = (UPLINK_FRAME_BITS/8)
|
||||
UPLINK_FRAME_BLOCKS = 6
|
||||
UPLINK_FRAME_DATA_BITS = (UPLINK_FRAME_BLOCKS * UPLINK_BLOCK_DATA_BITS)
|
||||
UPLINK_FRAME_BITS = (UPLINK_FRAME_BLOCKS * UPLINK_BLOCK_BITS)
|
||||
UPLINK_FRAME_DATA_BYTES = (UPLINK_FRAME_DATA_BITS / 8)
|
||||
UPLINK_FRAME_BYTES = (UPLINK_FRAME_BITS / 8)
|
||||
|
||||
// assume 6 byte frames: 2 header bytes, 4 byte payload
|
||||
// (TIS-B heartbeat with one address, or empty FIS-B APDU)
|
||||
UPLINK_MAX_INFO_FRAMES = (424/6)
|
||||
UPLINK_MAX_INFO_FRAMES = (424 / 6)
|
||||
|
||||
dlac_alpha = "\x03ABCDEFGHIJKLMNOPQRSTUVWXYZ\x1A\t\x1E\n| !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||
)
|
||||
|
@ -33,9 +32,8 @@ const (
|
|||
var logger *log.Logger
|
||||
var buf bytes.Buffer
|
||||
|
||||
|
||||
func dlac_decode(data []byte, data_len uint32) string {
|
||||
fmt.Printf("dlac on %s\n", hex.Dump(data))
|
||||
fmt.Printf("dlac on %s\n", hex.Dump(data))
|
||||
step := 0
|
||||
tab := false
|
||||
ret := ""
|
||||
|
@ -47,29 +45,29 @@ fmt.Printf("dlac on %s\n", hex.Dump(data))
|
|||
case 1:
|
||||
ch = ((uint32(data[i-1]) & 0x03) << 4) | (uint32(data[i+0]) >> 4)
|
||||
case 2:
|
||||
ch = ((uint32(data[i-1]) & 0x0f) << 2) | (uint32(data[i+0]) >> 6);
|
||||
ch = ((uint32(data[i-1]) & 0x0f) << 2) | (uint32(data[i+0]) >> 6)
|
||||
i = i - 1
|
||||
case 3:
|
||||
ch = uint32(data[i+0]) & 0x3f
|
||||
ch = uint32(data[i+0]) & 0x3f
|
||||
}
|
||||
if tab {
|
||||
for ch > 0 {
|
||||
ret += " "
|
||||
ch--
|
||||
}
|
||||
tab = false
|
||||
tab = false
|
||||
} else if ch == 28 { // tab
|
||||
tab = true
|
||||
} else {
|
||||
ret += string(dlac_alpha[ch])
|
||||
}
|
||||
step = (step+1)%4
|
||||
step = (step + 1) % 4
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func decodeInfoFrame(frame []byte, frame_start int, frame_len uint32, frame_type uint32) {
|
||||
data := frame[frame_start:frame_start+int(frame_len)]
|
||||
data := frame[frame_start : frame_start+int(frame_len)]
|
||||
|
||||
if frame_type != 0 {
|
||||
return // Not FIS-B.
|
||||
|
@ -80,7 +78,7 @@ func decodeInfoFrame(frame []byte, frame_start int, frame_len uint32, frame_type
|
|||
|
||||
t_opt := ((uint32(data[1]) & 0x01) << 1) | (uint32(data[2]) >> 7)
|
||||
product_id := ((uint32(data[0]) & 0x1f) << 6) | (uint32(data[1]) >> 2)
|
||||
fmt.Printf("%d %d\n", data[0], data[1])
|
||||
fmt.Printf("%d %d\n", data[0], data[1])
|
||||
if product_id != 413 { // FIXME.
|
||||
return
|
||||
}
|
||||
|
@ -91,9 +89,9 @@ fmt.Printf("%d %d\n", data[0], data[1])
|
|||
}
|
||||
|
||||
fisb_hours := (uint32(data[2]) & 0x7c) >> 2
|
||||
fisb_minutes := ((uint32(data[2]) & 0x03) << 4) | (uint32(data[3]) >> 4)
|
||||
fisb_length := frame_len - 4
|
||||
fisb_data := data[4:]
|
||||
fisb_minutes := ((uint32(data[2]) & 0x03) << 4) | (uint32(data[3]) >> 4)
|
||||
fisb_length := frame_len - 4
|
||||
fisb_data := data[4:]
|
||||
|
||||
p := dlac_decode(fisb_data, fisb_length)
|
||||
fmt.Printf("%v\n", p)
|
||||
|
@ -103,9 +101,9 @@ fmt.Printf("%d %d\n", data[0], data[1])
|
|||
|
||||
func decodeUplink(frame []byte) {
|
||||
position_valid := (uint32(frame[5]) & 0x01) != 0
|
||||
raw_lat := (uint32(frame[0]) << 15) | (uint32(frame[1]) << 7) | (uint32(frame[2]) >> 1)
|
||||
raw_lat := (uint32(frame[0]) << 15) | (uint32(frame[1]) << 7) | (uint32(frame[2]) >> 1)
|
||||
|
||||
raw_lon := ((uint32(frame[2]) & 0x01) << 23) | (uint32(frame[3]) << 15) | (uint32(frame[4]) << 7) | (uint32(frame[5]) >> 1)
|
||||
raw_lon := ((uint32(frame[2]) & 0x01) << 23) | (uint32(frame[3]) << 15) | (uint32(frame[4]) << 7) | (uint32(frame[5]) >> 1)
|
||||
lat := float64(raw_lat) * 360.0 / 16777216.0
|
||||
lon := float64(raw_lon) * 360.0 / 16777216.0
|
||||
|
||||
|
@ -118,8 +116,8 @@ func decodeUplink(frame []byte) {
|
|||
|
||||
utc_coupled := (uint32(frame[6]) & 0x80) != 0
|
||||
app_data_valid := (uint32(frame[6]) & 0x20) != 0
|
||||
slot_id := uint32(frame[6]) & 0x1f;
|
||||
tisb_site_id := uint32(frame[7]) >> 4;
|
||||
slot_id := uint32(frame[6]) & 0x1f
|
||||
tisb_site_id := uint32(frame[7]) >> 4
|
||||
|
||||
logger.Printf("position_valid=%t, %.04f, %.04f, %t, %t, %d, %d\n", position_valid, lat, lon, utc_coupled, app_data_valid, slot_id, tisb_site_id)
|
||||
|
||||
|
@ -131,11 +129,11 @@ func decodeUplink(frame []byte) {
|
|||
num_info_frames := 0
|
||||
pos := 0
|
||||
total_len := len(app_data)
|
||||
for (num_info_frames < UPLINK_MAX_INFO_FRAMES) && (pos + 2 <= total_len) {
|
||||
for (num_info_frames < UPLINK_MAX_INFO_FRAMES) && (pos+2 <= total_len) {
|
||||
data := app_data[pos:]
|
||||
frame_length := (uint32(data[0]) << 1) | (uint32(data[1]) >> 7)
|
||||
frame_type := uint32(data[1]) & 0x0f
|
||||
if pos + int(frame_length) > total_len {
|
||||
if pos+int(frame_length) > total_len {
|
||||
break // Overrun?
|
||||
}
|
||||
if frame_length == 0 && frame_type == 0 {
|
||||
|
@ -149,7 +147,7 @@ func decodeUplink(frame []byte) {
|
|||
|
||||
func parseInput(buf string) {
|
||||
buf = strings.Trim(buf, "\r\n") // Remove newlines.
|
||||
x := strings.Split(buf, ";") // We want to discard everything before the first ';'.
|
||||
x := strings.Split(buf, ";") // We want to discard everything before the first ';'.
|
||||
if len(x) == 0 {
|
||||
return
|
||||
}
|
||||
|
@ -164,7 +162,7 @@ func parseInput(buf string) {
|
|||
|
||||
s = s[1:]
|
||||
|
||||
if len(s) % 2 != 0 { // Bad format.
|
||||
if len(s)%2 != 0 { // Bad format.
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -182,7 +180,6 @@ func parseInput(buf string) {
|
|||
decodeUplink(frame)
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
logger = log.New(&buf, "logger: ", log.Lshortfile)
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
@ -190,4 +187,4 @@ func main() {
|
|||
buf, _ := reader.ReadString('\n')
|
||||
parseInput(buf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
58
gen_gdl90.go
58
gen_gdl90.go
|
@ -1,38 +1,36 @@
|
|||
package main
|
||||
|
||||
|
||||
import (
|
||||
"net"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
"strings"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"os"
|
||||
"bufio"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// http://www.faa.gov/nextgen/programs/adsb/wsa/media/GDL90_Public_ICD_RevA.PDF
|
||||
|
||||
const (
|
||||
ipadAddr = "192.168.10.255:4000" // Port 4000 for FreeFlight RANGR.
|
||||
maxDatagramSize = 8192
|
||||
UPLINK_BLOCK_DATA_BITS = 576
|
||||
UPLINK_BLOCK_BITS = (UPLINK_BLOCK_DATA_BITS+160)
|
||||
UPLINK_BLOCK_DATA_BYTES = (UPLINK_BLOCK_DATA_BITS/8)
|
||||
UPLINK_BLOCK_BYTES = (UPLINK_BLOCK_BITS/8)
|
||||
ipadAddr = "192.168.10.255:4000" // Port 4000 for FreeFlight RANGR.
|
||||
maxDatagramSize = 8192
|
||||
UPLINK_BLOCK_DATA_BITS = 576
|
||||
UPLINK_BLOCK_BITS = (UPLINK_BLOCK_DATA_BITS + 160)
|
||||
UPLINK_BLOCK_DATA_BYTES = (UPLINK_BLOCK_DATA_BITS / 8)
|
||||
UPLINK_BLOCK_BYTES = (UPLINK_BLOCK_BITS / 8)
|
||||
|
||||
UPLINK_FRAME_BLOCKS = 6
|
||||
UPLINK_FRAME_DATA_BITS = (UPLINK_FRAME_BLOCKS * UPLINK_BLOCK_DATA_BITS)
|
||||
UPLINK_FRAME_BITS = (UPLINK_FRAME_BLOCKS * UPLINK_BLOCK_BITS)
|
||||
UPLINK_FRAME_DATA_BYTES = (UPLINK_FRAME_DATA_BITS/8)
|
||||
UPLINK_FRAME_BYTES = (UPLINK_FRAME_BITS/8)
|
||||
UPLINK_FRAME_BLOCKS = 6
|
||||
UPLINK_FRAME_DATA_BITS = (UPLINK_FRAME_BLOCKS * UPLINK_BLOCK_DATA_BITS)
|
||||
UPLINK_FRAME_BITS = (UPLINK_FRAME_BLOCKS * UPLINK_BLOCK_BITS)
|
||||
UPLINK_FRAME_DATA_BYTES = (UPLINK_FRAME_DATA_BITS / 8)
|
||||
UPLINK_FRAME_BYTES = (UPLINK_FRAME_BITS / 8)
|
||||
|
||||
// assume 6 byte frames: 2 header bytes, 4 byte payload
|
||||
// (TIS-B heartbeat with one address, or empty FIS-B APDU)
|
||||
UPLINK_MAX_INFO_FRAMES = (424/6)
|
||||
UPLINK_MAX_INFO_FRAMES = (424 / 6)
|
||||
)
|
||||
|
||||
|
||||
var Crc16Table [256]uint16
|
||||
var outConn *net.UDPConn
|
||||
|
||||
|
@ -58,7 +56,7 @@ func crcInit() {
|
|||
func crcCompute(data []byte) uint16 {
|
||||
ret := uint16(0)
|
||||
for i := 0; i < len(data); i++ {
|
||||
ret = Crc16Table[ret >> 8] ^ (ret << 8) ^ uint16(data[i])
|
||||
ret = Crc16Table[ret>>8] ^ (ret << 8) ^ uint16(data[i])
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
@ -79,8 +77,8 @@ func prepareMessage(data []byte) []byte {
|
|||
}
|
||||
|
||||
// Add the two CRC16 bytes.
|
||||
tmp = append(tmp, byte(crc & 0xFF))
|
||||
tmp = append(tmp, byte(crc >> 8))
|
||||
tmp = append(tmp, byte(crc&0xFF))
|
||||
tmp = append(tmp, byte(crc>>8))
|
||||
|
||||
tmp = append(tmp, 0x7E) // Flag end.
|
||||
|
||||
|
@ -109,7 +107,7 @@ func makeHeartbeat() []byte {
|
|||
}
|
||||
|
||||
func relayUplinkMessage(msg []byte) {
|
||||
ret := make([]byte, len(msg) + 4)
|
||||
ret := make([]byte, len(msg)+4)
|
||||
// See p.15.
|
||||
ret[0] = 0x07 // Uplink message ID.
|
||||
ret[1] = 0x00 //TODO: Time.
|
||||
|
@ -130,10 +128,9 @@ func heartBeatSender() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func parseInput(buf string) []byte {
|
||||
buf = strings.Trim(buf, "\r\n") // Remove newlines.
|
||||
x := strings.Split(buf, ";") // We want to discard everything before the first ';'.
|
||||
x := strings.Split(buf, ";") // We want to discard everything before the first ';'.
|
||||
if len(x) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -147,13 +144,13 @@ func parseInput(buf string) []byte {
|
|||
|
||||
s = s[1:]
|
||||
|
||||
if len(s) % 2 != 0 { // Bad format.
|
||||
if len(s)%2 != 0 { // Bad format.
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(s)/2 != UPLINK_FRAME_DATA_BYTES {
|
||||
fmt.Printf("UPLINK_FRAME_DATA_BYTES=%d, len(s)=%d\n", UPLINK_FRAME_DATA_BYTES, len(s))
|
||||
// panic("Error")
|
||||
// panic("Error")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -164,7 +161,6 @@ func parseInput(buf string) []byte {
|
|||
return frame
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
crcInit() // Initialize CRC16 table.
|
||||
|
||||
|
@ -188,4 +184,4 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue