Skip to content

Commit 2e05a01

Browse files
committed
TinyG moved to 254 byte counter approach
Former-commit-id: b3015b9c764e9a79c8c1d722b9af138cd8e19b57 [formerly 9aa655d6cd33c4e11a60fa232dbc9c9bf2211d68] Former-commit-id: ea7ae3055366c33bf3b5d20d690560df61cf9bf7
1 parent c4fef66 commit 2e05a01

11 files changed

+182
-10
lines changed

bufferflow.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ type BufferMsg struct {
1616
}
1717

1818
type Bufferflow interface {
19-
BlockUntilReady(cmd string) bool // implement this method
19+
BlockUntilReady(cmd string, id string) bool // implement this method
20+
//JustQueue(cmd string, id string) bool // implement this method
2021
OnIncomingData(data string) // implement this method
22+
ClearOutSemaphore() // implement this method
2123
BreakApartCommands(cmd string) []string // implement this method
2224
Pause() // implement this method
2325
Unpause() // implement this method
2426
SeeIfSpecificCommandsShouldSkipBuffer(cmd string) bool // implement this method
2527
SeeIfSpecificCommandsShouldPauseBuffer(cmd string) bool // implement this method
2628
SeeIfSpecificCommandsShouldUnpauseBuffer(cmd string) bool // implement this method
2729
SeeIfSpecificCommandsShouldWipeBuffer(cmd string) bool // implement this method
30+
SeeIfSpecificCommandsReturnNoResponse(cmd string) bool // implement this method
2831
ReleaseLock() // implement this method
2932
IsBufferGloballySendingBackIncomingData() bool // implement this method
30-
Close() // implement this method
33+
Close() // implement this method
3134
}

bufferflow_default.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (b *BufferflowDefault) Init() {
1818
log.Println("Initting default buffer flow (which means no buffering)")
1919
}
2020

21-
func (b *BufferflowDefault) BlockUntilReady(cmd string) bool {
21+
func (b *BufferflowDefault) BlockUntilReady(cmd string, id string) bool {
2222
//log.Printf("BlockUntilReady() start\n")
2323
return true
2424
}
@@ -27,6 +27,10 @@ func (b *BufferflowDefault) OnIncomingData(data string) {
2727
//log.Printf("OnIncomingData() start. data:%v\n", data)
2828
}
2929

30+
// Clean out b.sem so it can truly block
31+
func (b *BufferflowDefault) ClearOutSemaphore() {
32+
}
33+
3034
func (b *BufferflowDefault) BreakApartCommands(cmd string) []string {
3135
return []string{cmd}
3236
}
@@ -55,6 +59,10 @@ func (b *BufferflowDefault) SeeIfSpecificCommandsShouldWipeBuffer(cmd string) bo
5559
return false
5660
}
5761

62+
func (b *BufferflowDefault) SeeIfSpecificCommandsReturnNoResponse(cmd string) bool {
63+
return false
64+
}
65+
5866
func (b *BufferflowDefault) ReleaseLock() {
5967
}
6068

bufferflow_dummypause.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type BufferflowDummypause struct {
1515
func (b *BufferflowDummypause) Init() {
1616
}
1717

18-
func (b *BufferflowDummypause) BlockUntilReady(cmd string) bool {
18+
func (b *BufferflowDummypause) BlockUntilReady(cmd string, id string) bool {
1919
log.Printf("BlockUntilReady() start. numLines:%v\n", b.NumLines)
2020
log.Printf("buffer:%v\n", b)
2121
//for b.Paused {
@@ -33,6 +33,10 @@ func (b *BufferflowDummypause) OnIncomingData(data string) {
3333
log.Printf("OnIncomingData() end. numLines:%v\n", b.NumLines)
3434
}
3535

36+
// Clean out b.sem so it can truly block
37+
func (b *BufferflowDummypause) ClearOutSemaphore() {
38+
}
39+
3640
func (b *BufferflowDummypause) BreakApartCommands(cmd string) []string {
3741
return []string{cmd}
3842
}
@@ -61,6 +65,19 @@ func (b *BufferflowDummypause) SeeIfSpecificCommandsShouldWipeBuffer(cmd string)
6165
return false
6266
}
6367

68+
func (b *BufferflowDummypause) SeeIfSpecificCommandsReturnNoResponse(cmd string) bool {
69+
/*
70+
// remove comments
71+
cmd = b.reComment.ReplaceAllString(cmd, "")
72+
cmd = b.reComment2.ReplaceAllString(cmd, "")
73+
if match := b.reNoResponse.MatchString(cmd); match {
74+
log.Printf("Found cmd that does not get a response from TinyG. cmd:%v\n", cmd)
75+
return true
76+
}
77+
*/
78+
return false
79+
}
80+
6481
func (b *BufferflowDummypause) ReleaseLock() {
6582
}
6683

bufferflow_grbl.go.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d090257a0ef221c8460c043cda82aa9b3e55cd09
1+
307d46d66f254ab5c1c8b1f8ed29b4c9a8f3fbca

bufferflow_tinyg.go.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
27430bacaafa7cba388b57ddf04965bcdf23b460
1+
02b57c77bf5180132ca681cea0429d81fdb06d0e
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
78351eb2eaef97c8f1787a283352d8344259219d

main.go.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
59afe9cfb4ea666fb567b2448eaa91efbcbbe311
1+
37b8e99e5897f7c1fda929af9997c9ff9a78a06f

queue.go

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
//
2+
// queue.go
3+
//
4+
// Created by Hicham Bouabdallah
5+
// Copyright (c) 2012 SimpleRocket LLC
6+
//
7+
// Permission is hereby granted, free of charge, to any person
8+
// obtaining a copy of this software and associated documentation
9+
// files (the "Software"), to deal in the Software without
10+
// restriction, including without limitation the rights to use,
11+
// copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the
13+
// Software is furnished to do so, subject to the following
14+
// conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be
17+
// included in all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21+
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23+
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24+
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26+
// OTHER DEALINGS IN THE SOFTWARE.
27+
//
28+
29+
package main
30+
31+
import "sync"
32+
33+
type queuenode struct {
34+
data string
35+
id string
36+
next *queuenode
37+
}
38+
39+
// A go-routine safe FIFO (first in first out) data stucture.
40+
type Queue struct {
41+
head *queuenode
42+
tail *queuenode
43+
count int
44+
lock *sync.Mutex
45+
lenOfCmds int
46+
}
47+
48+
// Creates a new pointer to a new queue.
49+
func NewQueue() *Queue {
50+
q := &Queue{}
51+
q.lock = &sync.Mutex{}
52+
return q
53+
}
54+
55+
// Returns the number of elements in the queue (i.e. size/length)
56+
// go-routine safe.
57+
func (q *Queue) Len() int {
58+
q.lock.Lock()
59+
defer q.lock.Unlock()
60+
return q.count
61+
}
62+
63+
// Returns the length of the data (gcode cmd) in the queue (i.e. size/length)
64+
// go-routine safe.
65+
func (q *Queue) LenOfCmds() int {
66+
q.lock.Lock()
67+
defer q.lock.Unlock()
68+
return q.lenOfCmds
69+
}
70+
71+
// Pushes/inserts a value at the end/tail of the queue.
72+
// Note: this function does mutate the queue.
73+
// go-routine safe.
74+
func (q *Queue) Push(item string, id string) {
75+
q.lock.Lock()
76+
defer q.lock.Unlock()
77+
78+
n := &queuenode{data: item, id: id}
79+
80+
if q.tail == nil {
81+
q.tail = n
82+
q.head = n
83+
} else {
84+
q.tail.next = n
85+
q.tail = n
86+
}
87+
q.count++
88+
q.lenOfCmds += len(item)
89+
}
90+
91+
// Returns the value at the front of the queue.
92+
// i.e. the oldest value in the queue.
93+
// Note: this function does mutate the queue.
94+
// go-routine safe.
95+
func (q *Queue) Poll() (string, string) {
96+
q.lock.Lock()
97+
defer q.lock.Unlock()
98+
99+
if q.head == nil {
100+
return "", ""
101+
}
102+
103+
n := q.head
104+
q.head = n.next
105+
106+
if q.head == nil {
107+
q.tail = nil
108+
}
109+
q.count--
110+
q.lenOfCmds -= len(n.data)
111+
112+
return n.data, n.id
113+
}
114+
115+
// Returns a read value at the front of the queue.
116+
// i.e. the oldest value in the queue.
117+
// Note: this function does NOT mutate the queue.
118+
// go-routine safe.
119+
func (q *Queue) Peek() (string, string) {
120+
q.lock.Lock()
121+
defer q.lock.Unlock()
122+
123+
n := q.head
124+
if n == nil || n.data == "" {
125+
return "", ""
126+
}
127+
128+
return n.data, n.id
129+
}
130+
131+
// Returns a read value at the front of the queue.
132+
// i.e. the oldest value in the queue.
133+
// Note: this function does NOT mutate the queue.
134+
// go-routine safe.
135+
func (q *Queue) Delete() {
136+
q.lock.Lock()
137+
defer q.lock.Unlock()
138+
139+
q.head = nil
140+
q.tail = nil
141+
q.count = 0
142+
q.lenOfCmds = 0
143+
}

serial.go.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
142fdd0ae5acea147043a47a9c267c19045fa2d0
1+
f5b2d4a727f069bc2e63da5ed3ae26c62c85fb0a

seriallist_windows.go.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
57149dd005b6ccdba7857262cdef1d59d081fdfd
1+
ac8642369e7419c013204879551c8ad35238e61c

serialport.go.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
353672d9d2343442b3dea6ef3a1f77ad925d73f2
1+
3025b9ac6f925c64a5fc5403a63d12d8e468d0bc

0 commit comments

Comments
 (0)