Webclient/gRPC: matched proto data for TriggerActions to ViewModel JS data of webclient

This commit is contained in:
MaMe82 2018-10-01 12:01:00 +02:00
parent 50586cd4fb
commit 6842c25117
5 changed files with 2017 additions and 784 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -57,42 +57,92 @@ message TriggerActionSettings {
message TriggerAction {
uint32 id = 1; // assigned by service, used as identifier to allow deletion of trigger actions
bool oneShot = 13;
bool oneShot = 2;
bool isActive = 3;
bool immutable = 4;
oneof Trigger {
TriggerServiceStarted serviceStarted = 2;
TriggerUSBGadgetConnected usbGadgetConnected = 3;
TriggerUSBGadgetDisconnected usbGadgetDisconnected = 4;
TriggerWifiAPStarted wifiAPStarted = 5;
TriggerWifiConnectedAsSta wifiConnectedAsSta = 6;
TriggerSSHLogin sshLogin = 7;
TriggerDHCPLeaseGranted dhcpLeaseGranted = 8;
TriggerServiceStarted serviceStarted = 5;
TriggerUSBGadgetConnected usbGadgetConnected = 6;
TriggerUSBGadgetDisconnected usbGadgetDisconnected = 7;
TriggerWifiAPStarted wifiAPStarted = 8;
TriggerWifiConnectedAsSta wifiConnectedAsSta = 9;
TriggerSSHLogin sshLogin = 10;
TriggerDHCPLeaseGranted dhcpLeaseGranted = 11;
TriggerGroupReceive groupReceive = 12;
TriggerGroupReceiveSequence groupReceiveSequence = 13;
TriggerGPIOIn gpioIn = 14;
}
oneof Action {
ActionStartBashScript bashScript = 9;
ActionStartHIDScript hidScript = 10;
ActionDeploySettingsTemplate deploySettingsTemplate = 11;
ActionLog log = 12;
ActionStartBashScript bashScript = 15;
ActionStartHIDScript hidScript = 16;
ActionDeploySettingsTemplate deploySettingsTemplate = 17;
ActionLog log = 18;
ActionGPIOOut gpioOut = 19;
ActionGroupSend groupSend = 20;
}
}
message TriggerServiceStarted {} //no fields
message TriggerGPIO{} // input and output params have to be defined
message TriggerUSBGadgetConnected{}
message TriggerUSBGadgetDisconnected{}
message TriggerWifiAPStarted{} // fired when an Access Point is running
message TriggerWifiConnectedAsSta{} // fired when successfully connected to an existing AP
message TriggerSSHLogin{ // fired when a user logs in
string resLoginUser = 1;
string loginUser = 1;
}
message TriggerDHCPLeaseGranted { // fired when a client receives a lease
string resInterface = 1;
string resClientIP = 2;
string resClientMac = 3;
message TriggerDHCPLeaseGranted {} // fired when a client receives a lease
message TriggerGroupReceive{ // fired when the correct value is received on the group channel
string groupName = 1;
int32 value = 2;
}
message TriggerGroupReceiveSequence{ // fired when the correct value is received on the group channel
string groupName = 1;
bool IgnoreOutOfOrder = 2;
repeated int32 values = 3;
}
enum GPIOInPullUpDown {
UP = 0;
DOWN = 1;
OFF = 2;
}
enum GPIOInEdge {
RISING = 0;
FALLING = 1;
BOTH = 2;
}
enum GPIONum {
NUM_1 = 0;
NUM_2 = 1;
NUM_3 = 2;
NUM_4 = 3;
NUM_5 = 4;
NUM_6 = 5;
NUM_7 = 6;
NUM_8 = 7;
NUM_9 = 8;
NUM_10 = 9;
NUM_11 = 10;
NUM_12 = 11;
NUM_13 = 12;
NUM_14 = 13;
NUM_15 = 14;
NUM_16 = 15;
NUM_17 = 16;
NUM_18 = 17;
NUM_19 = 18;
NUM_20 = 19;
}
message TriggerGPIOIn {
GPIONum gpioNum = 1;
GPIOInPullUpDown pullUpDown = 2;
GPIOInEdge gpioInEdge = 3;
}
message ActionStartBashScript {
string scriptPath = 1;
string scriptName = 1;
}
message ActionStartHIDScript {
string scriptName = 1; //could be combined into oneof with script path, to allow starting scripts from arbitrary filepath (avoids storing scripts in DB or fixed folder)
@ -105,10 +155,25 @@ message ActionDeploySettingsTemplate {
WIFI = 2;
USB = 3;
BLUETOOTH = 4;
TRIGGER_ACTIONS = 5;
}
TemplateType type = 2;
}
message ActionLog {}
enum GPIOOutValue {
LOW = 0;
HIGH = 1;
TOGGLE = 2;
}
message ActionGPIOOut {
GPIONum gpioNum = 1;
GPIOOutValue value = 2;
}
message ActionGroupSend {
string groupName = 1;
int32 value = 2;
}

View File

@ -8,289 +8,6 @@ import (
"strconv"
)
func ExportDefaultTriggerActions() {
// create test trigger
/*
// Trigger to run startup script
triggerData := &jsTriggerServiceStarted{Object:O()}
trigger := &jsTriggerAction_ServiceStarted{Object:O()}
trigger.ServiceStarted = triggerData
actionData := &jsActionStartBashScript{Object:O()}
actionData.ScriptPath = "/usr/local/P4wnP1/scripts/servicestart.sh"
action := &jsTriggerAction_BashScript{Object:O()}
action.BashScript = actionData
svcUpRunScript := &jsTriggerAction{Object:O()}
svcUpRunScript.OneShot = false
svcUpRunScript.Id = 0
svcUpRunScript.Trigger = trigger.Object
svcUpRunScript.Action = action.Object
js.Global.Set("testta", svcUpRunScript)
// Try to cast back (shouldn't work because of the interfaces
copyobj := &jsTriggerAction{Object:js.Global.Get("testta")}
js.Global.Set("copyobj", copyobj)
println("copyobj", copyobj)
println("copyobjtrigger", copyobj.Trigger) //<--- this wouldn't work
if isJsTriggerAction_ServiceStarted(copyobj.Trigger) {
println("is service started trigger")
}
if isJsTriggerAction_UsbGadgetConnected(copyobj.Trigger) {
println("is USB gadget connected trigger")
}
if isJsTriggerAction_BashScript(copyobj.Action) {
println("is BashScript action")
}
if isJsTriggerAction_HidScript(copyobj.Trigger) {
println("is HIDScript action")
}
*/
/*
serviceUpRunScript := &pb.TriggerAction{
Trigger: &pb.TriggerAction_ServiceStarted{
ServiceStarted: &pb.TriggerServiceStarted{},
},
Action: &pb.TriggerAction_BashScript{
BashScript: &pb.ActionStartBashScript{
ScriptPath: "/usr/local/P4wnP1/scripts/servicestart.sh", // ToDo: use real script path once ready
},
},
}
a[0] = serviceUpRunScript
logServiceStart := &pb.TriggerAction{
Trigger: &pb.TriggerAction_ServiceStarted{
ServiceStarted: &pb.TriggerServiceStarted{},
},
Action: &pb.TriggerAction_Log{
Log: &pb.ActionLog{},
},
}
a[1]= logServiceStart
logDHCPLease := &pb.TriggerAction{
Trigger: &pb.TriggerAction_DhcpLeaseGranted{
DhcpLeaseGranted: &pb.TriggerDHCPLeaseGranted{},
},
Action: &pb.TriggerAction_Log{
Log: &pb.ActionLog{},
},
}
a[2] = logDHCPLease
logUSBGadgetConnected := &pb.TriggerAction{
Trigger: &pb.TriggerAction_UsbGadgetConnected{
UsbGadgetConnected: &pb.TriggerUSBGadgetConnected{},
},
Action: &pb.TriggerAction_Log{
Log: &pb.ActionLog{},
},
}
a[3] = logUSBGadgetConnected
logUSBGadgetDisconnected := &pb.TriggerAction{
Trigger: &pb.TriggerAction_UsbGadgetDisconnected{
UsbGadgetDisconnected: &pb.TriggerUSBGadgetDisconnected{},
},
Action: &pb.TriggerAction_Log{
Log: &pb.ActionLog{},
},
}
a[4] = logUSBGadgetDisconnected
logWifiAp := &pb.TriggerAction{
Trigger: &pb.TriggerAction_WifiAPStarted{
WifiAPStarted: &pb.TriggerWifiAPStarted{},
},
Action: &pb.TriggerAction_Log{
Log: &pb.ActionLog{},
},
}
a[5] = logWifiAp
logWifiSta := &pb.TriggerAction{
Trigger: &pb.TriggerAction_WifiConnectedAsSta{
WifiConnectedAsSta: &pb.TriggerWifiConnectedAsSta{},
},
Action: &pb.TriggerAction_Log{
Log: &pb.ActionLog{},
},
}
a[6] = logWifiSta
logSSHLogin := &pb.TriggerAction{
Trigger: &pb.TriggerAction_SshLogin{
SshLogin: &pb.TriggerSSHLogin{},
},
Action: &pb.TriggerAction_Log{
Log: &pb.ActionLog{},
},
}
a[7] = logSSHLogin
*/
}
/*
type jsIsTriggerAction_Trigger interface {
isTriggerAction_Trigger()
}
type jsIsTriggerAction_Action interface{ isTriggerAction_Action() }
type jsTriggerAction struct {
*js.Object
Id uint32 `js:"Id"`
OneShot bool `js:"OnShot"`
Trigger *js.Object `js:"Trigger"`
Action *js.Object `js:"Action"`
}
// TriggerAction_ServiceStarted is assignable to Trigger
type jsTriggerAction_ServiceStarted struct {
*js.Object
ServiceStarted *jsTriggerServiceStarted `js:"ServiceStarted"`
}
func isJsTriggerAction_ServiceStarted(src *js.Object) bool {
test := jsTriggerAction_ServiceStarted{Object:src}
if test.ServiceStarted.Object == js.Undefined { return false }
return true
}
// TriggerAction_UsbGadgetConnected is assignable to Trigger
type jsTriggerAction_UsbGadgetConnected struct {
*js.Object
UsbGadgetConnected *jsTriggerUSBGadgetConnected `js:"UsbGadgetConnected"`
}
func isJsTriggerAction_UsbGadgetConnected(src *js.Object) bool {
test := jsTriggerAction_UsbGadgetConnected{Object:src}
if test.UsbGadgetConnected.Object == js.Undefined { return false }
return true
}
// TriggerAction_UsbGadgetDisconnected is assignable to Trigger
type jsTriggerAction_UsbGadgetDisconnected struct {
*js.Object
UsbGadgetDisconnected *jsTriggerUSBGadgetDisconnected `js:"UsbGadgetDisconnected"`
}
func isJsTriggerAction_UsbGadgetDisconnected(src *js.Object) bool {
test := jsTriggerAction_UsbGadgetDisconnected{Object:src}
if test.UsbGadgetDisconnected.Object == js.Undefined { return false }
return true
}
// TriggerAction_WifiAPStarted is assignable to Trigger
type jsTriggerAction_WifiAPStarted struct {
*js.Object
WifiAPStarted *jsTriggerWifiAPStarted `js:"WifiAPStarted"`
}
func iJsTriggerAction_WifiAPStarted(src *js.Object) bool {
test := jsTriggerAction_WifiAPStarted{Object:src}
if test.WifiAPStarted.Object == js.Undefined { return false }
return true
}
// TriggerAction_WifiConnectedAsSta is assignable to Trigger
type jsTriggerAction_WifiConnectedAsSta struct {
*js.Object
WifiConnectedAsSta *jsTriggerWifiConnectedAsSta `js:"WifiConnectedAsSta"`
}
func isJsTriggerAction_WifiConnectedAsSta(src *js.Object) bool {
test := jsTriggerAction_WifiConnectedAsSta{Object:src}
if test.WifiConnectedAsSta.Object == js.Undefined { return false }
return true
}
// TriggerAction_SshLogin is assignable to Trigger
type jsTriggerAction_SshLogin struct {
*js.Object
SshLogin *jsTriggerSSHLogin `js:"SshLogin"`
}
func isJsTriggerAction_SshLogin(src *js.Object) bool {
test := jsTriggerAction_SshLogin{Object:src}
if test.SshLogin.Object == js.Undefined { return false }
return true
}
// TriggerAction_DhcpLeaseGranted is assignable to Trigger
type jsTriggerAction_DhcpLeaseGranted struct {
*js.Object
DhcpLeaseGranted *jsTriggerDHCPLeaseGranted `js:"DhcpLeaseGranted"`
}
func isJsTriggerAction_DhcpLeaseGranted(src *js.Object) bool {
test := jsTriggerAction_DhcpLeaseGranted{Object:src}
if test.DhcpLeaseGranted.Object == js.Undefined { return false }
return true
}
// TriggerAction_BashScript is assignable to Action
type jsTriggerAction_BashScript struct {
*js.Object
BashScript *jsActionStartBashScript `js:"BashScript"`
}
func isJsTriggerAction_BashScript(src *js.Object) bool {
test := jsTriggerAction_BashScript{Object:src}
if test.BashScript.Object == js.Undefined { return false }
return true
}
// TriggerAction_HidScript is assignable to Action
type jsTriggerAction_HidScript struct {
*js.Object
HidScript *jsActionStartHIDScript `js:"HidScript"`
}
func isJsTriggerAction_HidScript(src *js.Object) bool {
test := jsTriggerAction_HidScript{Object:src}
if test.HidScript.Object == js.Undefined { return false }
return true
}
// TriggerAction_DeploySettingsTemplate is assignable to Action
type jsTriggerAction_DeploySettingsTemplate struct {
*js.Object
DeploySettingsTemplate *jsActionDeploySettingsTemplate `js:"DeploySettingsTemplate"`
}
func isJsTriggerAction_DeploySettingsTemplate(src *js.Object) bool {
test := jsTriggerAction_DeploySettingsTemplate{Object:src}
if test.DeploySettingsTemplate.Object == js.Undefined { return false }
return true
}
// TriggerAction_Log is assignable to Action
type jsTriggerAction_Log struct {
*js.Object
Log *jsActionLog `js:"Log"`
}
func isJsTriggerAction_Log(src *js.Object) bool {
test := jsTriggerAction_Log{Object:src}
if test.Log.Object == js.Undefined { return false }
return true
}
func (*jsTriggerAction_ServiceStarted) isTriggerAction_Trigger() {}
func (*jsTriggerAction_UsbGadgetConnected) isTriggerAction_Trigger() {}
func (*jsTriggerAction_UsbGadgetDisconnected) isTriggerAction_Trigger() {}
func (*jsTriggerAction_WifiAPStarted) isTriggerAction_Trigger() {}
func (*jsTriggerAction_WifiConnectedAsSta) isTriggerAction_Trigger() {}
func (*jsTriggerAction_SshLogin) isTriggerAction_Trigger() {}
func (*jsTriggerAction_DhcpLeaseGranted) isTriggerAction_Trigger() {}
func (*jsTriggerAction_BashScript) isTriggerAction_Action() {}
func (*jsTriggerAction_HidScript) isTriggerAction_Action() {}
func (*jsTriggerAction_DeploySettingsTemplate) isTriggerAction_Action() {}
func (*jsTriggerAction_Log) isTriggerAction_Action() {}
*/
func generateSelectOptionsTrigger() *js.Object {
tts := js.Global.Get("Array").New()
type option struct {
@ -343,6 +60,24 @@ func generateSelectOptionsGPIOOutValue() *js.Object {
return tts
}
func generateSelectOptionsGPIONum() *js.Object {
tts := js.Global.Get("Array").New()
type option struct {
*js.Object
Label string `js:"label"`
Value GPIONum `js:"value"`
}
for _, value := range availableGPIONums {
label := gpioNumNames[value]
o := option{Object:O()}
o.Value = value
o.Label = label
tts.Call("push", o)
}
return tts
}
func generateSelectOptionsGPIOInPullUpDown() *js.Object {
tts := js.Global.Get("Array").New()
type option struct {
@ -379,11 +114,26 @@ func generateSelectOptionsGPIOInEdges() *js.Object {
return tts
}
func generateSelectOptionsTemplateTypes() *js.Object {
tts := js.Global.Get("Array").New()
type option struct {
*js.Object
Label string `js:"label"`
Value TemplateType `js:"value"`
}
for _, value := range availableTemplateTypes {
label := templateTypeNames[value]
o := option{Object:O()}
o.Value = value
o.Label = label
tts.Call("push", o)
}
return tts
}
func InitComponentsTriggerActions() {
// ToDo: delete test
ExportDefaultTriggerActions()
hvue.NewComponent(
"triggeraction-manager",
hvue.Template(templateTriggerActionManager),
@ -418,6 +168,9 @@ func InitComponentsTriggerActions() {
hvue.Computed("edge", func(vm *hvue.VM) interface{} {
return generateSelectOptionsGPIOInEdges()
}),
hvue.Computed("gpionum", func(vm *hvue.VM) interface{} {
return generateSelectOptionsGPIONum()
}),
hvue.ComputedWithGetSet(
"triggerType",
func(vm *hvue.VM) interface{} {
@ -440,7 +193,7 @@ func InitComponentsTriggerActions() {
strVal := newVal.String()
if intVal,errconv := strconv.Atoi(strVal); errconv == nil {
//append to Values
tgrs.ValueSequence = append(tgrs.ValueSequence, intVal)
tgrs.ValueSequence = append(tgrs.ValueSequence, int32(intVal))
}
}),
hvue.ComputedWithGetSet(
@ -454,7 +207,7 @@ func InitComponentsTriggerActions() {
res := make([]string, len(tgrs.ValueSequence))
for idx,intVal := range tgrs.ValueSequence {
res[idx] = strconv.Itoa(intVal)
res[idx] = strconv.Itoa(int(intVal))
}
return res
},
@ -466,7 +219,7 @@ func InitComponentsTriggerActions() {
tgrs := &jsTriggerGroupReceiveSequence{Object:ta.TriggerData}
// clear old array
tgrs.ValueSequence = []int{}
tgrs.ValueSequence = []int32{}
// iterate over newValue, which is assumed to be an Array of strings
for idx := 0; idx < newValue.Length(); idx++ {
@ -475,7 +228,7 @@ func InitComponentsTriggerActions() {
// try to cast to int
if intVal,errconv := strconv.Atoi(strVal); errconv == nil {
//append to Values
tgrs.ValueSequence = append(tgrs.ValueSequence, intVal)
tgrs.ValueSequence = append(tgrs.ValueSequence, int32(intVal))
}
}
}),
@ -499,6 +252,12 @@ func InitComponentsTriggerActions() {
hvue.Computed("gpiooutvalues", func(vm *hvue.VM) interface{} {
return generateSelectOptionsGPIOOutValue()
}),
hvue.Computed("gpionum", func(vm *hvue.VM) interface{} {
return generateSelectOptionsGPIONum()
}),
hvue.Computed("templatetypes", func(vm *hvue.VM) interface{} {
return generateSelectOptionsTemplateTypes()
}),
hvue.ComputedWithGetSet(
"actionType",
func(vm *hvue.VM) interface{} {
@ -534,7 +293,7 @@ func InitComponentsTriggerActions() {
const templateTriggerAction = `
<q-card class="fit">
<!-- {{ ta }} -->
<q-card-title>TriggereAction (ID {{ ta.Id }})</q-card-title>
<q-card-title>TriggerAction (ID {{ ta.Id }})</q-card-title>
<q-list>
<q-item tag="label" link>
<q-item-side>
@ -552,7 +311,7 @@ const templateTriggerAction = `
</q-item-side>
<q-item-main>
<q-item-tile label>One shot</q-item-tile>
<q-item-tile sublabel>The trigger fires every time the respective event occurs. If "one shot" is enabled it fores only once.</q-item-tile>
<q-item-tile sublabel>The trigger fires every time the respective event occurs. If "one shot" is enabled it fires only once.</q-item-tile>
</q-item-main>
</q-item>
</q-list>
@ -603,7 +362,7 @@ const templateTrigger = `
<q-item tag="label" v-if="isTriggerGroupReceiveSequence">
<q-item-main>
<q-item-tile label>Values</q-item-tile>
<q-item-tile sublabel>The numeric value which has to be received to activate the trigger</q-item-tile>
<q-item-tile sublabel>The numeric value sequence which has to be received to activate the trigger</q-item-tile>
<q-item-tile>
<q-chips-input v-model="TriggerGroupReceiveSequenceValues" @duplicate="TriggerGroupReceiveSequenceAddValue($event)" decimals="0" inverted :disable="!ta.IsActive"></q-chips-input>
</q-item-tile>
@ -625,7 +384,7 @@ const templateTrigger = `
<q-item-tile label>GPIO Number</q-item-tile>
<q-item-tile sublabel>The number of the GPIO to monitor</q-item-tile>
<q-item-tile>
<q-input v-model="ta.TriggerData.GpioNum" type="number" decimals="0" inverted :disable="!ta.IsActive"></q-input>
<q-select v-model="ta.TriggerData.GpioNum" :options="gpionum" inverted :disable="!ta.IsActive"></q-select>
</q-item-tile>
</q-item-main>
</q-item>
@ -688,7 +447,7 @@ const templateAction = `
<q-item-tile label>GPIO Number</q-item-tile>
<q-item-tile sublabel>The number of the GPIO to output on</q-item-tile>
<q-item-tile>
<q-input v-model="ta.ActionData.GpioNum" type="number" decimals="0" color="secondary" inverted :disable="!ta.IsActive"></q-input>
<q-select v-model="ta.ActionData.GpioNum" :options="gpionum" color="secondary" inverted :disable="!ta.IsActive"></q-select>
</q-item-tile>
</q-item-main>
</q-item>
@ -723,6 +482,29 @@ const templateAction = `
</q-item>
<q-item tag="label" v-if="isActionDeploySettingsTemplate">
<q-item-main>
<q-item-tile label>Type</q-item-tile>
<q-item-tile sublabel>Name of the stored settings template to load</q-item-tile>
<q-item-tile>
<q-select v-model="ta.ActionData.Type" :options="templatetypes" color="secondary" inverted :disable="!ta.IsActive"></q-select>
</q-item-tile>
</q-item-main>
</q-item>
<q-item tag="label" v-if="isActionDeploySettingsTemplate">
<q-item-main>
<q-item-tile label>Template name</q-item-tile>
<q-item-tile sublabel>Name of the stored settings template to load</q-item-tile>
<q-item-tile>
<q-input v-model="ta.ActionData.TemplateName" color="secondary" inverted :disable="!ta.IsActive"></q-input>
</q-item-tile>
</q-item-main>
</q-item>
</q-list>
`

View File

@ -1,6 +1,9 @@
package main
import "github.com/gopherjs/gopherjs/js"
import (
"github.com/gopherjs/gopherjs/js"
pb "github.com/mame82/P4wnP1_go/proto/gopherjs"
)
type triggerType int
type actionType int
@ -80,6 +83,210 @@ type jsTriggerAction struct {
ActionData *js.Object `js:"ActionData"`
}
func (dst *jsTriggerAction) fromGo(src *pb.TriggerAction) {
dst.IsActive = src.IsActive
dst.Immutable = src.Immutable
dst.OneShot = src.OneShot
dst.Id = src.Id
// convert action
switch srcAction := src.Action.(type) {
case *pb.TriggerAction_Log:
dst.ChangeActionType(ActionLog)
case *pb.TriggerAction_HidScript:
dst.ChangeActionType(ActionHidScript)
dstAction := &jsActionStartHIDScript{Object: dst.ActionData}
dstAction.ScriptName = srcAction.HidScript.ScriptName
case *pb.TriggerAction_DeploySettingsTemplate:
dst.ChangeActionType(ActionDeploySettingsTemplate)
dstAction := &jsActionDeploySettingsTemplate{Object: dst.ActionData}
dstAction.TemplateName = srcAction.DeploySettingsTemplate.TemplateName
dstAction.Type = TemplateType(srcAction.DeploySettingsTemplate.Type)
case *pb.TriggerAction_BashScript:
dst.ChangeActionType(ActionBashScript)
dstAction := &jsActionStartBashScript{Object: dst.ActionData}
dstAction.ScriptName = srcAction.BashScript.ScriptName
case *pb.TriggerAction_GpioOut:
dst.ChangeActionType(ActionGPIOOut)
dstAction := &jsActionGPIOOut{Object: dst.ActionData}
dstAction.Value = GPIOOutValue(srcAction.GpioOut.Value)
dstAction.GpioNum = GPIONum(srcAction.GpioOut.GpioNum)
case *pb.TriggerAction_GroupSend:
dst.ChangeActionType(ActionGroupSend)
dstAction := &jsActionGroupSend{Object: dst.ActionData}
dstAction.Value = srcAction.GroupSend.Value
dstAction.GroupName = srcAction.GroupSend.GroupName
default:
// do nothing
// Note: no default case, we don't change any values of jsTriggerAction if there isn't a type match
}
// convert trigger
switch srcTrigger := src.Trigger.(type) {
case *pb.TriggerAction_SshLogin:
dst.ChangeTriggerType(TriggerSshLogin)
dstTrigger := &jsTriggerSSHLogin{Object: dst.ActionData}
dstTrigger.LoginUser = srcTrigger.SshLogin.LoginUser
case *pb.TriggerAction_DhcpLeaseGranted:
dst.ChangeTriggerType(TriggerDhcpLeaseGranted)
case *pb.TriggerAction_WifiAPStarted:
dst.ChangeTriggerType(TriggerWifiAPStarted)
case *pb.TriggerAction_WifiConnectedAsSta:
dst.ChangeTriggerType(TriggerWifiConnectedAsSta)
case *pb.TriggerAction_UsbGadgetConnected:
dst.ChangeTriggerType(TriggerUsbGadgetConnected)
case *pb.TriggerAction_UsbGadgetDisconnected:
dst.ChangeTriggerType(TriggerUsbGadgetDisconnected)
case *pb.TriggerAction_ServiceStarted:
dst.ChangeTriggerType(TriggerServiceStarted)
case *pb.TriggerAction_GpioIn:
dst.ChangeTriggerType(TriggerGPIOIn)
dstTrigger := &jsTriggerGPIOIn{Object: dst.ActionData}
dstTrigger.GpioNum = GPIONum(srcTrigger.GpioIn.GpioNum)
dstTrigger.Edge = GPIOInEdge(srcTrigger.GpioIn.GpioInEdge)
dstTrigger.PullUpDown = GPIOInPullUpDown(srcTrigger.GpioIn.PullUpDown)
case *pb.TriggerAction_GroupReceive:
dst.ChangeTriggerType(TriggerGroupReceive)
dstTrigger := &jsTriggerGroupReceive{Object: dst.ActionData}
dstTrigger.GroupName = srcTrigger.GroupReceive.GroupName
dstTrigger.Value = srcTrigger.GroupReceive.Value
case *pb.TriggerAction_GroupReceiveSequence:
dst.ChangeTriggerType(TriggerGroupReceiveSequence)
dstTrigger := &jsTriggerGroupReceiveSequence{Object: dst.ActionData}
dstTrigger.GroupName = srcTrigger.GroupReceiveSequence.GroupName
dstTrigger.ValueSequence = srcTrigger.GroupReceiveSequence.Values
default:
// change nothing
}
}
func (ta *jsTriggerAction) toGo() (res *pb.TriggerAction) {
res = &pb.TriggerAction{
OneShot: ta.OneShot,
Immutable: ta.Immutable,
IsActive: ta.IsActive,
Id: ta.Id,
}
// Convert action
switch ta.ActionType {
case ActionLog:
res.Action = &pb.TriggerAction_Log{
Log: &pb.ActionLog{},
}
case ActionHidScript:
actionData := &jsActionStartHIDScript{Object: ta.ActionData}
res.Action = &pb.TriggerAction_HidScript{
HidScript: &pb.ActionStartHIDScript{
ScriptName: actionData.ScriptName,
},
}
case ActionDeploySettingsTemplate:
actionData := &jsActionDeploySettingsTemplate{Object: ta.ActionData}
res.Action = &pb.TriggerAction_DeploySettingsTemplate{
DeploySettingsTemplate: &pb.ActionDeploySettingsTemplate{
Type: pb.ActionDeploySettingsTemplate_TemplateType(actionData.Type),
TemplateName: actionData.TemplateName,
},
}
case ActionBashScript:
actionData := &jsActionStartBashScript{Object: ta.ActionData}
res.Action = &pb.TriggerAction_BashScript {
BashScript: &pb.ActionStartBashScript{
ScriptName: actionData.ScriptName,
},
}
case ActionGPIOOut:
actionData := &jsActionGPIOOut{Object: ta.ActionData}
res.Action = &pb.TriggerAction_GpioOut{
GpioOut: &pb.ActionGPIOOut{
GpioNum: pb.GPIONum(actionData.GpioNum),
Value: pb.GPIOOutValue(actionData.Value),
},
}
case ActionGroupSend:
actionData := &jsActionGroupSend{Object: ta.ActionData}
res.Action = &pb.TriggerAction_GroupSend{
GroupSend: &pb.ActionGroupSend{
GroupName: actionData.GroupName,
Value: actionData.Value,
},
}
default:
println("Unknown action type")
res.Action = nil
}
// convert trigger
switch ta.TriggerType {
case TriggerSshLogin:
triggerData := &jsTriggerSSHLogin{Object: ta.TriggerData}
res.Trigger = &pb.TriggerAction_SshLogin{
SshLogin: &pb.TriggerSSHLogin{
LoginUser: triggerData.LoginUser,
},
}
case TriggerDhcpLeaseGranted:
//triggerData := &jsTriggerDHCPLeaseGranted{Object: ta.TriggerData}
res.Trigger = &pb.TriggerAction_DhcpLeaseGranted{
DhcpLeaseGranted: &pb.TriggerDHCPLeaseGranted{},
}
case TriggerWifiAPStarted:
res.Trigger = &pb.TriggerAction_WifiAPStarted{
WifiAPStarted: &pb.TriggerWifiAPStarted{},
}
case TriggerWifiConnectedAsSta:
res.Trigger = &pb.TriggerAction_WifiConnectedAsSta{
WifiConnectedAsSta: &pb.TriggerWifiConnectedAsSta{},
}
case TriggerUsbGadgetConnected:
res.Trigger = &pb.TriggerAction_UsbGadgetConnected{
UsbGadgetConnected: &pb.TriggerUSBGadgetConnected{},
}
case TriggerUsbGadgetDisconnected:
res.Trigger = &pb.TriggerAction_UsbGadgetDisconnected{
UsbGadgetDisconnected: &pb.TriggerUSBGadgetDisconnected{},
}
case TriggerServiceStarted:
res.Trigger = &pb.TriggerAction_ServiceStarted{
ServiceStarted: &pb.TriggerServiceStarted{},
}
case TriggerGPIOIn:
triggerData := &jsTriggerGPIOIn{Object: ta.TriggerData}
res.Trigger = &pb.TriggerAction_GpioIn{
GpioIn: &pb.TriggerGPIOIn{
GpioNum: pb.GPIONum(triggerData.GpioNum),
PullUpDown: pb.GPIOInPullUpDown(triggerData.PullUpDown),
GpioInEdge: pb.GPIOInEdge(triggerData.Edge),
},
}
case TriggerGroupReceive:
triggerData := &jsTriggerGroupReceive{Object: ta.TriggerData}
res.Trigger = &pb.TriggerAction_GroupReceive{
GroupReceive: &pb.TriggerGroupReceive {
GroupName: triggerData.GroupName,
Value: triggerData.Value,
},
}
case TriggerGroupReceiveSequence:
triggerData := &jsTriggerGroupReceiveSequence{Object: ta.TriggerData}
res.Trigger = &pb.TriggerAction_GroupReceiveSequence{
GroupReceiveSequence: &pb.TriggerGroupReceiveSequence {
GroupName: triggerData.GroupName,
Values: triggerData.ValueSequence,
},
}
default:
println("Unknown trigger type")
res.Trigger = nil
}
return res
}
func (ta *jsTriggerAction) ChangeActionType(newAt actionType) {
var data *js.Object
switch newAt {
@ -93,7 +300,7 @@ func (ta *jsTriggerAction) ChangeActionType(newAt actionType) {
case ActionDeploySettingsTemplate:
d := &jsActionDeploySettingsTemplate{Object:O()}
d.TemplateName = "somescript"
d.Type = "Template type"
d.Type = availableTemplateTypes[0]
data = d.Object
case ActionBashScript:
d := &jsActionStartBashScript{Object:O()}
@ -145,7 +352,7 @@ func (ta *jsTriggerAction) ChangeTriggerType(newTt triggerType) {
switch newTt {
case TriggerSshLogin:
d := &jsTriggerSSHLogin{Object:O()}
d.ResLoginUser = "root"
d.LoginUser = "root"
data = d.Object
case TriggerDhcpLeaseGranted:
d := &jsTriggerDHCPLeaseGranted{Object:O()}
@ -180,7 +387,7 @@ func (ta *jsTriggerAction) ChangeTriggerType(newTt triggerType) {
d := &jsTriggerGroupReceiveSequence{Object:O()}
d.GroupName = "Channel1"
d.IgnoreOutOfOrder = false
d.ValueSequence = []int{1,1}
d.ValueSequence = []int32{1,1}
data = d.Object
default:
println("Unknown trigger type")
@ -256,7 +463,7 @@ type jsTriggerWifiConnectedAsSta struct {
}
type jsTriggerSSHLogin struct {
*js.Object
ResLoginUser string `js:"ResLoginUser"`
LoginUser string `js:"LoginUser"`
}
type jsTriggerDHCPLeaseGranted struct {
*js.Object
@ -264,17 +471,17 @@ type jsTriggerDHCPLeaseGranted struct {
type jsTriggerGroupReceive struct {
*js.Object
GroupName string `js:"GroupName"`
Value int `js:"Value"`
Value int32 `js:"Value"`
}
type jsTriggerGroupReceiveSequence struct {
*js.Object
GroupName string `js:"GroupName"`
IgnoreOutOfOrder bool `js:"IgnoreOutOfOrder"`
ValueSequence []int `js:"ValueSequence"`
ValueSequence []int32 `js:"ValueSequence"`
}
type jsTriggerGPIOIn struct {
*js.Object
GpioNum int `js:"GpioNum"`
GpioNum GPIONum `js:"GpioNum"`
PullUpDown GPIOInPullUpDown `js:"PullUpDown"` //PullUp resistor, pull down otherwise
Edge GPIOInEdge `js:"Edge"` // 0 == GPIO.RISING, 1 == GPIO.FALLING, every value > 1 == GPIO.BOTH
}
@ -311,11 +518,11 @@ type jsActionStartHIDScript struct {
type jsActionDeploySettingsTemplate struct {
*js.Object
TemplateName string `js:"TemplateName"`
Type string `js:"Type"`
Type TemplateType `js:"Type"`
}
type jsActionGPIOOut struct {
*js.Object
GpioNum int `js:"GpioNum"`
GpioNum GPIONum `js:"GpioNum"`
Value GPIOOutValue `js:"Value"` //PullUp resistor, pull down otherwise
}
type GPIOOutValue int
@ -333,8 +540,80 @@ var availableGPIOOutValues = []GPIOOutValue{GPIOOutValueLow, GPIOOutValueHigh, G
type jsActionGroupSend struct {
*js.Object
GroupName string `js:"GroupName"`
Value int `js:"Value"`
Value int32 `js:"Value"`
}
type jsActionLog struct {
*js.Object
}
}
type GPIONum int
const GPIO_NUM_1 = GPIONum(pb.GPIONum_NUM_1)
const GPIO_NUM_2 = GPIONum(pb.GPIONum_NUM_2)
const GPIO_NUM_3 = GPIONum(pb.GPIONum_NUM_3)
const GPIO_NUM_4 = GPIONum(pb.GPIONum_NUM_4)
const GPIO_NUM_5 = GPIONum(pb.GPIONum_NUM_5)
const GPIO_NUM_6 = GPIONum(pb.GPIONum_NUM_6)
const GPIO_NUM_7 = GPIONum(pb.GPIONum_NUM_7)
const GPIO_NUM_8 = GPIONum(pb.GPIONum_NUM_8)
const GPIO_NUM_9 = GPIONum(pb.GPIONum_NUM_9)
const GPIO_NUM_10 = GPIONum(pb.GPIONum_NUM_10)
const GPIO_NUM_11 = GPIONum(pb.GPIONum_NUM_11)
const GPIO_NUM_12 = GPIONum(pb.GPIONum_NUM_12)
const GPIO_NUM_13 = GPIONum(pb.GPIONum_NUM_13)
const GPIO_NUM_14 = GPIONum(pb.GPIONum_NUM_14)
const GPIO_NUM_15 = GPIONum(pb.GPIONum_NUM_15)
const GPIO_NUM_16 = GPIONum(pb.GPIONum_NUM_16)
const GPIO_NUM_17 = GPIONum(pb.GPIONum_NUM_17)
const GPIO_NUM_18 = GPIONum(pb.GPIONum_NUM_18)
const GPIO_NUM_19 = GPIONum(pb.GPIONum_NUM_19)
const GPIO_NUM_20 = GPIONum(pb.GPIONum_NUM_20)
var gpioNumNames = map[GPIONum]string{
GPIO_NUM_1: "GPIO 1",
GPIO_NUM_2: "GPIO 2",
GPIO_NUM_3: "GPIO 3",
GPIO_NUM_4: "GPIO 4",
GPIO_NUM_5: "GPIO 5",
GPIO_NUM_6: "GPIO 6",
GPIO_NUM_7: "GPIO 7",
GPIO_NUM_8: "GPIO 8",
GPIO_NUM_9: "GPIO 9",
GPIO_NUM_10: "GPIO 10",
GPIO_NUM_11: "GPIO 11",
GPIO_NUM_12: "GPIO 12",
GPIO_NUM_13: "GPIO 13",
GPIO_NUM_14: "GPIO 14",
GPIO_NUM_15: "GPIO 15",
GPIO_NUM_16: "GPIO 16",
GPIO_NUM_17: "GPIO 17",
GPIO_NUM_18: "GPIO 18",
GPIO_NUM_19: "GPIO 19",
GPIO_NUM_20: "GPIO 20",
}
var availableGPIONums = []GPIONum{
GPIO_NUM_1, GPIO_NUM_2, GPIO_NUM_3, GPIO_NUM_4, GPIO_NUM_5, GPIO_NUM_6, GPIO_NUM_7, GPIO_NUM_8, GPIO_NUM_9, GPIO_NUM_10,
GPIO_NUM_11, GPIO_NUM_12, GPIO_NUM_13, GPIO_NUM_14, GPIO_NUM_15, GPIO_NUM_16, GPIO_NUM_17, GPIO_NUM_18, GPIO_NUM_19, GPIO_NUM_20,
}
type TemplateType int
const TemplateTypeFullSettings = TemplateType(pb.ActionDeploySettingsTemplate_FULL_SETTINGS)
const TemplateTypeNetwork = TemplateType(pb.ActionDeploySettingsTemplate_NETWORK)
const TemplateTypeWifi = TemplateType(pb.ActionDeploySettingsTemplate_WIFI)
const TemplateTypeUSB = TemplateType(pb.ActionDeploySettingsTemplate_USB)
const TemplateTypeBluetooth = TemplateType(pb.ActionDeploySettingsTemplate_BLUETOOTH)
const TemplateTypeTriggerActions = TemplateType(pb.ActionDeploySettingsTemplate_TRIGGER_ACTIONS)
var templateTypeNames = map[TemplateType]string{
TemplateTypeFullSettings: "Overall settings",
TemplateTypeNetwork: "Network interface settings",
TemplateTypeWifi: "WiFi settings",
TemplateTypeUSB: "USB settings",
TemplateTypeBluetooth: "Bluetooth settings",
TemplateTypeTriggerActions: "Stored TriggerAction set",
}
var availableTemplateTypes = []TemplateType{
TemplateTypeFullSettings,
TemplateTypeNetwork,
TemplateTypeWifi,
TemplateTypeUSB,
TemplateTypeBluetooth,
TemplateTypeTriggerActions,
}