Add STM command-line tool 67/142767/6
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Fri, 4 Aug 2017 13:28:10 +0000 (15:28 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 3 Oct 2017 12:43:04 +0000 (14:43 +0200)
Only basic functions are available as LED and OLED control
is reserved for administrator or Boruta system.

Usage of stm:
  -dut
     connect SD card to DUT
  -m duration
     time delay for tick command (default 1s)
  -tick
     power off the DUT, wait 'm' seconds and switch it on again
  -ts
     connect SD card to test server

Change-Id: I6fd035c3b07169b40e861f95b90d6bd9d4d7e732

cmd/stm/stm.go [new file with mode: 0644]

diff --git a/cmd/stm/stm.go b/cmd/stm/stm.go
new file mode 100644 (file)
index 0000000..1499fe5
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+package main
+
+import (
+       "flag"
+       "log"
+       "time"
+
+       "git.tizen.org/tools/muxpi/stm"
+)
+
+var (
+       ts, dut, tick bool
+       tickDuration  time.Duration
+)
+
+func setFlags() {
+       flag.DurationVar(&tickDuration, "m", time.Second, "time delay for tick command")
+       flag.BoolVar(&ts, "ts", false, "connect SD card to test server")
+       flag.BoolVar(&dut, "dut", false, "connect SD card to DUT")
+       flag.BoolVar(&tick, "tick", false, "power off the DUT, wait 'm' seconds and switch it on again")
+}
+
+func checkErr(ctx string, err error) {
+       if err != nil {
+               log.Fatal(ctx, err)
+       }
+}
+
+func main() {
+       setFlags()
+       flag.Parse()
+
+       checkErr("failed to open connection to STM:", stm.Open())
+       defer stm.Close()
+
+       // SD card multiplexer related actions.
+       switch {
+       // Only one is allowed at a time.
+       case ts && dut:
+               log.Fatal("conflicting flags: DUT and TS")
+       case ts:
+               checkErr("failed to switch to the test server: ", stm.TS())
+       case dut:
+               checkErr("failed to switch to the DUT: ", stm.DUT())
+       }
+       if tick {
+               checkErr("failed to tick the power supply: ", stm.PowerTick(tickDuration))
+       }
+}