52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
|
package reach
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
|
||
|
"forge.cadoles.com/Pyxis/golang-socketio"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
// EventGetTestResults is a request for the ReachRS module's test results
|
||
|
EventGetTestResults = "get test results"
|
||
|
// EventTestResults is the response of the EventGetTestResults request
|
||
|
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)
|
||
|
|
||
|
c.conn.On(EventTestResults, func(h *gosocketio.Channel, res *TestResults) {
|
||
|
results = res
|
||
|
c.conn.On(EventTestResults, nil)
|
||
|
wg.Done()
|
||
|
})
|
||
|
|
||
|
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
|
||
|
|
||
|
}
|