-
-
Notifications
You must be signed in to change notification settings - Fork 150
Add serial binary communication #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
895cc03
update bufferflow_timedraw as bufferflow_timed
umbynos 05ee6f5
remove old commands
umbynos 6a50f87
remove utf8 decoding with timedraw buffer type
umbynos e80400b
binary support (WIP)
umbynos eb2b3f3
use switch case
umbynos 1cd174a
fixed test deps
umbynos 48cc695
socketio test connection is working 🎉 (with the correct python-socket…
umbynos fc1222e
add callback to capture returned message, add new test for serial
umbynos 9c7d3f8
fix tests: "socketio.exceptions.ConnectionError: Connection refused b…
umbynos dfcc14e
minor optimizations: data and buf are already an array of bytes
umbynos b7f70f1
enhanced a bit how the logic of the serial works
umbynos c86bb4f
enhance a lot test on serial communication (with different buffer types)
umbynos 099a575
update and enhance commands output (the space in front of `<` and `>`…
umbynos b41d0cc
increased sleeptime, remove harcoded message[i]: should work on diffe…
umbynos fcaa53c
generalize the tests
umbynos 43451a3
Apply suggestions from code review
umbynos 15af2e4
add sketch used for testing
umbynos 575efa1
Fix panic closing closed channel
silvanocerza 2d78733
apply suggestions
umbynos 8f9ff20
Partially revert #e80400b7ddbbc2e8f34f1e6701b55102c3a99289
umbynos 0bbb45b
🧹(cleanup) and 🛠️(refactoring) of bufferflow stuff
umbynos 5e2ad37
extract code in helper function and uniform the code
umbynos 5d0bd27
optimize the handling of data coming from the serial port
umbynos f3d5dca
uniform default bufferflow and 🧹
umbynos 5db1975
forgot to fix this in #621
umbynos 37cf997
apply suggestions from code review ✨
umbynos 724de59
remove timedbinary: it's the same as timedraw except for the casting
umbynos 402a848
Escape html commands string
silvanocerza d5228ec
forgot to remove timed_binary
umbynos bcf0023
remove useless id field (was unused)
umbynos d077ded
remove useless channel done & other stuff
umbynos d704dd2
make sendNoBuf more general: will be used later 😏
umbynos 791b03e
add `sendraw` command to send base64 encoded bytes, add tests (for se…
umbynos 8dadd0c
forgot to skip test_sendraw_serial on CI
umbynos 500a1ee
update comments
umbynos a86a61a
refactor tests
umbynos a21ae9e
remove BlockUntilReady because it was unused
umbynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type BufferflowTimedBinary struct { | ||
Name string | ||
Port string | ||
Output chan []byte | ||
Input chan []byte | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
done chan bool | ||
ticker *time.Ticker | ||
} | ||
|
||
var ( | ||
bufferedOutputBinary []byte | ||
sPortBinary string | ||
umbynos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
func (b *BufferflowTimedBinary) Init() { | ||
log.Println("Initting timed buffer binary flow (output once every 16ms)") | ||
bufferedOutputBinary = nil | ||
sPortBinary = "" | ||
|
||
go func() { | ||
b.ticker = time.NewTicker(16 * time.Millisecond) | ||
b.done = make(chan bool) | ||
Loop: | ||
for { | ||
select { | ||
case data := <-b.Input: | ||
bufferedOutputBinary = append(bufferedOutputBinary, data...) | ||
sPortBinary = b.Port | ||
case <-b.ticker.C: | ||
if bufferedOutputBinary != nil { | ||
m := SpPortMessageRaw{sPortBinary, bufferedOutputBinary} | ||
buf, _ := json.Marshal(m) | ||
b.Output <- buf | ||
bufferedOutputBinary = nil | ||
sPortBinary = "" | ||
} | ||
case <-b.done: | ||
break Loop | ||
} | ||
} | ||
|
||
close(b.Input) | ||
silvanocerza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}() | ||
} | ||
|
||
func (b *BufferflowTimedBinary) BlockUntilReady(cmd string, id string) (bool, bool) { | ||
//log.Printf("BlockUntilReady() start\n") | ||
return true, false | ||
} | ||
|
||
func (b *BufferflowTimedBinary) OnIncomingDataBinary(data []byte) { | ||
b.Input <- data | ||
} | ||
|
||
// not implemented, we are gonna use OnIncomingDataBinary | ||
func (b *BufferflowTimedBinary) OnIncomingData(data string) { | ||
} | ||
|
||
// Clean out b.sem so it can truly block | ||
func (b *BufferflowTimedBinary) ClearOutSemaphore() { | ||
} | ||
|
||
func (b *BufferflowTimedBinary) BreakApartCommands(cmd string) []string { | ||
return []string{cmd} | ||
} | ||
|
||
func (b *BufferflowTimedBinary) Pause() { | ||
return | ||
} | ||
|
||
func (b *BufferflowTimedBinary) Unpause() { | ||
return | ||
} | ||
|
||
func (b *BufferflowTimedBinary) SeeIfSpecificCommandsShouldSkipBuffer(cmd string) bool { | ||
return false | ||
} | ||
|
||
func (b *BufferflowTimedBinary) SeeIfSpecificCommandsShouldPauseBuffer(cmd string) bool { | ||
return false | ||
} | ||
|
||
func (b *BufferflowTimedBinary) SeeIfSpecificCommandsShouldUnpauseBuffer(cmd string) bool { | ||
return false | ||
} | ||
|
||
func (b *BufferflowTimedBinary) SeeIfSpecificCommandsShouldWipeBuffer(cmd string) bool { | ||
return false | ||
} | ||
|
||
func (b *BufferflowTimedBinary) SeeIfSpecificCommandsReturnNoResponse(cmd string) bool { | ||
return false | ||
} | ||
|
||
func (b *BufferflowTimedBinary) ReleaseLock() { | ||
} | ||
|
||
func (b *BufferflowTimedBinary) IsBufferGloballySendingBackIncomingData() bool { | ||
return true | ||
} | ||
|
||
func (b *BufferflowTimedBinary) Close() { | ||
b.ticker.Stop() | ||
close(b.Input) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.