|
|
|
@ -9,15 +9,10 @@ import (
|
|
|
|
|
"github.com/RPIZeroDuplexPOCSAG/rfm69"
|
|
|
|
|
|
|
|
|
|
"github.com/davecheney/gpio"
|
|
|
|
|
|
|
|
|
|
"github.com/streadway/amqp"
|
|
|
|
|
"github.com/sirius1024/go-amqp-reconnect/rabbitmq"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/RPIZeroDuplexPOCSAG/go-pocsag/notint_ernal/datatypes"
|
|
|
|
|
"github.com/RPIZeroDuplexPOCSAG/go-pocsag/notint_ernal/pocsag"
|
|
|
|
|
//"github.com/RPIZeroDuplexPOCSAG/go-pocsag/notint_ernal/utils"
|
|
|
|
|
|
|
|
|
|
"github.com/RPIZeroDuplexPOCSAG/pocsag-gateway/settings"
|
|
|
|
|
)
|
|
|
|
|
var (
|
|
|
|
@ -60,6 +55,10 @@ func main() {
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panic(err)
|
|
|
|
|
}
|
|
|
|
|
publishCh, err := connection.Channel()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panic(err)
|
|
|
|
|
}
|
|
|
|
|
// Only if we allow TX, we process Messages
|
|
|
|
|
if conf.TXFreq != 0 {
|
|
|
|
|
go func() {
|
|
|
|
@ -81,6 +80,10 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
err = publishCh.ExchangeDeclare("rx", amqp.ExchangeFanout, true, false, false, false, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panic(err)
|
|
|
|
|
}
|
|
|
|
|
/***** RABBITMQ END**/
|
|
|
|
|
|
|
|
|
|
if rfm, err = rfm69.NewDevice(true); err != nil {
|
|
|
|
@ -158,60 +161,25 @@ func main() {
|
|
|
|
|
fmt.Printf("%x", byte)
|
|
|
|
|
break*/
|
|
|
|
|
case <-stream.Process:
|
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
|
<-stream.ByteStream
|
|
|
|
|
}
|
|
|
|
|
/*for i := 0; i < 32; i++ {
|
|
|
|
|
bits = append(bits, false)
|
|
|
|
|
}*/
|
|
|
|
|
var tByte = 0
|
|
|
|
|
var bitstring = ""
|
|
|
|
|
log.Println("--PROCESS=", len(stream.ByteStream), " bytes--")
|
|
|
|
|
data := make([]byte, len(stream.ByteStream))
|
|
|
|
|
//log.Println("--PROCESS=", len(stream.ByteStream), " bytes--")
|
|
|
|
|
for i:= 0; i < len(stream.ByteStream); i++ {
|
|
|
|
|
tByte = int(<-stream.ByteStream)
|
|
|
|
|
if tByte == 0xAA && bitstring == "" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("%x", tByte)
|
|
|
|
|
for BB := 7; BB > -1; BB-- {
|
|
|
|
|
// Compare bits 7-0 in byte
|
|
|
|
|
if tByte & (1 << uint(BB)) > 0 {
|
|
|
|
|
bitstring = bitstring + "1"
|
|
|
|
|
} else {
|
|
|
|
|
bitstring = bitstring + "0"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// bitstring = bitstring + fmt.Sprintf("%b", tByte)
|
|
|
|
|
/*bits = append(bits, datatypes.Bit(tByte & 128 > 0))
|
|
|
|
|
bits = append(bits, datatypes.Bit(tByte & 64 > 0))
|
|
|
|
|
bits = append(bits, datatypes.Bit(tByte & 32 > 0))
|
|
|
|
|
bits = append(bits, datatypes.Bit(tByte & 16 > 0))
|
|
|
|
|
bits = append(bits, datatypes.Bit(tByte & 8 > 0))
|
|
|
|
|
bits = append(bits, datatypes.Bit(tByte & 4 > 0))
|
|
|
|
|
bits = append(bits, datatypes.Bit(tByte & 2 > 0))
|
|
|
|
|
bits = append(bits, datatypes.Bit(tByte & 1 > 0))*/
|
|
|
|
|
}
|
|
|
|
|
// bitstring = fmt.Sprintf("%b", 0xAA)+ fmt.Sprintf("%b", 0xAA)+ fmt.Sprintf("%b", 0xAA)+ fmt.Sprintf("%b", 0xAA) + bitstring
|
|
|
|
|
fmt.Print("\n")
|
|
|
|
|
//fmt.Print(bitstring)
|
|
|
|
|
fmt.Print("\n")
|
|
|
|
|
for i := 0; i < 512; i++ {
|
|
|
|
|
bitstring = bitstring + "0"
|
|
|
|
|
}
|
|
|
|
|
var bits = make([]datatypes.Bit, len(bitstring))
|
|
|
|
|
for i, c := range bitstring {
|
|
|
|
|
if string(c) == "1" {
|
|
|
|
|
bits[i] = datatypes.Bit(true)
|
|
|
|
|
} else {
|
|
|
|
|
bits[i] = datatypes.Bit(false)
|
|
|
|
|
}
|
|
|
|
|
data[i] = <-stream.ByteStream
|
|
|
|
|
//fmt.Printf("%x", data[i])
|
|
|
|
|
}
|
|
|
|
|
parsedMsgs := pocsag.ParsePOCSAG(bits, pocsag.MessageTypeAuto)
|
|
|
|
|
for _, m := range parsedMsgs {
|
|
|
|
|
log.Println(m.ReciptientString())
|
|
|
|
|
log.Println(m.PayloadString(pocsag.MessageTypeAuto))
|
|
|
|
|
err := publishCh.Publish("rx", "", false, false, amqp.Publishing{
|
|
|
|
|
ContentType: "application/octet-stream",
|
|
|
|
|
Body: data,
|
|
|
|
|
Headers: map[string]interface{}{
|
|
|
|
|
"rssi": rssiStart,
|
|
|
|
|
"len": len(data),
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Panic(err)
|
|
|
|
|
}
|
|
|
|
|
log.Println("--END--")
|
|
|
|
|
//fmt.Print("\n")
|
|
|
|
|
log.Println("--RX SENT--")
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|