53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package reach
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"forge.cadoles.com/Pyxis/golang-socketio"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const (
|
|
eventGetTestResults = "get test results"
|
|
eventTestResults = "test results"
|
|
)
|
|
|
|
// TestResults are the ReachRS module's test results
|
|
type TestResults struct {
|
|
UBlox bool `json:"u-blox"`
|
|
STC bool `json:"stc"`
|
|
MPU bool `json:"mpu"`
|
|
Device string `json:"device"`
|
|
Lora bool `json:"lora"`
|
|
}
|
|
|
|
// TestResults returns the ReachRS module tests results
|
|
func (u *Updater) TestResults() (*TestResults, error) {
|
|
|
|
var err error
|
|
var results *TestResults
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
err = u.conn.On(eventTestResults, func(h *gosocketio.Channel, res *TestResults) {
|
|
results = res
|
|
u.conn.Off(eventTestResults)
|
|
wg.Done()
|
|
})
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "error while binding to '%s' event", eventTestResults)
|
|
}
|
|
|
|
u.logf("sending '%s' event", eventGetTestResults)
|
|
if err = u.conn.Emit(eventGetTestResults, nil); err != nil {
|
|
return nil, errors.Wrapf(err, "error while emitting '%s' event", eventGetTestResults)
|
|
}
|
|
u.logf("'%s' event sent", eventGetTestResults)
|
|
|
|
wg.Wait()
|
|
|
|
return results, err
|
|
|
|
}
|