kopia lustrzana https://github.com/cyoung/stratux
Formatting.
rodzic
5eb079dae6
commit
04ee9d8b1b
|
@ -745,11 +745,10 @@ type WeatherMessage struct {
|
||||||
Time string
|
Time string
|
||||||
Data string
|
Data string
|
||||||
LocaltimeReceived time.Time
|
LocaltimeReceived time.Time
|
||||||
Ticks int64
|
Ticks int64
|
||||||
TowerLon float64
|
TowerLon float64
|
||||||
TowerLat float64
|
TowerLat float64
|
||||||
TisId byte
|
TisId byte
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send update to connected websockets.
|
// Send update to connected websockets.
|
||||||
|
@ -774,7 +773,7 @@ func registerADSBTextMessageReceived(msg string, uatMsg *uatparse.UATMsg) {
|
||||||
globalStatus.UAT_PIREP_total++
|
globalStatus.UAT_PIREP_total++
|
||||||
}
|
}
|
||||||
if x[0] == "NEXRAD" {
|
if x[0] == "NEXRAD" {
|
||||||
log.Printf("registerADSBTextMessageReceived: %s\n",msg)
|
log.Printf("registerADSBTextMessageReceived: %s\n", msg)
|
||||||
wm.Type = x[0]
|
wm.Type = x[0]
|
||||||
wm.Data = strings.Join(x[1:], " ")
|
wm.Data = strings.Join(x[1:], " ")
|
||||||
wm.Location = "NEXRAD"
|
wm.Location = "NEXRAD"
|
||||||
|
@ -788,9 +787,9 @@ func registerADSBTextMessageReceived(msg string, uatMsg *uatparse.UATMsg) {
|
||||||
wm.LocaltimeReceived = stratuxClock.Time
|
wm.LocaltimeReceived = stratuxClock.Time
|
||||||
wm.TowerLon = uatMsg.Lon
|
wm.TowerLon = uatMsg.Lon
|
||||||
wm.TowerLat = uatMsg.Lat
|
wm.TowerLat = uatMsg.Lat
|
||||||
// now := time.Now()
|
// now := time.Now()
|
||||||
// Year := time.Year()
|
// Year := time.Year()
|
||||||
uatTime := time.Date(2016, time.Month(uatMsg.Frames[0].FISB_month),int(uatMsg.Frames[0].FISB_day), int(uatMsg.Frames[0].FISB_hours), int(uatMsg.Frames[0].FISB_minutes), int(uatMsg.Frames[0].FISB_seconds), 0, time.UTC)
|
uatTime := time.Date(2016, time.Month(uatMsg.Frames[0].FISB_month), int(uatMsg.Frames[0].FISB_day), int(uatMsg.Frames[0].FISB_hours), int(uatMsg.Frames[0].FISB_minutes), int(uatMsg.Frames[0].FISB_seconds), 0, time.UTC)
|
||||||
wm.Ticks = uatTime.UnixNano() / 1000000
|
wm.Ticks = uatTime.UnixNano() / 1000000
|
||||||
wmJSON, _ := json.Marshal(&wm)
|
wmJSON, _ := json.Marshal(&wm)
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ func handleJsonIo(conn *websocket.Conn) {
|
||||||
// Subscribe the socket to receive updates.
|
// Subscribe the socket to receive updates.
|
||||||
trafficUpdate.AddSocket(conn)
|
trafficUpdate.AddSocket(conn)
|
||||||
weatherUpdate.AddSocket(conn)
|
weatherUpdate.AddSocket(conn)
|
||||||
|
|
||||||
trafficMutex.Unlock()
|
trafficMutex.Unlock()
|
||||||
|
|
||||||
// Connection closes when function returns. Since uibroadcast is writing and we don't need to read anything (for now), just keep it busy.
|
// Connection closes when function returns. Since uibroadcast is writing and we don't need to read anything (for now), just keep it busy.
|
||||||
|
|
|
@ -75,7 +75,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type TrafficInfo struct {
|
type TrafficInfo struct {
|
||||||
Type string //
|
Type string //
|
||||||
Icao_addr uint32
|
Icao_addr uint32
|
||||||
Reg string // Registration. Calculated from Icao_addr for civil aircraft of US registry.
|
Reg string // Registration. Calculated from Icao_addr for civil aircraft of US registry.
|
||||||
Tail string // Callsign. Transmitted by aircraft.
|
Tail string // Callsign. Transmitted by aircraft.
|
||||||
|
|
|
@ -4,13 +4,14 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var elementIdentifier byte
|
var elementIdentifier byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UPLINK_BLOCK_DATA_BITS = 576
|
UPLINK_BLOCK_DATA_BITS = 576
|
||||||
UPLINK_BLOCK_BITS = (UPLINK_BLOCK_DATA_BITS + 160)
|
UPLINK_BLOCK_BITS = (UPLINK_BLOCK_DATA_BITS + 160)
|
||||||
|
@ -26,9 +27,9 @@ const (
|
||||||
// assume 6 byte frames: 2 header bytes, 4 byte payload
|
// assume 6 byte frames: 2 header bytes, 4 byte payload
|
||||||
// (TIS-B heartbeat with one address, or empty FIS-B APDU)
|
// (TIS-B heartbeat with one address, or empty FIS-B APDU)
|
||||||
UPLINK_MAX_INFO_FRAMES = (424 / 6)
|
UPLINK_MAX_INFO_FRAMES = (424 / 6)
|
||||||
COLS_PER_BIN = 32
|
COLS_PER_BIN = 32
|
||||||
ROWS_PER_BIN = 4
|
ROWS_PER_BIN = 4
|
||||||
|
|
||||||
dlac_alpha = "\x03ABCDEFGHIJKLMNOPQRSTUVWXYZ\x1A\t\x1E\n| !\"#$%&'()*+,-./0123456789:;<=>?"
|
dlac_alpha = "\x03ABCDEFGHIJKLMNOPQRSTUVWXYZ\x1A\t\x1E\n| !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -194,27 +195,27 @@ func formatDLACData(p string) []string {
|
||||||
func (f *UATFrame) decodeNexradFrame() {
|
func (f *UATFrame) decodeNexradFrame() {
|
||||||
ret := make([]string, 0)
|
ret := make([]string, 0)
|
||||||
builder := make([]string, 0)
|
builder := make([]string, 0)
|
||||||
|
|
||||||
if len(f.FISB_data) < int(f.FISB_length) {
|
if len(f.FISB_data) < int(f.FISB_length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mEmpty := make([]int32, 1)
|
mEmpty := make([]int32, 1)
|
||||||
mData := make([]int32, COLS_PER_BIN * ROWS_PER_BIN)
|
mData := make([]int32, COLS_PER_BIN*ROWS_PER_BIN)
|
||||||
elementIdentifier := f.FISB_data[0] & 0x80
|
elementIdentifier := f.FISB_data[0] & 0x80
|
||||||
mBlock := uint32(f.FISB_data[0] & 0x0f) << 16
|
mBlock := uint32(f.FISB_data[0]&0x0f) << 16
|
||||||
mBlock = mBlock | uint32(f.FISB_data[1]) << 8
|
mBlock = mBlock | uint32(f.FISB_data[1])<<8
|
||||||
mBlock = mBlock | uint32(f.FISB_data[2])
|
mBlock = mBlock | uint32(f.FISB_data[2])
|
||||||
index := 3
|
index := 3
|
||||||
// Make 32 * 4 array
|
// Make 32 * 4 array
|
||||||
if elementIdentifier != 0 {
|
if elementIdentifier != 0 {
|
||||||
// Clear the array
|
// Clear the array
|
||||||
for c:=0; c < (COLS_PER_BIN * ROWS_PER_BIN); c++ {
|
for c := 0; c < (COLS_PER_BIN * ROWS_PER_BIN); c++ {
|
||||||
mData[c] = 0
|
mData[c] = 0
|
||||||
}
|
}
|
||||||
j := 0
|
j := 0
|
||||||
for index < int(f.FISB_length) {
|
for index < int(f.FISB_length) {
|
||||||
numberOfBins := ((f.FISB_data[index] & 0xf8) >> 3) + 1
|
numberOfBins := ((f.FISB_data[index] & 0xf8) >> 3) + 1
|
||||||
for i:=0; i < int(numberOfBins); i++ {
|
for i := 0; i < int(numberOfBins); i++ {
|
||||||
if j >= int(COLS_PER_BIN*ROWS_PER_BIN) {
|
if j >= int(COLS_PER_BIN*ROWS_PER_BIN) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -226,7 +227,7 @@ func (f *UATFrame) decodeNexradFrame() {
|
||||||
} else {
|
} else {
|
||||||
bitmapLen := int32(f.FISB_data[index] & 0x0f)
|
bitmapLen := int32(f.FISB_data[index] & 0x0f)
|
||||||
// Start with 1 element
|
// Start with 1 element
|
||||||
|
|
||||||
mEmpty[0] = int32(mBlock)
|
mEmpty[0] = int32(mBlock)
|
||||||
if (f.FISB_data[index] & 0x10) != 0 {
|
if (f.FISB_data[index] & 0x10) != 0 {
|
||||||
mEmpty = append(mEmpty, int32(mBlock+1))
|
mEmpty = append(mEmpty, int32(mBlock+1))
|
||||||
|
@ -240,69 +241,69 @@ func (f *UATFrame) decodeNexradFrame() {
|
||||||
if (f.FISB_data[index] & 0x40) != 0 {
|
if (f.FISB_data[index] & 0x40) != 0 {
|
||||||
mEmpty = append(mEmpty, int32(mBlock+4))
|
mEmpty = append(mEmpty, int32(mBlock+4))
|
||||||
}
|
}
|
||||||
for i:=1; i<int(bitmapLen); i++ {
|
for i := 1; i < int(bitmapLen); i++ {
|
||||||
if (f.FISB_data[index+i] & 0x01) != 0 {
|
if (f.FISB_data[index+i] & 0x01) != 0 {
|
||||||
mEmpty = append(mEmpty, int32(mBlock + uint32(i) * 8 - 3))
|
mEmpty = append(mEmpty, int32(mBlock+uint32(i)*8-3))
|
||||||
}
|
}
|
||||||
if (f.FISB_data[index+i] & 0x02) != 0 {
|
if (f.FISB_data[index+i] & 0x02) != 0 {
|
||||||
mEmpty = append(mEmpty, int32(mBlock + uint32(i) * 8 - 2))
|
mEmpty = append(mEmpty, int32(mBlock+uint32(i)*8-2))
|
||||||
}
|
}
|
||||||
if (f.FISB_data[index+i] & 0x04) != 0 {
|
if (f.FISB_data[index+i] & 0x04) != 0 {
|
||||||
mEmpty = append(mEmpty, int32(mBlock + uint32(i) * 8 - 1))
|
mEmpty = append(mEmpty, int32(mBlock+uint32(i)*8-1))
|
||||||
}
|
}
|
||||||
if (f.FISB_data[index+i] & 0x08) != 0 {
|
if (f.FISB_data[index+i] & 0x08) != 0 {
|
||||||
mEmpty = append(mEmpty, int32( mBlock + uint32(i) * 8 - 0))
|
mEmpty = append(mEmpty, int32(mBlock+uint32(i)*8-0))
|
||||||
}
|
}
|
||||||
if (f.FISB_data[index+i] & 0x10) != 0 {
|
if (f.FISB_data[index+i] & 0x10) != 0 {
|
||||||
mEmpty = append(mEmpty, int32(mBlock + uint32(i) * 8 + 1))
|
mEmpty = append(mEmpty, int32(mBlock+uint32(i)*8+1))
|
||||||
}
|
}
|
||||||
if (f.FISB_data[index+i] & 0x20) != 0 {
|
if (f.FISB_data[index+i] & 0x20) != 0 {
|
||||||
mEmpty = append(mEmpty, int32(mBlock + uint32(i) * 8 + 2))
|
mEmpty = append(mEmpty, int32(mBlock+uint32(i)*8+2))
|
||||||
}
|
}
|
||||||
if (f.FISB_data[index+i] & 0x40) != 0 {
|
if (f.FISB_data[index+i] & 0x40) != 0 {
|
||||||
mEmpty = append(mEmpty, int32(mBlock + uint32(i) * 8 + 3))
|
mEmpty = append(mEmpty, int32(mBlock+uint32(i)*8+3))
|
||||||
}
|
}
|
||||||
if (f.FISB_data[index+i] & 0x80) != 0 {
|
if (f.FISB_data[index+i] & 0x80) != 0 {
|
||||||
mEmpty = append(mEmpty, int32(mBlock + uint32(i) * 8 + 4))
|
mEmpty = append(mEmpty, int32(mBlock+uint32(i)*8+4))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf("NEXRAD: elementIdentifier %d mBlock %d\n",elementIdentifier, mBlock)
|
log.Printf("NEXRAD: elementIdentifier %d mBlock %d\n", elementIdentifier, mBlock)
|
||||||
log.Printf("NEXRAD: mEmpty %d mData %d\n",mEmpty, mData)
|
log.Printf("NEXRAD: mEmpty %d mData %d\n", mEmpty, mData)
|
||||||
// field 1 - NEXRAD
|
// field 1 - NEXRAD
|
||||||
builder = append(builder,"NEXRAD")
|
builder = append(builder, "NEXRAD")
|
||||||
// CONUS
|
// CONUS
|
||||||
if f.Product_id == 63 {
|
if f.Product_id == 63 {
|
||||||
builder = append(builder,"0")
|
builder = append(builder, "0")
|
||||||
} else {
|
} else {
|
||||||
builder = append(builder,"1")
|
builder = append(builder, "1")
|
||||||
}
|
}
|
||||||
// Field 3 block
|
// Field 3 block
|
||||||
builder = append(builder,fmt.Sprintf("%d",mBlock))
|
builder = append(builder, fmt.Sprintf("%d", mBlock))
|
||||||
// Field 4 Columns
|
// Field 4 Columns
|
||||||
builder = append(builder,fmt.Sprintf("%d",COLS_PER_BIN))
|
builder = append(builder, fmt.Sprintf("%d", COLS_PER_BIN))
|
||||||
// Field 5 Rows
|
// Field 5 Rows
|
||||||
builder = append(builder,fmt.Sprintf("%d",ROWS_PER_BIN))
|
builder = append(builder, fmt.Sprintf("%d", ROWS_PER_BIN))
|
||||||
if elementIdentifier != 0 {
|
if elementIdentifier != 0 {
|
||||||
builder = append(builder,"1")
|
builder = append(builder, "1")
|
||||||
bin := ""
|
bin := ""
|
||||||
for br := range mData {
|
for br := range mData {
|
||||||
bin = bin + fmt.Sprintf("%d,",mData[br])
|
bin = bin + fmt.Sprintf("%d,", mData[br])
|
||||||
}
|
}
|
||||||
if bin[len(bin)-1] == ',' {
|
if bin[len(bin)-1] == ',' {
|
||||||
bin = bin[0:len(bin)-1]
|
bin = bin[0 : len(bin)-1]
|
||||||
}
|
}
|
||||||
builder = append(builder,bin)
|
builder = append(builder, bin)
|
||||||
} else {
|
} else {
|
||||||
builder = append(builder,"0")
|
builder = append(builder, "0")
|
||||||
bin2 := ""
|
bin2 := ""
|
||||||
for be := range mEmpty {
|
for be := range mEmpty {
|
||||||
bin2 = bin2 + fmt.Sprintf("%d,",mEmpty[be])
|
bin2 = bin2 + fmt.Sprintf("%d,", mEmpty[be])
|
||||||
}
|
}
|
||||||
if bin2[len(bin2)-1] == ',' {
|
if bin2[len(bin2)-1] == ',' {
|
||||||
bin2 = bin2[0:len(bin2)-1]
|
bin2 = bin2[0 : len(bin2)-1]
|
||||||
}
|
}
|
||||||
builder = append(builder,bin2)
|
builder = append(builder, bin2)
|
||||||
}
|
}
|
||||||
ret = append(ret, fmt.Sprintf(strings.Join(builder, " ")))
|
ret = append(ret, fmt.Sprintf(strings.Join(builder, " ")))
|
||||||
f.Text_data = ret
|
f.Text_data = ret
|
||||||
|
@ -621,9 +622,9 @@ func (f *UATFrame) decodeInfoFrame() {
|
||||||
case 8, 11, 13:
|
case 8, 11, 13:
|
||||||
f.decodeAirmet()
|
f.decodeAirmet()
|
||||||
*/
|
*/
|
||||||
case 63, 64:
|
case 63, 64:
|
||||||
f.decodeNexradFrame()
|
f.decodeNexradFrame()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(ioutil.Discard, "don't know what to do with product id: %d\n", f.Product_id)
|
fmt.Fprintf(ioutil.Discard, "don't know what to do with product id: %d\n", f.Product_id)
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue