From 59e009d207ae899a26acc228596c58ab7a3b3e27 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Tue, 9 Feb 2021 16:59:11 +0100 Subject: [PATCH 1/3] add port to serial output --- bufferflow_timed.go | 2 +- bufferflow_timedraw.go | 2 +- serialport.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bufferflow_timed.go b/bufferflow_timed.go index c4a7b6117..19e685be9 100644 --- a/bufferflow_timed.go +++ b/bufferflow_timed.go @@ -34,7 +34,7 @@ func (b *BufferflowTimed) Init() { bufferedOutput = bufferedOutput + data case <-b.ticker.C: if bufferedOutput != "" { - m := SpPortMessage{bufferedOutput} + m := SpPortMessage{b.Port, bufferedOutput} buf, _ := json.Marshal(m) // data is now encoded in base64 format // need a decoder on the other side diff --git a/bufferflow_timedraw.go b/bufferflow_timedraw.go index 0c3acf7b8..b20f27f48 100644 --- a/bufferflow_timedraw.go +++ b/bufferflow_timedraw.go @@ -32,7 +32,7 @@ func (b *BufferflowTimedRaw) Init() { b.ticker = time.NewTicker(16 * time.Millisecond) for _ = range b.ticker.C { if len(bufferedOutputRaw) != 0 { - m := SpPortMessageRaw{bufferedOutputRaw} + m := SpPortMessageRaw{b.Port, bufferedOutputRaw} buf, _ := json.Marshal(m) // data is now encoded in base64 format // need a decoder on the other side diff --git a/serialport.go b/serialport.go index cad1a971d..c7e574a7a 100755 --- a/serialport.go +++ b/serialport.go @@ -83,12 +83,12 @@ type qwReport struct { } type SpPortMessage struct { - // P string // the port, i.e. com22 + P string // the port, i.e. com22 D string // the data, i.e. G0 X0 Y0 } type SpPortMessageRaw struct { - // P string // the port, i.e. com22 + P string // the port, i.e. com22 D []byte // the data, i.e. G0 X0 Y0 } @@ -157,7 +157,7 @@ func (p *serport) reader() { if p.bufferwatcher.IsBufferGloballySendingBackIncomingData() == false { //m := SpPortMessage{"Alice", "Hello"} - m := SpPortMessage{data} + m := SpPortMessage{p.portConf.Name, data} //log.Print("The m obj struct is:") //log.Print(m) From 4fc615a93c0a3784e24c12a8df7a1e901b5fd58e Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Wed, 10 Feb 2021 16:55:28 +0100 Subject: [PATCH 2/3] fix port not being consistent (if more devices were connected) --- bufferflow_timed.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bufferflow_timed.go b/bufferflow_timed.go index 19e685be9..725372a30 100644 --- a/bufferflow_timed.go +++ b/bufferflow_timed.go @@ -23,6 +23,7 @@ var ( func (b *BufferflowTimed) Init() { log.Println("Initting timed buffer flow (output once every 16ms)") bufferedOutput = "" + port = "" go func() { b.ticker = time.NewTicker(16 * time.Millisecond) @@ -32,14 +33,16 @@ func (b *BufferflowTimed) Init() { select { case data := <-b.Input: bufferedOutput = bufferedOutput + data + port = b.Port case <-b.ticker.C: if bufferedOutput != "" { - m := SpPortMessage{b.Port, bufferedOutput} + m := SpPortMessage{port, bufferedOutput} buf, _ := json.Marshal(m) // data is now encoded in base64 format // need a decoder on the other side b.Output <- []byte(buf) bufferedOutput = "" + port = "" } case <-b.done: break Loop From c1bdc2bf63976456f2aa966b5b436489b732064b Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Thu, 11 Feb 2021 13:25:17 +0100 Subject: [PATCH 3/3] =?UTF-8?q?fix=20web-server=20port=20being=20overwritt?= =?UTF-8?q?en=20=F0=9F=A4=A6=F0=9F=8F=BB=E2=80=8D=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bufferflow_timed.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bufferflow_timed.go b/bufferflow_timed.go index 725372a30..248292208 100644 --- a/bufferflow_timed.go +++ b/bufferflow_timed.go @@ -18,12 +18,13 @@ type BufferflowTimed struct { var ( bufferedOutput string + sPort string ) func (b *BufferflowTimed) Init() { log.Println("Initting timed buffer flow (output once every 16ms)") bufferedOutput = "" - port = "" + sPort = "" go func() { b.ticker = time.NewTicker(16 * time.Millisecond) @@ -33,16 +34,16 @@ func (b *BufferflowTimed) Init() { select { case data := <-b.Input: bufferedOutput = bufferedOutput + data - port = b.Port + sPort = b.Port case <-b.ticker.C: if bufferedOutput != "" { - m := SpPortMessage{port, bufferedOutput} + m := SpPortMessage{sPort, bufferedOutput} buf, _ := json.Marshal(m) // data is now encoded in base64 format // need a decoder on the other side b.Output <- []byte(buf) bufferedOutput = "" - port = "" + sPort = "" } case <-b.done: break Loop