You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2017/11/05 19:01:05 UTC

[GitHub] mkiiskila closed pull request #49: mtech_lora; don't use '-' with deveui's.

mkiiskila closed pull request #49: mtech_lora; don't use '-' with deveui's.
URL: https://github.com/apache/mynewt-newtmgr/pull/49
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nmxact/mtech_lora/mtech_lora_sesn.go b/nmxact/mtech_lora/mtech_lora_sesn.go
index 9bde337..7936275 100644
--- a/nmxact/mtech_lora/mtech_lora_sesn.go
+++ b/nmxact/mtech_lora/mtech_lora_sesn.go
@@ -24,7 +24,6 @@ import (
 	"encoding/base64"
 	"encoding/binary"
 	"fmt"
-	"strings"
 	"sync"
 
 	log "github.com/Sirupsen/logrus"
@@ -57,14 +56,8 @@ type mtechLoraTx struct {
 	Ack  bool   `json:"ack"`
 }
 
-func normalizeAddr(addr string) (string, error) {
-	a := strings.Replace(addr, ":", "-", -1)
-	// XXX check that there's 8 components, 2 chars each, which are in [0-9,a-f]
-	return a, nil
-}
-
 func NewLoraSesn(cfg sesn.SesnCfg, lx *LoraXport) (*LoraSesn, error) {
-	addr, err := normalizeAddr(cfg.Lora.Addr)
+	addr, err := NormalizeAddr(cfg.Lora.Addr)
 	if err != nil {
 		return nil, fmt.Errorf("Invalid Lora address %s\n", cfg.Lora.Addr)
 	}
@@ -227,7 +220,7 @@ func (s *LoraSesn) sendFragments(b []byte) error {
 		var outData bytes.Buffer
 
 		outData.Write([]byte(fmt.Sprintf("lora/%s/down %s\n",
-			s.cfg.Lora.Addr, payload)))
+			DenormalizeAddr(s.cfg.Lora.Addr), payload)))
 		err := s.xport.Tx(outData.Bytes())
 		if err != nil {
 			return err
diff --git a/nmxact/mtech_lora/mtech_lora_xport.go b/nmxact/mtech_lora/mtech_lora_xport.go
index 4abfd29..4f5d994 100644
--- a/nmxact/mtech_lora/mtech_lora_xport.go
+++ b/nmxact/mtech_lora/mtech_lora_xport.go
@@ -57,6 +57,8 @@ type LoraXport struct {
 }
 
 type LoraXportCfg struct {
+	AppPortDown int // UDP TX port
+	AppPortUp   int // UDP RX port
 }
 
 type LoraData struct {
@@ -87,7 +89,10 @@ const UDP_TX_PORT = 1786
 const OIC_LORA_PORT = 0xbb
 
 func NewXportCfg() *LoraXportCfg {
-	return &LoraXportCfg{}
+	return &LoraXportCfg{
+		AppPortDown: UDP_TX_PORT,
+		AppPortUp:   UDP_RX_PORT,
+	}
 }
 
 func NewLoraXport(cfg *LoraXportCfg) *LoraXport {
@@ -101,6 +106,30 @@ func (lx *LoraXport) minMtu() int {
 	return 33
 }
 
+func NormalizeAddr(addr string) (string, error) {
+	a := strings.Replace(addr, ":", "", -1)
+	a = strings.Replace(addr, "-", "", -1)
+	// XXX check that there's 8 components, 2 chars each, which are in [0-9,a-f]
+	if len(a) != 16 {
+		return "", fmt.Errorf("Invalid addr")
+	}
+	return a, nil
+}
+
+func DenormalizeAddr(addr string) string {
+	if len(addr) != 16 {
+		return "<invalid>"
+	}
+	rc := ""
+	for i := 0; i < 16; i += 2 {
+		rc += addr[i : i+2]
+		if 16-i > 2 {
+			rc += "-"
+		}
+	}
+	return rc
+}
+
 func (lx *LoraXport) BuildSesn(cfg sesn.SesnCfg) (sesn.Sesn, error) {
 	if cfg.Lora.Addr == "" {
 		return nil, fmt.Errorf("Need an address of endpoint")
@@ -193,11 +222,12 @@ func (lx *LoraXport) processData(data string) {
 	if len(splitHdr) != 3 {
 		return
 	}
+	dev, _ := NormalizeAddr(splitHdr[1])
 	switch splitHdr[2] {
 	case "joined":
 		log.Debugf("loraxport rx: %s", data)
-		log.Debugf("%s joined", splitHdr[1])
-		lx.reportJoin(splitHdr[1])
+		log.Debugf("%s joined", dev)
+		lx.reportJoin(dev)
 	case "up":
 		var msg LoraData
 
@@ -218,7 +248,7 @@ func (lx *LoraXport) processData(data string) {
 			log.Debugf("loraxport rx: error decoding base64: %v", err)
 			return
 		}
-		lx.reass(splitHdr[1], dec)
+		lx.reass(dev, dec)
 	case "packet_sent":
 		var sent LoraPacketSent
 
@@ -230,7 +260,7 @@ func (lx *LoraXport) processData(data string) {
 			return
 		}
 
-		lx.dataRateSeen(splitHdr[1], sent.DataRate)
+		lx.dataRateSeen(dev, sent.DataRate)
 	}
 }
 
@@ -239,20 +269,21 @@ func (lx *LoraXport) Start() error {
 		return nmxutil.NewXportError("Lora xport started twice")
 	}
 
-	addr, err := net.ResolveUDPAddr("udp", "127.0.0.1:1784")
+	addr, err := net.ResolveUDPAddr("udp",
+		fmt.Sprintf("127.0.0.1:%d", lx.cfg.AppPortUp))
 	if err != nil {
 		return fmt.Errorf("Failure resolving name for UDP session: %s",
 			err.Error())
 	}
 
-	// XXX need so_reuseport
 	conn, err := net.ListenUDP("udp", addr)
 	if err != nil {
 		return fmt.Errorf("Failed to open RX to lora-network-server %s", addr)
 	}
 	lx.rxConn = conn
 
-	addr, err = net.ResolveUDPAddr("udp", "127.0.0.1:1786")
+	addr, err = net.ResolveUDPAddr("udp",
+		fmt.Sprintf("127.0.0.1:%d", lx.cfg.AppPortDown))
 	if err != nil {
 		return fmt.Errorf("Failure resolving name for UDP session: %s",
 			err.Error())


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services