@@ -2,7 +2,6 @@ package main
22
33import (
44 "bytes"
5- "encoding/json"
65 "io"
76 "strconv"
87 "time"
@@ -121,6 +120,10 @@ func (p *serport) reader(buftype string) {
121120 switch buftype {
122121 case "timedraw" , "timed" , "timedbinary" :
123122 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
124127 p .bufferwatcher .OnIncomingData (data )
125128 case "default" : // the bufferbuftype is actually called default 🤷♂️
126129 // save the left out bytes for the next iteration due to UTF-8 encoding
@@ -139,41 +142,10 @@ func (p *serport) reader(buftype string) {
139142 data += string (runeValue )
140143 w = width
141144 }
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
146145 p .bufferwatcher .OnIncomingData (data )
147146 default :
148147 log .Panicf ("unknown buffer type %s" , buftype )
149148 }
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- }
177149 }
178150
179151 // double check that we got characters in the buffer
@@ -332,7 +304,7 @@ func spHandlerOpen(portname string, baud int, buftype string) {
332304 case "timedbinary" :
333305 bw = NewBufferflowTimedBinary (portname , h .broadcastSys )
334306 case "default" :
335- bw = NewBufferflowDefault (portname )
307+ bw = NewBufferflowDefault (portname , h . broadcastSys )
336308 default :
337309 log .Panicf ("unknown buffer type: %s" , buftype )
338310 }
0 commit comments