Skip to content

Commit

Permalink
git fire - It's not working yet..... backup commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hb9fxq committed Oct 7, 2017
1 parent 2c112b2 commit c5cdd17
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea/
.bin/
.pkg/
**/bin/*
**/pkg/*
10 changes: 5 additions & 5 deletions GRC/iq-transfer/iq-transfer-test.grc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(576, 185)</value>
<value>(408, 241)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -183,7 +183,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(768, 185)</value>
<value>(600, 241)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -226,7 +226,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(352, 176)</value>
<value>(184, 231)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -309,7 +309,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(1064, 64)</value>
<value>(896, 118)</value>
</param>
<param>
<key>_rotation</key>
Expand Down Expand Up @@ -420,7 +420,7 @@
</param>
<param>
<key>_coordinate</key>
<value>(1024, 300)</value>
<value>(856, 356)</value>
</param>
<param>
<key>_rotation</key>
Expand Down
43 changes: 35 additions & 8 deletions src/github.com/krippendorf/cmd/iq-transfer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"flag"
"github.com/krippendorf/flexlib-go/obj"
"github.com/krippendorf/flexlib-go/sdrobjects"
"log"
"net"
"os"
"strconv"
"strings"
"time"
"net"
)

type AppContext struct {
Expand All @@ -18,23 +19,26 @@ type AppContext struct {
sampleRate string
forwardAddess string
RadioReponseStreamSequence int
forwardConnection net.Conn
forwardConnection net.Conn
}

func main() {

l := log.New(os.Stderr, "RADIO_MSG", 0)

appContext := new(AppContext)
flag.StringVar(&appContext.radioAddr, "RADIO", "", "IP ADDRESS OF THE RADIO e.g 192.168.41.8")
flag.StringVar(&appContext.myPort, "MYUDP", "", "LOCAL UDP PORT 7788")
flag.StringVar(&appContext.daxIqChan, "CH", "", "DAX IQ CHANNEL NUMBER e.g. ")
flag.StringVar(&appContext.sampleRate, "RATE", "", "DAX IQ sample rate in kHz - 24 / 48 / 96 / 192")
flag.StringVar(&appContext.forwardAddess, "FWD", "", "UDP Forward address for the IQ samples with port, e.g. 192.168.50.5:5000")
flag.StringVar(&appContext.forwardAddess, "FWD", "", "If empty, IQ data will be written to stdout. UDP Forward address for the IQ samples with port, e.g. 192.168.50.5:5000")
flag.Parse()

if appContext.sampleRate != "24" && appContext.sampleRate != "48" && appContext.sampleRate != "96" && appContext.sampleRate != "192" {
panic("Invalid Sample Rate! Allowed values 24, 48, 96, 192")
}

if(len(appContext.forwardAddess) > 0){
if len(appContext.forwardAddess) > 0 {
appContext.forwardConnection, _ = net.Dial("udp", appContext.forwardAddess)
}

Expand All @@ -54,7 +58,6 @@ func main() {
if strings.HasPrefix(response, "R"+strconv.Itoa(appContext.RadioReponseStreamSequence)) {
cmd := "daxiq set" + appContext.daxIqChan + " rate=" + appContext.sampleRate + "000"
obj.SendRadioCommand(radioContext, cmd)
//fmt.Println("stream response sequence" + strconv.Itoa(streamResp))
}
}
}(radioContext)
Expand All @@ -74,14 +77,38 @@ func main() {

appContext.RadioReponseStreamSequence = obj.SendRadioCommand(radioContext, "stream create daxiq=1ip="+radioContext.MyUdpEndpointIP.String()+" port="+appContext.myPort)

var centerFrequencyOfStream int32

for {

if val, ok := radioContext.IqStreams.Load(appContext.daxIqChan); ok {
iqStream := val.(obj.IqStream)
if len(iqStream.Pan) > 0 {

if panVal, panOk := radioContext.Panadapters.Load(iqStream.Pan); panOk {
pan := panVal.(obj.Panadapter)
if centerFrequencyOfStream != pan.Center {
centerFrequencyOfStream = pan.Center
l.Println("CENTER_FREQ_CHANGE " + strconv.Itoa(int(centerFrequencyOfStream)))
}
}

}
}
}

forever := make(chan bool)
forever <- true
}

func handleData(appctx *AppContext, ifDataPackage sdrobjects.SdrIfData){
if(len(appctx.forwardAddess) > 0){
func handleData(appctx *AppContext, ifDataPackage sdrobjects.SdrIfData) {
if len(appctx.forwardAddess) > 0 {
appctx.forwardConnection.Write(ifDataPackage.Data)
} else{
} else {
os.Stdout.Write(ifDataPackage.Data)
}
}

func FloatToString(input_num float64) string {
return strconv.FormatFloat(input_num, 'f', 6, 64)
}
18 changes: 8 additions & 10 deletions src/github.com/krippendorf/flexlib-go/obj/panadapter.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package obj

type Panadapter struct {
id string
x_pixels int
y_pixels int
center float32
bandwidth float32
min_dbm float32
max_dbm float32
fps int
average int
rfgain int
Id string
Center int32
}

type IqStream struct{
Id int
Pan string
Rate int
}
135 changes: 109 additions & 26 deletions src/github.com/krippendorf/flexlib-go/obj/radio.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package obj

import (
"errors"
"github.com/krippendorf/flexlib-go/sdrobjects"
"github.com/krippendorf/flexlib-go/vita"
"log"
"net"
"os"
"strconv"
"strings"
"sync"
)

type RadioData struct {
Expand All @@ -30,7 +32,8 @@ type RadioContext struct {
ChannelVitaIfData chan *sdrobjects.SdrIfData
ChannelVitaMeter chan *sdrobjects.SdrMeterPacket
ChannelVitaWaterfallTile chan *sdrobjects.SdrWaterfallTile
Panadapters map[string]Panadapter
Panadapters sync.Map
IqStreams sync.Map
Debug bool
}

Expand Down Expand Up @@ -147,7 +150,7 @@ func subscribeRadioUpdates(conn *net.TCPConn, ctx *RadioContext) {
} else {
ctx.ChannelRadioResponse <- responseLine
parseResponseLine(ctx, responseLine)
if(ctx.Debug){
if ctx.Debug {
l.Println("DEBU:RESP:" + responseLine)
}
}
Expand All @@ -160,44 +163,126 @@ func subscribeRadioUpdates(conn *net.TCPConn, ctx *RadioContext) {
}
}
func parseResponseLine(context *RadioContext, respLine string) {
if strings.Contains(respLine, "display pan") {
parsePanAdapterParams(context, respLine)

_, message := parseReplyStringPrefix(respLine)

if strings.Contains(message, "display pan") {
parsePanAdapterParams(context, message)
} else if strings.Contains(message, "daxiq ") {
parseDaxIqStatusParams(context, message)
}
}

func parsePanAdapterParams(context *RadioContext, i string) {
/*
>0x40000000 wnb=0 wnb_level=50 wnb_updating=0 x_pixels=490 y_pixels=535 center=3.792057 bandwidth=0.885342 min_dbm=-126.84 max_dbm=-66.812 fps=5 average=70 weighted_average=0 rfgain=0 rxant=ANT2 wide=1 loopa=0 loopb=0 band=80 daxiq=0 daxiq_rate=0 capacity=16 available=16 waterfall=42000000 min_bw=0.004919999957085 max_b<>w=14.74560058594 xvtr= pre= ant_list=ANT1,ANT2,RX_A,XVTR<
*/
_, res, objectValue := parseKeyValueString(i, 1)

if context.Panadapters == nil {
context.Panadapters = map[string]Panadapter{}
var panadapter Panadapter
panadapter.Id = objectValue
dirty := false;

actual, loaded := context.Panadapters.LoadOrStore(objectValue, panadapter)

if(loaded){
panadapter = actual.(Panadapter)
}

tokens := strings.Split(i, " ")
if val, ok := res["center"]; ok {
rawFloatCenter, _ := strconv.ParseFloat(val, 64)
panadapter.Center = int32(rawFloatCenter*1000000)
dirty = true
}

if dirty {
context.Panadapters.Store(objectValue, panadapter)
}
}

func parseDaxIqStatusParams(context *RadioContext, i string) {


var pan Panadapter
_, res, objectValue := parseKeyValueString(i, 1)

if val, ok := context.Panadapters[tokens[2]]; ok {
pan = val
streamId, _ := strconv.Atoi(objectValue)
var iqStream IqStream
iqStream.Id = streamId
dirty := false;

actual, loaded := context.IqStreams.LoadOrStore(objectValue, iqStream)

if(loaded){
iqStream = actual.(IqStream)
}

for rngAttr := range tokens[3:] {
if val, ok := res["pan"]; ok {
iqStream.Pan = val
dirty = true
}

if strings.Index(tokens[rngAttr+3], "=") < 0 {
continue
}
if val, ok := res["rate"]; ok {
iqStream.Rate, _ = strconv.Atoi(val)
dirty = true
}

attrName := strings.Split(tokens[rngAttr+3], "=")[0]
val := strings.Split(tokens[rngAttr+3], "=")[1]
if dirty {
context.IqStreams.Store(objectValue, iqStream)
}
}

switch attrName {
case "center":
floatVal, _ := strconv.ParseFloat(val, 32)
pan.center = float32(floatVal)
break
}
func parseReplyStringPrefix(in string) (string, string) {
var prefix string
var message string

tokens := strings.Split(in, "|")

if len(tokens) == 2 {
return tokens[0], tokens[1]
}

context.Panadapters[tokens[2]] = pan
return prefix, message
}

func parseKeyValueString(in string, words int) (error, map[string]string, string) {

var res map[string]string
res = map[string]string{}

tokens := strings.Split(in, " ")

if len(tokens) == 0 {
return errors.New("no tokens found"), res, ""
}

if strings.Index(in, "=") < 0 {
return errors.New("not a key value list"), res, ""
}

skipedWords := 0
var objectValue string
for rngAttr := range tokens[:] {

contentTokens := strings.Split(tokens[rngAttr], " ")

for cntToken := range contentTokens {

keyValueTokens := strings.Split(contentTokens[cntToken], "=")

if len(keyValueTokens) == 2 {
res[keyValueTokens[0]] = keyValueTokens[1]
} else if len(keyValueTokens) == 1 {

if skipedWords == words { // first prefix is object identifier itself
objectValue = keyValueTokens[0]
} else {
skipedWords++
}
}
}
}

return nil, res, objectValue
}

func subscribeRadioUdp(ctx *RadioContext) {
Expand Down Expand Up @@ -253,7 +338,6 @@ func dispatchDataToChannels(ctx *RadioContext, data *RadioData) {
if nil != ctx.ChannelVitaOpus {
ctx.ChannelVitaOpus <- data.Payload[:len(data.Payload)-data.Preampble.Header.Payload_cutoff_bytes]
}

break
case vita.SL_VITA_IF_NARROW_CLASS:
if nil != ctx.ChannelVitaIfData {
Expand All @@ -264,7 +348,6 @@ func dispatchDataToChannels(ctx *RadioContext, data *RadioData) {
if nil != ctx.ChannelVitaMeter {
ctx.ChannelVitaMeter <- vita.ParseVitaMeterPacket(data.Payload, data.Preampble)
}

break
case vita.SL_VITA_DISCOVERY_CLASS:
// maybe later - we use static addresses
Expand Down Expand Up @@ -295,4 +378,4 @@ func dispatchDataToChannels(ctx *RadioContext, data *RadioData) {
}
break
}
}
}

0 comments on commit c5cdd17

Please sign in to comment.