ollie: correct race condition error on seq

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-04-05 13:21:26 +02:00
parent 408d187e38
commit eff58377af
1 changed files with 7 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/binary"
"fmt"
"sync"
"time"
"gobot.io/x/gobot"
@ -16,6 +17,7 @@ type Driver struct {
name string
connection gobot.Connection
seq uint8
mtx sync.Mutex
collisionResponse []uint8
packetChannel chan *packet
gobot.Eventer
@ -222,11 +224,16 @@ func (b *Driver) write(packet *packet) (err error) {
return err
}
b.mtx.Lock()
defer b.mtx.Unlock()
b.seq++
return
}
func (b *Driver) craftPacket(body []uint8, did byte, cid byte) *packet {
b.mtx.Lock()
defer b.mtx.Unlock()
packet := new(packet)
packet.body = body
dlen := len(packet.body) + 1