You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/10/26 18:59:02 UTC
[1/3] incubator-mynewt-newt git commit: newtmgr;
oic_serial, oic_ble for newtmgr inside CoAP. Add oic_net, and net
profiles for carrying OIC/newtmgr over UDP.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop cd7eec894 -> 609bd6a04
newtmgr; oic_serial, oic_ble for newtmgr inside CoAP.
Add oic_net, and net profiles for carrying OIC/newtmgr over UDP.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/00487272
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/00487272
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/00487272
Branch: refs/heads/develop
Commit: 004872724a3fff353316c7c066d15a3edef5baff
Parents: cd7eec8
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Oct 26 11:30:31 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Oct 26 11:31:42 2016 -0700
----------------------------------------------------------------------
newtmgr/protocol/cmdrunner.go | 16 ++++-
newtmgr/protocol/omgr.go | 112 +++++++++++++++++++++++++++++++++++
newtmgr/transport/conn.go | 16 +++++
newtmgr/transport/connble.go | 12 +++-
newtmgr/transport/connserial.go | 9 +++
newtmgr/transport/connudp.go | 99 +++++++++++++++++++++++++++++++
6 files changed, 259 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/00487272/newtmgr/protocol/cmdrunner.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/cmdrunner.go b/newtmgr/protocol/cmdrunner.go
index cbb8427..7ec3d56 100644
--- a/newtmgr/protocol/cmdrunner.go
+++ b/newtmgr/protocol/cmdrunner.go
@@ -42,7 +42,12 @@ func (cr *CmdRunner) ReadResp() (*NmgrReq, error) {
bytes := pkt.GetBytes()
log.Debugf("Rx packet dump:\n%s", hex.Dump(bytes))
- nmrfrag, err := DeserializeNmgrReq(bytes)
+ var nmrfrag *NmgrReq
+ if cr.Conn.GetOICEncoded() == true {
+ nmrfrag, err = DeserializeOmgrReq(bytes)
+ } else {
+ nmrfrag, err = DeserializeNmgrReq(bytes)
+ }
if err != nil {
return nil, err
}
@@ -58,10 +63,15 @@ func (cr *CmdRunner) ReadResp() (*NmgrReq, error) {
func (cr *CmdRunner) WriteReq(nmr *NmgrReq) error {
data := []byte{}
+ var err error
- log.Debugf("Writing netmgr request %+v", nmr)
+ log.Debugf("Writing newtmgr request %+v", nmr)
- data, err := nmr.SerializeRequest(data)
+ if cr.Conn.GetOICEncoded() == true {
+ data, err = nmr.SerializeOmgrRequest(data)
+ } else {
+ data, err = nmr.SerializeRequest(data)
+ }
if err != nil {
return err
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/00487272/newtmgr/protocol/omgr.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/omgr.go b/newtmgr/protocol/omgr.go
new file mode 100644
index 0000000..a0ab05f
--- /dev/null
+++ b/newtmgr/protocol/omgr.go
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package protocol
+
+import (
+ "fmt"
+
+ log "github.com/Sirupsen/logrus"
+ "github.com/dustin/go-coap"
+ "github.com/ugorji/go/codec"
+
+ "mynewt.apache.org/newt/util"
+)
+
+type OicRsp struct {
+ Read map[string]interface{} `codec:"r"`
+ Write map[string]interface{} `codec:"w"`
+}
+
+/*
+ * Not able to install custom decoder for indefite length objects with the codec.
+ * So we need to decode the whole response, and then re-encode the newtmgr response
+ * part.
+ */
+func DeserializeOmgrReq(data []byte) (*NmgrReq, error) {
+ req := coap.Message{}
+ err := req.UnmarshalBinary(data)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf(
+ "Oicmgr request invalid %s", err.Error()))
+ }
+ log.Debugf("Deserialized COAP %+v", req)
+
+ var rsp OicRsp
+ err = codec.NewDecoderBytes(req.Payload, new(codec.CborHandle)).Decode(&rsp)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming cbor: %s",
+ err.Error()))
+ }
+
+ nmr := &NmgrReq{}
+
+ var ndata []byte = make([]byte, 0)
+ if len(rsp.Read) != 0 {
+ err = codec.NewEncoderBytes(&ndata,
+ new(codec.CborHandle)).Encode(rsp.Read)
+ nmr.Op = NMGR_OP_READ_RSP
+ } else {
+ err = codec.NewEncoderBytes(&ndata,
+ new(codec.CborHandle)).Encode(rsp.Read)
+ nmr.Op = NMGR_OP_WRITE_RSP
+ }
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Internal error: %s",
+ err.Error()))
+ }
+
+ nmr.Len = uint16(len(ndata))
+ nmr.Flags = NMGR_F_JSON_RSP_COMPLETE
+ nmr.Group = 0
+ nmr.Seq = 0
+ nmr.Id = 0
+
+ nmr.Data = ndata
+
+ log.Debugf("Deserialized response %+v", nmr)
+
+ return nmr, nil
+}
+
+func (nmr *NmgrReq) SerializeOmgrRequest(data []byte) ([]byte, error) {
+ req := coap.Message{
+ Type: coap.Confirmable,
+ MessageID: uint16(nmr.Seq),
+ }
+ if nmr.Op == NMGR_OP_READ {
+ req.Code = coap.GET
+ } else {
+ req.Code = coap.PUT
+ }
+ req.SetPathString("/omgr")
+ req.AddOption(coap.URIQuery, fmt.Sprintf("gr=%d", nmr.Group))
+ req.AddOption(coap.URIQuery, fmt.Sprintf("id=%d", nmr.Id))
+
+ req.Payload = nmr.Data
+
+ log.Debugf("Serializing request %+v into buffer %+v", nmr, data)
+
+ data, err := req.MarshalBinary()
+ if err != nil {
+ return nil, util.NewNewtError(
+ fmt.Sprintf("Failed to encode: %s\n", err.Error()))
+ }
+ return data, nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/00487272/newtmgr/transport/conn.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/conn.go b/newtmgr/transport/conn.go
index 2410ab6..715071d 100644
--- a/newtmgr/transport/conn.go
+++ b/newtmgr/transport/conn.go
@@ -32,6 +32,8 @@ type Conn interface {
ReadPacket() (*Packet, error)
WritePacket(pkt *Packet) error
Close() error
+ SetOICEncoded(bool)
+ GetOICEncoded() bool
}
type Packet struct {
@@ -84,8 +86,22 @@ func newConn(cp config.NewtmgrConnProfile, readTimeout time.Duration) (Conn, err
switch cp.Type() {
case "serial":
c = &ConnSerial{}
+ c.SetOICEncoded(false)
+ case "oic_serial":
+ c = &ConnSerial{}
+ c.SetOICEncoded(true)
case "ble":
c = &ConnBLE{}
+ c.SetOICEncoded(false)
+ case "oic_ble":
+ c = &ConnBLE{}
+ c.SetOICEncoded(true)
+ case "udp":
+ c = &ConnUDP{}
+ c.SetOICEncoded(false)
+ case "oic_udp":
+ c = &ConnUDP{}
+ c.SetOICEncoded(true)
default:
return nil, util.NewNewtError("Invalid conn profile " + cp.Type() +
" not implemented")
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/00487272/newtmgr/transport/connble.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connble.go b/newtmgr/transport/connble.go
index 6160340..f0ad978 100644
--- a/newtmgr/transport/connble.go
+++ b/newtmgr/transport/connble.go
@@ -43,8 +43,8 @@ var deviceAddressType uint8
type ConnBLE struct {
connProfile config.NewtmgrConnProfile
currentPacket *Packet
-
- bleDevice gatt.Device
+ bleDevice gatt.Device
+ isOIC bool
}
var deviceChar *gatt.Characteristic
@@ -135,6 +135,14 @@ func onPeriphDisconnected(p gatt.Peripheral, err error) {
log.Debugf("Disconnected", err)
}
+func (cs *ConnBLE) SetOICEncoded(b bool) {
+ cs.isOIC = b
+}
+
+func (cs *ConnBLE) GetOICEncoded() bool {
+ return cs.isOIC
+}
+
func (cb *ConnBLE) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration) error {
var err error
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/00487272/newtmgr/transport/connserial.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connserial.go b/newtmgr/transport/connserial.go
index b97dd07..4344b67 100644
--- a/newtmgr/transport/connserial.go
+++ b/newtmgr/transport/connserial.go
@@ -44,6 +44,15 @@ type ConnSerial struct {
scanner *bufio.Scanner
serialChannel *serial.Port
+ isOIC bool
+}
+
+func (cs *ConnSerial) SetOICEncoded(b bool) {
+ cs.isOIC = b
+}
+
+func (cs *ConnSerial) GetOICEncoded() bool {
+ return cs.isOIC
}
func newSerialConfig(
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/00487272/newtmgr/transport/connudp.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connudp.go b/newtmgr/transport/connudp.go
new file mode 100644
index 0000000..0be57b6
--- /dev/null
+++ b/newtmgr/transport/connudp.go
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package transport
+
+import (
+ "fmt"
+ "net"
+ "time"
+
+ "mynewt.apache.org/newt/newtmgr/config"
+ "mynewt.apache.org/newt/util"
+)
+
+type ConnUDP struct {
+ connProfile config.NewtmgrConnProfile
+ conn *net.UDPConn
+ dst *net.UDPAddr
+ isOIC bool
+}
+
+func (cs *ConnUDP) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration) error {
+ addr, err := net.ResolveUDPAddr("udp", cp.ConnString())
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("Name not resolving: %s",
+ err.Error()))
+ }
+ cs.dst = addr
+
+ // bind local endpoint to wait for response afterwards
+ s, err := net.ListenUDP("udp", nil)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("UDP conn failed: %s\n",
+ err.Error()))
+ }
+ cs.conn = s
+ return nil
+}
+
+func (cs *ConnUDP) Close() error {
+ cs.conn.Close()
+ cs.conn = nil
+ return nil
+}
+
+func (cs *ConnUDP) SetOICEncoded(b bool) {
+ cs.isOIC = b
+}
+
+func (cs *ConnUDP) GetOICEncoded() bool {
+ return cs.isOIC
+}
+
+func (cs *ConnUDP) WritePacket(pkt *Packet) error {
+ if cs.conn == nil {
+ return util.NewNewtError("Connection not open")
+ }
+
+ _, err := cs.conn.WriteTo(pkt.GetBytes(), cs.dst)
+ if err != nil {
+ return util.NewNewtError(fmt.Sprintf("failed to write: %s",
+ err.Error()))
+ }
+ return nil
+}
+
+func (cs *ConnUDP) ReadPacket() (*Packet, error) {
+ // cs.conn.SetDeadline(time.Now().Add(time.Second * 4))
+
+ data := make([]byte, 2048)
+ nr, srcAddr, err := cs.conn.ReadFromUDP(data)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("failed to read: %s",
+ err.Error()))
+ }
+ data = data[0:nr]
+ fmt.Printf("Received message from %v %d\n", srcAddr, nr)
+ pkt, err := NewPacket(uint16(nr))
+ if err != nil {
+ return nil, err
+ }
+ pkt.AddBytes(data)
+ return pkt, nil
+}
[3/3] incubator-mynewt-newt git commit: newt;
native targets don't have linker scripts. Don't error out.
Posted by ma...@apache.org.
newt; native targets don't have linker scripts. Don't error out.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/609bd6a0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/609bd6a0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/609bd6a0
Branch: refs/heads/develop
Commit: 609bd6a044f61bd00121bf50e8961026effbce06
Parents: 059bd7a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Oct 26 11:57:17 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Oct 26 11:57:17 2016 -0700
----------------------------------------------------------------------
newt/builder/targetbuild.go | 3 ---
1 file changed, 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/609bd6a0/newt/builder/targetbuild.go
----------------------------------------------------------------------
diff --git a/newt/builder/targetbuild.go b/newt/builder/targetbuild.go
index 7d1dce3..9274a8d 100644
--- a/newt/builder/targetbuild.go
+++ b/newt/builder/targetbuild.go
@@ -361,9 +361,6 @@ func (t *TargetBuilder) Build() error {
linkerScript := ""
if t.LoaderBuilder == nil {
linkerScript = t.bspPkg.LinkerScript
- if linkerScript == "" {
- return util.NewNewtError("BSP does not specify linker script")
- }
} else {
if err := t.buildLoader(); err != nil {
return err
[2/3] incubator-mynewt-newt git commit: newt;
not having download script is ok. Don't error out.
Posted by ma...@apache.org.
newt; not having download script is ok. Don't error out.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/059bd7a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/059bd7a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/059bd7a1
Branch: refs/heads/develop
Commit: 059bd7a117bb8719e5c8719cd687e8aad32b4af6
Parents: 0048727
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Oct 26 11:56:32 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed Oct 26 11:56:32 2016 -0700
----------------------------------------------------------------------
newt/builder/load.go | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/059bd7a1/newt/builder/load.go
----------------------------------------------------------------------
diff --git a/newt/builder/load.go b/newt/builder/load.go
index b370a4d..2fd4e7f 100644
--- a/newt/builder/load.go
+++ b/newt/builder/load.go
@@ -55,8 +55,7 @@ func Load(binBaseName string, bspPkg *pkg.BspPackage,
extraEnvSettings map[string]string) error {
if bspPkg.DownloadScript == "" {
- return util.FmtNewtError("No download script for BSP %s\n",
- bspPkg.Name())
+ return nil
}
bspPath := bspPkg.BasePath()