This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 276
/
applications_pf.go
80 lines (67 loc) · 1.74 KB
/
applications_pf.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
76
77
78
79
80
// Copyright © 2016 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
package cmd
import (
"fmt"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)
var applicationsPayloadFunctionsCmd = &cobra.Command{
Use: "pf",
Short: "Show the payload functions",
Long: `ttnctl applications pf shows the payload functions for decoding,
converting and validating binary payload.`,
Example: `$ ttnctl applications pf
INFO Discovering Handler...
INFO Connecting with Handler...
INFO Found Application
INFO Decoder function
function Decoder(bytes, port) {
var decoded = {};
if (port === 1) {
decoded.led = bytes[0];
}
return decoded;
}
INFO No converter function
INFO No validator function
INFO No encoder function
`,
Run: func(cmd *cobra.Command, args []string) {
appID := util.GetAppID(ctx)
conn, manager := util.GetHandlerManager(ctx, appID)
defer conn.Close()
app, err := manager.GetApplication(appID)
if err != nil {
ctx.WithError(err).Fatal("Could not get application.")
}
ctx.Info("Found Application")
if app.Decoder != "" {
ctx.Info("Decoder function")
fmt.Println(app.Decoder)
} else {
ctx.Info("No decoder function")
}
if app.Converter != "" {
ctx.Info("Converter function")
fmt.Println(app.Converter)
} else {
ctx.Info("No converter function")
}
if app.Validator != "" {
ctx.Info("Validator function")
fmt.Println(app.Validator)
} else {
ctx.Info("No validator function")
}
if app.Encoder != "" {
ctx.Info("Encoder function")
fmt.Println(app.Encoder)
} else {
ctx.Info("No encoder function")
}
},
}
func init() {
applicationsCmd.AddCommand(applicationsPayloadFunctionsCmd)
}