Skip to content

Commit ad6fc20

Browse files
committed
add autoupdate and rethink zip package
now depends on github.com/sanbornm/go-selfupdate and the result update files are generated under public/ folder also split listPort between serial (syncronous) and network (async) Former-commit-id: 43c6343eb63dc3399645bc4a952c9791a1b890fc [formerly e3db227f58ab0cbc7167684a3370f5bdb2d2bf9e] Former-commit-id: 14070939f371e58d86f1f25476db7fdf3f012f78
1 parent 5bfc8fd commit ad6fc20

File tree

7 files changed

+593
-122
lines changed

7 files changed

+593
-122
lines changed

Diff for: arduino

Submodule arduino updated 46 files

Diff for: compile_webidebridge.sh

+52-68
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
# git submodule init
22
# git submodule update
33

4+
#dependencies
5+
#go install github.com/sanbornm/go-selfupdate
6+
7+
VERSION=xxx
8+
APP_NAME=Arduino_Create_Bridge
9+
10+
# OUTPUT-COLORING
11+
red='\e[0;31m'
12+
green='\e[0;32m'
13+
NC='\e[0m' # No Color
14+
15+
extractVersionFromMain()
16+
{
17+
VERSION=`grep versionFloat main.go | cut -d "(" -f2 | cut -d ")" -f1`
18+
}
19+
20+
createZipEmbeddableFileArduino()
21+
{
22+
GOOS=$1
23+
GOARCH=$2
24+
25+
# start clean
26+
rm arduino/arduino.zip
27+
rm -r arduino/arduino
28+
mkdir arduino/arduino
29+
cp -r arduino/hardware arduino/tools\_$GOOS\_$GOARCH arduino/boards.json arduino/arduino
30+
cp config.ini arduino
31+
mv arduino/arduino/tools* arduino/arduino/tools
32+
cd arduino
33+
zip -r arduino.zip arduino/* config.ini > /dev/null
34+
cd ..
35+
cat arduino/arduino.zip >> $3
36+
zip --adjust-sfx $3
37+
mkdir -p snapshot/$GOOS\_$GOARCH
38+
cp $3 snapshot/$GOOS\_$GOARCH/$3
39+
ls -la snapshot/$GOOS\_$GOARCH/$3
40+
}
41+
442
bootstrapPlatforms()
543
{
644
#export PATH=$PATH:/home/martino/osxcross/target/bin
@@ -17,84 +55,30 @@ compilePlatform()
1755
GOOS=$1
1856
GOARCH=$2
1957
CC=$3
20-
cp -r arduino/tools_$GOOS arduino/tools
21-
echo "compiling for $GOOS, $GOARCH"
22-
rm snapshot/Arduino_Create_Bridge-$GOOS-$GOARCH.zip
58+
CGO_ENABLED=$4
59+
NAME=$APP_NAME
2360
if [ $GOOS == "windows" ]
2461
then
25-
env GOOS=$GOOS GOARCH=$GOARCH CC=$CC CGO_ENABLED=1 go build -o="Arduino_Create_Bridge.exe"
26-
else
27-
env GOOS=$GOOS GOARCH=$GOARCH CC=$CC CGO_ENABLED=1 go build -o="Arduino_Create_Bridge"
28-
fi
29-
if [ $? != 0 ]
30-
then
31-
echo "Target $GOOS, $GOARCH failed"
32-
exit 1
33-
fi
34-
zip -r snapshot/Arduino_Create_Bridge-$GOOS-$GOARCH.zip arduino/hardware arduino/tools arduino/resources Arduino_Create_Bridge* > /dev/null
35-
rm -rf arduino/tools
36-
rm -rf Arduino_Create_Bridge*
37-
ls -la snapshot/Arduino_Create_Bridge-$GOOS-$GOARCH.zip
38-
}
39-
40-
compilePlatformLinux()
41-
{
42-
GOOS=$1
43-
GOARCH=$2
44-
CC=$3
45-
if [ $GOARCH == "386" ]
46-
then
47-
TOOLS_DIR=32
48-
fi
49-
if [ $GOARCH == "amd64" ]
50-
then
51-
TOOLS_DIR=64
52-
fi
53-
cp -r arduino/tools_$GOOS\_$TOOLS_DIR arduino/tools
54-
echo "compiling for $GOOS, $GOARCH"
55-
rm snapshot/Arduino_Create_Bridge-$GOOS-$GOARCH.zip
56-
env GOOS=$GOOS GOARCH=$GOARCH CC=$CC CGO_ENABLED=1 go build -o="Arduino_Create_Bridge"
57-
if [ $? != 0 ]
58-
then
59-
echo "Target $GOOS, $GOARCH failed"
60-
exit 1
61-
fi
62-
zip -r snapshot/Arduino_Create_Bridge-$GOOS-$GOARCH.zip arduino/hardware arduino/tools arduino/resources Arduino_Create_Bridge > /dev/null
63-
rm -rf arduino/tools
64-
rm -rf Arduino_Create_Bridge*
65-
ls -la snapshot/Arduino_Create_Bridge-$GOOS-$GOARCH.zip
66-
}
67-
68-
compilePlatformNoCGO()
69-
{
70-
GOOS=$1
71-
GOARCH=$2
72-
cp -r arduino/tools_$GOOS\_$GOARCH arduino/tools
73-
echo "compiling for $GOOS, $GOARCH"
74-
rm snapshot/Arduino_Create_Bridge-$GOOS-$GOARCH.zip
75-
if [ $GOARCH == "arm" ]
76-
then
77-
env GOARM=6 GOOS=$GOOS GOARCH=$GOARCH go build -o="Arduino_Create_Bridge"
78-
else
79-
env GOOS=$GOOS GOARCH=$GOARCH go build -o="Arduino_Create_Bridge"
62+
NAME=$NAME".exe"
8063
fi
64+
echo -e "${green}=== Compiling for $GOOS, $GOARCH ===${NC}"
65+
env GOOS=$GOOS GOARCH=$GOARCH CC=$CC CGO_ENABLED=$CGO_ENABLED go build -o=$NAME
8166
if [ $? != 0 ]
8267
then
83-
echo "Target $GOOS, $GOARCH failed"
68+
echo -e "${red}Target $GOOS, $GOARCH failed${NC}"
8469
exit 1
8570
fi
86-
zip -r snapshot/Arduino_Create_Bridge-$GOOS-$GOARCH.zip arduino/hardware arduino/tools arduino/resources Arduino_Create_Bridge > /dev/null
87-
rm -rf arduino/tools
88-
rm -rf Arduino_Create_Bridge*
89-
ls -la snapshot/Arduino_Create_Bridge-$GOOS-$GOARCH.zip
71+
createZipEmbeddableFileArduino $GOOS $GOARCH $NAME
72+
GOOS=$GOOS GOARCH=$GOARCH go-selfupdate $NAME $VERSION
73+
rm -rf $NAME*
9074
}
9175

92-
rm -rf arduino/tools
93-
compilePlatform darwin amd64 o64-clang
76+
extractVersionFromMain
77+
compilePlatform darwin amd64 o64-clang 1
9478
#compilePlatformLinux linux 386 gcc
95-
compilePlatformLinux linux amd64 gcc
96-
compilePlatformNoCGO linux arm
97-
compilePlatform windows 386 i686-w64-mingw32-gcc
79+
compilePlatform linux amd64 gcc 1
80+
compilePlatform linux arm 0
81+
compilePlatform windows 386 i686-w64-mingw32-gcc 1
9882

9983

10084
exit 0

Diff for: config.ini

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
addr = :8990 # http service address
2+
bufflowdebug = off # off = (default) We do not send back any debug JSON, on = We will send back a JSON response with debug info based on the configuration of the buffer flow that the user picked
3+
configUpdateInterval = 0 # Update interval for re-reading config file set via -config flag. Zero disables config file re-reading.
4+
gc = std # Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)
5+
hostname = unknown-hostname # Override the hostname we get from the OS
6+
ls = false # launch self 5 seconds later
7+
regex = usb|acm|com # Regular expression to filter serial port list
8+
v = true # show debug logging
9+
appName = Arduino_Create_Bridge
10+
updateUrl = http://localhost/

Diff for: main.go

+63-22
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,28 @@ import (
1212
"net"
1313
"net/http"
1414
"os"
15+
"path/filepath"
1516
//"net/http/pprof"
17+
"github.com/kardianos/osext"
18+
//"github.com/sanbornm/go-selfupdate/selfupdate" #included in update.go to change heavily
19+
//"github.com/sanderhahn/gozip"
20+
"github.com/vharitonsky/iniflags"
1621
"runtime/debug"
1722
"text/template"
1823
"time"
1924
)
2025

2126
var (
22-
version = "1.82"
23-
versionFloat = float32(1.82)
27+
version = "1.83"
28+
versionFloat = float32(1.83)
2429
addr = flag.String("addr", ":8989", "http service address")
2530
//assets = flag.String("assets", defaultAssetPath(), "path to assets")
2631
verbose = flag.Bool("v", true, "show debug logging")
2732
//verbose = flag.Bool("v", false, "show debug logging")
2833
//homeTempl *template.Template
2934
isLaunchSelf = flag.Bool("ls", false, "launch self 5 seconds later")
3035

36+
configIni = flag.String("configFile", "config.ini", "config file path")
3137
// regular expression to sort the serial port list
3238
// typically this wouldn't be provided, but if the user wants to clean
3339
// up their list with a regexp so it's cleaner inside their end-user interface
@@ -45,6 +51,9 @@ var (
4551

4652
// hostname. allow user to override, otherwise we look it up
4753
hostname = flag.String("hostname", "unknown-hostname", "Override the hostname we get from the OS")
54+
55+
updateUrl = flag.String("updateUrl", "", "")
56+
appName = flag.String("appName", "", "")
4857
)
4958

5059
type NullWriter int
@@ -72,16 +81,48 @@ func launchSelfLater() {
7281

7382
func main() {
7483

75-
flag.Parse()
76-
// setup logging
77-
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
84+
go func() {
7885

79-
// see if we are supposed to wait 5 seconds
80-
if *isLaunchSelf {
81-
launchSelfLater()
82-
}
86+
// autoextract self
87+
src, _ := osext.Executable()
88+
dest := filepath.Dir(src)
89+
err := Unzip(src, dest)
90+
fmt.Println("Self extraction, err:", err)
91+
92+
if _, err := os.Stat(*configIni); os.IsNotExist(err) {
93+
flag.Parse()
94+
fmt.Println("No config.ini at", *configIni)
95+
} else {
96+
flag.Set("config", *configIni)
97+
iniflags.Parse()
98+
}
99+
100+
// setup logging
101+
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
102+
103+
// see if we are supposed to wait 5 seconds
104+
if *isLaunchSelf {
105+
launchSelfLater()
106+
}
107+
108+
var updater = &Updater{
109+
CurrentVersion: version,
110+
ApiURL: *updateUrl,
111+
BinURL: *updateUrl,
112+
DiffURL: "",
113+
Dir: "update/",
114+
CmdName: *appName,
115+
}
116+
117+
if updater != nil {
118+
go updater.BackgroundRun()
119+
}
120+
121+
// data, err := Asset("arduino.zip")
122+
// if err != nil {
123+
// log.Println("arduino tools not found")
124+
// }
83125

84-
go func() {
85126
//getList()
86127
f := flag.Lookup("addr")
87128
log.Println("Version:" + version)
@@ -122,19 +163,19 @@ func main() {
122163
}
123164

124165
// list serial ports
125-
// portList, _ := GetList()
126-
// /*if errSys != nil {
127-
// log.Printf("Got system error trying to retrieve serial port list. Err:%v\n", errSys)
128-
// log.Fatal("Exiting")
129-
// }*/
130-
// log.Println("Your serial ports:")
131-
// if len(portList) == 0 {
132-
// log.Println("\tThere are no serial ports to list.")
133-
// }
134-
// for _, element := range portList {
135-
// log.Printf("\t%v\n", element)
166+
portList, _ := GetList(false)
167+
/*if errSys != nil {
168+
log.Printf("Got system error trying to retrieve serial port list. Err:%v\n", errSys)
169+
log.Fatal("Exiting")
170+
}*/
171+
log.Println("Your serial ports:")
172+
if len(portList) == 0 {
173+
log.Println("\tThere are no serial ports to list.")
174+
}
175+
for _, element := range portList {
176+
log.Printf("\t%v\n", element)
136177

137-
// }
178+
}
138179

139180
if !*verbose {
140181
log.Println("You can enter verbose mode to see all logging by starting with the -v command line switch.")

Diff for: serial.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,14 @@ func writeToChannels(cmds []string, idArr []string, bufTypeArr []string) {
415415
}
416416

417417
func spList() {
418+
go spListDual(true)
419+
go spListDual(false)
420+
}
421+
422+
func spListDual(network bool) {
418423

419424
// call our os specific implementation of getting the serial list
420-
list, _ := GetList(true)
425+
list, _ := GetList(network)
421426

422427
// do a quick loop to see if any of our open ports
423428
// did not end up in the list port list. this can

Diff for: seriallist.go

+30-30
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,42 @@ func GetList(network bool) ([]OsSerialPort, error) {
2626

2727
//log.Println("Doing GetList()")
2828

29-
// will timeout in 2 seconds
30-
ports, err := serial.GetPortsList()
29+
if network {
30+
netportList, err := GetNetworkList()
31+
return netportList, err
32+
} else {
3133

32-
arrPorts := []OsSerialPort{}
33-
for _, element := range ports {
34-
arrPorts = append(arrPorts, OsSerialPort{Name: element, FriendlyName: element})
35-
}
34+
// will timeout in 2 seconds
35+
ports, err := serial.GetPortsList()
3636

37-
// see if we should filter the list
38-
if len(*regExpFilter) > 0 {
39-
// yes, user asked for a filter
40-
reFilter := regexp.MustCompile("(?i)" + *regExpFilter)
37+
arrPorts := []OsSerialPort{}
38+
for _, element := range ports {
39+
arrPorts = append(arrPorts, OsSerialPort{Name: element, FriendlyName: element})
40+
}
4141

42-
newarrPorts := []OsSerialPort{}
43-
for _, element := range arrPorts {
44-
// if matches regex, include
45-
if reFilter.MatchString(element.Name) {
46-
newarrPorts = append(newarrPorts, element)
47-
} else if reFilter.MatchString(element.FriendlyName) {
48-
newarrPorts = append(newarrPorts, element)
49-
} else {
50-
log.Printf("serial port did not match. port: %v\n", element)
51-
}
42+
// see if we should filter the list
43+
if len(*regExpFilter) > 0 {
44+
// yes, user asked for a filter
45+
reFilter := regexp.MustCompile("(?i)" + *regExpFilter)
5246

53-
}
54-
arrPorts = newarrPorts
55-
}
47+
newarrPorts := []OsSerialPort{}
48+
for _, element := range arrPorts {
49+
// if matches regex, include
50+
if reFilter.MatchString(element.Name) {
51+
newarrPorts = append(newarrPorts, element)
52+
} else if reFilter.MatchString(element.FriendlyName) {
53+
newarrPorts = append(newarrPorts, element)
54+
} else {
55+
log.Printf("serial port did not match. port: %v\n", element)
56+
}
5657

57-
arrPorts = removeNonArduinoBoards(arrPorts)
58+
}
59+
arrPorts = newarrPorts
60+
}
5861

59-
if network {
60-
netportList, _ := GetNetworkList()
61-
arrPorts = append(arrPorts, netportList...)
62+
arrPorts = removeNonArduinoBoards(arrPorts)
63+
return arrPorts, err
64+
//log.Printf("Done doing GetList(). arrPorts:%v\n", arrPorts)
6265
}
6366

64-
//log.Printf("Done doing GetList(). arrPorts:%v\n", arrPorts)
65-
66-
return arrPorts, err
6767
}

0 commit comments

Comments
 (0)