This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/emlid/reachview/configuration.go

52 lines
1.8 KiB
Go
Raw Permalink Normal View History

package reachview
2018-09-20 17:28:18 +02:00
import "context"
2018-09-20 17:28:18 +02:00
const (
eventGetConfiguration = "get configuration"
eventCurrentConfiguration = "current configuration"
eventApplyConfiguration = "apply configuration"
eventConfigurationApplied = "configuration applied"
eventResetConfiguration = "reset configuration to default"
2018-09-20 17:28:18 +02:00
)
// Configuration fetches and return the current configuration of the ReachRS module
func (r *Client) Configuration(ctx context.Context) (*Configuration, error) {
2018-09-20 17:28:18 +02:00
configuration := &Configuration{}
if err := r.ReqResp(ctx, eventGetConfiguration, nil, eventCurrentConfiguration, configuration); err != nil {
2018-09-20 17:28:18 +02:00
return nil, err
}
return configuration, nil
}
type configurationApplied struct {
Configuration *Configuration `mapstructure:"configuration,omitempty"`
Result string `mapstructure:"result"`
Constraints *Constraints `mapstructure:"Constraints,omitempty"`
}
const (
// ConfigurationApplySuccess -
ConfigurationApplySuccess = "success"
// ConfigurationApplyFailed -
ConfigurationApplyFailed = "failed"
)
// ApplyConfiguration applies the given configuration
func (r *Client) ApplyConfiguration(ctx context.Context, config *Configuration) (string, *Configuration, error) {
res := &configurationApplied{}
if err := r.ReqResp(ctx, eventApplyConfiguration, config, eventConfigurationApplied, res); err != nil {
return ConfigurationApplyFailed, nil, err
}
return res.Result, res.Configuration, nil
}
// ResetConfiguration resets the module configuration to factory defaults
func (r *Client) ResetConfiguration(ctx context.Context) (string, *Configuration, error) {
res := &configurationApplied{}
if err := r.ReqResp(ctx, eventResetConfiguration, nil, eventConfigurationApplied, res); err != nil {
return ConfigurationApplyFailed, nil, err
}
return res.Result, res.Configuration, nil
}