added some checks

master
cheetah 4 years ago
parent c5c9e664f3
commit 912ff0fba0

@ -56,24 +56,27 @@ func main() {
if err != nil { if err != nil {
log.Panic(err) log.Panic(err)
} }
go func() { // Only if we allow TX, we process Messages
d, err := consumeCh.Consume("input", "", false, false, false, false, nil) if conf.TXFreq != 0 {
if err != nil { go func() {
log.Panic(err) d, err := consumeCh.Consume("input", "", false, false, false, false, nil)
} if err != nil {
log.Panic(err)
}
for msg := range d { for msg := range d {
if msg.Headers["ric"] == nil { continue } if msg.Headers["ric"] == nil { continue }
log.Printf("ric: %s", string(msg.Headers["ric"].(string))) log.Printf("ric: %s", string(msg.Headers["ric"].(string)))
log.Printf("msg: %s", string(msg.Body)) log.Printf("msg: %s", string(msg.Body))
/*queueMessage(&pocsagencode.Message { /*queueMessage(&pocsagencode.Message {
Addr: uint32(msg.Headers["ric"].(int)), Addr: uint32(msg.Headers["ric"].(int)),
Content: string(msg.Body), Content: string(msg.Body),
IsNumeric: (msg.Headers["numeric"] != nil), IsNumeric: (msg.Headers["numeric"] != nil),
})*/ })*/
msg.Ack(true) msg.Ack(true)
} }
}() }()
}
/***** RABBITMQ END**/ /***** RABBITMQ END**/
if rfm, err = rfm69.NewDevice(true); err != nil { if rfm, err = rfm69.NewDevice(true); err != nil {
@ -81,10 +84,12 @@ func main() {
} }
rfm.FreqOffset = conf.FreqOffset rfm.FreqOffset = conf.FreqOffset
rfm.TXBaud = conf.TXBaud
rfm.RXBaud = conf.RXBaud
rfm.TXFreq = conf.TXFreq rfm.TXFreq = conf.TXFreq
rfm.TXBaud = conf.TXBaud
rfm.RXFreq = conf.RXFreq rfm.RXFreq = conf.RXFreq
rfm.RXBaud = conf.RXBaud
if err = rfm.SetModeAndWait(rfm69.RF_OPMODE_STANDBY); err != nil { if err = rfm.SetModeAndWait(rfm69.RF_OPMODE_STANDBY); err != nil {
panic(err) panic(err)
@ -92,14 +97,13 @@ func main() {
if err = rfm.SetInvert(conf.InvertBits); err != nil { if err = rfm.SetInvert(conf.InvertBits); err != nil {
panic(err) panic(err)
} }
//rfm.SetFrequency(466238000, 25)
log.Println("Running with following Config:")
log.Println("Config")
log.Println("AMQP Server: ", conf.AMQPURL) log.Println("AMQP Server: ", conf.AMQPURL)
log.Println("Frequency Offset(Correction): ", conf.FreqOffset, "Hz") log.Println("Frequency Offset(Correction): ", conf.FreqOffset, "Hz")
log.Println("Transmit Freq: ", conf.TXFreq, "Hz @", conf.TXBaud, "bps") log.Println("Transmit Freq: ", conf.TXFreq, "Hz @", conf.TXBaud, "bps")
log.Println("Receive Freq: ", conf.RXFreq, "Hz @", conf.RXBaud, "bps") log.Println("Receive Freq: ", conf.RXFreq, "Hz @", conf.RXBaud, "bps")
/*
messages := []*pocsagencode.Message{ messages := []*pocsagencode.Message{
&pocsagencode.Message{133701, "Hello 1234567890!", false}, &pocsagencode.Message{133701, "Hello 1234567890!", false},
//&pocsagencode.Message{133702, "Hello d2efa947-7618-440c-8f79-fab32762af8ed2bb9c62-007e-4b2c-93d5-3124a247032eefe71db4-ef8d-46fb-9cf8-dac70db000bc12067966-da61-447c-a9ce-c0c24be17df5 Pager!", false}, //&pocsagencode.Message{133702, "Hello d2efa947-7618-440c-8f79-fab32762af8ed2bb9c62-007e-4b2c-93d5-3124a247032eefe71db4-ef8d-46fb-9cf8-dac70db000bc12067966-da61-447c-a9ce-c0c24be17df5 Pager!", false},
@ -121,47 +125,48 @@ func main() {
} }
rfm.Send(data) rfm.Send(data)
} }
*/
rfm.OnReceive = func(stream *rfm69.RXStream) { if conf.RXFreq != 0 {
rssiMeasurementArray := make([]int, 5) rfm.OnReceive = func(stream *rfm69.RXStream) {
rssiStart := -0 rssiMeasurementArray := make([]int, 5)
for { rssiStart := -0
select { for {
case rssi := <-stream.RSSI: select {
//fmt.Printf("RSSI:%d\n", rssiStart - rssi) case rssi := <-stream.RSSI:
if (stream.ByteCounter < 20) { //fmt.Printf("RSSI:%d\n", rssiStart - rssi)
rssiMeasurementArray[int(stream.ByteCounter / 4)] = rssi if (stream.ByteCounter < 20) {
rssiStart = 0 rssiMeasurementArray[int(stream.ByteCounter / 4)] = rssi
for i := 0; i<5; i++ { rssiStart = 0
rssiStart += rssiMeasurementArray[i] for i := 0; i<5; i++ {
} rssiStart += rssiMeasurementArray[i]
rssiStart = rssiStart / 5 }
} else { rssiStart = rssiStart / 5
if rssiStart - rssi > 20 { } else {
stream.Cancel = true if rssiStart - rssi > 20 {
stream.Cancel = true
}
if stream.ByteCounter > 1024e2 {
stream.Cancel = true
}
} }
if stream.ByteCounter > 1024e2 { break
stream.Cancel = true /*case byte := <-stream.ByteStream:
fmt.Printf("%x", byte)
break*/
case <-stream.Process:
log.Println("--PROCESS=", len(stream.ByteStream), " bytes--")
for i:= 0; i < len(stream.ByteStream); i++ {
fmt.Printf("%x", <-stream.ByteStream)
} }
fmt.Print("\n")
log.Println("--END--")
break
} }
break
/*case byte := <-stream.ByteStream:
fmt.Printf("%x", byte)
break*/
case <-stream.Process:
log.Println("--PROCESS=", len(stream.ByteStream), " bytes--")
for i:= 0; i < len(stream.ByteStream); i++ {
fmt.Printf("%x", <-stream.ByteStream)
}
fmt.Print("\n")
log.Println("--END--")
break
} }
} }
rfm.PrepareRX()
} }
rfm.PrepareRX()
rfm.Loop() rfm.Loop()
log.Println("Done") log.Println("Done")
} }

Loading…
Cancel
Save