wip deprecated V1
This commit is contained in:
@ -2,6 +2,7 @@ package v1
|
|||||||
|
|
||||||
import "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
import "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
func init() {
|
func init() {
|
||||||
protocol.Register(Identifier, func(opts *protocol.ProtocolOptions) (protocol.Protocol, error) {
|
protocol.Register(Identifier, func(opts *protocol.ProtocolOptions) (protocol.Protocol, error) {
|
||||||
return &Protocol{
|
return &Protocol{
|
||||||
|
@ -22,12 +22,14 @@ const (
|
|||||||
eventSettingsResetToDefault = "settings reset to default"
|
eventSettingsResetToDefault = "settings reset to default"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
type configurationApplied struct {
|
type configurationApplied struct {
|
||||||
Configuration *model.Configuration `mapstructure:"configuration,omitempty"`
|
Configuration *model.Configuration `mapstructure:"configuration,omitempty"`
|
||||||
Result string `mapstructure:"result"`
|
Result string `mapstructure:"result"`
|
||||||
Constraints *model.Constraints `mapstructure:"constraints,omitempty"`
|
Constraints *model.Constraints `mapstructure:"constraints,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
func (o *Operations) ApplyConfiguration(ctx context.Context, config *model.Configuration) (string, *model.Configuration, error) {
|
func (o *Operations) ApplyConfiguration(ctx context.Context, config *model.Configuration) (string, *model.Configuration, error) {
|
||||||
o.logger.Debug("applying configuration", logger.Attr("configuration", spew.Sdump(config)))
|
o.logger.Debug("applying configuration", logger.Attr("configuration", spew.Sdump(config)))
|
||||||
|
|
||||||
@ -41,6 +43,7 @@ func (o *Operations) ApplyConfiguration(ctx context.Context, config *model.Confi
|
|||||||
return res.Result, res.Configuration, nil
|
return res.Result, res.Configuration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
func (o *Operations) RequestConfiguration(ctx context.Context) (*model.Configuration, error) {
|
func (o *Operations) RequestConfiguration(ctx context.Context) (*model.Configuration, error) {
|
||||||
configuration := &model.Configuration{}
|
configuration := &model.Configuration{}
|
||||||
if err := o.ReqResp(ctx, eventGetConfiguration, nil, eventCurrentConfiguration, configuration); err != nil {
|
if err := o.ReqResp(ctx, eventGetConfiguration, nil, eventCurrentConfiguration, configuration); err != nil {
|
||||||
@ -49,6 +52,7 @@ func (o *Operations) RequestConfiguration(ctx context.Context) (*model.Configura
|
|||||||
return configuration, nil
|
return configuration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// ReqResp emits an event with the given data and waits for a response
|
// ReqResp emits an event with the given data and waits for a response
|
||||||
func (o *Operations) ReqResp(ctx context.Context,
|
func (o *Operations) ReqResp(ctx context.Context,
|
||||||
requestEvent string, requestData any,
|
requestEvent string, requestData any,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
var (
|
var (
|
||||||
// On -
|
// On -
|
||||||
On = String("on")
|
On = String("on")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
type TaskMessage struct {
|
type TaskMessage struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
|
@ -2,7 +2,6 @@ package v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -14,6 +13,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
type Operations struct {
|
type Operations struct {
|
||||||
addr string
|
addr string
|
||||||
client *socketio.Client
|
client *socketio.Client
|
||||||
@ -23,6 +23,7 @@ type Operations struct {
|
|||||||
dial protocol.DialFunc
|
dial protocol.DialFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Close implements protocol.Operations.
|
// Close implements protocol.Operations.
|
||||||
func (o *Operations) Close(ctx context.Context) error {
|
func (o *Operations) Close(ctx context.Context) error {
|
||||||
o.mutex.Lock()
|
o.mutex.Lock()
|
||||||
@ -37,12 +38,14 @@ func (o *Operations) Close(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
const (
|
const (
|
||||||
// EventBrowserConnected is emitted after the initial connection to the
|
// EventBrowserConnected is emitted after the initial connection to the
|
||||||
// ReachView endpoint
|
// ReachView endpoint
|
||||||
eventBrowserConnected = "browser connected"
|
eventBrowserConnected = "browser connected"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Connect implements protocol.Operations.
|
// Connect implements protocol.Operations.
|
||||||
func (o *Operations) Connect(ctx context.Context) error {
|
func (o *Operations) Connect(ctx context.Context) error {
|
||||||
o.mutex.Lock()
|
o.mutex.Lock()
|
||||||
@ -81,6 +84,7 @@ func (o *Operations) Connect(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Emit implements protocol.Operations.
|
// Emit implements protocol.Operations.
|
||||||
func (o *Operations) Emit(ctx context.Context, mType string, message any) error {
|
func (o *Operations) Emit(ctx context.Context, mType string, message any) error {
|
||||||
o.mutex.RLock()
|
o.mutex.RLock()
|
||||||
@ -97,6 +101,7 @@ func (o *Operations) Emit(ctx context.Context, mType string, message any) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// On implements protocol.Operations.
|
// On implements protocol.Operations.
|
||||||
func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
|
func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
|
||||||
o.mutex.RLock()
|
o.mutex.RLock()
|
||||||
@ -137,6 +142,7 @@ func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Alive implements protocol.Operations.
|
// Alive implements protocol.Operations.
|
||||||
func (o *Operations) Alive(ctx context.Context) (bool, error) {
|
func (o *Operations) Alive(ctx context.Context) (bool, error) {
|
||||||
o.mutex.RLock()
|
o.mutex.RLock()
|
||||||
@ -149,6 +155,7 @@ func (o *Operations) Alive(ctx context.Context) (bool, error) {
|
|||||||
return o.client.Alive(), nil
|
return o.client.Alive(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Configuration implements protocol.Operations.
|
// Configuration implements protocol.Operations.
|
||||||
func (o *Operations) Configuration(ctx context.Context) (any, error) {
|
func (o *Operations) Configuration(ctx context.Context) (any, error) {
|
||||||
config, err := o.RequestConfiguration(ctx)
|
config, err := o.RequestConfiguration(ctx)
|
||||||
@ -163,6 +170,7 @@ const (
|
|||||||
eventReboot = "reboot"
|
eventReboot = "reboot"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Reboot implements protocol.Operations.
|
// Reboot implements protocol.Operations.
|
||||||
func (o *Operations) Reboot(ctx context.Context) error {
|
func (o *Operations) Reboot(ctx context.Context) error {
|
||||||
o.mutex.RLock()
|
o.mutex.RLock()
|
||||||
@ -213,6 +221,7 @@ const (
|
|||||||
configurationApplyFailed = "failed"
|
configurationApplyFailed = "failed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// SetBase implements protocol.Operations.
|
// SetBase implements protocol.Operations.
|
||||||
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||||
rawConfig, err := o.Configuration(ctx)
|
rawConfig, err := o.Configuration(ctx)
|
||||||
@ -298,6 +307,7 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// GetBaseInfo implements protocol.Operations.
|
// GetBaseInfo implements protocol.Operations.
|
||||||
func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
|
func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
|
||||||
rawConfig, err := o.Configuration(ctx)
|
rawConfig, err := o.Configuration(ctx)
|
||||||
@ -354,6 +364,7 @@ type reachViewVersion struct {
|
|||||||
Stable bool `json:"bool"`
|
Stable bool `json:"bool"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Version implements protocol.Operations.
|
// Version implements protocol.Operations.
|
||||||
func (o *Operations) Version(ctx context.Context) (string, bool, error) {
|
func (o *Operations) Version(ctx context.Context) (string, bool, error) {
|
||||||
res := &reachViewVersion{}
|
res := &reachViewVersion{}
|
||||||
@ -364,79 +375,24 @@ func (o *Operations) Version(ctx context.Context) (string, bool, error) {
|
|||||||
return strings.TrimSpace(res.Version), res.Stable, nil
|
return strings.TrimSpace(res.Version), res.Stable, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage, error) {
|
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage, error) {
|
||||||
var err error
|
return nil, protocol.ErrUnimplemented
|
||||||
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
err = ctx.Err()
|
|
||||||
}()
|
|
||||||
|
|
||||||
if err = o.client.Emit("task", map[string]string{"name": "average_base_coordinates"}); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ch, err := o.On(ctx, "task_status")
|
|
||||||
for message := range ch {
|
|
||||||
// Convertir vers notre struct
|
|
||||||
jsonData, err := json.Marshal(message)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var taskMsg protocol.TaskMessage
|
|
||||||
if err := json.Unmarshal(jsonData, &taskMsg); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if taskMsg.State == "completed" {
|
|
||||||
return &taskMsg, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO À VOIR POUR LES VERSION 1
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
|
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
|
||||||
var err error
|
return protocol.ErrUnimplemented
|
||||||
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
err = ctx.Err()
|
|
||||||
}()
|
|
||||||
payloadJSON, err := json.Marshal(map[string]interface{}{
|
|
||||||
"address": "crtk.net",
|
|
||||||
"port": 2101,
|
|
||||||
})
|
|
||||||
if err = o.client.Emit("task", map[string]string{"name": "get_ntrip_mountpoints", "payload": string(payloadJSON)}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.SetBaseCorrectionsFunc) error {
|
func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.SetBaseCorrectionsFunc) error {
|
||||||
var err error
|
return protocol.ErrUnimplemented
|
||||||
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
err = ctx.Err()
|
|
||||||
}()
|
|
||||||
// todo
|
|
||||||
payloadJSON, err := json.Marshal(map[string]interface{}{
|
|
||||||
"address": "crtk.net",
|
|
||||||
"port": 2101,
|
|
||||||
})
|
|
||||||
if err = o.client.Emit("task", map[string]string{"name": "get_ntrip_mountpoints", "payload": string(payloadJSON)}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
|
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
|
||||||
var err error
|
return protocol.ErrUnimplemented
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ protocol.Operations = &Operations{}
|
var _ protocol.Operations = &Operations{}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
const Identifier protocol.Identifier = "v1"
|
const Identifier protocol.Identifier = "v1"
|
||||||
|
|
||||||
const compatibleVersionConstraint = "^2.24"
|
const compatibleVersionConstraint = "^2.24"
|
||||||
@ -19,6 +20,7 @@ type Protocol struct {
|
|||||||
dial protocol.DialFunc
|
dial protocol.DialFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Available implements protocol.Protocol.
|
// Available implements protocol.Protocol.
|
||||||
func (p *Protocol) Available(ctx context.Context, addr string) (bool, error) {
|
func (p *Protocol) Available(ctx context.Context, addr string) (bool, error) {
|
||||||
ops := p.Operations(addr).(*Operations)
|
ops := p.Operations(addr).(*Operations)
|
||||||
@ -53,11 +55,13 @@ func (p *Protocol) Available(ctx context.Context, addr string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Identifier implements protocol.Protocol.
|
// Identifier implements protocol.Protocol.
|
||||||
func (p *Protocol) Identifier() protocol.Identifier {
|
func (p *Protocol) Identifier() protocol.Identifier {
|
||||||
return Identifier
|
return Identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
// Operations implements protocol.Protocol.
|
// Operations implements protocol.Protocol.
|
||||||
func (p *Protocol) Operations(addr string) protocol.Operations {
|
func (p *Protocol) Operations(addr string) protocol.Operations {
|
||||||
return &Operations{addr: addr, logger: p.logger, dial: p.dial}
|
return &Operations{addr: addr, logger: p.logger, dial: p.dial}
|
||||||
|
Reference in New Issue
Block a user