mirror of
https://github.com/RoganDawes/P4wnP1_aloa.git
synced 2025-11-15 00:17:08 +01:00
TriggerAction 'Load settings', fix kill wpa_supplicant', minor fix webclient
This commit is contained in:
@@ -156,7 +156,7 @@ func (bt *BtService) EnableBridge() (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// SetBridgeSTP(BT_ETHERNET_BRIDGE_NAME, true) //enable spanning tree
|
||||
|
||||
err = SetBridgeForwardDelay(BT_ETHERNET_BRIDGE_NAME, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -6,5 +6,5 @@ const (
|
||||
PATH_WEBROOT = PATH_ROOT + "/www"
|
||||
PATH_BASH_SCRIPTS = PATH_ROOT + "/scripts"
|
||||
PATH_HID_SCRIPTS = PATH_ROOT + "/HIDScripts"
|
||||
PATH_DATA_STORE = "/tmp/store"
|
||||
PATH_DATA_STORE = PATH_ROOT + "/store"
|
||||
)
|
||||
|
||||
@@ -293,11 +293,6 @@ func (tam *TriggerActionManager) onGroupReceive(evt *pb.Event, ta *pb.TriggerAct
|
||||
default:
|
||||
return errors.New("Wrong trigger for onGroupReceive event")
|
||||
}
|
||||
// only triggers if
|
||||
// - group of event macthes group of trigger
|
||||
// - value of event matches value of trigger
|
||||
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -333,7 +328,37 @@ func (tam *TriggerActionManager) executeActionDeploySettingsTemplate(evt *pb.Eve
|
||||
templateTypeName := pb.ActionDeploySettingsTemplate_TemplateType_name[int32(action.Type)]
|
||||
fmt.Printf("Trigger '%s' fired -> executing action '%s' (%s: '%s')\n", triggerName, actionName, templateTypeName, action.TemplateName)
|
||||
|
||||
// ToDo: Implement
|
||||
switch action.Type {
|
||||
case pb.ActionDeploySettingsTemplate_FULL_SETTINGS:
|
||||
// ToDo: Implement
|
||||
case pb.ActionDeploySettingsTemplate_NETWORK:
|
||||
_,err := tam.rootSvc.SubSysRPC.DeployStoredEthernetInterfaceSettings(context.Background(), &pb.StringMessage{Msg: action.TemplateName})
|
||||
if err == nil {
|
||||
fmt.Println("... stored settings deployed")
|
||||
} else {
|
||||
fmt.Println("... deploying stored settings failed: ", err.Error())
|
||||
}
|
||||
case pb.ActionDeploySettingsTemplate_USB:
|
||||
// ToDo: Implement
|
||||
case pb.ActionDeploySettingsTemplate_WIFI:
|
||||
_,err := tam.rootSvc.SubSysRPC.DeployStoredWifiSettings(context.Background(), &pb.StringMessage{Msg: action.TemplateName})
|
||||
if err == nil {
|
||||
fmt.Println("... stored settings deployed")
|
||||
} else {
|
||||
fmt.Println("... deploying stored settings failed: ", err.Error())
|
||||
}
|
||||
case pb.ActionDeploySettingsTemplate_BLUETOOTH:
|
||||
// ToDo: Implement
|
||||
case pb.ActionDeploySettingsTemplate_TRIGGER_ACTIONS:
|
||||
_,err := tam.rootSvc.SubSysRPC.DeployStoredTriggerActionSetReplace(context.Background(), &pb.StringMessage{Msg: action.TemplateName})
|
||||
if err == nil {
|
||||
fmt.Println("... stored settings deployed")
|
||||
} else {
|
||||
fmt.Println("... deploying stored settings failed: ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (tam *TriggerActionManager) executeActionGPIOOut(evt *pb.Event, ta *pb.TriggerAction, tt triggerType, at actionType, action *pb.ActionGPIOOut) {
|
||||
|
||||
@@ -256,9 +256,7 @@ func addUSBEthernetBridge() {
|
||||
//Create the bridge
|
||||
CreateBridge(USB_ETHERNET_BRIDGE_NAME)
|
||||
setInterfaceMac(USB_ETHERNET_BRIDGE_NAME, USB_ETHERNET_BRIDGE_MAC)
|
||||
//Note: STP hopefully deals with issues when both, RNDIS and ECM, are enabled and both are detected
|
||||
// and both are detected and configured by the remote host (redundant link)
|
||||
SetBridgeSTP(USB_ETHERNET_BRIDGE_NAME, true) //enable spanning tree
|
||||
SetBridgeSTP(USB_ETHERNET_BRIDGE_NAME, false) //aboid loosing time by learning interface states, both usb0 and usb1 have to be set to forward
|
||||
SetBridgeForwardDelay(USB_ETHERNET_BRIDGE_NAME, 0)
|
||||
|
||||
//add the interfaces
|
||||
|
||||
@@ -176,6 +176,7 @@ func (wSvc *WiFiService) StopWpaSupplicant() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
log.Printf("... sending SIGTERM for wpa_supplicant on interface '%s' with PID\n", wSvc.IfaceName, wSvc.CmdWpaSupplicant.Process.Pid)
|
||||
wSvc.CmdWpaSupplicant.Process.Signal(syscall.SIGTERM)
|
||||
wSvc.CmdWpaSupplicant.Wait()
|
||||
@@ -193,6 +194,10 @@ func (wSvc *WiFiService) StopWpaSupplicant() (err error) {
|
||||
return errors.New(eCantStop)
|
||||
}
|
||||
}
|
||||
*/
|
||||
log.Printf("... stopping wpa_supplicant\n", wSvc.IfaceName, wSvc.CmdWpaSupplicant.Process.Pid)
|
||||
err = ProcSoftKill(wSvc.CmdWpaSupplicant, time.Second*2)
|
||||
if err != nil { return errors.New(eCantStop) }
|
||||
|
||||
wSvc.CmdWpaSupplicant = nil
|
||||
log.Println(eSuccess)
|
||||
@@ -369,28 +374,27 @@ func (wSvc *WiFiService) DeploySettings(newWifiSettings *pb.WiFiSettings) (wstat
|
||||
log.Printf("Error setting WiFi regulatory domain '%s': %v\n", newWifiSettings.Regulatory , err) //we don't abort on error here
|
||||
}
|
||||
|
||||
var triggerEvent *pb.Event = nil
|
||||
if !newWifiSettings.Disabled {
|
||||
switch newWifiSettings.WorkingMode {
|
||||
case pb.WiFiWorkingMode_AP:
|
||||
err = wSvc.runAPMode(newWifiSettings)
|
||||
// emit Trigger event if AP is Up
|
||||
if err == nil {
|
||||
wSvc.RootSvc.SubSysEvent.Emit(ConstructEventTrigger(common_web.TRIGGER_EVT_TYPE_WIFI_AP_STARTED))
|
||||
triggerEvent = ConstructEventTrigger(common_web.TRIGGER_EVT_TYPE_WIFI_AP_STARTED)
|
||||
}
|
||||
case pb.WiFiWorkingMode_STA, pb.WiFiWorkingMode_STA_FAILOVER_AP:
|
||||
errSta := wSvc.runStaMode(newWifiSettings)
|
||||
if errSta == nil {
|
||||
wSvc.RootSvc.SubSysEvent.Emit(ConstructEventTrigger(common_web.TRIGGER_EVT_TYPE_WIFI_CONNECTED_AS_STA))
|
||||
}
|
||||
|
||||
if errSta != nil {
|
||||
triggerEvent = ConstructEventTrigger(common_web.TRIGGER_EVT_TYPE_WIFI_CONNECTED_AS_STA)
|
||||
} else {
|
||||
//in failover mode, we try to enable AP first
|
||||
if newWifiSettings.WorkingMode == pb.WiFiWorkingMode_STA_FAILOVER_AP {
|
||||
log.Println(errSta)
|
||||
log.Printf("Trying to fail over to Access Point Mode...")
|
||||
err = wSvc.runAPMode(newWifiSettings)
|
||||
if err == nil {
|
||||
wSvc.RootSvc.SubSysEvent.Emit(ConstructEventTrigger(common_web.TRIGGER_EVT_TYPE_WIFI_AP_STARTED))
|
||||
triggerEvent = ConstructEventTrigger(common_web.TRIGGER_EVT_TYPE_WIFI_AP_STARTED)
|
||||
}
|
||||
} else {
|
||||
err = errSta
|
||||
@@ -424,6 +428,16 @@ func (wSvc *WiFiService) DeploySettings(newWifiSettings *pb.WiFiSettings) (wstat
|
||||
if serr := wSvc.UpdateStateFromIw(); serr != nil {
|
||||
log.Println("Couldn't update internal WiFi state:", serr)
|
||||
}
|
||||
|
||||
// Fire the event after everything is done, especially after redeployment of the network interface settings
|
||||
// to allow an ActionTrigger which deploys another ethernet settings template (without changing the settings
|
||||
// in parallel)
|
||||
// ToDo: check if it makes sense to lock the methods responsible for deploying ethernet interface settings and WifI settings (both long-running)
|
||||
if triggerEvent != nil {
|
||||
wSvc.RootSvc.SubSysEvent.Emit(triggerEvent)
|
||||
}
|
||||
|
||||
|
||||
return wSvc.State, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,9 @@ func InitComponentsWiFi() {
|
||||
return vm.Get("$store").Get("state").Get("deployingWifiSettings")
|
||||
}),
|
||||
hvue.Mounted(func(vm *hvue.VM) {
|
||||
println("wifi component mounted")
|
||||
vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_STORED_WIFI_SETTINGS_LIST)
|
||||
vm.Get("$store").Call("dispatch", VUEX_ACTION_UPDATE_WIFI_STATE)
|
||||
}),
|
||||
|
||||
)
|
||||
@@ -176,11 +178,11 @@ func InitComponentsWiFi() {
|
||||
|
||||
const templateWiFi = `
|
||||
<q-page padding>
|
||||
<div class="row gutter-sm">
|
||||
<select-string-from-array :values="$store.state.StoredWifiSettingsList" v-model="showLoadModal" title="Load WiFi settings" @load="load($event)"></select-string-from-array>
|
||||
<select-string-from-array :values="$store.state.StoredWifiSettingsList" v-model="showDeployStoredModal" title="Deploy stored WiFi settings" @load="deployStored($event)"></select-string-from-array>
|
||||
<modal-string-input v-model="showStoreModal" title="Store current WiFi Settings" @save="store($event)"></modal-string-input>
|
||||
|
||||
<div class="row gutter-sm">
|
||||
<div class="col-lg-4">
|
||||
<q-card class="full-height">
|
||||
<q-card-title>
|
||||
|
||||
@@ -116,6 +116,7 @@ func InitComponentsNetwork() {
|
||||
// The following method doesn't make much sense anymore, but is kept as an example for working with promises
|
||||
hvue.Mounted(func(vm *hvue.VM) {
|
||||
// update network interface
|
||||
println("ethernet settings component mounted")
|
||||
promise := vm.Store.Call("dispatch", VUEX_ACTION_UPDATE_ALL_ETHERNET_INTERFACE_SETTINGS)
|
||||
|
||||
promise.Call("then",
|
||||
@@ -131,6 +132,7 @@ func InitComponentsNetwork() {
|
||||
println("... No interface found")
|
||||
}
|
||||
*/
|
||||
println("ethernet interface settings reloaded")
|
||||
hvue.Set(vm, "currentIdx", 0)
|
||||
},
|
||||
func() {
|
||||
|
||||
@@ -17,7 +17,6 @@ type PromiseFunc func() (result interface{}, err error)
|
||||
|
||||
func NewPromise(pf PromiseFunc) (p *Promise) {
|
||||
f := func(resolve *js.Object, reject *js.Object) {
|
||||
println("Promise called ", resolve, reject)
|
||||
p := &struct {
|
||||
*js.Object
|
||||
Resolve *js.Object `js:"resolve"`
|
||||
|
||||
Reference in New Issue
Block a user