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 f3e2130c3f refactor(plc4go/cbus): struct fields should now start with
a lower case
f3e2130c3f is described below
commit f3e2130c3f5fe5cd12974f38d6dc1978d143d684
Author: Sebastian Rühl <[email protected]>
AuthorDate: Fri Mar 24 16:54:41 2023 +0100
refactor(plc4go/cbus): struct fields should now start with a lower case
---
plc4go/internal/cbus/Reader.go | 98 ++++++++++-----------
plc4go/internal/cbus/Reader_test.go | 171 ++++++++++++++++++++++++++++++++++++
2 files changed, 220 insertions(+), 49 deletions(-)
diff --git a/plc4go/internal/cbus/Reader.go b/plc4go/internal/cbus/Reader.go
index 59af9a8789..730a433186 100644
--- a/plc4go/internal/cbus/Reader.go
+++ b/plc4go/internal/cbus/Reader.go
@@ -291,49 +291,49 @@ func (m *Reader) mapEncodedReply(transaction
*spi.RequestTransaction, encodedRep
addPlcValue(tagName,
spiValues.NewPlcRawByteArray(identifyReplyCommand.GetCurrentSenseLevels()))
case readWriteModel.IdentifyReplyCommandDelaysExactly:
addPlcValue(tagName,
spiValues.NewPlcStruct(map[string]apiValues.PlcValue{
- "ReStrikeDelay":
spiValues.NewPlcUSINT(identifyReplyCommand.GetReStrikeDelay()),
- "TerminalLevel":
spiValues.NewPlcRawByteArray(identifyReplyCommand.GetTerminalLevels()),
+ "reStrikeDelay":
spiValues.NewPlcUSINT(identifyReplyCommand.GetReStrikeDelay()),
+ "terminalLevel":
spiValues.NewPlcRawByteArray(identifyReplyCommand.GetTerminalLevels()),
}))
case
readWriteModel.IdentifyReplyCommandDSIStatusExactly:
addPlcValue(tagName,
spiValues.NewPlcStruct(map[string]apiValues.PlcValue{
- "ChannelStatus1":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus1().String()),
- "ChannelStatus2":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus2().String()),
- "ChannelStatus3":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus3().String()),
- "ChannelStatus4":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus4().String()),
- "ChannelStatus5":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus5().String()),
- "ChannelStatus6":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus6().String()),
- "ChannelStatus7":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus7().String()),
- "ChannelStatus8":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus8().String()),
- "UnitStatus":
spiValues.NewPlcSTRING(identifyReplyCommand.GetUnitStatus().String()),
- "DimmingUCRevisionNumber":
spiValues.NewPlcUSINT(identifyReplyCommand.GetDimmingUCRevisionNumber()),
+ "channelStatus1":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus1().String()),
+ "channelStatus2":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus2().String()),
+ "channelStatus3":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus3().String()),
+ "channelStatus4":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus4().String()),
+ "channelStatus5":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus5().String()),
+ "channelStatus6":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus6().String()),
+ "channelStatus7":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus7().String()),
+ "channelStatus8":
spiValues.NewPlcSTRING(identifyReplyCommand.GetChannelStatus8().String()),
+ "unitStatus":
spiValues.NewPlcSTRING(identifyReplyCommand.GetUnitStatus().String()),
+ "dimmingUCRevisionNumber":
spiValues.NewPlcUSINT(identifyReplyCommand.GetDimmingUCRevisionNumber()),
}))
case
readWriteModel.IdentifyReplyCommandExtendedDiagnosticSummaryExactly:
addPlcValue(tagName,
spiValues.NewPlcStruct(map[string]apiValues.PlcValue{
- "LowApplication":
spiValues.NewPlcSTRING(identifyReplyCommand.GetLowApplication().String()),
- "HighApplication":
spiValues.NewPlcSTRING(identifyReplyCommand.GetHighApplication().String()),
- "Area":
spiValues.NewPlcUSINT(identifyReplyCommand.GetArea()),
- "Crc":
spiValues.NewPlcUINT(identifyReplyCommand.GetCrc()),
- "SerialNumber":
spiValues.NewPlcUDINT(identifyReplyCommand.GetSerialNumber()),
- "NetworkVoltage":
spiValues.NewPlcUSINT(identifyReplyCommand.GetNetworkVoltage()),
- "UnitInLearnMode":
spiValues.NewPlcBOOL(identifyReplyCommand.GetUnitInLearnMode()),
- "NetworkVoltageLow":
spiValues.NewPlcBOOL(identifyReplyCommand.GetNetworkVoltageLow()),
- "NetworkVoltageMarginal":
spiValues.NewPlcBOOL(identifyReplyCommand.GetNetworkVoltageMarginal()),
- "EnableChecksumAlarm":
spiValues.NewPlcBOOL(identifyReplyCommand.GetEnableChecksumAlarm()),
- "OutputUnit":
spiValues.NewPlcBOOL(identifyReplyCommand.GetOutputUnit()),
- "InstallationMMIError":
spiValues.NewPlcBOOL(identifyReplyCommand.GetInstallationMMIError()),
+ "lowApplication":
spiValues.NewPlcSTRING(identifyReplyCommand.GetLowApplication().String()),
+ "highApplication":
spiValues.NewPlcSTRING(identifyReplyCommand.GetHighApplication().String()),
+ "area":
spiValues.NewPlcUSINT(identifyReplyCommand.GetArea()),
+ "crc":
spiValues.NewPlcUINT(identifyReplyCommand.GetCrc()),
+ "serialNumber":
spiValues.NewPlcUDINT(identifyReplyCommand.GetSerialNumber()),
+ "networkVoltage":
spiValues.NewPlcUSINT(identifyReplyCommand.GetNetworkVoltage()),
+ "unitInLearnMode":
spiValues.NewPlcBOOL(identifyReplyCommand.GetUnitInLearnMode()),
+ "networkVoltageLow":
spiValues.NewPlcBOOL(identifyReplyCommand.GetNetworkVoltageLow()),
+ "networkVoltageMarginal":
spiValues.NewPlcBOOL(identifyReplyCommand.GetNetworkVoltageMarginal()),
+ "enableChecksumAlarm":
spiValues.NewPlcBOOL(identifyReplyCommand.GetEnableChecksumAlarm()),
+ "outputUnit":
spiValues.NewPlcBOOL(identifyReplyCommand.GetOutputUnit()),
+ "installationMMIError":
spiValues.NewPlcBOOL(identifyReplyCommand.GetInstallationMMIError()),
"EEWriteError":
spiValues.NewPlcBOOL(identifyReplyCommand.GetEEWriteError()),
"EEChecksumError":
spiValues.NewPlcBOOL(identifyReplyCommand.GetEEChecksumError()),
"EEDataError":
spiValues.NewPlcBOOL(identifyReplyCommand.GetEEDataError()),
- "MicroReset":
spiValues.NewPlcBOOL(identifyReplyCommand.GetMicroReset()),
- "CommsTxError":
spiValues.NewPlcBOOL(identifyReplyCommand.GetCommsTxError()),
- "InternalStackOverflow":
spiValues.NewPlcBOOL(identifyReplyCommand.GetInternalStackOverflow()),
- "MicroPowerReset":
spiValues.NewPlcBOOL(identifyReplyCommand.GetMicroPowerReset()),
+ "microReset":
spiValues.NewPlcBOOL(identifyReplyCommand.GetMicroReset()),
+ "commsTxError":
spiValues.NewPlcBOOL(identifyReplyCommand.GetCommsTxError()),
+ "internalStackOverflow":
spiValues.NewPlcBOOL(identifyReplyCommand.GetInternalStackOverflow()),
+ "microPowerReset":
spiValues.NewPlcBOOL(identifyReplyCommand.GetMicroPowerReset()),
}))
case readWriteModel.IdentifyReplyCommandSummaryExactly:
addPlcValue(tagName,
spiValues.NewPlcStruct(map[string]apiValues.PlcValue{
- "PartName":
spiValues.NewPlcSTRING(identifyReplyCommand.GetPartName()),
- "UnitServiceType":
spiValues.NewPlcUSINT(identifyReplyCommand.GetUnitServiceType()),
- "Version":
spiValues.NewPlcSTRING(identifyReplyCommand.GetVersion()),
+ "partName":
spiValues.NewPlcSTRING(identifyReplyCommand.GetPartName()),
+ "unitServiceType":
spiValues.NewPlcUSINT(identifyReplyCommand.GetUnitServiceType()),
+ "version":
spiValues.NewPlcSTRING(identifyReplyCommand.GetVersion()),
}))
case
readWriteModel.IdentifyReplyCommandFirmwareVersionExactly:
addPlcValue(tagName,
spiValues.NewPlcSTRING(identifyReplyCommand.GetFirmwareVersion()))
@@ -347,12 +347,12 @@ func (m *Reader) mapEncodedReply(transaction
*spi.RequestTransaction, encodedRep
var plcValues []apiValues.PlcValue
for _, logicAssigment := range
identifyReplyCommand.GetLogicAssigment() {
plcValues = append(plcValues,
spiValues.NewPlcStruct(map[string]apiValues.PlcValue{
- "GreaterOfOrLogic":
spiValues.NewPlcBOOL(logicAssigment.GetGreaterOfOrLogic()),
- "ReStrikeDelay":
spiValues.NewPlcBOOL(logicAssigment.GetReStrikeDelay()),
- "AssignedToGav16":
spiValues.NewPlcBOOL(logicAssigment.GetAssignedToGav16()),
- "AssignedToGav15":
spiValues.NewPlcBOOL(logicAssigment.GetAssignedToGav15()),
- "AssignedToGav14":
spiValues.NewPlcBOOL(logicAssigment.GetAssignedToGav14()),
- "AssignedToGav13":
spiValues.NewPlcBOOL(logicAssigment.GetAssignedToGav13()),
+ "greaterOfOrLogic":
spiValues.NewPlcBOOL(logicAssigment.GetGreaterOfOrLogic()),
+ "reStrikeDelay":
spiValues.NewPlcBOOL(logicAssigment.GetReStrikeDelay()),
+ "assignedToGav16":
spiValues.NewPlcBOOL(logicAssigment.GetAssignedToGav16()),
+ "assignedToGav15":
spiValues.NewPlcBOOL(logicAssigment.GetAssignedToGav15()),
+ "assignedToGav14":
spiValues.NewPlcBOOL(logicAssigment.GetAssignedToGav14()),
+ "assignedToGav13":
spiValues.NewPlcBOOL(logicAssigment.GetAssignedToGav13()),
}))
}
addPlcValue(tagName,
spiValues.NewPlcList(plcValues))
@@ -382,23 +382,23 @@ func (m *Reader) mapEncodedReply(transaction
*spi.RequestTransaction, encodedRep
case
readWriteModel.IdentifyReplyCommandOutputUnitSummaryExactly:
unitFlags := identifyReplyCommand.GetUnitFlags()
structContent := map[string]apiValues.PlcValue{
- "UnitFlags":
spiValues.NewPlcStruct(map[string]apiValues.PlcValue{
- "AssertingNetworkBurden":
spiValues.NewPlcBOOL(unitFlags.GetAssertingNetworkBurden()),
- "RestrikeTimingActive":
spiValues.NewPlcBOOL(unitFlags.GetRestrikeTimingActive()),
- "RemoteOFFInputAsserted":
spiValues.NewPlcBOOL(unitFlags.GetRemoteOFFInputAsserted()),
- "RemoteONInputAsserted":
spiValues.NewPlcBOOL(unitFlags.GetRemoteONInputAsserted()),
- "LocalToggleEnabled":
spiValues.NewPlcBOOL(unitFlags.GetLocalToggleEnabled()),
- "LocalToggleActiveState":
spiValues.NewPlcBOOL(unitFlags.GetLocalToggleActiveState()),
- "ClockGenerationEnabled":
spiValues.NewPlcBOOL(unitFlags.GetClockGenerationEnabled()),
- "UnitGeneratingClock":
spiValues.NewPlcBOOL(unitFlags.GetUnitGeneratingClock()),
+ "unitFlags":
spiValues.NewPlcStruct(map[string]apiValues.PlcValue{
+ "assertingNetworkBurden":
spiValues.NewPlcBOOL(unitFlags.GetAssertingNetworkBurden()),
+ "restrikeTimingActive":
spiValues.NewPlcBOOL(unitFlags.GetRestrikeTimingActive()),
+ "remoteOFFInputAsserted":
spiValues.NewPlcBOOL(unitFlags.GetRemoteOFFInputAsserted()),
+ "remoteONInputAsserted":
spiValues.NewPlcBOOL(unitFlags.GetRemoteONInputAsserted()),
+ "localToggleEnabled":
spiValues.NewPlcBOOL(unitFlags.GetLocalToggleEnabled()),
+ "localToggleActiveState":
spiValues.NewPlcBOOL(unitFlags.GetLocalToggleActiveState()),
+ "clockGenerationEnabled":
spiValues.NewPlcBOOL(unitFlags.GetClockGenerationEnabled()),
+ "unitGeneratingClock":
spiValues.NewPlcBOOL(unitFlags.GetUnitGeneratingClock()),
}),
- "TimeFromLastRecoverOfMainsInSeconds":
spiValues.NewPlcUSINT(identifyReplyCommand.GetTimeFromLastRecoverOfMainsInSeconds()),
+ "timeFromLastRecoverOfMainsInSeconds":
spiValues.NewPlcUSINT(identifyReplyCommand.GetTimeFromLastRecoverOfMainsInSeconds()),
}
if gavStoreEnabledByte1 :=
identifyReplyCommand.GetGavStoreEnabledByte1(); gavStoreEnabledByte1 != nil {
- structContent["GavStoreEnabledByte1"] =
spiValues.NewPlcUSINT(*gavStoreEnabledByte1)
+ structContent["gavStoreEnabledByte1"] =
spiValues.NewPlcUSINT(*gavStoreEnabledByte1)
}
if gavStoreEnabledByte2 :=
identifyReplyCommand.GetGavStoreEnabledByte2(); gavStoreEnabledByte2 != nil {
- structContent["GavStoreEnabledByte2"] =
spiValues.NewPlcUSINT(*gavStoreEnabledByte2)
+ structContent["gavStoreEnabledByte2"] =
spiValues.NewPlcUSINT(*gavStoreEnabledByte2)
}
addPlcValue(tagName,
spiValues.NewPlcStruct(structContent))
case
readWriteModel.IdentifyReplyCommandTerminalLevelsExactly:
diff --git a/plc4go/internal/cbus/Reader_test.go
b/plc4go/internal/cbus/Reader_test.go
new file mode 100644
index 0000000000..3fc33eaac1
--- /dev/null
+++ b/plc4go/internal/cbus/Reader_test.go
@@ -0,0 +1,171 @@
+package cbus
+
+import (
+ "context"
+ apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
+ apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
+ readWriteModel
"github.com/apache/plc4x/plc4go/protocols/cbus/readwrite/model"
+ "github.com/apache/plc4x/plc4go/spi"
+ "reflect"
+ "testing"
+)
+
+func TestNewReader(t *testing.T) {
+ type args struct {
+ tpduGenerator *AlphaGenerator
+ messageCodec spi.MessageCodec
+ tm *spi.RequestTransactionManager
+ }
+ tests := []struct {
+ name string
+ args args
+ want *Reader
+ }{
+ // TODO: Add test cases.
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := NewReader(tt.args.tpduGenerator,
tt.args.messageCodec, tt.args.tm); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("NewReader() = %v, want %v", got,
tt.want)
+ }
+ })
+ }
+}
+
+func TestReader_Read(t *testing.T) {
+ type fields struct {
+ alphaGenerator *AlphaGenerator
+ messageCodec spi.MessageCodec
+ tm *spi.RequestTransactionManager
+ }
+ type args struct {
+ ctx context.Context
+ readRequest apiModel.PlcReadRequest
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want <-chan apiModel.PlcReadRequestResult
+ }{
+ // TODO: Add test cases.
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ m := &Reader{
+ alphaGenerator: tt.fields.alphaGenerator,
+ messageCodec: tt.fields.messageCodec,
+ tm: tt.fields.tm,
+ }
+ if got := m.Read(tt.args.ctx, tt.args.readRequest);
!reflect.DeepEqual(got, tt.want) {
+ t.Errorf("Read() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestReader_readSync(t *testing.T) {
+ type fields struct {
+ alphaGenerator *AlphaGenerator
+ messageCodec spi.MessageCodec
+ tm *spi.RequestTransactionManager
+ }
+ type args struct {
+ ctx context.Context
+ readRequest apiModel.PlcReadRequest
+ result chan apiModel.PlcReadRequestResult
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ }{
+ // TODO: Add test cases.
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ m := &Reader{
+ alphaGenerator: tt.fields.alphaGenerator,
+ messageCodec: tt.fields.messageCodec,
+ tm: tt.fields.tm,
+ }
+ m.readSync(tt.args.ctx, tt.args.readRequest,
tt.args.result)
+ })
+ }
+}
+
+func TestReader_mapEncodedReply(t *testing.T) {
+ type fields struct {
+ alphaGenerator *AlphaGenerator
+ messageCodec spi.MessageCodec
+ tm *spi.RequestTransactionManager
+ }
+ type args struct {
+ transaction *spi.RequestTransaction
+ encodedReply readWriteModel.EncodedReply
+ tagName string
+ addResponseCode func(name string, responseCode
apiModel.PlcResponseCode)
+ addPlcValue func(name string, plcValue apiValues.PlcValue)
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ wantErr bool
+ }{
+ {
+ name: "empty input",
+ args: args{
+ transaction: func() *spi.RequestTransaction {
+ transactionManager :=
spi.NewRequestTransactionManager(1)
+ transaction :=
transactionManager.StartTransaction()
+ transaction.Submit(func() {
+ // NO-OP
+ })
+ return transaction
+ }(),
+ encodedReply: nil,
+ tagName: "",
+ addResponseCode: nil,
+ addPlcValue: nil,
+ },
+ },
+ {
+ name: "CALDataStatus",
+ args: args{
+ transaction: func() *spi.RequestTransaction {
+ transactionManager :=
spi.NewRequestTransactionManager(1)
+ transaction :=
transactionManager.StartTransaction()
+ transaction.Submit(func() {
+ // NO-OP
+ })
+ return transaction
+ }(),
+ encodedReply: func()
readWriteModel.EncodedReplyCALReply {
+ calDataStatus :=
readWriteModel.NewCALDataStatus(readWriteModel.ApplicationIdContainer_LIGHTING_3A,
0, nil, readWriteModel.CALCommandTypeContainer_CALCommandStatus_0Bytes, nil,
nil)
+ calReplyShort :=
readWriteModel.NewCALReplyShort(0, calDataStatus, nil, nil)
+ return
readWriteModel.NewEncodedReplyCALReply(calReplyShort, 0, nil, nil)
+ }(),
+ tagName: "someTag",
+ addResponseCode: func(name string, responseCode
apiModel.PlcResponseCode) {
+ // TODO: add assertions
+ },
+ addPlcValue: func(name string, plcValue
apiValues.PlcValue) {
+ // TODO: add assertions
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ m := &Reader{
+ alphaGenerator: tt.fields.alphaGenerator,
+ messageCodec: tt.fields.messageCodec,
+ tm: tt.fields.tm,
+ }
+ if err := m.mapEncodedReply(tt.args.transaction,
tt.args.encodedReply, tt.args.tagName, tt.args.addResponseCode,
tt.args.addPlcValue); (err != nil) != tt.wantErr {
+ t.Errorf("mapEncodedReply() error = %v, wantErr
%v", err, tt.wantErr)
+ }
+ })
+ }
+}