-
Notifications
You must be signed in to change notification settings - Fork 39
feat: introduce serial link recovery #123
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
Open
sansmoraxz
wants to merge
26
commits into
grid-x:master
Choose a base branch
from
sansmoraxz:feat/serial-recover
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b06173d
feat: implement protocol recovery and connection handling in serial t…
sansmoraxz 81d1a8b
Lint issue fix
sansmoraxz 8fb2118
feat: add PTY tests for RTUSerialTransporter functionality
sansmoraxz ea9f466
feat: add PTY tests for ASCIISerialTransporter functionality
sansmoraxz c4c7d0d
Merge branch 'master' into feat/serial-recover
sansmoraxz 673dfe2
consistent ascii and rtu serial recovery process with tcp
sansmoraxz 5ed3de9
Merge remote-tracking branch 'upstream/master' into feat/serial-recover
sansmoraxz 21047b5
refactor: recovery helper for connections
sansmoraxz 19c2260
rtuclient: aduResponse nil guard
sansmoraxz 3897339
expanded rtu test cases for non-happy paths
sansmoraxz fbe2cb7
drop darwin support for rtu tests
sansmoraxz a2f29cd
rewrap deadline error for rtu
sansmoraxz 81ce48c
set rtu conn deadline before each read request instead of shared dead…
sansmoraxz 15bfbc8
remove ECONNRESET check from serial as it's tcp only
sansmoraxz c931e8d
aduResponse nil check for ASCII before print
sansmoraxz 8ec9651
remove darwin support for ascii tests
sansmoraxz 73c84c3
doc: serial connection session management by the open caller
sansmoraxz b66461d
chore: remove commented code
sansmoraxz 8e346d6
wrap ascii error
sansmoraxz a8fd209
Add retry interval for serial connections to avoid link flapping
sansmoraxz 8a387f7
Add tests for serial port reconnect behavior with retry intervals
sansmoraxz 980c964
Refactor reconnect test cases for link recovery timeout handling
sansmoraxz a2ab32d
ASCII pty driven tests
sansmoraxz b6ab4a6
ASCII decoding and reading tests
sansmoraxz b79526a
support serial device hot plug
sansmoraxz e0c387e
hot plug test recovery
sansmoraxz 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| //go:build darwin || linux || freebsd || openbsd || netbsd | ||
|
sansmoraxz marked this conversation as resolved.
Outdated
|
||
| // +build darwin linux freebsd openbsd netbsd | ||
|
|
||
| // Copyright 2014 Quoc-Viet Nguyen. All rights reserved. | ||
| // This software may be modified and distributed under the terms | ||
| // of the BSD license. See the LICENSE file for details. | ||
|
|
||
| package modbus | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| func TestASCIISerialTransporter_Send_PTY(t *testing.T) { | ||
| master, slavePath, err := openPTY() | ||
| if err != nil { | ||
| t.Skipf("Skipping PTY test: %v", err) | ||
| } | ||
| defer master.Close() | ||
|
|
||
| // Request: 01 03 00 00 00 01 (Read Holding Registers) | ||
| // ASCII: :010300000001FB\r\n | ||
| reqASCII := []byte(":010300000001FB\r\n") | ||
|
|
||
| // Response: 01 03 02 00 00 | ||
| // ASCII: :0103020000FA\r\n | ||
| respASCII := []byte(":0103020000FA\r\n") | ||
|
|
||
| transporter := &asciiSerialTransporter{} | ||
| transporter.Address = slavePath | ||
| transporter.BaudRate = 19200 | ||
| transporter.Timeout = 1 * time.Second | ||
| transporter.IdleTimeout = serialIdleTimeout | ||
|
|
||
| // Start a goroutine to read request and write response to master | ||
| go func() { | ||
| buf := make([]byte, 1024) | ||
| n, err := master.Read(buf) | ||
| if err != nil { | ||
| return | ||
| } | ||
| if !bytes.Equal(buf[:n], reqASCII) { | ||
| // t.Errorf would be racy here, just log or ignore | ||
| return | ||
| } | ||
| // Write response | ||
| _, err = master.Write(respASCII) | ||
| if err != nil { | ||
| t.Errorf("Failed to write response: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| ctx := context.Background() | ||
| aduResponse, err := transporter.Send(ctx, reqASCII) | ||
| if err != nil { | ||
| t.Fatalf("Send failed: %v", err) | ||
| } | ||
|
|
||
| if !bytes.Equal(aduResponse, respASCII) { | ||
| t.Errorf("Expected response %s, got %s", respASCII, aduResponse) | ||
| } | ||
| } | ||
|
|
||
| func TestASCIISerialTransporter_Timeout_PTY(t *testing.T) { | ||
| master, slavePath, err := openPTY() | ||
| if err != nil { | ||
| t.Skipf("Skipping PTY test: %v", err) | ||
| } | ||
| defer master.Close() | ||
|
|
||
| reqASCII := []byte(":010300000001FB\r\n") | ||
|
|
||
| transporter := &asciiSerialTransporter{} | ||
| transporter.Address = slavePath | ||
| transporter.BaudRate = 19200 | ||
| transporter.Timeout = 100 * time.Millisecond | ||
| transporter.IdleTimeout = serialIdleTimeout | ||
|
|
||
| // Don't write anything to master | ||
|
|
||
| ctx := context.Background() | ||
| _, err = transporter.Send(ctx, reqASCII) | ||
| if err == nil { | ||
| t.Fatal("Expected timeout error, got nil") | ||
| } | ||
| } | ||
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.