Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 0558d537a -> f544ec6fb


write notes on the magic number here and test long images (> 64k)


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/dba476ce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/dba476ce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/dba476ce

Branch: refs/heads/develop
Commit: dba476ce79f3041c62f72cbf6cb744fe24349c64
Parents: 0558d53
Author: paulfdietrich <paulfdietr...@yahoo.com>
Authored: Tue Oct 18 15:38:28 2016 -0700
Committer: paulfdietrich <paulfdietr...@yahoo.com>
Committed: Tue Oct 18 15:39:20 2016 -0700

----------------------------------------------------------------------
 newtmgr/cli/image.go            | 26 ++++++++++++++++++++++++++
 newtmgr/transport/connserial.go | 11 ++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dba476ce/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index c8ca761..c2e94ed 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -253,6 +253,32 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
        if profile.Type() == "ble" {
                mtu = uint32((transport.BleMTU - 33) * 3 / 4)
        } else {
+               /* since this possibly gets base 64 encoded, we want
+                * to ensure that the payload leaving this layer is 91
+                * bytes or less (91 bytes plus 2 byte crc will encode
+                * to 124 with 4 bytes of header
+                * left over */
+
+               /* 00000000  02 00 00 4f 00 01 00 01  a2 64 64 61 74 61 58 40  
|...O.....ddataX@|
+                * 00000010  00 f0 5a f8 0e 4b 1c 70  0e 4b 5a 88 12 05 10 0f  
|..Z..K.p.KZ.....|
+                * 00000020  59 88 0d 4a 0a 40 5a 80  59 88 0c 4a 0a 40 5a 80  
|Y..J.@Z.Y..J.@Z.|
+                * 00000030  19 1c 80 22 d2 01 4b 88  13 42 fc d1 05 49 02 02  
|..."..K..B...I..|
+                * 00000040  48 88 05 4b 03 40 13 43  4b 80 00 f0 5d f8 10 bd  
|H..K.@.CK...]...|
+                * 00000050  63 6f 66 66 1a 00 01 5d  b8                       
|coff..x|
+                */
+
+               /* from this dump we can see the following
+               * 1) newtmgr hdr 8 bytes
+               * 2) cbor wrapper up to data (and length) 8 bytes
+               * 3) cbor data 64 bytes
+               * 4) offset tag 4 bytes
+               * 5) offsert value 3 (safely say 5 bytes since it could be 
bigger
+               *      than uint16_t
+               * That makes 25 bytes plus the data needs to fit in 91 bytes
+                */
+
+               /* however, something is not calcualated properly as we
+                * can only do 66 bytes here.  Use 64 for power of 2 */
                mtu = 64
        }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dba476ce/newtmgr/transport/connserial.go
----------------------------------------------------------------------
diff --git a/newtmgr/transport/connserial.go b/newtmgr/transport/connserial.go
index b7aaf4f..37514a0 100644
--- a/newtmgr/transport/connserial.go
+++ b/newtmgr/transport/connserial.go
@@ -212,13 +212,22 @@ func (cs *ConnSerial) WritePacket(pkt *Packet) error {
        totlen := len(base64Data)
 
        for written < totlen {
+               /* write the packet stat designators. They are
+               * different whether we are starting a new packet or continuing 
one */
                if written == 0 {
                        cs.writeData([]byte{6, 9})
                } else {
                        cs.writeData([]byte{4, 20})
                }
 
-               writeLen := util.Min(120, totlen-written)
+               /* ensure that the total frame fits into 128 bytes.
+                * base 64 is 3 ascii to 4 base 64 byte encoding.  so
+                * the number below should be a multiple of 4.  Also,
+                * we need to save room for the header (2 byte) and
+                * carriage return (and possibly LF 2 bytes), */
+
+               /* all totaled, 124 bytes should work */
+               writeLen := util.Min(124, totlen-written)
 
                writeBytes := base64Data[written : written+writeLen]
                cs.writeData(writeBytes)

Reply via email to