Skip to content

Commit 906b112

Browse files
committed
great cleanup phase 1
remove friendly names and unused code
1 parent 468a5d3 commit 906b112

14 files changed

+20
-928
lines changed

altbuild.sh

-36
This file was deleted.

bufferflow_default.go

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package main
22

33
import (
44
log "github.com/Sirupsen/logrus"
5-
//"regexp"
6-
//"strconv"
7-
//"time"
85
)
96

107
type BufferflowDefault struct {

compile_webidebridge.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ compilePlatform()
7575
fi
7676
echo createZipEmbeddableFileArduino $GOOS $GOARCH $NAME
7777
createZipEmbeddableFileArduino $GOOS $GOARCH $NAME
78-
GOOS=$GOOS GOARCH=$GOARCH go-selfupdate $NAME $VERSION
78+
#GOOS=$GOOS GOARCH=$GOARCH go-selfupdate $NAME $VERSION
7979
rm -rf $NAME*
8080
}
8181

8282
extractVersionFromMain
8383
compilePlatform darwin amd64 o64-clang 1
8484
#compilePlatformLinux linux 386 gcc
8585
compilePlatform linux amd64 gcc 1
86-
compilePlatform linux arm 0
86+
#compilePlatform linux arm 0
8787
compilePlatform windows 386 i686-w64-mingw32-gcc 1
8888

8989

discovery.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func GetNetworkList() ([]OsSerialPort, error) {
5353
SavedNetworkPorts = Filter(SavedNetworkPorts, func(port OsSerialPort) bool {
5454
any := true
5555
for _, p := range newPorts {
56-
if p.Name == port.Name && p.FriendlyName == port.FriendlyName {
56+
if p.Name == port.Name {
5757
any = false
5858
return any
5959
}
@@ -125,13 +125,7 @@ func getPorts() ([]OsSerialPort, error) {
125125
arrPorts := []OsSerialPort{}
126126
go func(results chan *bonjour.ServiceEntry, exitCh chan<- bool) {
127127
for e := range results {
128-
var boardInfosSlice []string
129-
for _, element := range e.Text {
130-
if strings.Contains(element, "board=yun") {
131-
boardInfosSlice = append(boardInfosSlice, "arduino:avr:yun")
132-
}
133-
}
134-
arrPorts = append(arrPorts, OsSerialPort{Name: e.AddrIPv4.String(), FriendlyName: e.Instance, NetworkPort: true, RelatedNames: boardInfosSlice})
128+
arrPorts = append(arrPorts, OsSerialPort{Name: e.AddrIPv4.String(), IdVendor: strings.Join(e.Text[:], " "), NetworkPort: true})
135129
}
136130
timeout <- true
137131
}(results, resolver.Exit)

hub.go

-8
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,6 @@ func checkCmd(m []byte) {
199199
} else if strings.HasPrefix(sl, "list") {
200200
go spList(false)
201201
go spList(true)
202-
// log.Println("Stack info", runtime.NumGoroutine())
203-
// if runtime.NumGoroutine() > 30 {
204-
// output := make([]byte, 1<<16)
205-
// runtime.Stack(output, true)
206-
// log.Println(output)
207-
// log.Fatal("Crash because something is going wrong")
208-
// }
209-
//go getListViaWmiPnpEntity()
210202
} else if strings.HasPrefix(sl, "bufferalgorithm") {
211203
go spBufferAlgorithms()
212204
} else if strings.HasPrefix(sl, "log") {

main.go

+5-12
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ package main
66
import (
77
"flag"
88
log "github.com/Sirupsen/logrus"
9-
"go/build"
10-
"os"
11-
"path/filepath"
12-
//"net/http/pprof"
13-
"github.com/kardianos/osext"
14-
//"github.com/sanbornm/go-selfupdate/selfupdate" #included in update.go to change heavily
15-
//"github.com/sanderhahn/gozip"
169
"github.com/gin-gonic/gin"
1710
"github.com/itsjamie/gin-cors"
11+
"github.com/kardianos/osext"
1812
"github.com/vharitonsky/iniflags"
13+
"go/build"
14+
"os"
15+
"path/filepath"
1916
"runtime/debug"
2017
"text/template"
2118
"time"
19+
//"github.com/sanbornm/go-selfupdate/selfupdate" #included in update.go to change heavily
2220
)
2321

2422
var (
@@ -60,8 +58,6 @@ var (
6058
appName = flag.String("appName", "", "")
6159
)
6260

63-
var globalConfigMap map[string]interface{}
64-
6561
type NullWriter int
6662

6763
func (NullWriter) Write([]byte) (int, error) { return 0, nil }
@@ -156,9 +152,6 @@ func main() {
156152
// }
157153
}
158154

159-
createGlobalConfigMap(&globalConfigMap)
160-
161-
//getList()
162155
f := flag.Lookup("addr")
163156
log.Println("Version:" + version)
164157

serial.go

-24
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33
package main
44

55
import (
6-
//"bufio"
76
"encoding/json"
87
"fmt"
9-
//"path/filepath"
10-
//"github.com/kballard/go-shellquote"
11-
//"github.com/johnlauer/goserial"
12-
//"github.com/mikepb/go-serial"
13-
//"github.com/facchinm/go-serial"
14-
//"github.com/kardianos/osext"
158
log "github.com/Sirupsen/logrus"
16-
//"os"
179
"regexp"
1810
"runtime/debug"
1911
"strconv"
@@ -91,12 +83,10 @@ type SpPortList struct {
9183

9284
type SpPortItem struct {
9385
Name string
94-
Friendly string
9586
SerialNumber string
9687
DeviceClass string
9788
IsOpen bool
9889
IsPrimary bool
99-
RelatedNames []string
10090
Baud int
10191
BufferAlgorithm string
10292
Ver string
@@ -518,12 +508,10 @@ func spListDual(network bool) {
518508
*/
519509
spl.Ports[ctr] = SpPortItem{
520510
Name: item.Name,
521-
Friendly: item.FriendlyName,
522511
SerialNumber: item.SerialNumber,
523512
DeviceClass: item.DeviceClass,
524513
IsOpen: false,
525514
IsPrimary: false,
526-
RelatedNames: item.RelatedNames,
527515
Baud: 0,
528516
BufferAlgorithm: "",
529517
Ver: version,
@@ -554,18 +542,6 @@ func spListDual(network bool) {
554542
}
555543
}
556544

557-
func spListOld() {
558-
ls := "{\"serialports\" : [\n"
559-
list, _ := getList()
560-
for _, item := range list {
561-
ls += "{ \"name\" : \"" + item.Name + "\", \"friendly\" : \"" + item.FriendlyName + "\" },\n"
562-
}
563-
ls = strings.TrimSuffix(ls, "},\n")
564-
ls += "}\n"
565-
ls += "]}\n"
566-
h.broadcastSys <- []byte(ls)
567-
}
568-
569545
func spErr(err string) {
570546
log.Println("Sending err back: ", err)
571547
//h.broadcastSys <- []byte(err)

seriallist.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ package main
55
import (
66
log "github.com/Sirupsen/logrus"
77
"github.com/facchinm/go-serial"
8-
//"os"
98
"regexp"
109
)
1110

1211
type OsSerialPort struct {
1312
Name string
14-
FriendlyName string
15-
RelatedNames []string // for some devices there are 2 or more ports, i.e. TinyG v9 has 2 serial ports
1613
SerialNumber string
1714
DeviceClass string
1815
Manufacturer string
@@ -36,7 +33,7 @@ func GetList(network bool) ([]OsSerialPort, error) {
3633

3734
arrPorts := []OsSerialPort{}
3835
for _, element := range ports {
39-
arrPorts = append(arrPorts, OsSerialPort{Name: element, FriendlyName: element})
36+
arrPorts = append(arrPorts, OsSerialPort{Name: element})
4037
}
4138

4239
// see if we should filter the list
@@ -49,8 +46,6 @@ func GetList(network bool) ([]OsSerialPort, error) {
4946
// if matches regex, include
5047
if reFilter.MatchString(element.Name) {
5148
newarrPorts = append(newarrPorts, element)
52-
} else if reFilter.MatchString(element.FriendlyName) {
53-
newarrPorts = append(newarrPorts, element)
5449
} else {
5550
log.Debug("serial port did not match. port: %v\n", element)
5651
}

seriallist_darwin.go

+2-56
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
package main
22

33
import (
4-
//"fmt"
5-
//"github.com/tarm/goserial"
6-
log "github.com/Sirupsen/logrus"
7-
"os"
8-
"strings"
9-
//"encoding/binary"
10-
//"strconv"
11-
//"syscall"
12-
//"fmt"
13-
//"bufio"
14-
"io/ioutil"
154
"os/exec"
5+
"strings"
166
)
177

188
// execute system_profiler SPUSBDataType | grep "Vendor ID: 0x2341" -A5 -B2
@@ -32,6 +22,7 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
3222

3323
for index, _ := range ports {
3424
port_hash := strings.Trim(ports[index].Name, "/dev/tty.usbmodem")
25+
port_hash = strings.Trim(port_hash, "/dev/tty.usbserial-")
3526

3627
usbcmd := exec.Command("system_profiler", "SPUSBDataType")
3728
grepcmd := exec.Command("grep", "Location ID: 0x"+port_hash[:len(port_hash)-1], "-B6")
@@ -65,48 +56,3 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
6556
}
6657
return ports
6758
}
68-
69-
func getList() ([]OsSerialPort, os.SyscallError) {
70-
//return getListViaWmiPnpEntity()
71-
return getListViaTtyList()
72-
}
73-
74-
func getListViaTtyList() ([]OsSerialPort, os.SyscallError) {
75-
var err os.SyscallError
76-
77-
log.Println("getting serial list on darwin")
78-
79-
// make buffer of 100 max serial ports
80-
// return a slice
81-
list := make([]OsSerialPort, 100)
82-
83-
files, _ := ioutil.ReadDir("/dev/")
84-
ctr := 0
85-
for _, f := range files {
86-
if strings.HasPrefix(f.Name(), "tty.") {
87-
// it is a legitimate serial port
88-
list[ctr].Name = "/dev/" + f.Name()
89-
list[ctr].FriendlyName = f.Name()
90-
log.Println("Added serial port to list: ", list[ctr])
91-
ctr++
92-
}
93-
// stop-gap in case going beyond 100 (which should never happen)
94-
// i mean, really, who has more than 100 serial ports?
95-
if ctr > 99 {
96-
ctr = 99
97-
}
98-
//fmt.Println(f.Name())
99-
//fmt.Println(f.)
100-
}
101-
/*
102-
list := make([]OsSerialPort, 3)
103-
list[0].Name = "tty.serial1"
104-
list[0].FriendlyName = "tty.serial1"
105-
list[1].Name = "tty.serial2"
106-
list[1].FriendlyName = "tty.serial2"
107-
list[2].Name = "tty.Bluetooth-Modem"
108-
list[2].FriendlyName = "tty.Bluetooth-Modem"
109-
*/
110-
111-
return list[0:ctr], err
112-
}

0 commit comments

Comments
 (0)