From d194f39900d0270f67acd9ec6d51b2a619c68152 Mon Sep 17 00:00:00 2001 From: MaMe82 Date: Sun, 29 Jul 2018 22:44:03 +0200 Subject: [PATCH] Included folder with binaries --- cmd/P4wnP1_cli/P4wnP1_cli.go | 9 +++ cmd/P4wnP1_service/P4wnP1_service.go | 82 ++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 cmd/P4wnP1_cli/P4wnP1_cli.go create mode 100644 cmd/P4wnP1_service/P4wnP1_service.go diff --git a/cmd/P4wnP1_cli/P4wnP1_cli.go b/cmd/P4wnP1_cli/P4wnP1_cli.go new file mode 100644 index 0000000..5ad071e --- /dev/null +++ b/cmd/P4wnP1_cli/P4wnP1_cli.go @@ -0,0 +1,9 @@ +package main + +import ( + "github.com/mame82/P4wnP1_go/cli_client" +) + +func main() { + cli_client.Execute() +} diff --git a/cmd/P4wnP1_service/P4wnP1_service.go b/cmd/P4wnP1_service/P4wnP1_service.go new file mode 100644 index 0000000..ef1853d --- /dev/null +++ b/cmd/P4wnP1_service/P4wnP1_service.go @@ -0,0 +1,82 @@ +// +build linux,arm + +package main + +import ( + "log" + + "github.com/mame82/P4wnP1_go/service" + "os" + "os/signal" + "syscall" + "fmt" + pb "github.com/mame82/P4wnP1_go/proto" + "github.com/mame82/P4wnP1_go/common" + "time" + "strconv" +) + + + +func main() { + + err := service.InitGlobalServiceState() + if err != nil { panic(err) } + + state := service.ServiceState + state.StartService() + + + //ToDo: Check for root privs + err = service.CheckLibComposite() + if err != nil { + log.Fatalf("Couldn't load libcomposite: %v", err) + } + + //service.NewLed(false) //Set LED to manual trigger + //service.InitDefaultLEDSettings() + + /* + log.Printf("Keyboard devFile: %s\n", service.HidDevPath[service.USB_FUNCTION_HID_KEYBOARD_name]) + log.Printf("Mouse devFile: %s\n", service.HidDevPath[service.USB_FUNCTION_HID_MOUSE_name]) + log.Printf("HID RAW devFile: %s\n", service.HidDevPath[service.USB_FUNCTION_HID_RAW_name]) + */ + + // ToDo: The webroot has to be changed to /usr/local/P4wnP1/www + service.StartRpcServerAndWeb("0.0.0.0", "50051", "80", "/home/pi/P4wnP1_go/dist/www") //start gRPC service + + //Indicate servers up with LED blink count 1 + state.Led.SetLed(&pb.LEDSettings{1}) + + //service.StartEventManager(20) + log.SetOutput(state.EvMgr) + log.Println("TESTMESSAGE") + go func() { + err := common.RunBashScript("/usr/local/P4wnP1/scripts/servicestart.sh") + if err != nil { log.Printf("Error executing service startup script: %v\n", err) } + }() + + + //Send some log messages for testing + textfill := "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea" + i := 0 + go func() { + for { + //println("Sending log event") + state.EvMgr.Emit(service.ConstructEventLog("test source", i%5, "message " +strconv.Itoa(i) + ": " + textfill)) + time.Sleep(time.Millisecond *2000) + i++ + } + }() + + + + //use a channel to wait for SIGTERM or SIGINT + fmt.Println("P4wnP1 service initialized, stop with SIGTERM or SIGINT") + sig := make(chan os.Signal) + signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) + s := <-sig + log.Printf("Signal (%v) received, ending P4wnP1_service ...\n", s) + state.StopService() + return +}