Skip to content

Commit 1943cb2

Browse files
author
Michal Sidor
committed
Add dummy mode to stm executable
It uses Dummy implementation of InterfaceCloser originally created by amistewicz. New boolean flag "-dummy" is provided. It should be used when only logging of the commands used is desired. Change-Id: If5dc582aef3e691282ed616c992c0e96d31dc087 Signed-off-by: Michal Sidor <m.sidor@samsung.com>
1 parent 7ec3443 commit 1943cb2

File tree

2 files changed

+121
-1
lines changed

2 files changed

+121
-1
lines changed

sw/nanopi/cmd/stm/stm.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ var (
2929
serviceSocket string
3030
serve bool
3131
remote string
32+
dummy bool
3233
)
3334

3435
func setGlobalFlags() {
3536
flag.StringVar(&userServiceSocket, "user-listen", "/run/stm-user.socket", "path to socket on which user RPC interface will be served")
3637
flag.StringVar(&serviceSocket, "listen", "/run/stm.socket", "path to socket on which user and admin RPC interface will be served")
3738
flag.BoolVar(&serve, "serve", false, "start RPC service")
3839
flag.StringVar(&remote, "remote", "", "path to socket to use as a RPC service instead of local connection")
40+
flag.BoolVar(&dummy, "dummy", false, "log actions instead of performing them")
3941
}
4042

4143
func checkErr(ctx string, err error) {
@@ -63,8 +65,14 @@ func main() {
6365
log.Fatal("conflicting flags: serve and remote")
6466
}
6567

68+
if (remote != "") && dummy {
69+
log.Fatal("conflicting flags: dummy and remote")
70+
}
71+
6672
var dev stm.InterfaceCloser
67-
if remote != "" {
73+
if dummy {
74+
dev = stm.NewDummy("stm")
75+
} else if remote != "" {
6876
cl, err := rpc.Dial("unix", remote)
6977
checkErr("failed to connect to RPC service: ", err)
7078

sw/nanopi/stm/dummy.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License
15+
*/
16+
17+
package stm
18+
19+
import (
20+
"log"
21+
"time"
22+
)
23+
24+
// Dummy is a dummy implementation of Interface.
25+
// It logs to the standard logger from "log" package.
26+
type Dummy struct {
27+
ctx string
28+
}
29+
30+
// NewDummy return a dummy implementation of Interface.
31+
// Each message will be prefixed with context.
32+
func NewDummy(context string) InterfaceCloser {
33+
return &Dummy{ctx: context}
34+
}
35+
36+
// Close prints "Close" to the standard logger.
37+
func (d *Dummy) Close() error {
38+
log.Println(d.ctx, "Close")
39+
return nil
40+
}
41+
42+
// PowerTick prints "PowerTick" and duration argument to the standard logger.
43+
func (d *Dummy) PowerTick(duration time.Duration) error {
44+
log.Println(d.ctx, "PowerTick", duration)
45+
return nil
46+
}
47+
48+
// SetLED prints "SetLED" and arguments to the standard logger.
49+
func (d *Dummy) SetLED(led LED, r, g, b uint8) error {
50+
log.Println(d.ctx, "SetLED", led, r, g, b)
51+
return nil
52+
}
53+
54+
// ClearDisplay prints "ClearDisplay" to the standard logger.
55+
func (d *Dummy) ClearDisplay() error {
56+
log.Println(d.ctx, "ClearDisplay")
57+
return nil
58+
}
59+
60+
// PrintText prints "PrintText" and arguments to the standard logger.
61+
func (d *Dummy) PrintText(x, y uint, color Color, text string) error {
62+
log.Println(d.ctx, "PrintText", x, y, color, text)
63+
return nil
64+
}
65+
66+
// DUT prints "DUT" to the standard logger.
67+
func (d *Dummy) DUT() error {
68+
log.Println(d.ctx, "DUT")
69+
return nil
70+
}
71+
72+
// TS prints "TS" to the standard logger.
73+
func (d *Dummy) TS() error {
74+
log.Println(d.ctx, "TS")
75+
return nil
76+
}
77+
78+
// GetCurrent prints "GetCurrent" to the standard logger and returns 0.
79+
func (d *Dummy) GetCurrent() (int, error) {
80+
log.Println(d.ctx, "GetCurrent")
81+
return 0, nil
82+
}
83+
84+
// StartCurrentRecord prints "StartCurrentRecord" and arguments to the standard logger.
85+
func (d *Dummy) StartCurrentRecord(samples int, interval time.Duration) error {
86+
log.Println(d.ctx, "StartCurrentRecord", samples, interval)
87+
return nil
88+
}
89+
90+
// StopCurrentRecord prints "StopCurrentRecord" to the standard logger.
91+
func (d *Dummy) StopCurrentRecord() error {
92+
log.Println(d.ctx, "StopCurrentRecord")
93+
return nil
94+
}
95+
96+
// GetCurrentRecord prints "GetCurrentRecord" to the standard logger and returns nil.
97+
func (d *Dummy) GetCurrentRecord() ([]int, error) {
98+
log.Println(d.ctx, "GetCurrentRecord")
99+
return nil, nil
100+
}
101+
102+
// HDMI prints "HDMI" and argument to the standard logger.
103+
func (d *Dummy) HDMI(on bool) (err error) {
104+
log.Println(d.ctx, "HDMI", on)
105+
return nil
106+
}
107+
108+
// SetDyper prints "SetDyper" and arguments to the standard logger.
109+
func (d *Dummy) SetDyper(dyper Dyper, on bool) error {
110+
log.Println(d.ctx, "SetDyper", dyper, on)
111+
return nil
112+
}

0 commit comments

Comments
 (0)