Skip to content

Commit 3751896

Browse files
committed
Allow case-insensitive 'ok'/'OK' replies from discoveries and monitors
1 parent 569e194 commit 3751896

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

arduino/discovery/discovery.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (disc *PluggableDiscovery) Run() (err error) {
312312
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "HELLO", err)
313313
} else if msg.EventType != "hello" {
314314
return errors.Errorf(tr("communication out of sync, expected 'hello', received '%s'"), msg.EventType)
315-
} else if msg.Message != "OK" || msg.Error {
315+
} else if strings.ToUpper(msg.Message) != "OK" || msg.Error {
316316
return errors.Errorf(tr("command failed: %s"), msg.Message)
317317
} else if msg.ProtocolVersion > 1 {
318318
return errors.Errorf(tr("protocol version not supported: requested 1, got %d"), msg.ProtocolVersion)
@@ -333,7 +333,7 @@ func (disc *PluggableDiscovery) Start() error {
333333
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "START", err)
334334
} else if msg.EventType != "start" {
335335
return errors.Errorf(tr("communication out of sync, expected 'start', received '%s'"), msg.EventType)
336-
} else if msg.Message != "OK" || msg.Error {
336+
} else if strings.ToUpper(msg.Message) != "OK" || msg.Error {
337337
return errors.Errorf(tr("command failed: %s"), msg.Message)
338338
}
339339
disc.statusMutex.Lock()
@@ -353,7 +353,7 @@ func (disc *PluggableDiscovery) Stop() error {
353353
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "STOP", err)
354354
} else if msg.EventType != "stop" {
355355
return errors.Errorf(tr("communication out of sync, expected 'stop', received '%s'"), msg.EventType)
356-
} else if msg.Message != "OK" || msg.Error {
356+
} else if strings.ToUpper(msg.Message) != "OK" || msg.Error {
357357
return errors.Errorf(tr("command failed: %s"), msg.Message)
358358
}
359359
disc.statusMutex.Lock()
@@ -376,7 +376,7 @@ func (disc *PluggableDiscovery) Quit() error {
376376
return fmt.Errorf(tr("calling %[1]s: %[2]w"), "QUIT", err)
377377
} else if msg.EventType != "quit" {
378378
return errors.Errorf(tr("communication out of sync, expected 'quit', received '%s'"), msg.EventType)
379-
} else if msg.Message != "OK" || msg.Error {
379+
} else if strings.ToUpper(msg.Message) != "OK" || msg.Error {
380380
return errors.Errorf(tr("command failed: %s"), msg.Message)
381381
}
382382
disc.killProcess()
@@ -416,7 +416,7 @@ func (disc *PluggableDiscovery) StartSync(size int) (<-chan *Event, error) {
416416
return nil, fmt.Errorf(tr("calling %[1]s: %[2]w"), "START_SYNC", err)
417417
} else if msg.EventType != "start_sync" {
418418
return nil, errors.Errorf(tr("communication out of sync, expected 'start_sync', received '%s'"), msg.EventType)
419-
} else if msg.Message != "OK" || msg.Error {
419+
} else if strings.ToUpper(msg.Message) != "OK" || msg.Error {
420420
return nil, errors.Errorf(tr("command failed: %s"), msg.Message)
421421
}
422422

arduino/monitor/monitor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (mon *PluggableMonitor) waitMessage(timeout time.Duration, expectedEvt stri
145145
if msg.EventType != expectedEvt {
146146
return msg, fmt.Errorf(tr("communication out of sync, expected '%[1]s', received '%[2]s'"), expectedEvt, msg.EventType)
147147
}
148-
if msg.Message != "OK" || msg.Error {
148+
if strings.ToUpper(msg.Message) != "OK" || msg.Error {
149149
return msg, fmt.Errorf(tr("command '%[1]s' failed: %[2]s"), expectedEvt, msg.Message)
150150
}
151151
return msg, nil

0 commit comments

Comments
 (0)