Skip to content

Commit

Permalink
handleResponse only needs an io.Reader
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Charvin <[email protected]>
  • Loading branch information
oliverpool committed Jul 13, 2018
1 parent a4d5479 commit 1a40eb9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions platforms/dji/tello/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"io"
"net"
"strconv"
"sync"
Expand Down Expand Up @@ -243,16 +244,17 @@ func (d *Driver) Start() error {
fmt.Println(err)
return err
}
d.reqConn, err = net.DialUDP("udp", respPort, reqAddr)
cmdConn, err := net.DialUDP("udp", respPort, reqAddr)
if err != nil {
fmt.Println(err)
return err
}
d.reqConn = cmdConn

// handle responses
go func() {
for {
err := d.handleResponse()
err := d.handleResponse(cmdConn)
if err != nil {
fmt.Println("response parse error:", err)
}
Expand Down Expand Up @@ -714,10 +716,10 @@ func (d *Driver) SendCommand(cmd string) (err error) {
return
}

func (d *Driver) handleResponse() error {
func (d *Driver) handleResponse(r io.Reader) error {
var buf [2048]byte
var msgType uint16
n, err := d.reqConn.Read(buf[0:])
n, err := r.Read(buf[0:])
if err != nil {
return err
}
Expand Down

0 comments on commit 1a40eb9

Please sign in to comment.