-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.go
75 lines (62 loc) · 1.99 KB
/
example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"github.com/ChargePi/ocppManager-go/ocpp_v16"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetLevel(log.DebugLevel)
supportedProfiles := []string{core.ProfileName, smartcharging.ProfileName}
defaultConfig, err := ocpp_v16.DefaultConfigurationFromProfiles(supportedProfiles...)
if err != nil {
log.Errorf("Error getting configuration value: %v", err)
return
}
manager, err := ocpp_v16.NewV16ConfigurationManager(*defaultConfig, supportedProfiles...)
// Get value
value, err := manager.GetConfigurationValue(ocpp_v16.AuthorizeRemoteTxRequests)
if err != nil {
log.Errorf("Error getting configuration value: %v", err)
return
}
log.Println(*value)
// Register update handler, which will be called when the key is updated
err = manager.OnUpdateKey(ocpp_v16.AuthorizeRemoteTxRequests, func(value *string) error {
log.Println("Key updated")
return nil
})
if err != nil {
log.Errorf("Error calling update handler for key: %v", err)
}
// Update key
val := "false"
err = manager.UpdateKey(ocpp_v16.AuthorizeRemoteTxRequests, &val)
if err != nil {
log.Errorf("Error updating key: %v", err)
return
}
// Get value
value, err = manager.GetConfigurationValue(ocpp_v16.AuthorizeRemoteTxRequests)
if err != nil {
log.Errorf("Error getting configuration value: %v", err)
return
}
log.Println(*value)
// Validate key before updating
err = manager.ValidateKey(ocpp_v16.AuthorizeRemoteTxRequests, &val)
if err != nil {
log.Errorf("Error validating key: %v", err)
}
// Register custom key validator, which will prevent the key from being updated
manager.RegisterCustomKeyValidator(func(key ocpp_v16.Key, value *string) bool {
return key != ocpp_v16.AuthorizeRemoteTxRequests
})
// Update key
val = "true"
err = manager.UpdateKey(ocpp_v16.AuthorizeRemoteTxRequests, &val)
if err != nil {
log.Errorf("Error updating key: %v", err)
return
}
}