Skip to content

Commit d47afcd

Browse files
committed
Merge branch 'devel' into updater
2 parents 8d60ac4 + 83bc945 commit d47afcd

8 files changed

+243
-35
lines changed

.drone.sec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.js55JcNOTOEYUK7TvkYbNUbvZvoKkze6nB0ql2b3ZWkMn6LGRdlfo3e7ktMiRf8e9RAffm86SQSEMorTw78h8iFmub7JI0Z8Xwm1A960SmkW-ULLrzE0uT6il7_pYzjOAxboUiH0ToCElvsTYEUBicc7p4a3gIhgZAezd1w52JIYxzbFQ0ca0fws3KH3H4iR6-N0d7Cc5xEXFIzHgH_OhJUXYiaCW-g5GLgbPQPu29Ofv3-_sZzXTJj4VSjvgRNzkudJieM5KjN_5L9KU6wSJyGECVsTd-kaM0yOesl9NbWq-6SMORIK43kBEgu679OWuMzJ6HbbW6Bk5I8XQASp0w.FvNQmCS3b0mq8MGN.uS9nMU1WjTWxIvkOr41zAGp6OY7MzxWQ2KteBaRm9hE3XDSWvOAwVO7i6BJOQNUX--SMCBs6tdhYyaC-x7PSGze0Ki33LU7pPc-yBhbLUdzGrxYLm1JF_IQ5QlVK2YRk5nFRSIimzylsPEkGHCd-nQciHC_m0Wetzldb-d49MNw6wZFsby8MQKVQJoWUVXM7LM-jZ5tmAmzxV1S0Py6LqUT7AAGL2RNax22YsNaOY214KTiSnIrT8eo3zmvzi28CdsapOIYxCFP8Z_JUAkjYAuow5ysxFkVvEGxr9d-W8TCyL36Sa4GgfEVvtzpcKpVmhzMllIXiXVh8ZdLJ_EuWomNSV_9veIy_ULmKo8B8tB6Uv2nlnFqGAxaf5DNYcqqQj4isHpEWFSR0ZIGU5ksoH_bY0pzQsf3wwii3KlzOJg.7WbHe_TOAdzgMW16sBvzIg
1+
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.pr9ZMRbPGFZ6rTQOAmHQJN4RRE8Hmnl6Sn6ek2DogiLA6qIZCCei6RHLppto2tpM1ApM5pLpW64TjGf_mCLIesk_GtnUF6baxrHodcI8EB3VV3CsXU3EJF3_FOk3uSJUOi7hbtn54ztMBL2QKeccUiO-KBC2BHiD8VVpjnY5C-TLYV-1Td2fUZc3QB4eoqeTlvglu0nSvHHGCL89RQU0ZEW_-h_tXXaDrvXS648g-U2B9uwnVgBgBPhQqOzP02cW2-ojgkAC7xNpO_BOWoYouT56kkeM5MEx1XyJ-tAdP0AU8mG3x6mRBbng2nwTiXt9RqIJ01RKysMdgth17SZQ8A.apeQnLTu98uqD1Xl.se-xrnl2-B63chHdq719TO98hjxVIN6qTkCnTv5y__LM7ku-FBmlUnZLKy6jDZfO3Fz0jUNwSxuU2LGJWuJ5-PEQkqhsjJuDNBbrAKbt9oqFpXUKXOyu5yw8f64GHgG0bmlrZS6X04P4JAx6t9pXE0rKV5yktoYLLcTgoHnWm3C8eX7H1ayewDJ_CD2ricdZ5J-YAe4sz1AR2mRPRiyx-LTheTc2sALqZv39_ctOI9weNIGy013Jc_6MchmERmT2c4QKlIhy2ra9CPZsOgyn6d008qse14Q32IP97VJ3KLCq69P7u3y28KGz6btjfurLFP1EuipKhWxpIsE4YWQcf_l-eXxpd-l2SUPFMMNBI6aXItKpPofgjMAPeJzlIkhkXCtfRRWIgDaHlS_eAk0nWaXSQyUljUnR7qaVyCqh.FAYZK3PkD_9u3cXwsD8WSw

.drone.yml

+47-24
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,42 @@
11
build:
2-
image: arduino/golang-linux-32
3-
commands:
4-
- apt-get update && apt-get install libgtk-3-dev libappindicator3-dev
5-
- GOOS=linux GOARCH=386 CC=gcc CXX=gcc CGO_ENABLED=1 go build -o artifacts/linux-386/arduino-create-agent
6-
- cp config.ini artifacts/linux-386
7-
build:
8-
image: arduino/golang-cross
9-
auth_config:
10-
username: $$DOCKER_USERNAME
11-
password: $$DOCKER_PASSWORD
12-
email: $$DOCKER_EMAIL
13-
commands:
14-
- apt-get update && apt-get install libgtk-3-dev libappindicator3-dev zip
15-
# Linux amd64
16-
- GOOS=linux GOARCH=amd64 CC=gcc CXX=gcc CGO_ENABLED=1 go build -o artifacts/linux-amd64/arduino-create-agent
17-
- cp config.ini artifacts/linux-amd64
18-
# Darwin amd64
19-
- GOOS=darwin GOARCH=amd64 CC=o64-clang CXX=o64-clang CGO_ENABLED=1 go build -o artifacts/osx/arduino-create-agent
20-
- cp config.ini artifacts/osx
21-
# Windows 386
22-
- GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-gcc CGO_ENABLED=1 go build -o artifacts/windows/arduino-create-agent.exe -ldflags -H=windowsgui
23-
- cp config.ini artifacts/windows
24-
- zip -r arduino-create-agent.zip artifacts/*
2+
crosscompilation:
3+
image: arduino/golang-cross
4+
auth_config:
5+
username: $$DOCKER_USERNAME
6+
password: $$DOCKER_PASSWORD
7+
email: $$DOCKER_EMAIL
8+
commands:
9+
- go get github.com/kardianos/govendor
10+
- govendor vet +local
11+
- govendor test +local
12+
# Linux amd64
13+
- GOOS=linux GOARCH=amd64 CC=gcc CXX=gcc CGO_ENABLED=1 go build -o artifacts/linux-amd64/arduino-create-agent
14+
- cp config.ini artifacts/linux-amd64
15+
# Darwin amd64
16+
- GOOS=darwin GOARCH=amd64 CC=o64-clang CXX=o64-clang CGO_ENABLED=1 go build -o artifacts/osx/arduino-create-agent
17+
- cp config.ini artifacts/osx
18+
# Windows 386
19+
- GOOS=windows GOARCH=386 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-gcc CGO_ENABLED=1 go build -o artifacts/windows/arduino-create-agent.exe -ldflags -H=windowsgui
20+
- cp config.ini artifacts/windows
21+
- zip -r arduino-create-agent.zip artifacts/*
22+
linux32:
23+
image: arduino/golang-linux-32
24+
commands:
25+
- GOOS=linux GOARCH=386 CC=gcc CXX=gcc CGO_ENABLED=1 go build -o artifacts/linux-386/arduino-create-agent
26+
- cp config.ini artifacts/linux-386
2527
notify:
2628
slack:
2729
webhook_url: $$SLACK_WEBHOOK
2830
channel: $$SLACK_CHANNEL
2931
username: drone
32+
when:
33+
event: pull_request
34+
template: |
35+
{{#success build.status}}
36+
[{{ repo.name}}] Congrats {{ build.author }}! Your PR works: {{ build.link_url}}
37+
{{else}}
38+
[{{ repo.name}}] Damn {{ build.author }}! Something went wrong with your PR: {{ build.link_url}}
39+
{{/success}}
3040
publish:
3141
github_release:
3242
api_key: $$GITHUB_API_KEY
@@ -35,4 +45,17 @@ publish:
3545
checksum:
3646
- md5
3747
when:
38-
branch: [master, devel, test]
48+
event: tag
49+
notify:
50+
slack:
51+
webhook_url: $$SLACK_WEBHOOK
52+
channel: $$SLACK_CHANNEL
53+
username: drone
54+
when:
55+
event: tag
56+
template: |
57+
{{#success build.status}}
58+
[{{ repo.name}}/{{ build.branch }}] A new release is available: {{ build.link_url}}
59+
{{else}}
60+
[{{ repo.name}}/{{ build.branch }}] Something went wrong while building a new release: {{ build.link_url}}
61+
{{/success}}

bufferflow.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
//"time"
66
)
77

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

1010
type BufferMsg struct {
1111
Cmd string

bufferflow_timedraw.go

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

hub.go

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ func checkCmd(m []byte) {
171171
// kill the running process (assumes singleton for now)
172172
go spHandlerProgramKill()
173173

174+
} else if strings.HasPrefix(sl, "sendjsonraw") {
175+
// will catch sendjsonraw
176+
go spWriteJsonRaw(s)
177+
174178
} else if strings.HasPrefix(sl, "sendjson") {
175179
// will catch sendjson
176180
go spWriteJson(s)

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ const homeTemplateHtml = `<!DOCTYPE html>
315315
return false;
316316
}
317317
socket.emit("command", msg.val());
318-
if (msg.val().indexOf("log off") != -1) {only_log = true;}
319-
if (msg.val().indexOf("log on") != -1) {only_log = false;}
318+
if (msg.val().indexOf("log off") != -1) {only_log = true}
319+
if (msg.val().indexOf("log on") != -1) {only_log = false}
320320
msg.val("");
321321
return false
322322
});

serial.go

+79-7
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,24 @@ type writeRequestJson struct {
2626
Data []writeRequestJsonData
2727
}
2828

29+
type writeRequestJsonRaw struct {
30+
p *serport
31+
P string
32+
Data []writeRequestJsonDataRaw
33+
}
34+
2935
type writeRequestJsonData struct {
3036
D string
3137
Id string
3238
Buf string
3339
}
3440

41+
type writeRequestJsonDataRaw struct {
42+
D []byte
43+
Id string
44+
Buf string
45+
}
46+
3547
type qReportJson struct {
3648
Cmd string
3749
QCnt int
@@ -73,7 +85,8 @@ type serialhub struct {
7385
unregister chan *serport
7486

7587
// regexp for json trimming
76-
reJsonTrim *regexp.Regexp
88+
reJsonTrim *regexp.Regexp
89+
reJsonRawTrim *regexp.Regexp
7790
}
7891

7992
type SpPortList struct {
@@ -103,12 +116,13 @@ var NetworkPorts SpPortList
103116

104117
var sh = serialhub{
105118
//write: make(chan *serport, chan []byte),
106-
write: make(chan writeRequest),
107-
writeJson: make(chan writeRequestJson),
108-
register: make(chan *serport),
109-
unregister: make(chan *serport),
110-
ports: make(map[*serport]bool),
111-
reJsonTrim: regexp.MustCompile("sendjson"),
119+
write: make(chan writeRequest),
120+
writeJson: make(chan writeRequestJson),
121+
register: make(chan *serport),
122+
unregister: make(chan *serport),
123+
ports: make(map[*serport]bool),
124+
reJsonTrim: regexp.MustCompile("sendjson"),
125+
reJsonRawTrim: regexp.MustCompile("sendjsonraw"),
112126
}
113127

114128
func (sh *serialhub) run() {
@@ -615,6 +629,64 @@ func spWriteJson(arg string) {
615629
sh.writeJson <- m
616630
}
617631

632+
func spWriteJsonRaw(arg string) {
633+
634+
log.Printf("spWriteJson. arg:%v\n", arg)
635+
636+
// remove sendjson string
637+
arg = sh.reJsonRawTrim.ReplaceAllString(arg, "")
638+
//log.Printf("string we're going to parse:%v\n", arg)
639+
640+
// this is a structured command now for sending in serial commands multiple at a time
641+
// with an ID so we can send back the ID when the command is done
642+
var m writeRequestJsonRaw
643+
/*
644+
m.P = "COM22"
645+
var data writeRequestJsonData
646+
data.Id = "234"
647+
str := "yeah yeah"
648+
data.D = str //[]byte(str) //[]byte(string("blah blah"))
649+
m.Data = append(m.Data, data)
650+
//m.Data = append(m.Data, data)
651+
bm, err2 := json.Marshal(m)
652+
if err2 == nil {
653+
log.Printf("Test json serialize:%v\n", string(bm))
654+
}
655+
*/
656+
657+
err := json.Unmarshal([]byte(arg), &m)
658+
659+
if err != nil {
660+
log.Printf("Problem decoding json. giving up. json:%v, err:%v\n", arg, err)
661+
spErr(fmt.Sprintf("Problem decoding json. giving up. json:%v, err:%v", arg, err))
662+
return
663+
}
664+
665+
// see if we have this port open
666+
portname := m.P
667+
myport, isFound := findPortByName(portname)
668+
669+
if !isFound {
670+
// we couldn't find the port, so send err
671+
spErr("We could not find the serial port " + portname + " that you were trying to write to.")
672+
return
673+
}
674+
675+
// we found our port
676+
m.p = myport
677+
678+
var mr writeRequestJson
679+
680+
mr.p = m.p
681+
mr.P = m.P
682+
var data writeRequestJsonData
683+
data.D = string(m.Data[0].D)
684+
mr.Data = append(mr.Data, data)
685+
686+
// send it to the writeJson channel
687+
sh.writeJson <- mr
688+
}
689+
618690
func spWrite(arg string) {
619691
// we will get a string of comXX asdf asdf asdf
620692
log.Println("Inside spWrite arg: " + arg)

serialport.go

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ type SpPortMessage struct {
8888
D string // the data, i.e. G0 X0 Y0
8989
}
9090

91+
type SpPortMessageRaw struct {
92+
// P string // the port, i.e. com22
93+
D []byte // the data, i.e. G0 X0 Y0
94+
}
95+
9196
func (p *serport) reader() {
9297

9398
//var buf bytes.Buffer
@@ -344,6 +349,8 @@ func spHandlerOpen(portname string, baud int, buftype string, isSecondary bool)
344349

345350
if buftype == "timed" {
346351
bw = &BufferflowTimed{Name: "timed", Port: portname, Output: h.broadcastSys, Input: make(chan string)}
352+
} else if buftype == "timedraw" {
353+
bw = &BufferflowTimedRaw{Name: "timedraw", Port: portname, Output: h.broadcastSys, Input: make(chan string)}
347354
} else {
348355
bw = &BufferflowDefault{Port: portname}
349356
}

0 commit comments

Comments
 (0)