Skip to content

Commit 4feb3fc

Browse files
committed
version 1.86 ready for binaries
1 parent 996dfba commit 4feb3fc

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ sudo service serial-port-json-server start
328328
Revisions
329329
-------
330330
Changes in 1.86
331+
- Rewrote "tinyg" buffer to use better locking technique on in/out thread to remove chance that r:{}'s are lost and jobs get paused mysteriously. Now report {"Lbs":xx} which is a LocalBufferSize report that tells the UI how many characters are in the TinyG buffer from SPJS's perspective. This will help users see if in fact there is a mis-sync between what SPJS thinks is in the TinyG buffer and what actually is in that buffer. The {"Lbs":0} value will be reported back after every r:{} received from TinyG.
331332
- Added "Pause" value in sendjson command so you can ask SPJS to pause after sending a serial command. This was needed because on Atmel processors during an EEPROM write all data is dropped that is sent in on the serial lines. To use this value, send in a sendjson command similar to the following:
332333
`sendjson {"P":"COM7","Data":[{"D":"{\"ej\":1}\n","Id":"tinygInit-cmd182","Pause":50}]}`
333334
- Added "tinyg_tidmode" buffer which is the most advanced buffer ever added to SPJS. This buffer uses a primary key for each line sent to TinyG and TinyG sends back the primary key as it processes each line. This means that SPJS will be in 100% perfect sync with TinyG. This will solve the longstanding hard-to-find bug where users would occasionally get random pausing because SPJS thought TinyG's buffer was full, but it really wasn't.

bufferflow.go

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

8-
var availableBufferAlgorithms = []string{"default", "tinyg", "tinyg_v2", "tinyg_linemode", "tinyg_tidmode", "tinygg2", "grbl", "marlin"}
8+
var availableBufferAlgorithms = []string{"default", "tinyg", "tinyg_old", "tinyg_linemode", "tinyg_tidmode", "tinygg2", "grbl", "marlin"}
99

1010
//var availableBufferAlgorithms = []string{"default", "tinyg", "tinygg2", "dummypause", "grbl"}
1111

bufferflow_tinyg_v2.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"encoding/json"
55
"log"
66
"regexp"
7-
"strconv"
7+
//"strconv"
88
"strings"
99
"sync"
1010
//"time"
@@ -135,15 +135,13 @@ func (b *BufferflowTinygV2) Init() {
135135

136136
go func() {
137137
time.Sleep(2500 * time.Millisecond)
138-
spWriteJson("sendjson {\"P\":\"" + b.parent_serport.portConf.Name + "\",\"Data\":[{\"D\":\"" + "{\\\"rxm\\\":0}\\n\", \"Id\":\"internalInit0\", \"Pause\":50}]}")
138+
//spWriteJson("sendjson {\"P\":\"" + b.parent_serport.portConf.Name + "\",\"Data\":[{\"D\":\"" + "{\\\"rxm\\\":0}\\n\", \"Id\":\"internalInit0\", \"Pause\":50}]}")
139139

140140
}()
141141
}
142142

143143
func (b *BufferflowTinygV2) RewriteSerialData(cmd string, id string) string {
144144

145-
b.q.Push(cmd, id)
146-
147145
return ""
148146
}
149147

@@ -170,17 +168,19 @@ func (b *BufferflowTinygV2) BlockUntilReady(cmd string, id string) (bool, bool,
170168
// Normal Command - i.e. it returns response
171169

172170
newCmd = b.RewriteSerialData(cmd, id)
171+
b.q.Push(cmd, id)
172+
log.Printf("\tWe have cmd that returns response. cmd:%v\n", strings.Replace(cmd, "\n", "\\n", -1))
173173

174174
} else {
175175

176176
// this is sketchy. could we overrun the buffer by not counting !~%\n
177177
// so to give extra room don't actually allow full serial buffer to
178178
// be used in b.BufferMax
179-
log.Printf("\tWe have cmd that returns no response, so not incrementing buffer size for cmd:%v\n", cmd)
179+
log.Printf("\tWe have cmd that returns no response, so not incrementing buffer size for cmd:%v\n", strings.Replace(cmd, "\n", "\\n", -1))
180180

181181
}
182182

183-
log.Printf("\tLen of cmd: %v, new len of local queue:%v\n", len(cmd), b.q.LenOfCmds())
183+
log.Printf("\tLen of cmd: %v, new len of local queue:%v, debugStr:%v\n", len(cmd), b.q.LenOfCmds(), b.q.DebugStr())
184184

185185
if b.q.LenOfCmds() >= b.BufferMax {
186186
b.SetPaused(true, 0) // b.Paused = true
@@ -236,6 +236,9 @@ func (b *BufferflowTinygV2) BlockUntilReady(cmd string, id string) (bool, bool,
236236
}
237237

238238
type LocalRemoteBuffers struct {
239+
LocalBufSize int `json:"Lbs"`
240+
CmdCnt int `json:"-"`
241+
Cmds string `json:"-"`
239242
}
240243

241244
type BufferStats struct {
@@ -293,16 +296,30 @@ func (b *BufferflowTinygV2) OnIncomingData(data string) {
293296
h.broadcastSys <- bm
294297
}
295298

299+
// For debug
300+
mLocalQueue := LocalRemoteBuffers{}
301+
mLocalQueue.LocalBufSize = b.q.LenOfCmds()
302+
mLocalQueue.CmdCnt = b.q.Len()
303+
//mLocalQueue.Cmds = b.q.DebugStr()
304+
bmLocalQueue, errlq := json.Marshal(mLocalQueue)
305+
if errlq != nil {
306+
log.Printf("\tCould not marshal localBufSize debug stmt:%v", mLocalQueue)
307+
} else {
308+
log.Printf("\tHere is our localBufSize debug stmt:%v", string(bmLocalQueue))
309+
}
310+
296311
// we need to send a buffer size update
297312
mbs := BufferStats{}
298313
mbs.P = b.Port
299-
mbs.D = "{\"LocalBufSize\":" + strconv.Itoa(b.q.LenOfCmds()) + "}\n"
314+
//mbs.D = "{\"LocalBufSize\":" + strconv.Itoa(b.q.LenOfCmds()) + ",\"Cmds\":\"" + b.q.DebugStr() + "\"}\n"
315+
mbs.D = string(bmLocalQueue) + "\n"
300316
bmbs, err2 := json.Marshal(mbs)
301317
if err2 == nil {
302318
h.broadcastSys <- bmbs
319+
//log.Printf("\tFinal buf size update:%v", string(bmbs))
303320
}
304321

305-
log.Printf("\tLocal buffer decreased to itemCnt:%v, lenOfBuf:%v\n", b.q.Len(), b.q.LenOfCmds())
322+
//log.Printf("\tLocal buffer decreased to itemCnt:%v, lenOfBuf:%v\n", b.q.Len(), b.q.LenOfCmds())
306323

307324
if *bufFlowDebugType == "on" {
308325
// let's report on how our buffer is doing

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Version 1.85
1+
// Version 1.86
22
// Supports Windows, Linux, Mac, and Raspberry Pi, Beagle Bone Black
33

44
package main
@@ -22,8 +22,8 @@ import (
2222
)
2323

2424
var (
25-
version = "1.85"
26-
versionFloat = float32(1.85)
25+
version = "1.86"
26+
versionFloat = float32(1.86)
2727
addr = flag.String("addr", ":8989", "http service address")
2828
//assets = flag.String("assets", defaultAssetPath(), "path to assets")
2929
//verbose = flag.Bool("v", true, "show debug logging")

queue.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828

2929
package main
3030

31-
import "sync"
31+
import (
32+
"strings"
33+
"sync"
34+
)
3235

3336
type queuenode struct {
3437
data string
@@ -141,3 +144,21 @@ func (q *Queue) Delete() {
141144
q.count = 0
142145
q.lenOfCmds = 0
143146
}
147+
148+
func (q *Queue) DebugStr() string {
149+
q.lock.Lock()
150+
defer q.lock.Unlock()
151+
152+
str := ""
153+
if q.head != nil {
154+
str += q.head.id + ":" + strings.Replace(q.head.data, "\n", "\\n", -1)
155+
156+
n := q.head.next
157+
for n != nil {
158+
str += ", " + n.id + ":" + strings.Replace(n.data, "\n", "\\n", -1)
159+
n = n.next
160+
}
161+
}
162+
163+
return str
164+
}

serialport.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (p *serport) writerBuffered() {
227227
// sees something come in
228228
for data := range p.sendBuffered {
229229

230-
log.Printf("Got p.sendBuffered. data:%v, id:%v, pause:%v\n", string(data.data), string(data.id), data.pause)
230+
log.Printf("Got p.sendBuffered. data:%v, id:%v, pause:%v\n", strings.Replace(string(data.data), "\n", "\\n", -1), string(data.id), data.pause)
231231

232232
// we want to block here if we are being asked
233233
// to pause.
@@ -428,13 +428,13 @@ func spHandlerOpen(portname string, baud int, buftype string, isSecondary bool)
428428
p := &serport{sendBuffered: make(chan Cmd, 500000), sendNoBuf: make(chan Cmd), portConf: conf, portIo: sp, BufferType: buftype, IsPrimary: isPrimary, IsSecondary: isSecondary}
429429

430430
// if user asked for a buffer watcher, i.e. tinyg/grbl then attach here
431-
if buftype == "tinyg" {
431+
if buftype == "tinyg_old" {
432432

433433
bw := &BufferflowTinyg{Name: "tinyg", parent_serport: p}
434434
bw.Init()
435435
bw.Port = portname
436436
p.bufferwatcher = bw
437-
} else if buftype == "tinyg_v2" {
437+
} else if buftype == "tinyg" {
438438

439439
bw := &BufferflowTinygV2{Name: "tinyg_v2", parent_serport: p}
440440
bw.Init()

0 commit comments

Comments
 (0)