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 (c *Client) TestResults() (*TestResults, error) {
|
|
|
|
var err error
|
|
var results *TestResults
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
err = c.conn.On(eventTestResults, func(h *gosocketio.Channel, res *TestResults) {
|
|
results = res
|
|
c.conn.Off(eventTestResults)
|
|
wg.Done()
|
|
})
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "error while binding to '%s' event", eventTestResults)
|
|
}
|
|
|
|
c.logf("sending '%s' event", eventGetTestResults)
|
|
if err = c.conn.Emit(eventGetTestResults, nil); err != nil {
|
|
return nil, errors.Wrapf(err, "error while emitting '%s' event", eventGetTestResults)
|
|
}
|
|
c.logf("'%s' event sent", eventGetTestResults)
|
|
|
|
wg.Wait()
|
|
|
|
return results, err
|
|
|
|
}
|