wip deprecated V1

This commit is contained in:
2025-06-11 10:32:50 +02:00
parent 49a4642db2
commit 3885abbcc5
6 changed files with 32 additions and 65 deletions

View File

@ -2,6 +2,7 @@ package v1
import "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
// Deprecated : is no longer maintained for modules in V1
func init() {
protocol.Register(Identifier, func(opts *protocol.ProtocolOptions) (protocol.Protocol, error) {
return &Protocol{

View File

@ -22,12 +22,14 @@ const (
eventSettingsResetToDefault = "settings reset to default"
)
// Deprecated : is no longer maintained for modules in V1
type configurationApplied struct {
Configuration *model.Configuration `mapstructure:"configuration,omitempty"`
Result string `mapstructure:"result"`
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) {
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
}
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) RequestConfiguration(ctx context.Context) (*model.Configuration, error) {
configuration := &model.Configuration{}
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
}
// Deprecated : is no longer maintained for modules in V1
// ReqResp emits an event with the given data and waits for a response
func (o *Operations) ReqResp(ctx context.Context,
requestEvent string, requestData any,

View File

@ -1,5 +1,6 @@
package model
// Deprecated : is no longer maintained for modules in V1
var (
// On -
On = String("on")

View File

@ -1,5 +1,6 @@
package model
// Deprecated : is no longer maintained for modules in V1
type TaskMessage struct {
Name string `json:"name"`
State string `json:"state"`

View File

@ -2,7 +2,6 @@ package v1
import (
"context"
"encoding/json"
"strconv"
"strings"
"sync"
@ -14,6 +13,7 @@ import (
"github.com/pkg/errors"
)
// Deprecated : is no longer maintained for modules in V1
type Operations struct {
addr string
client *socketio.Client
@ -23,6 +23,7 @@ type Operations struct {
dial protocol.DialFunc
}
// Deprecated : is no longer maintained for modules in V1
// Close implements protocol.Operations.
func (o *Operations) Close(ctx context.Context) error {
o.mutex.Lock()
@ -37,12 +38,14 @@ func (o *Operations) Close(ctx context.Context) error {
return nil
}
// Deprecated : is no longer maintained for modules in V1
const (
// EventBrowserConnected is emitted after the initial connection to the
// ReachView endpoint
eventBrowserConnected = "browser connected"
)
// Deprecated : is no longer maintained for modules in V1
// Connect implements protocol.Operations.
func (o *Operations) Connect(ctx context.Context) error {
o.mutex.Lock()
@ -81,6 +84,7 @@ func (o *Operations) Connect(ctx context.Context) error {
return nil
}
// Deprecated : is no longer maintained for modules in V1
// Emit implements protocol.Operations.
func (o *Operations) Emit(ctx context.Context, mType string, message any) error {
o.mutex.RLock()
@ -97,6 +101,7 @@ func (o *Operations) Emit(ctx context.Context, mType string, message any) error
return nil
}
// Deprecated : is no longer maintained for modules in V1
// On implements protocol.Operations.
func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
o.mutex.RLock()
@ -137,6 +142,7 @@ func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
return out, nil
}
// Deprecated : is no longer maintained for modules in V1
// Alive implements protocol.Operations.
func (o *Operations) Alive(ctx context.Context) (bool, error) {
o.mutex.RLock()
@ -149,6 +155,7 @@ func (o *Operations) Alive(ctx context.Context) (bool, error) {
return o.client.Alive(), nil
}
// Deprecated : is no longer maintained for modules in V1
// Configuration implements protocol.Operations.
func (o *Operations) Configuration(ctx context.Context) (any, error) {
config, err := o.RequestConfiguration(ctx)
@ -163,6 +170,7 @@ const (
eventReboot = "reboot"
)
// Deprecated : is no longer maintained for modules in V1
// Reboot implements protocol.Operations.
func (o *Operations) Reboot(ctx context.Context) error {
o.mutex.RLock()
@ -213,6 +221,7 @@ const (
configurationApplyFailed = "failed"
)
// Deprecated : is no longer maintained for modules in V1
// SetBase implements protocol.Operations.
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
rawConfig, err := o.Configuration(ctx)
@ -298,6 +307,7 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
return nil
}
// Deprecated : is no longer maintained for modules in V1
// GetBaseInfo implements protocol.Operations.
func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
rawConfig, err := o.Configuration(ctx)
@ -354,6 +364,7 @@ type reachViewVersion struct {
Stable bool `json:"bool"`
}
// Deprecated : is no longer maintained for modules in V1
// Version implements protocol.Operations.
func (o *Operations) Version(ctx context.Context) (string, bool, error) {
res := &reachViewVersion{}
@ -364,79 +375,24 @@ func (o *Operations) Version(ctx context.Context) (string, bool, error) {
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) {
var err error
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
return nil, protocol.ErrUnimplemented
}
// TODO À VOIR POUR LES VERSION 1
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
var err error
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
return protocol.ErrUnimplemented
}
// todo
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.SetBaseCorrectionsFunc) error {
var err error
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
return protocol.ErrUnimplemented
}
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
var err error
return err
return protocol.ErrUnimplemented
}
var _ protocol.Operations = &Operations{}

View File

@ -10,6 +10,7 @@ import (
"github.com/pkg/errors"
)
// Deprecated : is no longer maintained for modules in V1
const Identifier protocol.Identifier = "v1"
const compatibleVersionConstraint = "^2.24"
@ -19,6 +20,7 @@ type Protocol struct {
dial protocol.DialFunc
}
// Deprecated : is no longer maintained for modules in V1
// Available implements protocol.Protocol.
func (p *Protocol) Available(ctx context.Context, addr string) (bool, error) {
ops := p.Operations(addr).(*Operations)
@ -53,11 +55,13 @@ func (p *Protocol) Available(ctx context.Context, addr string) (bool, error) {
return true, nil
}
// Deprecated : is no longer maintained for modules in V1
// Identifier implements protocol.Protocol.
func (p *Protocol) Identifier() protocol.Identifier {
return Identifier
}
// Deprecated : is no longer maintained for modules in V1
// Operations implements protocol.Protocol.
func (p *Protocol) Operations(addr string) protocol.Operations {
return &Operations{addr: addr, logger: p.logger, dial: p.dial}