@@ -2,7 +2,6 @@ package main
2
2
3
3
import (
4
4
"bytes"
5
- "encoding/json"
6
5
"io"
7
6
"strconv"
8
7
"time"
@@ -121,6 +120,10 @@ func (p *serport) reader(buftype string) {
121
120
switch buftype {
122
121
case "timedraw" , "timed" , "timedbinary" :
123
122
data = string (bufferPart [:n ])
123
+ // give the data to our bufferflow so it can do it's work
124
+ // to read/translate the data to see if it wants to block
125
+ // writes to the serialport. each bufferflow type will decide
126
+ // this on its own based on its logic
124
127
p .bufferwatcher .OnIncomingData (data )
125
128
case "default" : // the bufferbuftype is actually called default 🤷♂️
126
129
// save the left out bytes for the next iteration due to UTF-8 encoding
@@ -139,41 +142,10 @@ func (p *serport) reader(buftype string) {
139
142
data += string (runeValue )
140
143
w = width
141
144
}
142
- // give the data to our bufferflow so it can do it's work
143
- // to read/translate the data to see if it wants to block
144
- // writes to the serialport. each bufferflow type will decide
145
- // this on its own based on its logic, i.e. tinyg vs grbl vs others
146
145
p .bufferwatcher .OnIncomingData (data )
147
146
default :
148
147
log .Panicf ("unknown buffer type %s" , buftype )
149
148
}
150
-
151
- // see if the OnIncomingData handled the broadcast back
152
- // to the user. this option was added in case the OnIncomingData wanted
153
- // to do something fancier or implementation specific, i.e. TinyG Buffer
154
- // actually sends back data on a perline basis rather than our method
155
- // where we just send the moment we get it. the reason for this is that
156
- // the browser was sometimes getting back packets out of order which
157
- // of course would screw things up when parsing
158
-
159
- if p .bufferwatcher .IsBufferGloballySendingBackIncomingData () == false {
160
- //m := SpPortMessage{"Alice", "Hello"}
161
- m := SpPortMessage {p .portConf .Name , data }
162
- //log.Print("The m obj struct is:")
163
- //log.Print(m)
164
-
165
- //b, err := json.MarshalIndent(m, "", "\t")
166
- b , err := json .Marshal (m )
167
- if err != nil {
168
- log .Println (err )
169
- h .broadcastSys <- []byte ("Error creating json on " + p .portConf .Name + " " +
170
- err .Error () + " The data we were trying to convert is: " + string (ch [:n ]))
171
- break
172
- }
173
- //log.Print("Printing out json byte data...")
174
- //log.Print(string(b))
175
- h .broadcastSys <- b
176
- }
177
149
}
178
150
179
151
// double check that we got characters in the buffer
@@ -332,7 +304,7 @@ func spHandlerOpen(portname string, baud int, buftype string) {
332
304
case "timedbinary" :
333
305
bw = NewBufferflowTimedBinary (portname , h .broadcastSys )
334
306
case "default" :
335
- bw = NewBufferflowDefault (portname )
307
+ bw = NewBufferflowDefault (portname , h . broadcastSys )
336
308
default :
337
309
log .Panicf ("unknown buffer type: %s" , buftype )
338
310
}
0 commit comments