Skip to content

Commit 34455ab

Browse files
committed
Merge branch 'devel'
2 parents fb6ad13 + 17e2075 commit 34455ab

16 files changed

+185
-35
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "arduino"]
2-
path = arduino
3-
url = https://github.com/facchinm/arduino-flash-tools

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Please use the current latest version:
2323

2424
## Submitting an issue
2525

26-
Please attach the output of the commands running at http://localhost:8989 if useful.
26+
Please attach the output of the commands running at the debug console if useful.
2727

2828
## Submitting a pull request
2929

arduino

Lines changed: 0 additions & 1 deletion
This file was deleted.

bufferflow.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
//"time"
66
)
77

8-
var availableBufferAlgorithms = []string{"default"}
8+
var availableBufferAlgorithms = []string{"default", "timed"}
99

1010
type BufferMsg struct {
1111
Cmd string
@@ -16,6 +16,7 @@ type BufferMsg struct {
1616
}
1717

1818
type Bufferflow interface {
19+
Init()
1920
BlockUntilReady(cmd string, id string) (bool, bool) // implement this method
2021
//JustQueue(cmd string, id string) bool // implement this method
2122
OnIncomingData(data string) // implement this method

bufferflow_timed.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"time"
6+
7+
log "github.com/Sirupsen/logrus"
8+
)
9+
10+
type BufferflowTimed struct {
11+
Name string
12+
Port string
13+
Output chan []byte
14+
Input chan string
15+
ticker *time.Ticker
16+
}
17+
18+
var (
19+
bufferedOutput string
20+
)
21+
22+
func (b *BufferflowTimed) Init() {
23+
log.Println("Initting timed buffer flow (output once every 16ms)")
24+
bufferedOutput = ""
25+
26+
go func() {
27+
for data := range b.Input {
28+
bufferedOutput = bufferedOutput + data
29+
}
30+
}()
31+
32+
go func() {
33+
b.ticker = time.NewTicker(16 * time.Millisecond)
34+
for _ = range b.ticker.C {
35+
if bufferedOutput != "" {
36+
m := SpPortMessage{bufferedOutput}
37+
buf, _ := json.Marshal(m)
38+
b.Output <- []byte(buf)
39+
bufferedOutput = ""
40+
}
41+
}
42+
}()
43+
44+
}
45+
46+
func (b *BufferflowTimed) BlockUntilReady(cmd string, id string) (bool, bool) {
47+
//log.Printf("BlockUntilReady() start\n")
48+
return true, false
49+
}
50+
51+
func (b *BufferflowTimed) OnIncomingData(data string) {
52+
b.Input <- data
53+
}
54+
55+
// Clean out b.sem so it can truly block
56+
func (b *BufferflowTimed) ClearOutSemaphore() {
57+
}
58+
59+
func (b *BufferflowTimed) BreakApartCommands(cmd string) []string {
60+
return []string{cmd}
61+
}
62+
63+
func (b *BufferflowTimed) Pause() {
64+
return
65+
}
66+
67+
func (b *BufferflowTimed) Unpause() {
68+
return
69+
}
70+
71+
func (b *BufferflowTimed) SeeIfSpecificCommandsShouldSkipBuffer(cmd string) bool {
72+
return false
73+
}
74+
75+
func (b *BufferflowTimed) SeeIfSpecificCommandsShouldPauseBuffer(cmd string) bool {
76+
return false
77+
}
78+
79+
func (b *BufferflowTimed) SeeIfSpecificCommandsShouldUnpauseBuffer(cmd string) bool {
80+
return false
81+
}
82+
83+
func (b *BufferflowTimed) SeeIfSpecificCommandsShouldWipeBuffer(cmd string) bool {
84+
return false
85+
}
86+
87+
func (b *BufferflowTimed) SeeIfSpecificCommandsReturnNoResponse(cmd string) bool {
88+
return false
89+
}
90+
91+
func (b *BufferflowTimed) ReleaseLock() {
92+
}
93+
94+
func (b *BufferflowTimed) IsBufferGloballySendingBackIncomingData() bool {
95+
return true
96+
}
97+
98+
func (b *BufferflowTimed) Close() {
99+
b.ticker.Stop()
100+
close(b.Input)
101+
}

compile_webidebridge.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ createZipEmbeddableFileArduino()
3232
cp fakecerts/*.pem arduino/
3333
mv arduino/arduino/tools* arduino/arduino/tools
3434
cd arduino
35-
zip -r arduino.zip arduino/* config.ini *.pem > /dev/null
35+
zip -r arduino.zip config.ini *.pem > /dev/null
3636
cd ..
3737
#cat arduino/arduino.zip >> $3
3838
#zip --adjust-sfx $3

config.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
addr = :8989 # http service address
21
configUpdateInterval = 0 # Update interval for re-reading config file set via -config flag. Zero disables config file re-reading.
32
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)
43
hostname = unknown-hostname # Override the hostname we get from the OS

download.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ func spDownloadTool(name string, url string) {
110110
log.Info("Tool already present, skipping download")
111111
}
112112

113-
// will be something like ${tempfolder}/avrdude/bin/avrdude
114-
globalToolsMap["{runtime.tools."+name+".path}"] = filepath.ToSlash(tempToolsPath + "/" + name)
113+
folders, _ := ioutil.ReadDir(tempToolsPath)
114+
for _, f := range folders {
115+
globalToolsMap["{runtime.tools."+f.Name()+".path}"] = filepath.ToSlash(tempToolsPath + "/" + f.Name())
116+
}
115117

116118
log.Info("Map Updated")
117119
mapD := map[string]string{"DownloadStatus": "Success", "Msg": "Map Updated"}

hub.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func checkCmd(m []byte) {
197197
} else if strings.HasPrefix(sl, "broadcast") {
198198
go broadcast(s)
199199
} else if strings.HasPrefix(sl, "restart") {
200+
log.Println("Received restart from the daemon. Why? Boh")
200201
restart("")
201202
} else if strings.HasPrefix(sl, "exit") {
202203
exit()
@@ -266,6 +267,7 @@ func exit() {
266267
}
267268

268269
func restart(path string) {
270+
log.Println("called restart", path)
269271
// relaunch ourself and exit
270272
// the relaunch works because we pass a cmdline in
271273
// that has serial-port-json-server only initialize 5 seconds later
@@ -321,7 +323,7 @@ func restart(path string) {
321323
hiberString = "-hibernate"
322324
}
323325

324-
cmd = exec.Command(exePath, "-ls", "-addr", *addr, "-regex", *regExpFilter, "-gc", *gcType, hiberString)
326+
cmd = exec.Command(exePath, "-ls", "-regex", *regExpFilter, "-gc", *gcType, hiberString)
325327

326328
fmt.Println(cmd)
327329

info.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
)
6+
7+
func infoHandler(c *gin.Context) {
8+
c.JSON(200, gin.H{
9+
"http": "http://localhost" + port,
10+
"https": "https://localhost" + port,
11+
"ws": "ws://localhost" + port,
12+
"wss": "wss://localhost" + portSSL,
13+
})
14+
}

main.go

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ package main
55

66
import (
77
"flag"
8-
log "github.com/Sirupsen/logrus"
9-
"github.com/carlescere/scheduler"
10-
"github.com/gin-gonic/gin"
11-
"github.com/itsjamie/gin-cors"
12-
"github.com/kardianos/osext"
13-
"github.com/vharitonsky/iniflags"
148
"os"
159
"os/user"
1610
"path/filepath"
1711
"runtime/debug"
12+
"strconv"
1813
"text/template"
1914
"time"
15+
16+
log "github.com/Sirupsen/logrus"
17+
"github.com/carlescere/scheduler"
18+
"github.com/gin-gonic/gin"
19+
"github.com/itsjamie/gin-cors"
20+
"github.com/kardianos/osext"
21+
"github.com/vharitonsky/iniflags"
2022
//"github.com/sanbornm/go-selfupdate/selfupdate" #included in update.go to change heavily
2123
)
2224

@@ -26,8 +28,6 @@ var (
2628
embedded_autoupdate = true
2729
embedded_autoextract = false
2830
hibernate = flag.Bool("hibernate", false, "start hibernated")
29-
addr = flag.String("addr", ":8989", "http service address")
30-
addrSSL = flag.String("addrSSL", ":8990", "https service address")
3131
verbose = flag.Bool("v", true, "show debug logging")
3232
//verbose = flag.Bool("v", false, "show debug logging")
3333
isLaunchSelf = flag.Bool("ls", false, "launch self 5 seconds later")
@@ -41,6 +41,8 @@ var (
4141
appName = flag.String("appName", "", "")
4242
globalToolsMap = make(map[string]string)
4343
tempToolsPath = createToolsDir()
44+
port string
45+
portSSL string
4446
)
4547

4648
type NullWriter int
@@ -137,7 +139,6 @@ func main() {
137139
}
138140
}
139141

140-
f := flag.Lookup("addr")
141142
log.Println("Version:" + version)
142143

143144
// hostname
@@ -159,11 +160,6 @@ func main() {
159160
debug.SetGCPercent(-1)
160161
}
161162

162-
ip := "0.0.0.0"
163-
log.Print("Starting server and websocket on " + ip + "" + f.Value.String())
164-
165-
log.Println("The Arduino Create Agent is now running")
166-
167163
// see if they provided a regex filter
168164
if len(*regExpFilter) > 0 {
169165
log.Printf("You specified a serial port regular expression filter: %v\n", *regExpFilter)
@@ -214,17 +210,43 @@ func main() {
214210
r.POST("/socket.io/", socketHandler)
215211
r.Handle("WS", "/socket.io/", socketHandler)
216212
r.Handle("WSS", "/socket.io/", socketHandler)
213+
r.GET("/info", infoHandler)
217214
go func() {
218-
if err := r.RunTLS(*addrSSL, filepath.Join(dest, "cert.pem"), filepath.Join(dest, "key.pem")); err != nil {
219-
log.Printf("Error trying to bind to port: %v, so exiting...", err)
220-
log.Fatal("Error ListenAndServe:", err)
215+
start := 8990
216+
end := 9000
217+
i := start
218+
for i < end {
219+
i = i + 1
220+
portSSL = ":" + strconv.Itoa(i)
221+
if err := r.RunTLS(portSSL, filepath.Join(dest, "cert.pem"), filepath.Join(dest, "key.pem")); err != nil {
222+
log.Printf("Error trying to bind to port: %v, so exiting...", err)
223+
continue
224+
} else {
225+
ip := "0.0.0.0"
226+
log.Print("Starting server and websocket (SSL) on " + ip + "" + port)
227+
break
228+
}
229+
}
230+
}()
231+
232+
go func() {
233+
start := 8990
234+
end := 9000
235+
i := start
236+
for i < end {
237+
i = i + 1
238+
port = ":" + strconv.Itoa(i)
239+
if err := r.Run(port); err != nil {
240+
log.Printf("Error trying to bind to port: %v, so exiting...", err)
241+
continue
242+
} else {
243+
ip := "0.0.0.0"
244+
log.Print("Starting server and websocket on " + ip + "" + port)
245+
break
246+
}
221247
}
222248
}()
223249

224-
if err := r.Run(*addr); err != nil {
225-
log.Printf("Error trying to bind to port: %v, so exiting...", err)
226-
log.Fatal("Error ListenAndServe:", err)
227-
}
228250
}()
229251
}
230252
setupSysTray()

seriallist_darwin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ func associateVidPidWithPort(ports []OsSerialPort) []OsSerialPort {
2424
port_hash := strings.Trim(ports[index].Name, "/dev/tty.usbmodem")
2525
port_hash = strings.Trim(port_hash, "/dev/tty.usbserial-")
2626

27+
port_hash = strings.ToLower(port_hash)
28+
2729
usbcmd := exec.Command("system_profiler", "SPUSBDataType")
2830
grepcmd := exec.Command("grep", "Location ID: 0x"+port_hash[:len(port_hash)-1], "-B6")
2931
cmdOutput, _ := pipe_commands(usbcmd, grepcmd)

serialport.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,15 @@ func spHandlerOpen(portname string, baud int, buftype string, isSecondary bool)
340340
// we can go up to 256,000 lines of gcode in the buffer
341341
p := &serport{sendBuffered: make(chan Cmd, 256000), sendNoBuf: make(chan Cmd), portConf: conf, portIo: sp, BufferType: buftype, IsPrimary: isPrimary, IsSecondary: isSecondary}
342342

343-
bw := &BufferflowDefault{}
343+
var bw Bufferflow
344+
345+
if buftype == "timed" {
346+
bw = &BufferflowTimed{Name: "timed", Port: portname, Output: h.broadcastSys, Input: make(chan string)}
347+
} else {
348+
bw = &BufferflowDefault{Port: portname}
349+
}
350+
344351
bw.Init()
345-
bw.Port = portname
346352
p.bufferwatcher = bw
347353

348354
sh.register <- p

skel/ArduinoCreateAgent.app.zip

96.8 KB
Binary file not shown.

trayicon.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func addRebootTrayElement() {
5555
<-reboot_tray.ClickedCh
5656
systray.Quit()
5757
log.Println("Restarting now...")
58+
log.Println("Restart because addReebotTrayElement")
5859
restart("")
5960
}()
6061
}
@@ -78,6 +79,7 @@ func setupSysTrayReal() {
7879
}
7980
systray.Quit()
8081
*hibernate = true
82+
log.Println("Restart becayse setup went wrong?")
8183
restart("")
8284
}()
8385

@@ -91,7 +93,7 @@ func setupSysTrayReal() {
9193
for {
9294
<-mDebug.ClickedCh
9395
logAction("log on")
94-
open.Start("http://localhost:8989")
96+
open.Start("http://localhost" + port)
9597
}
9698
}()
9799

@@ -113,6 +115,7 @@ func setupSysTrayHibernate() {
113115
go func() {
114116
<-mOpen.ClickedCh
115117
*hibernate = false
118+
log.Println("Restart for hubernation")
116119
restart("")
117120
}()
118121

update.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ func (u *Updater) update() error {
325325
//shutil.CopyFile(*configIni, *configIni+".bak", false)
326326
//os.Remove(*configIni)
327327

328+
log.Println("Restarting because update!")
329+
328330
restart(path)
329331
//addRebootTrayElement()
330332

0 commit comments

Comments
 (0)