-
Notifications
You must be signed in to change notification settings - Fork 5
Drop support for connection to Senso on port 55568 #128
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
Closed
Conversation
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
Trying to connect to this port adds a lot of noise in the logs. Sensos with FW this old should be paired with an outdated PC, not PlayOS, so would not get a driver update we release through PlayOS.
Some small touches: - Use `let` and `const` for variables - Rename some variables
58f1989 to
2efe499
Compare
Member
|
FYI, this looks good, but I still want to think deeply through whether this could reach any device combination that would break. |
Member
|
I am not confident this is safe to ship. The chance that this would reach an incompatibly outdated Senso is small but not zero. If it did, this might create a logistic hassle. I see the following options (combineren mogelijk):
|
Member
|
Something like this maybe? diff --git a/src/dividat-driver/senso/main.go b/src/dividat-driver/senso/main.go
index 2b0ce4f..cd8e3a3 100644
--- a/src/dividat-driver/senso/main.go
+++ b/src/dividat-driver/senso/main.go
@@ -72,9 +72,12 @@ func (handle *Handle) Connect(address string) {
handle.broker.TryPub(data, "rx")
}
- go connectTCP(ctx, handle.log.WithField("channel", "data"), address+":55568", handle.broker.Sub("noTx"), onReceive)
+ // Attempt to connect to Senso at port 55568 for legacy firmware versions <= 1.2.0.0
+ // Reduce to DEBUG log level for this connection loop, as failure to connect is expected for most devices now
+ go connectTCP(ctx, handle.log.WithField("channel", "data"), logrus.DebugLevel, address+":55568", handle.broker.Sub("noTx"), onReceive)
time.Sleep(1000 * time.Millisecond)
- go connectTCP(ctx, handle.log.WithField("channel", "control"), address+":55567", handle.broker.Sub("tx"), onReceive)
+ // Connect to Senso at the port used by both current and legacy firmware versions
+ go connectTCP(ctx, handle.log.WithField("channel", "control"), logrus.InfoLevel, address+":55567", handle.broker.Sub("tx"), onReceive)
handle.cancelCurrentConnection = cancel
}
diff --git a/src/dividat-driver/senso/tcp.go b/src/dividat-driver/senso/tcp.go
index 6794063..d915105 100644
--- a/src/dividat-driver/senso/tcp.go
+++ b/src/dividat-driver/senso/tcp.go
@@ -20,7 +20,7 @@ const maxInterval = 30 * time.Second
type onReceive = func([]byte)
// connectTCP creates a persistent tcp connection to address
-func connectTCP(ctx context.Context, baseLogger *logrus.Entry, address string, tx chan interface{}, onReceive onReceive) {
+func connectTCP(ctx context.Context, baseLogger *logrus.Entry, logLevel logrus.Level, address string, tx chan interface{}, onReceive onReceive) {
var dialer net.Dialer
var log = baseLogger.WithField("address", address)
@@ -34,11 +34,11 @@ func connectTCP(ctx context.Context, baseLogger *logrus.Entry, address string, t
conn.Close()
}
- log.Info("Dialing TCP connection.")
+ logAt(logLevel, log, "Dialing TCP connection.")
conn, connErr = dialer.DialContext(ctx, "tcp", address)
if connErr != nil {
- log.WithError(connErr).Info("Could not connect with Senso.")
+ logAt(logLevel, log.WithError(connErr), "Could not connect with Senso.")
}
return connErr
}
@@ -120,7 +120,6 @@ func tcpReader(log *logrus.Entry, conn net.Conn, channel chan<- []byte) {
} else if err, ok := readErr.(net.Error); ok && err.Timeout() {
// Read timeout, just continue Nothing
} else {
- // log.WithError(readErr).Error("Read error.")
return
}
} else {
@@ -129,6 +128,27 @@ func tcpReader(log *logrus.Entry, conn net.Conn, channel chan<- []byte) {
}
}
+func logAt(level logrus.Level, logger *logrus.Entry, msg string) {
+ switch level {
+ case logrus.TraceLevel:
+ logger.Trace(msg)
+ case logrus.DebugLevel:
+ logger.Debug(msg)
+ case logrus.InfoLevel:
+ logger.Info(msg)
+ case logrus.WarnLevel:
+ logger.Warn(msg)
+ case logrus.ErrorLevel:
+ logger.Error(msg)
+ case logrus.FatalLevel:
+ logger.Fatal(msg)
+ case logrus.PanicLevel:
+ logger.Panic(msg)
+ default:
+ logger.Info(msg)
+ }
+}
+
func write(conn net.Conn, data []byte) error {
if conn != nil {
conn.SetWriteDeadline(time.Now().Add(1 * time.Millisecond))
|
Member
|
Superseded by #163 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Referring to a previous discussion we had:
This removes a lot of noise from the logs.
Checklist
[ ] Changelog updated[ ] Code documented