Skip to content

Commit 09b8ea8

Browse files
committed
Format code
1 parent a5798c0 commit 09b8ea8

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

cmd/candump.go

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,40 @@
33
// [1]: https://github.com/linux-can/can-utils
44
package main
55

6-
import(
7-
"github.com/brutella/can"
8-
"flag"
9-
"os"
10-
"os/signal"
11-
"net"
12-
"log"
13-
"fmt"
6+
import (
7+
"flag"
8+
"fmt"
9+
"github.com/brutella/can"
10+
"log"
11+
"net"
12+
"os"
13+
"os/signal"
1414
)
1515

1616
var i = flag.String("if", "", "network interface name")
1717

1818
func main() {
19-
flag.Parse()
20-
if len(*i) == 0 {
21-
flag.Usage()
22-
os.Exit(1)
23-
}
24-
25-
iface, err := net.InterfaceByName(*i)
26-
27-
if err != nil {
28-
log.Fatalf("Could not find network interface %s (%v)", *i, err)
29-
}
30-
31-
conn, err := can.NewReadWriteCloserForInterface(iface)
32-
33-
if err != nil {
34-
log.Fatal(err)
35-
}
36-
37-
bus := can.NewBus(conn)
38-
bus.SubscribeFunc(logCANFrame)
39-
19+
flag.Parse()
20+
if len(*i) == 0 {
21+
flag.Usage()
22+
os.Exit(1)
23+
}
24+
25+
iface, err := net.InterfaceByName(*i)
26+
27+
if err != nil {
28+
log.Fatalf("Could not find network interface %s (%v)", *i, err)
29+
}
30+
31+
conn, err := can.NewReadWriteCloserForInterface(iface)
32+
33+
if err != nil {
34+
log.Fatal(err)
35+
}
36+
37+
bus := can.NewBus(conn)
38+
bus.SubscribeFunc(logCANFrame)
39+
4040
c := make(chan os.Signal)
4141
signal.Notify(c, os.Interrupt)
4242
signal.Notify(c, os.Kill)
@@ -45,42 +45,42 @@ func main() {
4545
select {
4646
case <-c:
4747
bus.Disconnect()
48-
os.Exit(1)
48+
os.Exit(1)
4949
}
5050
}()
51-
52-
bus.ConnectAndPublish()
51+
52+
bus.ConnectAndPublish()
5353
}
5454

5555
// logCANFrame logs a frame with the same format as candump from can-utils.
56-
func logCANFrame(frm can.Frame) {
57-
data := trimSuffix(frm.Data[:], 0x00)
58-
length := fmt.Sprintf("[%x]", frm.Length)
59-
log.Printf("%-3s %-4x %-3s % -24X '%s'\n", *i, frm.ID, length, data, printableString(data[:]))
56+
func logCANFrame(frm can.Frame) {
57+
data := trimSuffix(frm.Data[:], 0x00)
58+
length := fmt.Sprintf("[%x]", frm.Length)
59+
log.Printf("%-3s %-4x %-3s % -24X '%s'\n", *i, frm.ID, length, data, printableString(data[:]))
6060
}
6161

6262
// trim returns a subslice of s by slicing off all trailing b bytes.
6363
func trimSuffix(s []byte, b byte) []byte {
64-
for i := len(s) - 1; i >= 0; i-- {
65-
if s[i] != b {
66-
return s[:i+1]
67-
}
68-
}
69-
70-
return []byte{}
64+
for i := len(s) - 1; i >= 0; i-- {
65+
if s[i] != b {
66+
return s[:i+1]
67+
}
68+
}
69+
70+
return []byte{}
7171
}
7272

73-
// printableString creates a string from s and replaces non-printable bytes (i.e. 0-32, 127)
73+
// printableString creates a string from s and replaces non-printable bytes (i.e. 0-32, 127)
7474
// with '.' – similar how candump from can-utils does it.
7575
func printableString(s []byte) string {
76-
var ascii []byte
77-
for _, b := range s {
78-
if b < 32 || b > 126 {
79-
b = byte('.')
80-
81-
}
82-
ascii = append(ascii, b)
83-
}
84-
85-
return string(ascii)
86-
}
76+
var ascii []byte
77+
for _, b := range s {
78+
if b < 32 || b > 126 {
79+
b = byte('.')
80+
81+
}
82+
ascii = append(ascii, b)
83+
}
84+
85+
return string(ascii)
86+
}

0 commit comments

Comments
 (0)