hybridgroup/gobot — pull request #85 by tangsoft (2014-07-29 09:52:13+00:00)
Title: add one more parameter to func craftPacket to identify which virtual dev...

As I stated in issue #84, packet sent to sphero gets a DID field, like 0x00, and 0x02, means the virtual device this packet is intended for.
So I change one of the parameters in the func craftPacket from fixed "0x02" to "did", so we can identify the DID when the request packet generated and sent.
func (s *SpheroDriver) craftPacket(body []uint8, did byte, cid byte) *packet {
249 packet := new(packet)
250 packet.body = body
251 dlen := len(packet.body) + 1
252 packet.header = []uint8{0xFF, 0xFF, did, cid, s.seq, uint8(dlen)}
253 packet.checksum = s.calculateChecksum(packet)
254 return packet

For example, if I want to get the power state of sphero, I have to send the packet to virtual device 0x00 like this:
func (s *SpheroDriver) GetPowerState() []uint8 {
189 return s.getSyncResponse(s.craftPacket([]uint8{}, 0x00, 0x20))
190 }

And for this change, I change each func which call the craftPacket.
I will try to submit more API implementation after this commit.