You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/04/24 11:00:01 UTC

[plc4x] branch develop updated: refactor(plc4go): fix hex formatting using the right fmt string

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 0f3a3304d0 refactor(plc4go): fix hex formatting using the right fmt string
0f3a3304d0 is described below

commit 0f3a3304d0b4f94dc6c5e7c57e972e84d198c846
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Apr 24 12:59:52 2023 +0200

    refactor(plc4go): fix hex formatting using the right fmt string
---
 plc4go/internal/cbus/Subscriber.go                               | 2 +-
 plc4go/internal/cbus/Tag.go                                      | 2 +-
 plc4go/internal/cbus/Tag_test.go                                 | 2 +-
 plc4go/protocols/cbus/readwrite/model/StaticHelper.go            | 2 +-
 plc4go/spi/testutils/DriverTestRunner.go                         | 6 +++---
 plc4go/spi/transports/test/Transport.go                          | 4 ++--
 plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer/analyzer.go | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/plc4go/internal/cbus/Subscriber.go b/plc4go/internal/cbus/Subscriber.go
index 40bff4f24d..c6819b779e 100644
--- a/plc4go/internal/cbus/Subscriber.go
+++ b/plc4go/internal/cbus/Subscriber.go
@@ -221,7 +221,7 @@ func (m *Subscriber) offerMMI(unitAddressString string, calData readWriteModel.C
 	}
 	statusType := "binary"
 	if isLevel {
-		statusType = fmt.Sprintf("level=0x%X", blockStart)
+		statusType = fmt.Sprintf("level=%#02X", blockStart)
 	}
 	address[tagName] = fmt.Sprintf("status/%s/%s", statusType, applicationString)
 
diff --git a/plc4go/internal/cbus/Tag.go b/plc4go/internal/cbus/Tag.go
index 475b20b339..e5cda0912f 100644
--- a/plc4go/internal/cbus/Tag.go
+++ b/plc4go/internal/cbus/Tag.go
@@ -271,7 +271,7 @@ func (s statusTag) GetAddressString() string {
 	case StatusRequestTypeLevel:
 		statusRequestType = "level"
 		if s.startingGroupAddressLabel != nil {
-			statusRequestType += fmt.Sprintf("=0x%x", *s.startingGroupAddressLabel)
+			statusRequestType += fmt.Sprintf("=%#02x", *s.startingGroupAddressLabel)
 		}
 	default:
 		statusRequestType = "invalid"
diff --git a/plc4go/internal/cbus/Tag_test.go b/plc4go/internal/cbus/Tag_test.go
index 2659e00ccb..7fefc48bfa 100644
--- a/plc4go/internal/cbus/Tag_test.go
+++ b/plc4go/internal/cbus/Tag_test.go
@@ -2340,7 +2340,7 @@ func Test_statusTag_GetAddressString(t *testing.T) {
 					return &label
 				}(),
 			},
-			want: "status/level=0x5/HEATING_88",
+			want: "status/level=0x05/HEATING_88",
 		},
 		{
 			name: "invalid",
diff --git a/plc4go/protocols/cbus/readwrite/model/StaticHelper.go b/plc4go/protocols/cbus/readwrite/model/StaticHelper.go
index d5529a15fd..100b1f4e41 100644
--- a/plc4go/protocols/cbus/readwrite/model/StaticHelper.go
+++ b/plc4go/protocols/cbus/readwrite/model/StaticHelper.go
@@ -41,7 +41,7 @@ func ReadAndValidateChecksum(readBuffer utils.ReadBuffer, message spi.Message, s
 		return nil, errors.Wrap(err, "Unable to calculate checksum")
 	}
 	if checksum != actualChecksum {
-		return nil, errors.Errorf("Expected checksum 0x%x doesn't match actual checksum 0x%x", checksum, actualChecksum)
+		return nil, errors.Errorf("Expected checksum %#x doesn't match actual checksum %#x", checksum, actualChecksum)
 	}
 	return NewChecksum(checksum), nil
 }
diff --git a/plc4go/spi/testutils/DriverTestRunner.go b/plc4go/spi/testutils/DriverTestRunner.go
index b682814689..c3a971acc5 100644
--- a/plc4go/spi/testutils/DriverTestRunner.go
+++ b/plc4go/spi/testutils/DriverTestRunner.go
@@ -316,7 +316,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti
 			if time.Now().Sub(now) > 2*time.Second {
 				drainableBytes := testTransportInstance.GetNumDrainableBytes()
 				actualRawOutput := testTransportInstance.DrainWriteBuffer(drainableBytes)
-				return errors.Errorf("error getting bytes from transport. Not enough data available: actual(%d)<expected(%d), \nactual:   0x%X\nexpected: 0x%X\nHexdumps:\n%s",
+				return errors.Errorf("error getting bytes from transport. Not enough data available: actual(%d)<expected(%d), \nactual:   %#X\nexpected: %#X\nHexdumps:\n%s",
 					drainableBytes, expectedRawOutputLength, actualRawOutput, expectedRawOutput, utils.DiffHex(expectedRawOutput, actualRawOutput))
 			}
 			time.Sleep(2 * time.Millisecond)
@@ -343,7 +343,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti
 					actual, err := m.rootTypeParser(readBufferByteBased)
 					t.Logf("A readable render of expectation:\n%v\nvs actual paket\n%v\n%#v", expectedSerializable, actual, err)
 				}
-				return errors.Errorf("actual output doesn't match expected output:\nactual:   0x%X\nexpected: 0x%X\nHexdumps:\n%s", actualRawOutput, expectedRawOutput, utils.DiffHex(expectedRawOutput, actualRawOutput))
+				return errors.Errorf("actual output doesn't match expected output:\nactual:   %#X\nexpected: %#X\nHexdumps:\n%s", actualRawOutput, expectedRawOutput, utils.DiffHex(expectedRawOutput, actualRawOutput))
 			}
 		}
 		// If there's a difference, parse the input and display it to simplify debugging
@@ -360,7 +360,7 @@ func (m DriverTestsuite) ExecuteStep(t *testing.T, connection plc4go.PlcConnecti
 		t.Log("Comparing bytes")
 		for i := range expectedRawInput {
 			if expectedRawInput[i] != rawInput[i] {
-				return errors.Errorf("actual output doesn't match expected output:\nactual:   0x%X\nexpected: 0x%X\nHexdumps:\n%s", rawInput, expectedRawInput, utils.DiffHex(expectedRawInput, rawInput))
+				return errors.Errorf("actual output doesn't match expected output:\nactual:   %#X\nexpected: %#X\nHexdumps:\n%s", rawInput, expectedRawInput, utils.DiffHex(expectedRawInput, rawInput))
 			}
 		}
 		// If there's a difference, parse the input and display it to simplify debugging
diff --git a/plc4go/spi/transports/test/Transport.go b/plc4go/spi/transports/test/Transport.go
index 9ef1605b5f..cdcc658611 100644
--- a/plc4go/spi/transports/test/Transport.go
+++ b/plc4go/spi/transports/test/Transport.go
@@ -152,13 +152,13 @@ func (m *TransportInstance) Write(data []byte) error {
 	if m.writeInterceptor != nil {
 		m.writeInterceptor(m, data)
 	}
-	log.Trace().Msgf("Write data 0x%x", data)
+	log.Trace().Msgf("Write data %#x", data)
 	m.writeBuffer = append(m.writeBuffer, data...)
 	return nil
 }
 
 func (m *TransportInstance) FillReadBuffer(data []byte) {
-	log.Trace().Msgf("FillReadBuffer with 0x%x", data)
+	log.Trace().Msgf("FillReadBuffer with %#x", data)
 	m.readBuffer = append(m.readBuffer, data...)
 }
 
diff --git a/plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer/analyzer.go b/plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer/analyzer.go
index d3e90d48df..a6c9ad4231 100644
--- a/plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer/analyzer.go
+++ b/plc4go/tools/plc4xpcapanalyzer/internal/cbusanalyzer/analyzer.go
@@ -153,7 +153,7 @@ func (a *Analyzer) getCurrentPayload(packetInformation common.PacketInformation,
 	if lastElement := currentPayload[len(currentPayload)-1]; (lastElement != '\r') && (lastElement != '\n') {
 		return nil, common.ErrUnterminatedPackage
 	} else {
-		log.Debug().Stringer("packetInformation", packetInformation).Msgf("Last element 0x%x", lastElement)
+		log.Debug().Stringer("packetInformation", packetInformation).Msgf("Last element %#x", lastElement)
 		if shouldClearInboundPayload {
 			if currentSavedPayload := currentInboundPayloads[srcUip]; currentSavedPayload != nil {
 				// We remove our current payload from the beginning of the cache