Add more firmata test coverage
This commit is contained in:
parent
e55744657c
commit
419193db49
|
@ -100,6 +100,7 @@ func newBoard(sp io.ReadWriteCloser) *board {
|
||||||
|
|
||||||
func (b *board) connect() {
|
func (b *board) connect() {
|
||||||
if b.connected == false {
|
if b.connected == false {
|
||||||
|
b.reset()
|
||||||
b.initBoard()
|
b.initBoard()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -240,7 +241,9 @@ func (b *board) process(data []byte) {
|
||||||
b.majorVersion, _ = buf.ReadByte()
|
b.majorVersion, _ = buf.ReadByte()
|
||||||
b.minorVersion, _ = buf.ReadByte()
|
b.minorVersion, _ = buf.ReadByte()
|
||||||
gobot.Publish(b.events["report_version"], b.version())
|
gobot.Publish(b.events["report_version"], b.version())
|
||||||
case analogMessageRangeStart <= messageType && analogMessageRangeEnd >= messageType:
|
case analogMessageRangeStart <= messageType &&
|
||||||
|
analogMessageRangeEnd >= messageType:
|
||||||
|
|
||||||
leastSignificantByte, _ := buf.ReadByte()
|
leastSignificantByte, _ := buf.ReadByte()
|
||||||
mostSignificantByte, _ := buf.ReadByte()
|
mostSignificantByte, _ := buf.ReadByte()
|
||||||
|
|
||||||
|
@ -256,7 +259,9 @@ func (b *board) process(data []byte) {
|
||||||
byte(value & 0xff),
|
byte(value & 0xff),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
case digitalMessageRangeStart <= messageType && digitalMessageRangeEnd >= messageType:
|
case digitalMessageRangeStart <= messageType &&
|
||||||
|
digitalMessageRangeEnd >= messageType:
|
||||||
|
|
||||||
port := messageType & 0x0F
|
port := messageType & 0x0F
|
||||||
firstBitmask, _ := buf.ReadByte()
|
firstBitmask, _ := buf.ReadByte()
|
||||||
secondBitmask, _ := buf.ReadByte()
|
secondBitmask, _ := buf.ReadByte()
|
||||||
|
@ -299,6 +304,7 @@ func (b *board) process(data []byte) {
|
||||||
}
|
}
|
||||||
b.pins = append(b.pins, pin{modes, output, 0, 0})
|
b.pins = append(b.pins, pin{modes, output, 0, 0})
|
||||||
b.events[fmt.Sprintf("digital_read_%v", len(b.pins)-1)] = gobot.NewEvent()
|
b.events[fmt.Sprintf("digital_read_%v", len(b.pins)-1)] = gobot.NewEvent()
|
||||||
|
b.events[fmt.Sprintf("pin_%v_state", len(b.pins)-1)] = gobot.NewEvent()
|
||||||
supportedModes = 0
|
supportedModes = 0
|
||||||
n = 0
|
n = 0
|
||||||
continue
|
continue
|
||||||
|
@ -338,7 +344,11 @@ func (b *board) process(data []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
gobot.Publish(b.events[fmt.Sprintf("pin_%v_state", currentBuffer[2])],
|
gobot.Publish(b.events[fmt.Sprintf("pin_%v_state", currentBuffer[2])],
|
||||||
[]byte{byte(pin.value & 0xff)},
|
map[string]int{
|
||||||
|
"pin": int(currentBuffer[2]),
|
||||||
|
"mode": int(pin.mode),
|
||||||
|
"value": int(pin.value),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
case i2CReply:
|
case i2CReply:
|
||||||
i2cReply := map[string][]byte{
|
i2cReply := map[string][]byte{
|
||||||
|
|
|
@ -28,6 +28,24 @@ func initTestFirmata() *board {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReportVersion(t *testing.T) {
|
||||||
|
b := initTestFirmata()
|
||||||
|
//test if functions executes
|
||||||
|
b.reportVersion()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestQueryFirmware(t *testing.T) {
|
||||||
|
b := initTestFirmata()
|
||||||
|
//test if functions executes
|
||||||
|
b.queryFirmware()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestQueryPinState(t *testing.T) {
|
||||||
|
b := initTestFirmata()
|
||||||
|
//test if functions executes
|
||||||
|
b.queryPinState(byte(1))
|
||||||
|
}
|
||||||
|
|
||||||
func TestProcess(t *testing.T) {
|
func TestProcess(t *testing.T) {
|
||||||
b := initTestFirmata()
|
b := initTestFirmata()
|
||||||
sem := make(chan bool)
|
sem := make(chan bool)
|
||||||
|
@ -72,14 +90,17 @@ func TestProcess(t *testing.T) {
|
||||||
})
|
})
|
||||||
b.process([]byte{0x90, 0x16, 0x00})
|
b.process([]byte{0x90, 0x16, 0x00})
|
||||||
<-sem
|
<-sem
|
||||||
//TODO we need a test here
|
|
||||||
//pinStateResponse
|
//pinStateResponse
|
||||||
//gobot.Once(b.events["pin_0_state"], func(data interface{}) {
|
gobot.Once(b.events["pin_13_state"], func(data interface{}) {
|
||||||
// gobot.Expect(t, data, "")
|
gobot.Expect(t, data, map[string]int{
|
||||||
// sem <- true
|
"pin": 13,
|
||||||
//})
|
"mode": 1,
|
||||||
//b.process([]byte{240, 0x6E})
|
"value": 1,
|
||||||
//<-sem
|
})
|
||||||
|
sem <- true
|
||||||
|
})
|
||||||
|
b.process([]byte{240, 110, 13, 1, 1, 247})
|
||||||
|
<-sem
|
||||||
//i2cReply
|
//i2cReply
|
||||||
gobot.Once(b.events["i2c_reply"], func(data interface{}) {
|
gobot.Once(b.events["i2c_reply"], func(data interface{}) {
|
||||||
i2c_reply := map[string][]byte{
|
i2c_reply := map[string][]byte{
|
||||||
|
|
Loading…
Reference in New Issue