This repository has been archived by the owner on Oct 21, 2021. It is now read-only.
/
hist_ctrl_client.go
91 lines (85 loc) · 2.85 KB
/
hist_ctrl_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* (C) 2021 Geotab Inc
*
* All files and artifacts in the repository at https://github.com/MEAE-GOT/W3C_VehicleSignalInterfaceImpl
* are licensed under the provisions of the license provided by the LICENSE file in this repository.
*
**/
package main
import (
// "io"
// "encoding/json"
// "io/ioutil"
"net"
// "net/http"
// "strconv"
// "strings"
// "time"
"os"
"fmt"
// "database/sql"
_ "github.com/mattn/go-sqlite3"
"github.com/MEAE-GOT/W3C_VehicleSignalInterfaceImpl/utils"
)
func main() {
buf := make([]byte, 128)
conn, err := net.Dial("unix", "/tmp/vissv2/histctrlserver.sock")
if err != nil {
utils.Error.Printf("HistCtrlClient:Accept failed, err = %s", err)
os.Exit(-1)
}
defer conn.Close()
var command string
fmt.Printf("********************* History control client ****************\n")
for {
fmt.Printf("Select command: c(reate)/s(tart)/(sto)p/d(elete)/q(uit): ")
fmt.Scanf("%s\n", &command)
payLoad := ""
switch command[0] {
case 'c': fallthrough
case 'C': // {"action":"create", "path": X, "buf-size":"Y"}
var path string
var bufSize string
fmt.Printf("Path=")
fmt.Scanf("%s\n", &path)
fmt.Printf("Buffer size=")
fmt.Scanf("%s\n", &bufSize)
payLoad = `{"action": "create", "path":"` + path + `", "buf-size":"` + bufSize + `"}`
case 's': fallthrough
case 'S': // {"action":"start", "path": X, "frequency":"Z"}
var path string
var freq string
fmt.Printf("Path=")
fmt.Scanf("%s\n", &path)
fmt.Printf("Frequency (captures/hr)=")
fmt.Scanf("%s\n", &freq)
payLoad = `{"action": "start", "path":"` + path + `", "frequency":"` + freq + `"}`
case 'p': fallthrough
case 'P': // {"action":"stop", "path": X}
var path string
fmt.Printf("Path=")
fmt.Scanf("%s\n", &path)
payLoad = `{"action": "stop", "path":"` + path + `"}`
case 'd': fallthrough
case 'D': // {"action":"delete", "path": X}
var path string
fmt.Printf("Path=")
fmt.Scanf("%s\n", &path)
payLoad = `{"action": "delete", "path":"` + path + `"}`
default: // quit
conn.Close()
os.Exit(0)
}
_, err := conn.Write([]byte(payLoad))
if err != nil {
utils.Error.Printf("HistCtrlClient:Write failed, err = %s", err)
os.Exit(-1)
}
n, err := conn.Read(buf)
if err != nil {
utils.Error.Printf("HistCtrlClient:Read failed, err = %s", err)
os.Exit(-1)
}
fmt.Printf("Server response: %s\n", string(buf[:n]))
}
}