http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/nmp.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/nmp.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/nmp.go new file mode 100644 index 0000000..bb35743 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/nmp.go @@ -0,0 +1,165 @@ +/** + * 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 nmp + +import ( + "encoding/binary" + "encoding/hex" + "fmt" + + log "github.com/Sirupsen/logrus" + "github.com/ugorji/go/codec" + + "mynewt.apache.org/newtmgr/nmxact/nmxutil" + "mynewt.apache.org/newt/util" +) + +const NMP_HDR_SIZE = 8 + +type NmpHdr struct { + Op uint8 /* 3 bits of opcode */ + Flags uint8 + Len uint16 + Group uint16 + Seq uint8 + Id uint8 +} + +type NmpMsg struct { + Hdr NmpHdr + Body interface{} +} + +// Combine req + rsp. +type NmpReq interface { + Hdr() *NmpHdr + SetHdr(hdr *NmpHdr) + + Msg() *NmpMsg +} + +type NmpRsp interface { + Hdr() *NmpHdr + SetHdr(msg *NmpHdr) + + Msg() *NmpMsg +} + +type NmpBase struct { + hdr NmpHdr `codec:"-"` +} + +func (b *NmpBase) Hdr() *NmpHdr { + return &b.hdr +} + +func (b *NmpBase) SetHdr(h *NmpHdr) { + b.hdr = *h +} + +func MsgFromReq(r NmpReq) *NmpMsg { + return &NmpMsg{ + *r.Hdr(), + r, + } +} + +func NewNmpMsg() *NmpMsg { + return &NmpMsg{} +} + +func DecodeNmpHdr(data []byte) (*NmpHdr, error) { + if len(data) < NMP_HDR_SIZE { + return nil, util.NewNewtError(fmt.Sprintf( + "Newtmgr request buffer too small %d bytes", len(data))) + } + + hdr := &NmpHdr{} + + hdr.Op = uint8(data[0]) + hdr.Flags = uint8(data[1]) + hdr.Len = binary.BigEndian.Uint16(data[2:4]) + hdr.Group = binary.BigEndian.Uint16(data[4:6]) + hdr.Seq = uint8(data[6]) + hdr.Id = uint8(data[7]) + + return hdr, nil +} + +func (hdr *NmpHdr) Bytes() []byte { + buf := make([]byte, 0, NMP_HDR_SIZE) + + buf = append(buf, byte(hdr.Op)) + buf = append(buf, byte(hdr.Flags)) + + u16b := make([]byte, 2) + binary.BigEndian.PutUint16(u16b, hdr.Len) + buf = append(buf, u16b...) + + binary.BigEndian.PutUint16(u16b, hdr.Group) + buf = append(buf, u16b...) + + buf = append(buf, byte(hdr.Seq)) + buf = append(buf, byte(hdr.Id)) + + return buf +} + +func BodyBytes(body interface{}) ([]byte, error) { + data := make([]byte, 0) + + enc := codec.NewEncoderBytes(&data, new(codec.CborHandle)) + if err := enc.Encode(body); err != nil { + return nil, fmt.Errorf("Failed to encode message %s", err.Error()) + } + + log.Debugf("Encoded %+v to:\n%s", body, hex.Dump(data)) + + return data, nil +} + +func EncodeNmpPlain(nmr *NmpMsg) ([]byte, error) { + bb, err := BodyBytes(nmr.Body) + if err != nil { + return nil, err + } + + nmr.Hdr.Len = uint16(len(bb)) + + hb := nmr.Hdr.Bytes() + data := append(hb, bb...) + + log.Debugf("Encoded:\n%s", hex.Dump(data)) + + return data, nil +} + +func fillNmpReq(req NmpReq, op uint8, group uint16, id uint8) { + hdr := NmpHdr{ + Op: op, + Flags: 0, + Len: 0, + Group: group, + Seq: nmxutil.NextNmpSeq(), + Id: id, + } + + req.SetHdr(&hdr) +}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/reset.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/reset.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/reset.go new file mode 100644 index 0000000..9b8cbad --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/reset.go @@ -0,0 +1,44 @@ +/** + * 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 nmp + +import () + +type ResetReq struct { + NmpBase +} + +type ResetRsp struct { + NmpBase +} + +func NewResetReq() *ResetReq { + r := &ResetReq{} + fillNmpReq(r, NMP_OP_WRITE, NMP_GROUP_DEFAULT, NMP_ID_DEF_RESET) + return r +} + +func (r *ResetReq) Msg() *NmpMsg { return MsgFromReq(r) } + +func NewResetRsp() *ResetRsp { + return &ResetRsp{} +} + +func (r *ResetRsp) Msg() *NmpMsg { return MsgFromReq(r) } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/run.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/run.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/run.go new file mode 100644 index 0000000..3672b0f --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/run.go @@ -0,0 +1,79 @@ +/** + * 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 nmp + +import () + +////////////////////////////////////////////////////////////////////////////// +// $test // +////////////////////////////////////////////////////////////////////////////// + +type RunTestReq struct { + NmpBase + Testname string `codec:"testname"` + Token string `codec:"token"` +} + +type RunTestRsp struct { + NmpBase + Rc int `codec:"rc" codec:",omitempty"` +} + +func NewRunTestReq() *RunTestReq { + r := &RunTestReq{} + fillNmpReq(r, NMP_OP_WRITE, NMP_GROUP_RUN, NMP_ID_RUN_TEST) + return r +} + +func (r *RunTestReq) Msg() *NmpMsg { return MsgFromReq(r) } + +func NewRunTestRsp() *RunTestRsp { + return &RunTestRsp{} +} + +func (r *RunTestRsp) Msg() *NmpMsg { return MsgFromReq(r) } + +////////////////////////////////////////////////////////////////////////////// +// $list // +////////////////////////////////////////////////////////////////////////////// + +type RunListReq struct { + NmpBase +} + +type RunListRsp struct { + NmpBase + Rc int `codec:"rc" codec:",omitempty"` + List []string `codec:"run_list"` +} + +func NewRunListReq() *RunListReq { + r := &RunListReq{} + fillNmpReq(r, NMP_OP_READ, NMP_GROUP_RUN, NMP_ID_RUN_LIST) + return r +} + +func (r *RunListReq) Msg() *NmpMsg { return MsgFromReq(r) } + +func NewRunListRsp() *RunListRsp { + return &RunListRsp{} +} + +func (r *RunListRsp) Msg() *NmpMsg { return MsgFromReq(r) } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/stat.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/stat.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/stat.go new file mode 100644 index 0000000..2839c02 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/stat.go @@ -0,0 +1,81 @@ +/** + * 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 nmp + +import () + +////////////////////////////////////////////////////////////////////////////// +// $read // +////////////////////////////////////////////////////////////////////////////// + +type StatReadReq struct { + NmpBase + Name string `codec:"name"` +} + +type StatReadRsp struct { + NmpBase + Rc int `codec:"rc"` + Name string `codec:"name"` + Group string `codec:"group"` + Fields map[string]interface{} `codec:"fields"` +} + +func NewStatReadReq() *StatReadReq { + r := &StatReadReq{} + fillNmpReq(r, NMP_OP_READ, NMP_GROUP_STAT, NMP_ID_STAT_READ) + return r +} + +func (r *StatReadReq) Msg() *NmpMsg { return MsgFromReq(r) } + +func NewStatReadRsp() *StatReadRsp { + return &StatReadRsp{} +} + +func (r *StatReadRsp) Msg() *NmpMsg { return MsgFromReq(r) } + +////////////////////////////////////////////////////////////////////////////// +// $list // +////////////////////////////////////////////////////////////////////////////// + +type StatListReq struct { + NmpBase +} + +type StatListRsp struct { + NmpBase + Rc int `codec:"rc"` + List []string `codec:"stat_list"` +} + +func NewStatListReq() *StatListReq { + r := &StatListReq{} + fillNmpReq(r, NMP_OP_READ, NMP_GROUP_STAT, NMP_ID_STAT_LIST) + return r +} + +func (r *StatListReq) Msg() *NmpMsg { return MsgFromReq(r) } + +func NewStatListRsp() *StatListRsp { + return &StatListRsp{} +} + +func (r *StatListRsp) Msg() *NmpMsg { return MsgFromReq(r) } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/taskstat.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/taskstat.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/taskstat.go new file mode 100644 index 0000000..6dda49d --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmp/taskstat.go @@ -0,0 +1,46 @@ +/** + * 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 nmp + +import () + +type TaskStatReq struct { + NmpBase +} + +type TaskStatRsp struct { + NmpBase + Rc int `codec:"rc" codec:",omitempty"` + Tasks map[string]map[string]int `codec:"tasks"` +} + +func NewTaskStatReq() *TaskStatReq { + r := &TaskStatReq{} + fillNmpReq(r, NMP_OP_READ, NMP_GROUP_DEFAULT, NMP_ID_DEF_TASKSTAT) + return r +} + +func (r *TaskStatReq) Msg() *NmpMsg { return MsgFromReq(r) } + +func NewTaskStatRsp() *TaskStatRsp { + return &TaskStatRsp{} +} + +func (r *TaskStatRsp) Msg() *NmpMsg { return MsgFromReq(r) } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/packet.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/packet.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/packet.go new file mode 100644 index 0000000..e25bc2e --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/packet.go @@ -0,0 +1,40 @@ +package nmserial + +import ( + "bytes" +) + +type Packet struct { + expectedLen uint16 + buffer *bytes.Buffer +} + +func NewPacket(expectedLen uint16) (*Packet, error) { + pkt := &Packet{ + expectedLen: expectedLen, + buffer: bytes.NewBuffer([]byte{}), + } + + return pkt, nil +} + +func (pkt *Packet) AddBytes(bytes []byte) bool { + pkt.buffer.Write(bytes) + if pkt.buffer.Len() >= int(pkt.expectedLen) { + return true + } else { + return false + } +} + +func (pkt *Packet) GetBytes() []byte { + return pkt.buffer.Bytes() +} + +func (pkt *Packet) TrimEnd(count int) { + + if pkt.buffer.Len() < count { + count = pkt.buffer.Len() + } + pkt.buffer.Truncate(pkt.buffer.Len() - count) +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/serial_plain_sesn.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/serial_plain_sesn.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/serial_plain_sesn.go new file mode 100644 index 0000000..fe7173e --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/serial_plain_sesn.go @@ -0,0 +1,137 @@ +package nmserial + +import ( + "fmt" + "sync" + + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +type SerialPlainSesn struct { + sx *SerialXport + nd *nmp.NmpDispatcher + isOpen bool + + // This mutex ensures: + // * each response get matched up with its corresponding request. + // * accesses to isOpen are protected. + m sync.Mutex +} + +func NewSerialPlainSesn(sx *SerialXport) *SerialPlainSesn { + return &SerialPlainSesn{ + sx: sx, + nd: nmp.NewNmpDispatcher(), + } +} + +func (sps *SerialPlainSesn) Open() error { + sps.m.Lock() + defer sps.m.Unlock() + + if sps.isOpen { + return nmxutil.NewSesnAlreadyOpenError( + "Attempt to open an already-open serial session") + } + + sps.isOpen = true + return nil +} + +func (sps *SerialPlainSesn) Close() error { + sps.m.Lock() + defer sps.m.Unlock() + + if !sps.isOpen { + return nmxutil.NewSesnClosedError( + "Attempt to close an unopened serial session") + } + sps.isOpen = false + return nil +} + +func (sps *SerialPlainSesn) IsOpen() bool { + sps.m.Lock() + defer sps.m.Unlock() + + return sps.isOpen +} + +func (sps *SerialPlainSesn) MtuIn() int { + return 1024 +} + +func (sps *SerialPlainSesn) MtuOut() int { + // Mynewt commands have a default chunk buffer size of 512. Account for + // base64 encoding. + return 512 * 3 / 4 +} + +func (sps *SerialPlainSesn) AbortRx(seq uint8) error { + return sps.nd.FakeRxError(seq, fmt.Errorf("Rx aborted")) +} + +func (sps *SerialPlainSesn) addNmpListener(seq uint8) ( + *nmp.NmpListener, error) { + + nl := nmp.NewNmpListener() + if err := sps.nd.AddListener(seq, nl); err != nil { + return nil, err + } + + return nl, nil +} + +func (sps *SerialPlainSesn) removeNmpListener(seq uint8) { + sps.nd.RemoveListener(seq) +} + +func (sps *SerialPlainSesn) EncodeNmpMsg(m *nmp.NmpMsg) ([]byte, error) { + return nmp.EncodeNmpPlain(m) +} + +func (sps *SerialPlainSesn) TxNmpOnce(m *nmp.NmpMsg, opt sesn.TxOptions) ( + nmp.NmpRsp, error) { + + sps.m.Lock() + defer sps.m.Unlock() + + if !sps.isOpen { + return nil, nmxutil.NewSesnClosedError( + "Attempt to transmit over closed serial session") + } + + nl, err := sps.addNmpListener(m.Hdr.Seq) + if err != nil { + return nil, err + } + defer sps.removeNmpListener(m.Hdr.Seq) + + reqb, err := sps.EncodeNmpMsg(m) + if err != nil { + return nil, err + } + + if err := sps.sx.Tx(reqb); err != nil { + return nil, err + } + + for { + rspb, err := sps.sx.Rx() + if err != nil { + return nil, err + } + + // Now wait for newtmgr response. + if sps.nd.Dispatch(rspb) { + select { + case err := <-nl.ErrChan: + return nil, err + case rsp := <-nl.RspChan: + return rsp, nil + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/serial_xport.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/serial_xport.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/serial_xport.go new file mode 100644 index 0000000..7dbb5ca --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmserial/serial_xport.go @@ -0,0 +1,217 @@ +package nmserial + +import ( + "bufio" + "encoding/base64" + "encoding/binary" + "encoding/hex" + "fmt" + "time" + + log "github.com/Sirupsen/logrus" + "github.com/joaojeronimo/go-crc16" + "github.com/tarm/serial" + + "mynewt.apache.org/newtmgr/nmxact/nmxutil" + "mynewt.apache.org/newtmgr/nmxact/sesn" + "mynewt.apache.org/newt/util" +) + +type XportCfg struct { + DevPath string + Baud int + ReadTimeout time.Duration +} + +func NewXportCfg() *XportCfg { + return &XportCfg{ + ReadTimeout: 10 * time.Second, + } +} + +type SerialXport struct { + cfg *XportCfg + port *serial.Port + scanner *bufio.Scanner + + pkt *Packet +} + +func NewSerialXport(cfg *XportCfg) *SerialXport { + return &SerialXport{ + cfg: cfg, + } +} + +func (sx *SerialXport) BuildSesn(cfg sesn.SesnCfg) (sesn.Sesn, error) { + switch cfg.MgmtProto { + case sesn.MGMT_PROTO_NMP: + return NewSerialPlainSesn(sx), nil + case sesn.MGMT_PROTO_OMP: + return nil, fmt.Errorf("OMP over serial currently unsupported") + default: + return nil, fmt.Errorf( + "Invalid management protocol: %d; expected NMP or OMP", + cfg.MgmtProto) + } +} + +func (sx *SerialXport) Start() error { + c := &serial.Config{ + Name: sx.cfg.DevPath, + Baud: sx.cfg.Baud, + ReadTimeout: sx.cfg.ReadTimeout, + } + + var err error + sx.port, err = serial.OpenPort(c) + if err != nil { + return err + } + + // Most of the reading will be done line by line, use the + // bufio.Scanner to do this + sx.scanner = bufio.NewScanner(sx.port) + + return nil +} + +func (sx *SerialXport) Stop() error { + return sx.port.Close() +} + +func (sx *SerialXport) txRaw(bytes []byte) error { + log.Debugf("Tx serial\n%s", hex.Dump(bytes)) + + _, err := sx.port.Write(bytes) + if err != nil { + return err + } + + return nil +} + +func (sx *SerialXport) Tx(bytes []byte) error { + log.Debugf("Base64 encoding request:\n%s", hex.Dump(bytes)) + + pktData := make([]byte, 2) + + crc := crc16.Crc16(bytes) + binary.BigEndian.PutUint16(pktData, crc) + bytes = append(bytes, pktData...) + + dLen := uint16(len(bytes)) + binary.BigEndian.PutUint16(pktData, dLen) + pktData = append(pktData, bytes...) + + base64Data := make([]byte, base64.StdEncoding.EncodedLen(len(pktData))) + + base64.StdEncoding.Encode(base64Data, pktData) + + written := 0 + 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 { + sx.txRaw([]byte{6, 9}) + } else { + /* slower platforms take some time to process each segment + * and have very small receive buffers. Give them a bit of + * time here */ + time.Sleep(20 * time.Millisecond) + sx.txRaw([]byte{4, 20}) + } + + /* 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] + sx.txRaw(writeBytes) + sx.txRaw([]byte{'\n'}) + + written += writeLen + } + + return nil +} + +// Blocking receive. +func (sx *SerialXport) Rx() ([]byte, error) { + for sx.scanner.Scan() { + line := []byte(sx.scanner.Text()) + + for { + if len(line) > 1 && line[0] == '\r' { + line = line[1:] + } else { + break + } + } + log.Debugf("Rx serial:\n%s", hex.Dump(line)) + if len(line) < 2 || ((line[0] != 4 || line[1] != 20) && + (line[0] != 6 || line[1] != 9)) { + continue + } + + base64Data := string(line[2:]) + + data, err := base64.StdEncoding.DecodeString(base64Data) + if err != nil { + return nil, fmt.Errorf("Couldn't decode base64 string:"+ + " %s\nPacket hex dump:\n%s", + base64Data, hex.Dump(line)) + } + + if line[0] == 6 && line[1] == 9 { + if len(data) < 2 { + continue + } + + pktLen := binary.BigEndian.Uint16(data[0:2]) + sx.pkt, err = NewPacket(pktLen) + if err != nil { + return nil, err + } + data = data[2:] + } + + if sx.pkt == nil { + continue + } + + full := sx.pkt.AddBytes(data) + if full { + if crc16.Crc16(sx.pkt.GetBytes()) != 0 { + return nil, fmt.Errorf("CRC error") + } + + /* + * Trim away the 2 bytes of CRC + */ + sx.pkt.TrimEnd(2) + b := sx.pkt.GetBytes() + sx.pkt = nil + + log.Debugf("Decoded input:\n%s", hex.Dump(b)) + return b, nil + } + } + + err := sx.scanner.Err() + if err == nil { + // Scanner hit EOF, so we'll need to create a new one. This only + // happens on timeouts. + err = nmxutil.NewXportTimeoutError( + "Timeout reading from serial connection") + sx.scanner = bufio.NewScanner(sx.port) + } + return nil, err +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmxutil/nmxerr.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmxutil/nmxerr.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmxutil/nmxerr.go new file mode 100644 index 0000000..aa9da23 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmxutil/nmxerr.go @@ -0,0 +1,160 @@ +package nmxutil + +import ( + "fmt" +) + +// Represents an NMP timeout; request sent, but no response received. +type NmpTimeoutError struct { + Text string +} + +func NewNmpTimeoutError(text string) *NmpTimeoutError { + return &NmpTimeoutError{ + Text: text, + } +} + +func FmtNmpTimeoutError(format string, args ...interface{}) *NmpTimeoutError { + return NewNmpTimeoutError(fmt.Sprintf(format, args...)) +} + +func (e *NmpTimeoutError) Error() string { + return e.Text +} + +func IsNmpTimeout(err error) bool { + _, ok := err.(*NmpTimeoutError) + return ok +} + +type BleSesnDisconnectError struct { + Text string + Reason int +} + +func NewBleSesnDisconnectError(reason int, + text string) *BleSesnDisconnectError { + + return &BleSesnDisconnectError{ + Reason: reason, + Text: text, + } +} + +func (e *BleSesnDisconnectError) Error() string { + return e.Text +} + +func IsBleSesnDisconnect(err error) bool { + _, ok := err.(*BleSesnDisconnectError) + return ok +} + +type SesnAlreadyOpenError struct { + Text string +} + +func NewSesnAlreadyOpenError(text string) *SesnAlreadyOpenError { + return &SesnAlreadyOpenError{ + Text: text, + } +} + +func (e *SesnAlreadyOpenError) Error() string { + return e.Text +} + +func IsSesnAlreadyOpen(err error) bool { + _, ok := err.(*SesnAlreadyOpenError) + return ok +} + +type SesnClosedError struct { + Text string +} + +func NewSesnClosedError(text string) *SesnClosedError { + return &SesnClosedError{ + Text: text, + } +} + +func (e *SesnClosedError) Error() string { + return e.Text +} + +func IsSesnClosed(err error) bool { + _, ok := err.(*SesnClosedError) + return ok +} + +// Represents a low-level transport error. +type XportError struct { + Text string +} + +func NewXportError(text string) *XportError { + return &XportError{text} +} + +func (e *XportError) Error() string { + return e.Text +} + +func IsXport(err error) bool { + _, ok := err.(*XportError) + return ok +} + +type XportTimeoutError struct { + Text string +} + +func NewXportTimeoutError(text string) *XportTimeoutError { + return &XportTimeoutError{text} +} + +func (e *XportTimeoutError) Error() string { + return e.Text +} + +func IsXportTimeout(err error) bool { + _, ok := err.(*XportTimeoutError) + return ok +} + +type BleHostError struct { + Text string + Status int +} + +func NewBleHostError(status int, text string) *BleHostError { + return &BleHostError{ + Status: status, + Text: text, + } +} + +func FmtBleHostError(status int, format string, + args ...interface{}) *BleHostError { + + return NewBleHostError(status, fmt.Sprintf(format, args...)) +} + +func (e *BleHostError) Error() string { + return e.Text +} + +func IsBleHost(err error) bool { + _, ok := err.(*BleHostError) + return ok +} + +func ToBleHost(err error) *BleHostError { + if berr, ok := err.(*BleHostError); ok { + return berr + } else { + return nil + } +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmxutil/nmxutil.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmxutil/nmxutil.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmxutil/nmxutil.go new file mode 100644 index 0000000..ef1ecd4 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/nmxutil/nmxutil.go @@ -0,0 +1,25 @@ +package nmxutil + +import ( + "math/rand" + "sync" +) + +var nextNmpSeq uint8 +var beenRead bool +var seqMutex sync.Mutex + +func NextNmpSeq() uint8 { + seqMutex.Lock() + defer seqMutex.Unlock() + + if !beenRead { + nextNmpSeq = uint8(rand.Uint32()) + beenRead = true + } + + val := nextNmpSeq + nextNmpSeq++ + + return val +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/dispatch.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/dispatch.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/dispatch.go new file mode 100644 index 0000000..44d1022 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/dispatch.go @@ -0,0 +1,66 @@ +/** + * 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 omp + +import ( + log "github.com/Sirupsen/logrus" + + "mynewt.apache.org/newtmgr/nmxact/nmp" +) + +type OmpDispatcher struct { + nd *nmp.NmpDispatcher + reassembler *Reassembler +} + +func NewOmpDispatcher() *OmpDispatcher { + return &OmpDispatcher{ + nd: nmp.NewNmpDispatcher(), + reassembler: NewReassembler(), + } +} + +func (od *OmpDispatcher) AddListener(seq uint8, rl *nmp.NmpListener) error { + return od.nd.AddListener(seq, rl) +} + +func (od *OmpDispatcher) RemoveListener(seq uint8) *nmp.NmpListener { + return od.nd.RemoveListener(seq) +} + +func (od *OmpDispatcher) FakeRxError(seq uint8, err error) error { + return od.nd.FakeRxError(seq, err) +} + +// Returns true if the response was dispatched. +func (om *OmpDispatcher) Dispatch(data []byte) bool { + tm := om.reassembler.RxFrag(data) + if tm == nil { + return false + } + + r, err := DecodeOmpTcp(tm) + if err != nil { + log.Printf("OMP decode failure: %s", err.Error()) + return false + } + + return om.nd.DispatchRsp(r) +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/frag.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/frag.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/frag.go new file mode 100644 index 0000000..caf7f48 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/frag.go @@ -0,0 +1,47 @@ +/** + * 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 omp + +import ( + log "github.com/Sirupsen/logrus" + "github.com/runtimeco/go-coap" +) + +type Reassembler struct { + cur []byte +} + +func NewReassembler() *Reassembler { + return &Reassembler{} +} + +func (r *Reassembler) RxFrag(frag []byte) *coap.TcpMessage { + r.cur = append(r.cur, frag...) + + var tm *coap.TcpMessage + var err error + tm, r.cur, err = coap.PullTcp(r.cur) + if err != nil { + log.Debugf("received invalid CoAP-TCP packet: %s", err.Error()) + return nil + } + + return tm +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/omp.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/omp.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/omp.go new file mode 100644 index 0000000..77dbd1b --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/omp/omp.go @@ -0,0 +1,125 @@ +/** + * 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 omp + +import ( + "encoding/hex" + "fmt" + + log "github.com/Sirupsen/logrus" + "github.com/fatih/structs" + "github.com/runtimeco/go-coap" + "github.com/ugorji/go/codec" + + "mynewt.apache.org/newtmgr/nmxact/nmp" +) + +// OIC wrapping adds this many bytes to an NMP message. +const OMP_MSG_OVERHEAD = 13 + +type OicMsg struct { + Hdr []byte `codec:"_h"` +} + +/* + * 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 DecodeOmpTcp(tm *coap.TcpMessage) (nmp.NmpRsp, error) { + // Ignore non-responses. + if tm.Code == coap.GET || tm.Code == coap.PUT { + return nil, nil + } + + if tm.Code != coap.Created && tm.Code != coap.Deleted && + tm.Code != coap.Valid && tm.Code != coap.Changed && + tm.Code != coap.Content { + return nil, fmt.Errorf( + "OMP response specifies unexpected code: %d (%s)", int(tm.Code), + tm.Code.String()) + } + + var om OicMsg + err := codec.NewDecoderBytes(tm.Payload, new(codec.CborHandle)).Decode(&om) + if err != nil { + return nil, fmt.Errorf("Invalid incoming cbor: %s", err.Error()) + } + if om.Hdr == nil { + return nil, fmt.Errorf("Invalid incoming OMP response; NMP header" + + "missing") + } + + hdr, err := nmp.DecodeNmpHdr(om.Hdr) + if err != nil { + return nil, err + } + + rsp, err := nmp.DecodeRspBody(hdr, tm.Payload) + if err != nil { + return nil, fmt.Errorf("Error decoding OMP response: %s", err.Error()) + } + if rsp == nil { + return nil, nil + } + + return rsp, nil +} + +func EncodeOmpTcp(nmr *nmp.NmpMsg) ([]byte, error) { + req := coap.TcpMessage{ + Message: coap.Message{ + Type: coap.Confirmable, + Code: coap.PUT, + }, + } + req.SetPathString("/omgr") + + payload := []byte{} + enc := codec.NewEncoderBytes(&payload, new(codec.CborHandle)) + + fields := structs.Fields(nmr.Body) + m := make(map[string]interface{}, len(fields)) + for _, f := range fields { + if cname := f.Tag("codec"); cname != "" { + m[cname] = f.Value() + } + } + + // Add the NMP heder to the OMP response map. + hbytes := nmr.Hdr.Bytes() + m["_h"] = hbytes + + if err := enc.Encode(m); err != nil { + return nil, err + } + req.Payload = payload + + data, err := req.MarshalBinary() + if err != nil { + return nil, fmt.Errorf("Failed to encode: %s\n", err.Error()) + } + + log.Debugf("Serialized OMP request:\n"+ + "Hdr %+v:\n%s\nPayload:%s\nData:\n%s", + nmr.Hdr, hex.Dump(hbytes), hex.Dump(req.Payload), hex.Dump(data)) + + return data, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn.go new file mode 100644 index 0000000..8ef8934 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn.go @@ -0,0 +1,79 @@ +package sesn + +import ( + "time" + + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" +) + +type TxOptions struct { + Timeout time.Duration + Tries int +} + +func (opt *TxOptions) AfterTimeout() <-chan time.Time { + if opt.Timeout == 0 { + return nil + } else { + return time.After(opt.Timeout) + } +} + +// Represents a communication session with a specific peer. The particulars +// vary according to protocol and transport. Several Sesn instances can use the +// same Xport. +type Sesn interface { + // Initiates communication with the peer. For connection-oriented + // transports, this creates a connection. + // Returns: + // * nil: success. + // * nmxutil.SesnAlreadyOpenError: session already open. + // * other error + Open() error + + // Ends communication with the peer. For connection-oriented transports, + // this closes the connection. + // * nil: success. + // * nmxutil.SesnClosedError: session not open. + // * other error + Close() error + + // Indicates whether the session is currently open. + IsOpen() bool + + // Retrieves the maximum data payload for outgoing NMP requests. + MtuOut() int + + // Retrieves the maximum data payload for incoming NMP responses. + MtuIn() int + + EncodeNmpMsg(msg *nmp.NmpMsg) ([]byte, error) + + // Performs a blocking transmit a single NMP message and listens for the + // response. + // * nil: success. + // * nmxutil.SesnClosedError: session not open. + // * other error + TxNmpOnce(m *nmp.NmpMsg, opt TxOptions) (nmp.NmpRsp, error) + + // Stops a receive operation in progress. This must be called from a + // separate thread, as sesn receive operations are blocking. + AbortRx(nmpSeq uint8) error +} + +func TxNmp(s Sesn, m *nmp.NmpMsg, o TxOptions) (nmp.NmpRsp, error) { + retries := o.Tries - 1 + for i := 0; ; i++ { + r, err := s.TxNmpOnce(m, o) + if err == nil { + return r, nil + } + + if (!nmxutil.IsNmpTimeout(err) && !nmxutil.IsXportTimeout(err)) || + i >= retries { + + return nil, err + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_cfg.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_cfg.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_cfg.go new file mode 100644 index 0000000..e18711d --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/sesn/sesn_cfg.go @@ -0,0 +1,65 @@ +package sesn + +import ( + "time" + + "mynewt.apache.org/newtmgr/nmxact/bledefs" +) + +type MgmtProto int + +const ( + MGMT_PROTO_NMP MgmtProto = iota + MGMT_PROTO_OMP +) + +type BleOnCloseFn func(s Sesn, peer bledefs.BleDev, err error) + +// Specifies the BLE peer to connect to. +type BlePeerSpec struct { + // This is filled in if you know the address of the peer to connect to. + Dev bledefs.BleDev + + // Otherwise, we must scan for a peer to connect to. This points to a + // function that indicates whether we should connect to the sender of the + // specified advertisement. This function gets called each time an + // incoming advertisement is received. If it returns true, the session + // will connect to the sender of the corresponding advertisement. Set this + // to nil if you populate the Dev field. + ScanPred bledefs.BleAdvPredicate +} + +func BlePeerSpecDev(dev bledefs.BleDev) BlePeerSpec { + return BlePeerSpec{Dev: dev} +} + +func BlePeerSpecName(name string) BlePeerSpec { + return BlePeerSpec{ + ScanPred: func(r bledefs.BleAdvReport) bool { + return r.Name == name + }, + } +} + +type SesnCfgBle struct { + OwnAddrType bledefs.BleAddrType + PeerSpec BlePeerSpec + CloseTimeout time.Duration + OnCloseCb BleOnCloseFn +} + +type SesnCfg struct { + // Used with all transport types. + MgmtProto MgmtProto + + // Only used with BLE transports. + Ble SesnCfgBle +} + +func NewSesnCfg() SesnCfg { + return SesnCfg{ + Ble: SesnCfgBle{ + CloseTimeout: 5 * time.Second, + }, + } +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/cmd.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/cmd.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/cmd.go new file mode 100644 index 0000000..d5d7a23 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/cmd.go @@ -0,0 +1,65 @@ +/** + * 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 xact + +import ( + "fmt" + + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +type Result interface { + Status() int +} + +type Cmd interface { + // Transmits request and listens for response; blocking. + Run(s sesn.Sesn) (Result, error) + Abort() error + + TxOptions() sesn.TxOptions + SetTxOptions(opt sesn.TxOptions) +} + +type CmdBase struct { + txOptions sesn.TxOptions + curNmpSeq uint8 + curSesn sesn.Sesn + abortErr error +} + +func (c *CmdBase) TxOptions() sesn.TxOptions { + return c.txOptions +} + +func (c *CmdBase) SetTxOptions(opt sesn.TxOptions) { + c.txOptions = opt +} + +func (c *CmdBase) Abort() error { + if c.curSesn != nil { + if err := c.curSesn.AbortRx(c.curNmpSeq); err != nil { + return err + } + } + + c.abortErr = fmt.Errorf("Command aborted") + return nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/config.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/config.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/config.go new file mode 100644 index 0000000..ddc893b --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/config.go @@ -0,0 +1,88 @@ +package xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +////////////////////////////////////////////////////////////////////////////// +// $read // +////////////////////////////////////////////////////////////////////////////// + +type ConfigReadCmd struct { + CmdBase + Name string +} + +func NewConfigReadCmd() *ConfigReadCmd { + return &ConfigReadCmd{} +} + +type ConfigReadResult struct { + Rsp *nmp.ConfigReadRsp +} + +func newConfigReadResult() *ConfigReadResult { + return &ConfigReadResult{} +} + +func (r *ConfigReadResult) Status() int { + return r.Rsp.Rc +} + +func (c *ConfigReadCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewConfigReadReq() + r.Name = c.Name + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.ConfigReadRsp) + + res := newConfigReadResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $write // +////////////////////////////////////////////////////////////////////////////// + +type ConfigWriteCmd struct { + CmdBase + Name string + Val string +} + +func NewConfigWriteCmd() *ConfigWriteCmd { + return &ConfigWriteCmd{} +} + +type ConfigWriteResult struct { + Rsp *nmp.ConfigWriteRsp +} + +func newConfigWriteResult() *ConfigWriteResult { + return &ConfigWriteResult{} +} + +func (r *ConfigWriteResult) Status() int { + return r.Rsp.Rc +} + +func (c *ConfigWriteCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewConfigWriteReq() + r.Name = c.Name + r.Val = c.Val + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.ConfigWriteRsp) + + res := newConfigWriteResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/crash.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/crash.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/crash.go new file mode 100644 index 0000000..ebb94c7 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/crash.go @@ -0,0 +1,87 @@ +package xact + +import ( + "fmt" + "sort" + + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +type CrashType int + +const ( + CRASH_TYPE_DIV0 CrashType = iota + CRASH_TYPE_JUMP0 + CRASH_TYPE_REF0 + CRASH_TYPE_ASSERT + CRASH_TYPE_WDOG +) + +var CrashTypeNameMap = map[CrashType]string{ + CRASH_TYPE_DIV0: "div0", + CRASH_TYPE_JUMP0: "jump0", + CRASH_TYPE_REF0: "ref0", + CRASH_TYPE_ASSERT: "assert", + CRASH_TYPE_WDOG: "wdog", +} + +func CrashTypeToString(ct CrashType) string { + return CrashTypeNameMap[ct] +} + +func CrashTypeFromString(s string) (CrashType, error) { + for k, v := range CrashTypeNameMap { + if s == v { + return k, nil + } + } + + return CrashType(0), fmt.Errorf("invalid crash type: %s", s) +} + +func CrashTypeNames() []string { + names := make([]string, 0, len(CrashTypeNameMap)) + for _, v := range CrashTypeNameMap { + names = append(names, v) + } + + sort.Strings(names) + return names +} + +type CrashCmd struct { + CmdBase + CrashType CrashType +} + +func NewCrashCmd() *CrashCmd { + return &CrashCmd{} +} + +type CrashResult struct { + Rsp *nmp.CrashRsp +} + +func newCrashResult() *CrashResult { + return &CrashResult{} +} + +func (r *CrashResult) Status() int { + return r.Rsp.Rc +} + +func (c *CrashCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewCrashReq() + r.CrashType = CrashTypeToString(c.CrashType) + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.CrashRsp) + + res := newCrashResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/datetime.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/datetime.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/datetime.go new file mode 100644 index 0000000..27bd089 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/datetime.go @@ -0,0 +1,84 @@ +package xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +/////////////////////////////////////////////////////////////////////////////// +// $read // +/////////////////////////////////////////////////////////////////////////////// + +type DateTimeReadCmd struct { + CmdBase +} + +func NewDateTimeReadCmd() *DateTimeReadCmd { + return &DateTimeReadCmd{} +} + +type DateTimeReadResult struct { + Rsp *nmp.DateTimeReadRsp +} + +func newDateTimeReadResult() *DateTimeReadResult { + return &DateTimeReadResult{} +} + +func (r *DateTimeReadResult) Status() int { + return r.Rsp.Rc +} + +func (c *DateTimeReadCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewDateTimeReadReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.DateTimeReadRsp) + + res := newDateTimeReadResult() + res.Rsp = srsp + return res, nil +} + +/////////////////////////////////////////////////////////////////////////////// +// $write // +/////////////////////////////////////////////////////////////////////////////// + +type DateTimeWriteCmd struct { + CmdBase + DateTime string +} + +func NewDateTimeWriteCmd() *DateTimeWriteCmd { + return &DateTimeWriteCmd{} +} + +type DateTimeWriteResult struct { + Rsp *nmp.DateTimeWriteRsp +} + +func newDateTimeWriteResult() *DateTimeWriteResult { + return &DateTimeWriteResult{} +} + +func (r *DateTimeWriteResult) Status() int { + return r.Rsp.Rc +} + +func (c *DateTimeWriteCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewDateTimeWriteReq() + r.DateTime = c.DateTime + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.DateTimeWriteRsp) + + res := newDateTimeWriteResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/echo.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/echo.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/echo.go new file mode 100644 index 0000000..09622b2 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/echo.go @@ -0,0 +1,42 @@ +package xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +type EchoCmd struct { + CmdBase + Payload string +} + +func NewEchoCmd() *EchoCmd { + return &EchoCmd{} +} + +type EchoResult struct { + Rsp *nmp.EchoRsp +} + +func newEchoResult() *EchoResult { + return &EchoResult{} +} + +func (r *EchoResult) Status() int { + return r.Rsp.Rc +} + +func (c *EchoCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewEchoReq() + r.Payload = c.Payload + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.EchoRsp) + + res := newEchoResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/fs.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/fs.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/fs.go new file mode 100644 index 0000000..0fe32c6 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/fs.go @@ -0,0 +1,178 @@ +package xact + +import ( + "fmt" + + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +////////////////////////////////////////////////////////////////////////////// +// $download // +////////////////////////////////////////////////////////////////////////////// + +type FsDownloadProgressCb func(c *FsDownloadCmd, r *nmp.FsDownloadRsp) +type FsDownloadCmd struct { + CmdBase + Name string + ProgressCb FsDownloadProgressCb +} + +func NewFsDownloadCmd() *FsDownloadCmd { + return &FsDownloadCmd{} +} + +type FsDownloadResult struct { + Rsps []*nmp.FsDownloadRsp +} + +func newFsDownloadResult() *FsDownloadResult { + return &FsDownloadResult{} +} + +func (r *FsDownloadResult) Status() int { + rsp := r.Rsps[len(r.Rsps)-1] + return rsp.Rc +} + +func (c *FsDownloadCmd) Run(s sesn.Sesn) (Result, error) { + res := newFsDownloadResult() + off := 0 + + for { + r := nmp.NewFsDownloadReq() + r.Name = c.Name + r.Off = uint32(off) + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + frsp := rsp.(*nmp.FsDownloadRsp) + res.Rsps = append(res.Rsps, frsp) + + if frsp.Rc != 0 { + break + } + + if c.ProgressCb != nil { + c.ProgressCb(c, frsp) + } + + off = int(frsp.Off) + len(frsp.Data) + if off >= int(frsp.Len) { + break + } + } + + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $upload // +////////////////////////////////////////////////////////////////////////////// + +type FsUploadProgressCb func(c *FsUploadCmd, r *nmp.FsUploadRsp) +type FsUploadCmd struct { + CmdBase + Name string + Data []byte + ProgressCb FsUploadProgressCb +} + +func NewFsUploadCmd() *FsUploadCmd { + return &FsUploadCmd{} +} + +type FsUploadResult struct { + Rsps []*nmp.FsUploadRsp +} + +func newFsUploadResult() *FsUploadResult { + return &FsUploadResult{} +} + +func (r *FsUploadResult) Status() int { + rsp := r.Rsps[len(r.Rsps)-1] + return rsp.Rc +} + +func buildFsUploadReq(name string, fileSz int, chunk []byte, + off int) *nmp.FsUploadReq { + + r := nmp.NewFsUploadReq() + + if r.Off == 0 { + r.Len = uint32(fileSz) + } + r.Name = name + r.Off = uint32(off) + r.Data = chunk + + return r +} + +func nextFsUploadReq(s sesn.Sesn, name string, data []byte, off int) ( + *nmp.FsUploadReq, error) { + + // First, build a request without data to determine how much data could + // fit. + empty := buildFsUploadReq(name, len(data), nil, off) + emptyEnc, err := s.EncodeNmpMsg(empty.Msg()) + if err != nil { + return nil, err + } + + room := s.MtuOut() - len(emptyEnc) + if room <= 0 { + return nil, fmt.Errorf("Cannot create image upload request; " + + "MTU too low to fit any image data") + } + + // Assume all the unused space can hold image data. This assumption may + // not be valid for some encodings (e.g., CBOR uses variable length fields + // to encodes byte string lengths). + r := buildFsUploadReq(name, len(data), data[off:off+room], off) + enc, err := s.EncodeNmpMsg(r.Msg()) + if err != nil { + return nil, err + } + + oversize := len(enc) - s.MtuOut() + if oversize > 0 { + // Request too big. Reduce the amount of image data. + r = buildFsUploadReq(name, len(data), data[off:off+room-oversize], off) + } + + return r, nil +} + +func (c *FsUploadCmd) Run(s sesn.Sesn) (Result, error) { + res := newFsUploadResult() + + for off := 0; off < len(c.Data); { + r, err := nextFsUploadReq(s, c.Name, c.Data, off) + if err != nil { + return nil, err + } + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + crsp := rsp.(*nmp.FsUploadRsp) + + off = int(crsp.Off) + + if c.ProgressCb != nil { + c.ProgressCb(c, crsp) + } + + res.Rsps = append(res.Rsps, crsp) + if crsp.Rc != 0 { + break + } + } + + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/image.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/image.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/image.go new file mode 100644 index 0000000..615dd74 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/image.go @@ -0,0 +1,332 @@ +package xact + +import ( + "fmt" + + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +////////////////////////////////////////////////////////////////////////////// +// $upload // +////////////////////////////////////////////////////////////////////////////// + +type ImageUploadProgressFn func(c *ImageUploadCmd, r *nmp.ImageUploadRsp) +type ImageUploadCmd struct { + CmdBase + Data []byte + ProgressCb ImageUploadProgressFn +} + +type ImageUploadResult struct { + Rsps []*nmp.ImageUploadRsp +} + +func NewImageUploadCmd() *ImageUploadCmd { + return &ImageUploadCmd{} +} + +func newImageUploadResult() *ImageUploadResult { + return &ImageUploadResult{} +} + +func (r *ImageUploadResult) Status() int { + rsp := r.Rsps[len(r.Rsps)-1] + return rsp.Rc +} + +func buildImageUploadReq(imageSz int, chunk []byte, + off int) *nmp.ImageUploadReq { + + r := nmp.NewImageUploadReq() + + if r.Off == 0 { + r.Len = uint32(imageSz) + } + r.Off = uint32(off) + r.Data = chunk + + return r +} + +func nextImageUploadReq(s sesn.Sesn, data []byte, off int) ( + *nmp.ImageUploadReq, error) { + + // First, build a request without data to determine how much data could + // fit. + empty := buildImageUploadReq(len(data), nil, off) + emptyEnc, err := s.EncodeNmpMsg(empty.Msg()) + if err != nil { + return nil, err + } + + room := s.MtuOut() - len(emptyEnc) + if room <= 0 { + return nil, fmt.Errorf("Cannot create image upload request; " + + "MTU too low to fit any image data") + } + + // Assume all the unused space can hold image data. This assumption may + // not be valid for some encodings (e.g., CBOR uses variable length fields + // to encodes byte string lengths). + r := buildImageUploadReq(len(data), data[off:off+room], off) + enc, err := s.EncodeNmpMsg(r.Msg()) + if err != nil { + return nil, err + } + + oversize := len(enc) - s.MtuOut() + if oversize > 0 { + // Request too big. Reduce the amount of image data. + r = buildImageUploadReq(len(data), data[off:off+room-oversize], off) + } + + return r, nil +} + +func (c *ImageUploadCmd) Run(s sesn.Sesn) (Result, error) { + res := newImageUploadResult() + + for off := 0; off < len(c.Data); { + r, err := nextImageUploadReq(s, c.Data, off) + if err != nil { + return nil, err + } + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + irsp := rsp.(*nmp.ImageUploadRsp) + + off = int(irsp.Off) + + if c.ProgressCb != nil { + c.ProgressCb(c, irsp) + } + + res.Rsps = append(res.Rsps, irsp) + if irsp.Rc != 0 { + break + } + } + + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $state read // +////////////////////////////////////////////////////////////////////////////// + +type ImageStateReadCmd struct { + CmdBase +} + +type ImageStateReadResult struct { + Rsp *nmp.ImageStateRsp +} + +func NewImageStateReadCmd() *ImageStateReadCmd { + return &ImageStateReadCmd{} +} + +func newImageStateReadResult() *ImageStateReadResult { + return &ImageStateReadResult{} +} + +func (r *ImageStateReadResult) Status() int { + return r.Rsp.Rc +} + +func (c *ImageStateReadCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewImageStateReadReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.ImageStateRsp) + + res := newImageStateReadResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $state write // +////////////////////////////////////////////////////////////////////////////// + +type ImageStateWriteCmd struct { + CmdBase + Hash []byte + Confirm bool +} + +type ImageStateWriteResult struct { + Rsp *nmp.ImageStateRsp +} + +func NewImageStateWriteCmd() *ImageStateWriteCmd { + return &ImageStateWriteCmd{} +} + +func newImageStateWriteResult() *ImageStateWriteResult { + return &ImageStateWriteResult{} +} + +func (r *ImageStateWriteResult) Status() int { + return r.Rsp.Rc +} + +func (c *ImageStateWriteCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewImageStateWriteReq() + r.Hash = c.Hash + r.Confirm = c.Confirm + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.ImageStateRsp) + + res := newImageStateWriteResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $corelist // +////////////////////////////////////////////////////////////////////////////// + +type CoreListCmd struct { + CmdBase +} + +type CoreListResult struct { + Rsp *nmp.CoreListRsp +} + +func NewCoreListCmd() *CoreListCmd { + return &CoreListCmd{} +} + +func newCoreListResult() *CoreListResult { + return &CoreListResult{} +} + +func (r *CoreListResult) Status() int { + return r.Rsp.Rc +} + +func (c *CoreListCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewCoreListReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.CoreListRsp) + + res := newCoreListResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $coreload // +////////////////////////////////////////////////////////////////////////////// + +type CoreLoadProgressFn func(c *CoreLoadCmd, r *nmp.CoreLoadRsp) +type CoreLoadCmd struct { + CmdBase + ProgressCb CoreLoadProgressFn +} + +type CoreLoadResult struct { + Rsps []*nmp.CoreLoadRsp +} + +func NewCoreLoadCmd() *CoreLoadCmd { + return &CoreLoadCmd{} +} + +func newCoreLoadResult() *CoreLoadResult { + return &CoreLoadResult{} +} + +func (r *CoreLoadResult) Status() int { + rsp := r.Rsps[len(r.Rsps)-1] + return rsp.Rc +} + +func (c *CoreLoadCmd) Run(s sesn.Sesn) (Result, error) { + res := newCoreLoadResult() + off := 0 + + for { + r := nmp.NewCoreLoadReq() + r.Off = uint32(off) + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + irsp := rsp.(*nmp.CoreLoadRsp) + + if c.ProgressCb != nil { + c.ProgressCb(c, irsp) + } + + res.Rsps = append(res.Rsps, irsp) + if irsp.Rc != 0 { + break + } + + if len(irsp.Data) == 0 { + // Download complete. + break + } + + off = int(irsp.Off) + len(irsp.Data) + } + + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $coreerase // +////////////////////////////////////////////////////////////////////////////// + +type CoreEraseCmd struct { + CmdBase +} + +type CoreEraseResult struct { + Rsp *nmp.CoreEraseRsp +} + +func NewCoreEraseCmd() *CoreEraseCmd { + return &CoreEraseCmd{} +} + +func newCoreEraseResult() *CoreEraseResult { + return &CoreEraseResult{} +} + +func (r *CoreEraseResult) Status() int { + return r.Rsp.Rc +} + +func (c *CoreEraseCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewCoreEraseReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.CoreEraseRsp) + + res := newCoreEraseResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/log.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/log.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/log.go new file mode 100644 index 0000000..86b348f --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/log.go @@ -0,0 +1,202 @@ +package xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +////////////////////////////////////////////////////////////////////////////// +// $read // +////////////////////////////////////////////////////////////////////////////// + +type LogShowCmd struct { + CmdBase + Name string + Timestamp int64 + Index uint32 +} + +func NewLogShowCmd() *LogShowCmd { + return &LogShowCmd{} +} + +type LogShowResult struct { + Rsp *nmp.LogShowRsp +} + +func newLogShowResult() *LogShowResult { + return &LogShowResult{} +} + +func (r *LogShowResult) Status() int { + return r.Rsp.Rc +} + +func (c *LogShowCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewLogShowReq() + r.Name = c.Name + r.Timestamp = c.Timestamp + r.Index = c.Index + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.LogShowRsp) + + res := newLogShowResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $list // +////////////////////////////////////////////////////////////////////////////// + +type LogListCmd struct { + CmdBase +} + +func NewLogListCmd() *LogListCmd { + return &LogListCmd{} +} + +type LogListResult struct { + Rsp *nmp.LogListRsp +} + +func newLogListResult() *LogListResult { + return &LogListResult{} +} + +func (r *LogListResult) Status() int { + return r.Rsp.Rc +} + +func (c *LogListCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewLogListReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.LogListRsp) + + res := newLogListResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $module list // +////////////////////////////////////////////////////////////////////////////// + +type LogModuleListCmd struct { + CmdBase +} + +func NewLogModuleListCmd() *LogModuleListCmd { + return &LogModuleListCmd{} +} + +type LogModuleListResult struct { + Rsp *nmp.LogModuleListRsp +} + +func newLogModuleListResult() *LogModuleListResult { + return &LogModuleListResult{} +} + +func (r *LogModuleListResult) Status() int { + return r.Rsp.Rc +} + +func (c *LogModuleListCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewLogModuleListReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.LogModuleListRsp) + + res := newLogModuleListResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $level list // +////////////////////////////////////////////////////////////////////////////// + +type LogLevelListCmd struct { + CmdBase +} + +func NewLogLevelListCmd() *LogLevelListCmd { + return &LogLevelListCmd{} +} + +type LogLevelListResult struct { + Rsp *nmp.LogLevelListRsp +} + +func newLogLevelListResult() *LogLevelListResult { + return &LogLevelListResult{} +} + +func (r *LogLevelListResult) Status() int { + return r.Rsp.Rc +} + +func (c *LogLevelListCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewLogLevelListReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.LogLevelListRsp) + + res := newLogLevelListResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $clear // +////////////////////////////////////////////////////////////////////////////// + +type LogClearCmd struct { + CmdBase +} + +func NewLogClearCmd() *LogClearCmd { + return &LogClearCmd{} +} + +type LogClearResult struct { + Rsp *nmp.LogClearRsp +} + +func newLogClearResult() *LogClearResult { + return &LogClearResult{} +} + +func (r *LogClearResult) Status() int { + return r.Rsp.Rc +} + +func (c *LogClearCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewLogClearReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.LogClearRsp) + + res := newLogClearResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/mpstat.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/mpstat.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/mpstat.go new file mode 100644 index 0000000..acff3e2 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/mpstat.go @@ -0,0 +1,40 @@ +package xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +type MempoolStatCmd struct { + CmdBase +} + +func NewMempoolStatCmd() *MempoolStatCmd { + return &MempoolStatCmd{} +} + +type MempoolStatResult struct { + Rsp *nmp.MempoolStatRsp +} + +func newMempoolStatResult() *MempoolStatResult { + return &MempoolStatResult{} +} + +func (r *MempoolStatResult) Status() int { + return r.Rsp.Rc +} + +func (c *MempoolStatCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewMempoolStatReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.MempoolStatRsp) + + res := newMempoolStatResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/reset.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/reset.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/reset.go new file mode 100644 index 0000000..397ad60 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/reset.go @@ -0,0 +1,41 @@ +package xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +type ResetCmd struct { + CmdBase + Payload string +} + +func NewResetCmd() *ResetCmd { + return &ResetCmd{} +} + +type ResetResult struct { + Rsp *nmp.ResetRsp +} + +func newResetResult() *ResetResult { + return &ResetResult{} +} + +func (r *ResetResult) Status() int { + return 0 +} + +func (c *ResetCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewResetReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.ResetRsp) + + res := newResetResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/run.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/run.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/run.go new file mode 100644 index 0000000..28d71a9 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/run.go @@ -0,0 +1,86 @@ +package xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +////////////////////////////////////////////////////////////////////////////// +// $test // +////////////////////////////////////////////////////////////////////////////// + +type RunTestCmd struct { + CmdBase + Testname string + Token string +} + +func NewRunTestCmd() *RunTestCmd { + return &RunTestCmd{} +} + +type RunTestResult struct { + Rsp *nmp.RunTestRsp +} + +func newRunTestResult() *RunTestResult { + return &RunTestResult{} +} + +func (r *RunTestResult) Status() int { + return r.Rsp.Rc +} + +func (c *RunTestCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewRunTestReq() + r.Testname = c.Testname + r.Token = c.Token + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.RunTestRsp) + + res := newRunTestResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $list // +////////////////////////////////////////////////////////////////////////////// + +type RunListCmd struct { + CmdBase +} + +func NewRunListCmd() *RunListCmd { + return &RunListCmd{} +} + +type RunListResult struct { + Rsp *nmp.RunListRsp +} + +func newRunListResult() *RunListResult { + return &RunListResult{} +} + +func (r *RunListResult) Status() int { + return r.Rsp.Rc +} + +func (c *RunListCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewRunListReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.RunListRsp) + + res := newRunListResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/stat.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/stat.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/stat.go new file mode 100644 index 0000000..a38eba9 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/stat.go @@ -0,0 +1,84 @@ +package xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +////////////////////////////////////////////////////////////////////////////// +// $read // +////////////////////////////////////////////////////////////////////////////// + +type StatReadCmd struct { + CmdBase + Name string +} + +func NewStatReadCmd() *StatReadCmd { + return &StatReadCmd{} +} + +type StatReadResult struct { + Rsp *nmp.StatReadRsp +} + +func newStatReadResult() *StatReadResult { + return &StatReadResult{} +} + +func (r *StatReadResult) Status() int { + return r.Rsp.Rc +} + +func (c *StatReadCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewStatReadReq() + r.Name = c.Name + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.StatReadRsp) + + res := newStatReadResult() + res.Rsp = srsp + return res, nil +} + +////////////////////////////////////////////////////////////////////////////// +// $list // +////////////////////////////////////////////////////////////////////////////// + +type StatListCmd struct { + CmdBase +} + +func NewStatListCmd() *StatListCmd { + return &StatListCmd{} +} + +type StatListResult struct { + Rsp *nmp.StatListRsp +} + +func newStatListResult() *StatListResult { + return &StatListResult{} +} + +func (r *StatListResult) Status() int { + return r.Rsp.Rc +} + +func (c *StatListCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewStatListReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.StatListRsp) + + res := newStatListResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/taskstat.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/taskstat.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/taskstat.go new file mode 100644 index 0000000..bb03357 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/taskstat.go @@ -0,0 +1,40 @@ +package xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +type TaskStatCmd struct { + CmdBase +} + +func NewTaskStatCmd() *TaskStatCmd { + return &TaskStatCmd{} +} + +type TaskStatResult struct { + Rsp *nmp.TaskStatRsp +} + +func newTaskStatResult() *TaskStatResult { + return &TaskStatResult{} +} + +func (r *TaskStatResult) Status() int { + return r.Rsp.Rc +} + +func (c *TaskStatCmd) Run(s sesn.Sesn) (Result, error) { + r := nmp.NewTaskStatReq() + + rsp, err := txReq(s, r.Msg(), &c.CmdBase) + if err != nil { + return nil, err + } + srsp := rsp.(*nmp.TaskStatRsp) + + res := newTaskStatResult() + res.Rsp = srsp + return res, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/xact.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/xact.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/xact.go new file mode 100644 index 0000000..00c177f --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xact/xact.go @@ -0,0 +1,47 @@ +/** + * 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 xact + +import ( + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +func txReq(s sesn.Sesn, m *nmp.NmpMsg, c *CmdBase) ( + nmp.NmpRsp, error) { + + if c.abortErr != nil { + return nil, c.abortErr + } + + c.curNmpSeq = m.Hdr.Seq + c.curSesn = s + defer func() { + c.curNmpSeq = 0 + c.curSesn = nil + }() + + rsp, err := sesn.TxNmp(s, m, c.TxOptions()) + if err != nil { + return nil, err + } + + return rsp, nil +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xport/xport.go ---------------------------------------------------------------------- diff --git a/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xport/xport.go b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xport/xport.go new file mode 100644 index 0000000..85ef2b2 --- /dev/null +++ b/newtmgr/vendor/mynewt.apache.org/newtmgr/nmxact/xport/xport.go @@ -0,0 +1,15 @@ +package xport + +import ( + "mynewt.apache.org/newtmgr/nmxact/sesn" +) + +type RxFn func(data []byte) + +type Xport interface { + Start() error + Stop() error + BuildSesn(cfg sesn.SesnCfg) (sesn.Sesn, error) + + Tx(data []byte) error +} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/example/ble_plain/ble_plain.go ---------------------------------------------------------------------- diff --git a/nmxact/example/ble_plain/ble_plain.go b/nmxact/example/ble_plain/ble_plain.go index 98c8f9f..44d0566 100644 --- a/nmxact/example/ble_plain/ble_plain.go +++ b/nmxact/example/ble_plain/ble_plain.go @@ -23,10 +23,10 @@ import ( "fmt" "os" - "mynewt.apache.org/newt/nmxact/bledefs" - "mynewt.apache.org/newt/nmxact/nmble" - "mynewt.apache.org/newt/nmxact/sesn" - "mynewt.apache.org/newt/nmxact/xact" + "mynewt.apache.org/newtmgr/nmxact/bledefs" + "mynewt.apache.org/newtmgr/nmxact/nmble" + "mynewt.apache.org/newtmgr/nmxact/sesn" + "mynewt.apache.org/newtmgr/nmxact/xact" ) func main() { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/example/serial_plain/serial_plain.go ---------------------------------------------------------------------- diff --git a/nmxact/example/serial_plain/serial_plain.go b/nmxact/example/serial_plain/serial_plain.go index 05fab27..5b0c3b1 100644 --- a/nmxact/example/serial_plain/serial_plain.go +++ b/nmxact/example/serial_plain/serial_plain.go @@ -24,9 +24,9 @@ import ( "os" "time" - "mynewt.apache.org/newt/nmxact/nmserial" - "mynewt.apache.org/newt/nmxact/sesn" - "mynewt.apache.org/newt/nmxact/xact" + "mynewt.apache.org/newtmgr/nmxact/nmserial" + "mynewt.apache.org/newtmgr/nmxact/sesn" + "mynewt.apache.org/newtmgr/nmxact/xact" ) func main() { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmble/ble_act.go ---------------------------------------------------------------------- diff --git a/nmxact/nmble/ble_act.go b/nmxact/nmble/ble_act.go index 08c396f..2aa6678 100644 --- a/nmxact/nmble/ble_act.go +++ b/nmxact/nmble/ble_act.go @@ -3,7 +3,7 @@ package nmble import ( "encoding/json" - "mynewt.apache.org/newt/nmxact/nmxutil" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" ) // Blocking http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmble/ble_fsm.go ---------------------------------------------------------------------- diff --git a/nmxact/nmble/ble_fsm.go b/nmxact/nmble/ble_fsm.go index daa930b..9c96526 100644 --- a/nmxact/nmble/ble_fsm.go +++ b/nmxact/nmble/ble_fsm.go @@ -8,10 +8,10 @@ import ( log "github.com/Sirupsen/logrus" - . "mynewt.apache.org/newt/nmxact/bledefs" - "mynewt.apache.org/newt/nmxact/nmp" - "mynewt.apache.org/newt/nmxact/nmxutil" - "mynewt.apache.org/newt/nmxact/sesn" + . "mynewt.apache.org/newtmgr/nmxact/bledefs" + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" + "mynewt.apache.org/newtmgr/nmxact/sesn" ) type BleSesnState int32 http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmble/ble_oic_sesn.go ---------------------------------------------------------------------- diff --git a/nmxact/nmble/ble_oic_sesn.go b/nmxact/nmble/ble_oic_sesn.go index 949d7aa..365efc6 100644 --- a/nmxact/nmble/ble_oic_sesn.go +++ b/nmxact/nmble/ble_oic_sesn.go @@ -5,10 +5,10 @@ import ( "sync" "time" - . "mynewt.apache.org/newt/nmxact/bledefs" - "mynewt.apache.org/newt/nmxact/nmp" - "mynewt.apache.org/newt/nmxact/omp" - "mynewt.apache.org/newt/nmxact/sesn" + . "mynewt.apache.org/newtmgr/nmxact/bledefs" + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/omp" + "mynewt.apache.org/newtmgr/nmxact/sesn" "mynewt.apache.org/newt/util" ) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmble/ble_plain_sesn.go ---------------------------------------------------------------------- diff --git a/nmxact/nmble/ble_plain_sesn.go b/nmxact/nmble/ble_plain_sesn.go index 71133e7..a8a46d6 100644 --- a/nmxact/nmble/ble_plain_sesn.go +++ b/nmxact/nmble/ble_plain_sesn.go @@ -5,9 +5,9 @@ import ( "sync" "time" - . "mynewt.apache.org/newt/nmxact/bledefs" - "mynewt.apache.org/newt/nmxact/nmp" - "mynewt.apache.org/newt/nmxact/sesn" + . "mynewt.apache.org/newtmgr/nmxact/bledefs" + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" "mynewt.apache.org/newt/util" ) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmble/ble_proto.go ---------------------------------------------------------------------- diff --git a/nmxact/nmble/ble_proto.go b/nmxact/nmble/ble_proto.go index 85a26f8..fe9112d 100644 --- a/nmxact/nmble/ble_proto.go +++ b/nmxact/nmble/ble_proto.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - . "mynewt.apache.org/newt/nmxact/bledefs" + . "mynewt.apache.org/newtmgr/nmxact/bledefs" ) type MsgOp int http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmble/ble_util.go ---------------------------------------------------------------------- diff --git a/nmxact/nmble/ble_util.go b/nmxact/nmble/ble_util.go index 08eb8d9..31f0e62 100644 --- a/nmxact/nmble/ble_util.go +++ b/nmxact/nmble/ble_util.go @@ -7,8 +7,8 @@ import ( log "github.com/Sirupsen/logrus" - . "mynewt.apache.org/newt/nmxact/bledefs" - "mynewt.apache.org/newt/nmxact/nmxutil" + . "mynewt.apache.org/newtmgr/nmxact/bledefs" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" ) const NmpPlainSvcUuid = "8D53DC1D-1DB7-4CD3-868B-8A527460AA84" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmble/ble_xport.go ---------------------------------------------------------------------- diff --git a/nmxact/nmble/ble_xport.go b/nmxact/nmble/ble_xport.go index 483bfd1..ba38b9d 100644 --- a/nmxact/nmble/ble_xport.go +++ b/nmxact/nmble/ble_xport.go @@ -9,8 +9,8 @@ import ( log "github.com/Sirupsen/logrus" - "mynewt.apache.org/newt/nmxact/nmxutil" - "mynewt.apache.org/newt/nmxact/sesn" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" + "mynewt.apache.org/newtmgr/nmxact/sesn" "mynewt.apache.org/newt/util/unixchild" ) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmp/nmp.go ---------------------------------------------------------------------- diff --git a/nmxact/nmp/nmp.go b/nmxact/nmp/nmp.go index b868e25..bb35743 100644 --- a/nmxact/nmp/nmp.go +++ b/nmxact/nmp/nmp.go @@ -27,7 +27,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/ugorji/go/codec" - "mynewt.apache.org/newt/nmxact/nmxutil" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" "mynewt.apache.org/newt/util" ) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmserial/serial_plain_sesn.go ---------------------------------------------------------------------- diff --git a/nmxact/nmserial/serial_plain_sesn.go b/nmxact/nmserial/serial_plain_sesn.go index a407a98..fe7173e 100644 --- a/nmxact/nmserial/serial_plain_sesn.go +++ b/nmxact/nmserial/serial_plain_sesn.go @@ -4,9 +4,9 @@ import ( "fmt" "sync" - "mynewt.apache.org/newt/nmxact/nmp" - "mynewt.apache.org/newt/nmxact/nmxutil" - "mynewt.apache.org/newt/nmxact/sesn" + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" + "mynewt.apache.org/newtmgr/nmxact/sesn" ) type SerialPlainSesn struct { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/nmserial/serial_xport.go ---------------------------------------------------------------------- diff --git a/nmxact/nmserial/serial_xport.go b/nmxact/nmserial/serial_xport.go index 6f5aa7c..7dbb5ca 100644 --- a/nmxact/nmserial/serial_xport.go +++ b/nmxact/nmserial/serial_xport.go @@ -12,8 +12,8 @@ import ( "github.com/joaojeronimo/go-crc16" "github.com/tarm/serial" - "mynewt.apache.org/newt/nmxact/nmxutil" - "mynewt.apache.org/newt/nmxact/sesn" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" + "mynewt.apache.org/newtmgr/nmxact/sesn" "mynewt.apache.org/newt/util" ) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/omp/dispatch.go ---------------------------------------------------------------------- diff --git a/nmxact/omp/dispatch.go b/nmxact/omp/dispatch.go index fb25f98..44d1022 100644 --- a/nmxact/omp/dispatch.go +++ b/nmxact/omp/dispatch.go @@ -22,7 +22,7 @@ package omp import ( log "github.com/Sirupsen/logrus" - "mynewt.apache.org/newt/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/nmp" ) type OmpDispatcher struct { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/omp/omp.go ---------------------------------------------------------------------- diff --git a/nmxact/omp/omp.go b/nmxact/omp/omp.go index 5bed071..77dbd1b 100644 --- a/nmxact/omp/omp.go +++ b/nmxact/omp/omp.go @@ -28,7 +28,7 @@ import ( "github.com/runtimeco/go-coap" "github.com/ugorji/go/codec" - "mynewt.apache.org/newt/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/nmp" ) // OIC wrapping adds this many bytes to an NMP message. http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/sesn/sesn.go ---------------------------------------------------------------------- diff --git a/nmxact/sesn/sesn.go b/nmxact/sesn/sesn.go index f5bbd3c..8ef8934 100644 --- a/nmxact/sesn/sesn.go +++ b/nmxact/sesn/sesn.go @@ -3,8 +3,8 @@ package sesn import ( "time" - "mynewt.apache.org/newt/nmxact/nmp" - "mynewt.apache.org/newt/nmxact/nmxutil" + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/nmxutil" ) type TxOptions struct { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/sesn/sesn_cfg.go ---------------------------------------------------------------------- diff --git a/nmxact/sesn/sesn_cfg.go b/nmxact/sesn/sesn_cfg.go index 9e07c71..e18711d 100644 --- a/nmxact/sesn/sesn_cfg.go +++ b/nmxact/sesn/sesn_cfg.go @@ -3,7 +3,7 @@ package sesn import ( "time" - "mynewt.apache.org/newt/nmxact/bledefs" + "mynewt.apache.org/newtmgr/nmxact/bledefs" ) type MgmtProto int http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/xact/cmd.go ---------------------------------------------------------------------- diff --git a/nmxact/xact/cmd.go b/nmxact/xact/cmd.go index f42b2df..d5d7a23 100644 --- a/nmxact/xact/cmd.go +++ b/nmxact/xact/cmd.go @@ -22,7 +22,7 @@ package xact import ( "fmt" - "mynewt.apache.org/newt/nmxact/sesn" + "mynewt.apache.org/newtmgr/nmxact/sesn" ) type Result interface { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/15498bdc/nmxact/xact/config.go ---------------------------------------------------------------------- diff --git a/nmxact/xact/config.go b/nmxact/xact/config.go index a0d2f70..ddc893b 100644 --- a/nmxact/xact/config.go +++ b/nmxact/xact/config.go @@ -1,8 +1,8 @@ package xact import ( - "mynewt.apache.org/newt/nmxact/nmp" - "mynewt.apache.org/newt/nmxact/sesn" + "mynewt.apache.org/newtmgr/nmxact/nmp" + "mynewt.apache.org/newtmgr/nmxact/sesn" ) //////////////////////////////////////////////////////////////////////////////
