kopia lustrzana https://github.com/cyoung/stratux
commit
c4762633b0
|
@ -1,14 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"sync"
|
||||
"github.com/sevlyar/go-daemon"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -17,7 +16,6 @@ const (
|
|||
maxDatagramSize = 8192
|
||||
)
|
||||
|
||||
|
||||
type PositionInfo struct {
|
||||
lat string
|
||||
lng string
|
||||
|
|
|
@ -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_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_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,7 +45,7 @@ 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
|
||||
|
@ -63,13 +61,13 @@ fmt.Printf("dlac on %s\n", hex.Dump(data))
|
|||
} 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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
|
38
gen_gdl90.go
38
gen_gdl90.go
|
@ -1,14 +1,13 @@
|
|||
package main
|
||||
|
||||
|
||||
import (
|
||||
"net"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
"strings"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// http://www.faa.gov/nextgen/programs/adsb/wsa/media/GDL90_Public_ICD_RevA.PDF
|
||||
|
@ -17,22 +16,21 @@ 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)
|
||||
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_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,7 +128,6 @@ 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 ';'.
|
||||
|
@ -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.
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue