Skip to content

Instantly share code, notes, and snippets.

@cwt8805
Created June 2, 2020 02:16
Show Gist options
  • Select an option

  • Save cwt8805/c1e47861ff8b907f0ae27dbe5a187654 to your computer and use it in GitHub Desktop.

Select an option

Save cwt8805/c1e47861ff8b907f0ae27dbe5a187654 to your computer and use it in GitHub Desktop.
调用adb logcat显示433串口信息,定时清屏
package main
import (
"fmt"
"os"
"os/exec"
"strconv"
"time"
)
func main() {
clsDelay := 10
if len(os.Args) > 1 {
var err error
clsDelay, err = strconv.Atoi(os.Args[1])
if err != nil || clsDelay < 3 {
fmt.Printf("usage: %s delay(>=3)\n", os.Args[0])
os.Exit(1)
}
}
cmd := exec.Command("adb", "logcat", "-v", "time", "UartHandler:D", "*:S")
stdout, err := cmd.StdoutPipe()
if err != nil {
os.Exit(1)
}
cmd.Start()
buf := make([]byte, 1024)
go func() {
for {
n, err := stdout.Read(buf)
if err != nil {
break
}
if n > 0 {
fmt.Print(string(buf[:n]))
}
}
}()
go func() {
for {
time.Sleep(time.Duration(clsDelay) * time.Second)
clsCmd := exec.Command("cmd", "/c", "cls")
clsCmd.Stdout = os.Stdout
clsCmd.Run()
}
}()
cmd.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment