From 218812eb5dbf04d11f54d8d1f29b4419ba9721ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20R=C3=BChl?= Date: Tue, 19 Jul 2022 12:06:32 +0200 Subject: [PATCH] feat(cbus): implemented clock and timekeeping application --- .../protocols/cbus/readwrite/ParserHelper.go | 2 + .../cbus/readwrite/XmlParserHelper.go | 2 + .../model/ClockAndTimekeepingCommandType.go | 129 +++++++ ...ClockAndTimekeepingCommandTypeContainer.go | 294 +++++++++++++++ .../model/ClockAndTimekeepingData.go | 273 ++++++++++++++ .../ClockAndTimekeepingDataRequestRefresh.go | 155 ++++++++ .../ClockAndTimekeepingDataUpdateDate.go | 295 +++++++++++++++ .../ClockAndTimekeepingDataUpdateTime.go | 346 ++++++++++++++++++ .../model/SALDataClockAndTimekeeping.go | 54 ++- .../cbus/readwrite/model/StaticHelper.go | 10 + .../cbus/readwrite/utils/StaticHelper.java | 11 + .../apache/plc4x/java/cbus/ReferenceTest.java | 49 ++- .../main/resources/protocols/cbus/c-bus.mspec | 48 ++- 13 files changed, 1658 insertions(+), 10 deletions(-) create mode 100644 plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingCommandType.go create mode 100644 plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingCommandTypeContainer.go create mode 100644 plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingData.go create mode 100644 plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataRequestRefresh.go create mode 100644 plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataUpdateDate.go create mode 100644 plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataUpdateTime.go diff --git a/plc4go/protocols/cbus/readwrite/ParserHelper.go b/plc4go/protocols/cbus/readwrite/ParserHelper.go index 51cd487f57e..d4a8e897fa5 100644 --- a/plc4go/protocols/cbus/readwrite/ParserHelper.go +++ b/plc4go/protocols/cbus/readwrite/ParserHelper.go @@ -144,6 +144,8 @@ func (m CbusParserHelper) Parse(typeName string, arguments []string, io utils.Re return model.LightingDataParse(io) case "AccessControlData": return model.AccessControlDataParse(io) + case "ClockAndTimekeepingData": + return model.ClockAndTimekeepingDataParse(io) case "NetworkRoute": return model.NetworkRouteParse(io) case "StandardFormatStatusReply": diff --git a/plc4go/protocols/cbus/readwrite/XmlParserHelper.go b/plc4go/protocols/cbus/readwrite/XmlParserHelper.go index 092627e69f5..f988ee00276 100644 --- a/plc4go/protocols/cbus/readwrite/XmlParserHelper.go +++ b/plc4go/protocols/cbus/readwrite/XmlParserHelper.go @@ -167,6 +167,8 @@ func (m CbusXmlParserHelper) Parse(typeName string, xmlString string, parserArgu return model.LightingDataParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "AccessControlData": return model.AccessControlDataParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString))) + case "ClockAndTimekeepingData": + return model.ClockAndTimekeepingDataParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "NetworkRoute": return model.NetworkRouteParse(utils.NewXmlReadBuffer(strings.NewReader(xmlString))) case "StandardFormatStatusReply": diff --git a/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingCommandType.go b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingCommandType.go new file mode 100644 index 00000000000..b16307551d0 --- /dev/null +++ b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingCommandType.go @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "github.com/apache/plc4x/plc4go/internal/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog/log" +) + +// Code generated by code-generation. DO NOT EDIT. + +// ClockAndTimekeepingCommandType is an enum +type ClockAndTimekeepingCommandType uint8 + +type IClockAndTimekeepingCommandType interface { + Serialize(writeBuffer utils.WriteBuffer) error +} + +const ( + ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE ClockAndTimekeepingCommandType = 0x00 + ClockAndTimekeepingCommandType_REQUEST_REFRESH ClockAndTimekeepingCommandType = 0x01 +) + +var ClockAndTimekeepingCommandTypeValues []ClockAndTimekeepingCommandType + +func init() { + _ = errors.New + ClockAndTimekeepingCommandTypeValues = []ClockAndTimekeepingCommandType{ + ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE, + ClockAndTimekeepingCommandType_REQUEST_REFRESH, + } +} + +func ClockAndTimekeepingCommandTypeByValue(value uint8) (enum ClockAndTimekeepingCommandType, ok bool) { + switch value { + case 0x00: + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE, true + case 0x01: + return ClockAndTimekeepingCommandType_REQUEST_REFRESH, true + } + return 0, false +} + +func ClockAndTimekeepingCommandTypeByName(value string) (enum ClockAndTimekeepingCommandType, ok bool) { + switch value { + case "UPDATE_NETWORK_VARIABLE": + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE, true + case "REQUEST_REFRESH": + return ClockAndTimekeepingCommandType_REQUEST_REFRESH, true + } + return 0, false +} + +func ClockAndTimekeepingCommandTypeKnows(value uint8) bool { + for _, typeValue := range ClockAndTimekeepingCommandTypeValues { + if uint8(typeValue) == value { + return true + } + } + return false +} + +func CastClockAndTimekeepingCommandType(structType interface{}) ClockAndTimekeepingCommandType { + castFunc := func(typ interface{}) ClockAndTimekeepingCommandType { + if sClockAndTimekeepingCommandType, ok := typ.(ClockAndTimekeepingCommandType); ok { + return sClockAndTimekeepingCommandType + } + return 0 + } + return castFunc(structType) +} + +func (m ClockAndTimekeepingCommandType) GetLengthInBits() uint16 { + return 4 +} + +func (m ClockAndTimekeepingCommandType) GetLengthInBytes() uint16 { + return m.GetLengthInBits() / 8 +} + +func ClockAndTimekeepingCommandTypeParse(readBuffer utils.ReadBuffer) (ClockAndTimekeepingCommandType, error) { + val, err := readBuffer.ReadUint8("ClockAndTimekeepingCommandType", 4) + if err != nil { + return 0, errors.Wrap(err, "error reading ClockAndTimekeepingCommandType") + } + if enum, ok := ClockAndTimekeepingCommandTypeByValue(val); !ok { + log.Debug().Msgf("no value %x found for RequestType", val) + return ClockAndTimekeepingCommandType(val), nil + } else { + return enum, nil + } +} + +func (e ClockAndTimekeepingCommandType) Serialize(writeBuffer utils.WriteBuffer) error { + return writeBuffer.WriteUint8("ClockAndTimekeepingCommandType", 4, uint8(e), utils.WithAdditionalStringRepresentation(e.PLC4XEnumName())) +} + +// PLC4XEnumName returns the name that is used in code to identify this enum +func (e ClockAndTimekeepingCommandType) PLC4XEnumName() string { + switch e { + case ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE: + return "UPDATE_NETWORK_VARIABLE" + case ClockAndTimekeepingCommandType_REQUEST_REFRESH: + return "REQUEST_REFRESH" + } + return "" +} + +func (e ClockAndTimekeepingCommandType) String() string { + return e.PLC4XEnumName() +} diff --git a/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingCommandTypeContainer.go b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingCommandTypeContainer.go new file mode 100644 index 00000000000..f172a23b86d --- /dev/null +++ b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingCommandTypeContainer.go @@ -0,0 +1,294 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "github.com/apache/plc4x/plc4go/internal/spi/utils" + "github.com/pkg/errors" + "github.com/rs/zerolog/log" +) + +// Code generated by code-generation. DO NOT EDIT. + +// ClockAndTimekeepingCommandTypeContainer is an enum +type ClockAndTimekeepingCommandTypeContainer uint8 + +type IClockAndTimekeepingCommandTypeContainer interface { + NumBytes() uint8 + CommandType() ClockAndTimekeepingCommandType + Serialize(writeBuffer utils.WriteBuffer) error +} + +const ( + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_0Bytes ClockAndTimekeepingCommandTypeContainer = 0x08 + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_1Bytes ClockAndTimekeepingCommandTypeContainer = 0x09 + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_2Bytes ClockAndTimekeepingCommandTypeContainer = 0x0A + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_3Bytes ClockAndTimekeepingCommandTypeContainer = 0x0B + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_4Bytes ClockAndTimekeepingCommandTypeContainer = 0x0C + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_5Bytes ClockAndTimekeepingCommandTypeContainer = 0x0D + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_6Bytes ClockAndTimekeepingCommandTypeContainer = 0x0E + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_7Bytes ClockAndTimekeepingCommandTypeContainer = 0x0F + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandRequestRefresh ClockAndTimekeepingCommandTypeContainer = 0x11 +) + +var ClockAndTimekeepingCommandTypeContainerValues []ClockAndTimekeepingCommandTypeContainer + +func init() { + _ = errors.New + ClockAndTimekeepingCommandTypeContainerValues = []ClockAndTimekeepingCommandTypeContainer{ + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_0Bytes, + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_1Bytes, + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_2Bytes, + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_3Bytes, + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_4Bytes, + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_5Bytes, + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_6Bytes, + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_7Bytes, + ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandRequestRefresh, + } +} + +func (e ClockAndTimekeepingCommandTypeContainer) NumBytes() uint8 { + switch e { + case 0x08: + { /* '0x08' */ + return 0 + } + case 0x09: + { /* '0x09' */ + return 1 + } + case 0x0A: + { /* '0x0A' */ + return 2 + } + case 0x0B: + { /* '0x0B' */ + return 3 + } + case 0x0C: + { /* '0x0C' */ + return 4 + } + case 0x0D: + { /* '0x0D' */ + return 5 + } + case 0x0E: + { /* '0x0E' */ + return 6 + } + case 0x0F: + { /* '0x0F' */ + return 7 + } + case 0x11: + { /* '0x11' */ + return 1 + } + default: + { + return 0 + } + } +} + +func ClockAndTimekeepingCommandTypeContainerFirstEnumForFieldNumBytes(value uint8) (ClockAndTimekeepingCommandTypeContainer, error) { + for _, sizeValue := range ClockAndTimekeepingCommandTypeContainerValues { + if sizeValue.NumBytes() == value { + return sizeValue, nil + } + } + return 0, errors.Errorf("enum for %v describing NumBytes not found", value) +} + +func (e ClockAndTimekeepingCommandTypeContainer) CommandType() ClockAndTimekeepingCommandType { + switch e { + case 0x08: + { /* '0x08' */ + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE + } + case 0x09: + { /* '0x09' */ + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE + } + case 0x0A: + { /* '0x0A' */ + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE + } + case 0x0B: + { /* '0x0B' */ + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE + } + case 0x0C: + { /* '0x0C' */ + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE + } + case 0x0D: + { /* '0x0D' */ + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE + } + case 0x0E: + { /* '0x0E' */ + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE + } + case 0x0F: + { /* '0x0F' */ + return ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE + } + case 0x11: + { /* '0x11' */ + return ClockAndTimekeepingCommandType_REQUEST_REFRESH + } + default: + { + return 0 + } + } +} + +func ClockAndTimekeepingCommandTypeContainerFirstEnumForFieldCommandType(value ClockAndTimekeepingCommandType) (ClockAndTimekeepingCommandTypeContainer, error) { + for _, sizeValue := range ClockAndTimekeepingCommandTypeContainerValues { + if sizeValue.CommandType() == value { + return sizeValue, nil + } + } + return 0, errors.Errorf("enum for %v describing CommandType not found", value) +} +func ClockAndTimekeepingCommandTypeContainerByValue(value uint8) (enum ClockAndTimekeepingCommandTypeContainer, ok bool) { + switch value { + case 0x08: + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_0Bytes, true + case 0x09: + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_1Bytes, true + case 0x0A: + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_2Bytes, true + case 0x0B: + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_3Bytes, true + case 0x0C: + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_4Bytes, true + case 0x0D: + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_5Bytes, true + case 0x0E: + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_6Bytes, true + case 0x0F: + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_7Bytes, true + case 0x11: + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandRequestRefresh, true + } + return 0, false +} + +func ClockAndTimekeepingCommandTypeContainerByName(value string) (enum ClockAndTimekeepingCommandTypeContainer, ok bool) { + switch value { + case "MediaTransportControlCommandUpdateNetworkVariable_0Bytes": + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_0Bytes, true + case "MediaTransportControlCommandUpdateNetworkVariable_1Bytes": + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_1Bytes, true + case "MediaTransportControlCommandUpdateNetworkVariable_2Bytes": + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_2Bytes, true + case "MediaTransportControlCommandUpdateNetworkVariable_3Bytes": + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_3Bytes, true + case "MediaTransportControlCommandUpdateNetworkVariable_4Bytes": + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_4Bytes, true + case "MediaTransportControlCommandUpdateNetworkVariable_5Bytes": + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_5Bytes, true + case "MediaTransportControlCommandUpdateNetworkVariable_6Bytes": + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_6Bytes, true + case "MediaTransportControlCommandUpdateNetworkVariable_7Bytes": + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_7Bytes, true + case "MediaTransportControlCommandRequestRefresh": + return ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandRequestRefresh, true + } + return 0, false +} + +func ClockAndTimekeepingCommandTypeContainerKnows(value uint8) bool { + for _, typeValue := range ClockAndTimekeepingCommandTypeContainerValues { + if uint8(typeValue) == value { + return true + } + } + return false +} + +func CastClockAndTimekeepingCommandTypeContainer(structType interface{}) ClockAndTimekeepingCommandTypeContainer { + castFunc := func(typ interface{}) ClockAndTimekeepingCommandTypeContainer { + if sClockAndTimekeepingCommandTypeContainer, ok := typ.(ClockAndTimekeepingCommandTypeContainer); ok { + return sClockAndTimekeepingCommandTypeContainer + } + return 0 + } + return castFunc(structType) +} + +func (m ClockAndTimekeepingCommandTypeContainer) GetLengthInBits() uint16 { + return 8 +} + +func (m ClockAndTimekeepingCommandTypeContainer) GetLengthInBytes() uint16 { + return m.GetLengthInBits() / 8 +} + +func ClockAndTimekeepingCommandTypeContainerParse(readBuffer utils.ReadBuffer) (ClockAndTimekeepingCommandTypeContainer, error) { + val, err := readBuffer.ReadUint8("ClockAndTimekeepingCommandTypeContainer", 8) + if err != nil { + return 0, errors.Wrap(err, "error reading ClockAndTimekeepingCommandTypeContainer") + } + if enum, ok := ClockAndTimekeepingCommandTypeContainerByValue(val); !ok { + log.Debug().Msgf("no value %x found for RequestType", val) + return ClockAndTimekeepingCommandTypeContainer(val), nil + } else { + return enum, nil + } +} + +func (e ClockAndTimekeepingCommandTypeContainer) Serialize(writeBuffer utils.WriteBuffer) error { + return writeBuffer.WriteUint8("ClockAndTimekeepingCommandTypeContainer", 8, uint8(e), utils.WithAdditionalStringRepresentation(e.PLC4XEnumName())) +} + +// PLC4XEnumName returns the name that is used in code to identify this enum +func (e ClockAndTimekeepingCommandTypeContainer) PLC4XEnumName() string { + switch e { + case ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_0Bytes: + return "MediaTransportControlCommandUpdateNetworkVariable_0Bytes" + case ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_1Bytes: + return "MediaTransportControlCommandUpdateNetworkVariable_1Bytes" + case ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_2Bytes: + return "MediaTransportControlCommandUpdateNetworkVariable_2Bytes" + case ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_3Bytes: + return "MediaTransportControlCommandUpdateNetworkVariable_3Bytes" + case ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_4Bytes: + return "MediaTransportControlCommandUpdateNetworkVariable_4Bytes" + case ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_5Bytes: + return "MediaTransportControlCommandUpdateNetworkVariable_5Bytes" + case ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_6Bytes: + return "MediaTransportControlCommandUpdateNetworkVariable_6Bytes" + case ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandUpdateNetworkVariable_7Bytes: + return "MediaTransportControlCommandUpdateNetworkVariable_7Bytes" + case ClockAndTimekeepingCommandTypeContainer_MediaTransportControlCommandRequestRefresh: + return "MediaTransportControlCommandRequestRefresh" + } + return "" +} + +func (e ClockAndTimekeepingCommandTypeContainer) String() string { + return e.PLC4XEnumName() +} diff --git a/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingData.go b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingData.go new file mode 100644 index 00000000000..b0cff1da5a4 --- /dev/null +++ b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingData.go @@ -0,0 +1,273 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "github.com/apache/plc4x/plc4go/internal/spi/utils" + "github.com/pkg/errors" +) + +// Code generated by code-generation. DO NOT EDIT. + +// ClockAndTimekeepingData is the corresponding interface of ClockAndTimekeepingData +type ClockAndTimekeepingData interface { + utils.LengthAware + utils.Serializable + // GetCommandTypeContainer returns CommandTypeContainer (property field) + GetCommandTypeContainer() ClockAndTimekeepingCommandTypeContainer + // GetArgument returns Argument (property field) + GetArgument() byte + // GetCommandType returns CommandType (virtual field) + GetCommandType() ClockAndTimekeepingCommandType +} + +// ClockAndTimekeepingDataExactly can be used when we want exactly this type and not a type which fulfills ClockAndTimekeepingData. +// This is useful for switch cases. +type ClockAndTimekeepingDataExactly interface { + ClockAndTimekeepingData + isClockAndTimekeepingData() bool +} + +// _ClockAndTimekeepingData is the data-structure of this message +type _ClockAndTimekeepingData struct { + _ClockAndTimekeepingDataChildRequirements + CommandTypeContainer ClockAndTimekeepingCommandTypeContainer + Argument byte +} + +type _ClockAndTimekeepingDataChildRequirements interface { + utils.Serializable + GetLengthInBits() uint16 + GetLengthInBitsConditional(lastItem bool) uint16 +} + +type ClockAndTimekeepingDataParent interface { + SerializeParent(writeBuffer utils.WriteBuffer, child ClockAndTimekeepingData, serializeChildFunction func() error) error + GetTypeName() string +} + +type ClockAndTimekeepingDataChild interface { + utils.Serializable + InitializeParent(parent ClockAndTimekeepingData, commandTypeContainer ClockAndTimekeepingCommandTypeContainer, argument byte) + GetParent() *ClockAndTimekeepingData + + GetTypeName() string + ClockAndTimekeepingData +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_ClockAndTimekeepingData) GetCommandTypeContainer() ClockAndTimekeepingCommandTypeContainer { + return m.CommandTypeContainer +} + +func (m *_ClockAndTimekeepingData) GetArgument() byte { + return m.Argument +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for virtual fields. +/////////////////////// + +func (m *_ClockAndTimekeepingData) GetCommandType() ClockAndTimekeepingCommandType { + return CastClockAndTimekeepingCommandType(m.GetCommandTypeContainer().CommandType()) +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewClockAndTimekeepingData factory function for _ClockAndTimekeepingData +func NewClockAndTimekeepingData(commandTypeContainer ClockAndTimekeepingCommandTypeContainer, argument byte) *_ClockAndTimekeepingData { + return &_ClockAndTimekeepingData{CommandTypeContainer: commandTypeContainer, Argument: argument} +} + +// Deprecated: use the interface for direct cast +func CastClockAndTimekeepingData(structType interface{}) ClockAndTimekeepingData { + if casted, ok := structType.(ClockAndTimekeepingData); ok { + return casted + } + if casted, ok := structType.(*ClockAndTimekeepingData); ok { + return *casted + } + return nil +} + +func (m *_ClockAndTimekeepingData) GetTypeName() string { + return "ClockAndTimekeepingData" +} + +func (m *_ClockAndTimekeepingData) GetParentLengthInBits() uint16 { + lengthInBits := uint16(0) + + // Simple field (commandTypeContainer) + lengthInBits += 8 + + // A virtual field doesn't have any in- or output. + + // Simple field (argument) + lengthInBits += 8 + + return lengthInBits +} + +func (m *_ClockAndTimekeepingData) GetLengthInBytes() uint16 { + return m.GetLengthInBits() / 8 +} + +func ClockAndTimekeepingDataParse(readBuffer utils.ReadBuffer) (ClockAndTimekeepingData, error) { + positionAware := readBuffer + _ = positionAware + if pullErr := readBuffer.PullContext("ClockAndTimekeepingData"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for ClockAndTimekeepingData") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Validation + if !(KnowsClockAndTimekeepingCommandTypeContainer(readBuffer)) { + return nil, errors.WithStack(utils.ParseAssertError{"no command type could be found"}) + } + + // Simple Field (commandTypeContainer) + if pullErr := readBuffer.PullContext("commandTypeContainer"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for commandTypeContainer") + } + _commandTypeContainer, _commandTypeContainerErr := ClockAndTimekeepingCommandTypeContainerParse(readBuffer) + if _commandTypeContainerErr != nil { + return nil, errors.Wrap(_commandTypeContainerErr, "Error parsing 'commandTypeContainer' field of ClockAndTimekeepingData") + } + commandTypeContainer := _commandTypeContainer + if closeErr := readBuffer.CloseContext("commandTypeContainer"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for commandTypeContainer") + } + + // Virtual field + _commandType := commandTypeContainer.CommandType() + commandType := ClockAndTimekeepingCommandType(_commandType) + _ = commandType + + // Simple Field (argument) + _argument, _argumentErr := readBuffer.ReadByte("argument") + if _argumentErr != nil { + return nil, errors.Wrap(_argumentErr, "Error parsing 'argument' field of ClockAndTimekeepingData") + } + argument := _argument + + // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) + type ClockAndTimekeepingDataChildSerializeRequirement interface { + ClockAndTimekeepingData + InitializeParent(ClockAndTimekeepingData, ClockAndTimekeepingCommandTypeContainer, byte) + GetParent() ClockAndTimekeepingData + } + var _childTemp interface{} + var _child ClockAndTimekeepingDataChildSerializeRequirement + var typeSwitchError error + switch { + case commandType == ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE && argument == 0x01: // ClockAndTimekeepingDataUpdateTime + _childTemp, typeSwitchError = ClockAndTimekeepingDataUpdateTimeParse(readBuffer) + case commandType == ClockAndTimekeepingCommandType_UPDATE_NETWORK_VARIABLE && argument == 0x02: // ClockAndTimekeepingDataUpdateDate + _childTemp, typeSwitchError = ClockAndTimekeepingDataUpdateDateParse(readBuffer) + case commandType == ClockAndTimekeepingCommandType_REQUEST_REFRESH && argument == 0x03: // ClockAndTimekeepingDataRequestRefresh + _childTemp, typeSwitchError = ClockAndTimekeepingDataRequestRefreshParse(readBuffer) + default: + typeSwitchError = errors.Errorf("Unmapped type for parameters [commandType=%v, argument=%v]", commandType, argument) + } + if typeSwitchError != nil { + return nil, errors.Wrap(typeSwitchError, "Error parsing sub-type for type-switch of ClockAndTimekeepingData") + } + _child = _childTemp.(ClockAndTimekeepingDataChildSerializeRequirement) + + if closeErr := readBuffer.CloseContext("ClockAndTimekeepingData"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for ClockAndTimekeepingData") + } + + // Finish initializing + _child.InitializeParent(_child, commandTypeContainer, argument) + return _child, nil +} + +func (pm *_ClockAndTimekeepingData) SerializeParent(writeBuffer utils.WriteBuffer, child ClockAndTimekeepingData, serializeChildFunction func() error) error { + // We redirect all calls through client as some methods are only implemented there + m := child + _ = m + positionAware := writeBuffer + _ = positionAware + if pushErr := writeBuffer.PushContext("ClockAndTimekeepingData"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for ClockAndTimekeepingData") + } + + // Simple Field (commandTypeContainer) + if pushErr := writeBuffer.PushContext("commandTypeContainer"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for commandTypeContainer") + } + _commandTypeContainerErr := writeBuffer.WriteSerializable(m.GetCommandTypeContainer()) + if popErr := writeBuffer.PopContext("commandTypeContainer"); popErr != nil { + return errors.Wrap(popErr, "Error popping for commandTypeContainer") + } + if _commandTypeContainerErr != nil { + return errors.Wrap(_commandTypeContainerErr, "Error serializing 'commandTypeContainer' field") + } + // Virtual field + if _commandTypeErr := writeBuffer.WriteVirtual("commandType", m.GetCommandType()); _commandTypeErr != nil { + return errors.Wrap(_commandTypeErr, "Error serializing 'commandType' field") + } + + // Simple Field (argument) + argument := byte(m.GetArgument()) + _argumentErr := writeBuffer.WriteByte("argument", (argument)) + if _argumentErr != nil { + return errors.Wrap(_argumentErr, "Error serializing 'argument' field") + } + + // Switch field (Depending on the discriminator values, passes the serialization to a sub-type) + if _typeSwitchErr := serializeChildFunction(); _typeSwitchErr != nil { + return errors.Wrap(_typeSwitchErr, "Error serializing sub-type field") + } + + if popErr := writeBuffer.PopContext("ClockAndTimekeepingData"); popErr != nil { + return errors.Wrap(popErr, "Error popping for ClockAndTimekeepingData") + } + return nil +} + +func (m *_ClockAndTimekeepingData) isClockAndTimekeepingData() bool { + return true +} + +func (m *_ClockAndTimekeepingData) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewBoxedWriteBufferWithOptions(true, true) + if err := writeBuffer.WriteSerializable(m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataRequestRefresh.go b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataRequestRefresh.go new file mode 100644 index 00000000000..0d333b66cc7 --- /dev/null +++ b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataRequestRefresh.go @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "github.com/apache/plc4x/plc4go/internal/spi/utils" + "github.com/pkg/errors" +) + +// Code generated by code-generation. DO NOT EDIT. + +// ClockAndTimekeepingDataRequestRefresh is the corresponding interface of ClockAndTimekeepingDataRequestRefresh +type ClockAndTimekeepingDataRequestRefresh interface { + utils.LengthAware + utils.Serializable + ClockAndTimekeepingData +} + +// ClockAndTimekeepingDataRequestRefreshExactly can be used when we want exactly this type and not a type which fulfills ClockAndTimekeepingDataRequestRefresh. +// This is useful for switch cases. +type ClockAndTimekeepingDataRequestRefreshExactly interface { + ClockAndTimekeepingDataRequestRefresh + isClockAndTimekeepingDataRequestRefresh() bool +} + +// _ClockAndTimekeepingDataRequestRefresh is the data-structure of this message +type _ClockAndTimekeepingDataRequestRefresh struct { + *_ClockAndTimekeepingData +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for discriminator values. +/////////////////////// + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +func (m *_ClockAndTimekeepingDataRequestRefresh) InitializeParent(parent ClockAndTimekeepingData, commandTypeContainer ClockAndTimekeepingCommandTypeContainer, argument byte) { + m.CommandTypeContainer = commandTypeContainer + m.Argument = argument +} + +func (m *_ClockAndTimekeepingDataRequestRefresh) GetParent() ClockAndTimekeepingData { + return m._ClockAndTimekeepingData +} + +// NewClockAndTimekeepingDataRequestRefresh factory function for _ClockAndTimekeepingDataRequestRefresh +func NewClockAndTimekeepingDataRequestRefresh(commandTypeContainer ClockAndTimekeepingCommandTypeContainer, argument byte) *_ClockAndTimekeepingDataRequestRefresh { + _result := &_ClockAndTimekeepingDataRequestRefresh{ + _ClockAndTimekeepingData: NewClockAndTimekeepingData(commandTypeContainer, argument), + } + _result._ClockAndTimekeepingData._ClockAndTimekeepingDataChildRequirements = _result + return _result +} + +// Deprecated: use the interface for direct cast +func CastClockAndTimekeepingDataRequestRefresh(structType interface{}) ClockAndTimekeepingDataRequestRefresh { + if casted, ok := structType.(ClockAndTimekeepingDataRequestRefresh); ok { + return casted + } + if casted, ok := structType.(*ClockAndTimekeepingDataRequestRefresh); ok { + return *casted + } + return nil +} + +func (m *_ClockAndTimekeepingDataRequestRefresh) GetTypeName() string { + return "ClockAndTimekeepingDataRequestRefresh" +} + +func (m *_ClockAndTimekeepingDataRequestRefresh) GetLengthInBits() uint16 { + return m.GetLengthInBitsConditional(false) +} + +func (m *_ClockAndTimekeepingDataRequestRefresh) GetLengthInBitsConditional(lastItem bool) uint16 { + lengthInBits := uint16(m.GetParentLengthInBits()) + + return lengthInBits +} + +func (m *_ClockAndTimekeepingDataRequestRefresh) GetLengthInBytes() uint16 { + return m.GetLengthInBits() / 8 +} + +func ClockAndTimekeepingDataRequestRefreshParse(readBuffer utils.ReadBuffer) (ClockAndTimekeepingDataRequestRefresh, error) { + positionAware := readBuffer + _ = positionAware + if pullErr := readBuffer.PullContext("ClockAndTimekeepingDataRequestRefresh"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for ClockAndTimekeepingDataRequestRefresh") + } + currentPos := positionAware.GetPos() + _ = currentPos + + if closeErr := readBuffer.CloseContext("ClockAndTimekeepingDataRequestRefresh"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for ClockAndTimekeepingDataRequestRefresh") + } + + // Create a partially initialized instance + _child := &_ClockAndTimekeepingDataRequestRefresh{ + _ClockAndTimekeepingData: &_ClockAndTimekeepingData{}, + } + _child._ClockAndTimekeepingData._ClockAndTimekeepingDataChildRequirements = _child + return _child, nil +} + +func (m *_ClockAndTimekeepingDataRequestRefresh) Serialize(writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + ser := func() error { + if pushErr := writeBuffer.PushContext("ClockAndTimekeepingDataRequestRefresh"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for ClockAndTimekeepingDataRequestRefresh") + } + + if popErr := writeBuffer.PopContext("ClockAndTimekeepingDataRequestRefresh"); popErr != nil { + return errors.Wrap(popErr, "Error popping for ClockAndTimekeepingDataRequestRefresh") + } + return nil + } + return m.SerializeParent(writeBuffer, m, ser) +} + +func (m *_ClockAndTimekeepingDataRequestRefresh) isClockAndTimekeepingDataRequestRefresh() bool { + return true +} + +func (m *_ClockAndTimekeepingDataRequestRefresh) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewBoxedWriteBufferWithOptions(true, true) + if err := writeBuffer.WriteSerializable(m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataUpdateDate.go b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataUpdateDate.go new file mode 100644 index 00000000000..56db00b04a0 --- /dev/null +++ b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataUpdateDate.go @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "github.com/apache/plc4x/plc4go/internal/spi/utils" + "github.com/pkg/errors" +) + +// Code generated by code-generation. DO NOT EDIT. + +// ClockAndTimekeepingDataUpdateDate is the corresponding interface of ClockAndTimekeepingDataUpdateDate +type ClockAndTimekeepingDataUpdateDate interface { + utils.LengthAware + utils.Serializable + ClockAndTimekeepingData + // GetYearHigh returns YearHigh (property field) + GetYearHigh() byte + // GetYearLow returns YearLow (property field) + GetYearLow() byte + // GetMonth returns Month (property field) + GetMonth() uint8 + // GetDay returns Day (property field) + GetDay() uint8 + // GetDayOfWeek returns DayOfWeek (property field) + GetDayOfWeek() uint8 +} + +// ClockAndTimekeepingDataUpdateDateExactly can be used when we want exactly this type and not a type which fulfills ClockAndTimekeepingDataUpdateDate. +// This is useful for switch cases. +type ClockAndTimekeepingDataUpdateDateExactly interface { + ClockAndTimekeepingDataUpdateDate + isClockAndTimekeepingDataUpdateDate() bool +} + +// _ClockAndTimekeepingDataUpdateDate is the data-structure of this message +type _ClockAndTimekeepingDataUpdateDate struct { + *_ClockAndTimekeepingData + YearHigh byte + YearLow byte + Month uint8 + Day uint8 + DayOfWeek uint8 +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for discriminator values. +/////////////////////// + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +func (m *_ClockAndTimekeepingDataUpdateDate) InitializeParent(parent ClockAndTimekeepingData, commandTypeContainer ClockAndTimekeepingCommandTypeContainer, argument byte) { + m.CommandTypeContainer = commandTypeContainer + m.Argument = argument +} + +func (m *_ClockAndTimekeepingDataUpdateDate) GetParent() ClockAndTimekeepingData { + return m._ClockAndTimekeepingData +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_ClockAndTimekeepingDataUpdateDate) GetYearHigh() byte { + return m.YearHigh +} + +func (m *_ClockAndTimekeepingDataUpdateDate) GetYearLow() byte { + return m.YearLow +} + +func (m *_ClockAndTimekeepingDataUpdateDate) GetMonth() uint8 { + return m.Month +} + +func (m *_ClockAndTimekeepingDataUpdateDate) GetDay() uint8 { + return m.Day +} + +func (m *_ClockAndTimekeepingDataUpdateDate) GetDayOfWeek() uint8 { + return m.DayOfWeek +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewClockAndTimekeepingDataUpdateDate factory function for _ClockAndTimekeepingDataUpdateDate +func NewClockAndTimekeepingDataUpdateDate(yearHigh byte, yearLow byte, month uint8, day uint8, dayOfWeek uint8, commandTypeContainer ClockAndTimekeepingCommandTypeContainer, argument byte) *_ClockAndTimekeepingDataUpdateDate { + _result := &_ClockAndTimekeepingDataUpdateDate{ + YearHigh: yearHigh, + YearLow: yearLow, + Month: month, + Day: day, + DayOfWeek: dayOfWeek, + _ClockAndTimekeepingData: NewClockAndTimekeepingData(commandTypeContainer, argument), + } + _result._ClockAndTimekeepingData._ClockAndTimekeepingDataChildRequirements = _result + return _result +} + +// Deprecated: use the interface for direct cast +func CastClockAndTimekeepingDataUpdateDate(structType interface{}) ClockAndTimekeepingDataUpdateDate { + if casted, ok := structType.(ClockAndTimekeepingDataUpdateDate); ok { + return casted + } + if casted, ok := structType.(*ClockAndTimekeepingDataUpdateDate); ok { + return *casted + } + return nil +} + +func (m *_ClockAndTimekeepingDataUpdateDate) GetTypeName() string { + return "ClockAndTimekeepingDataUpdateDate" +} + +func (m *_ClockAndTimekeepingDataUpdateDate) GetLengthInBits() uint16 { + return m.GetLengthInBitsConditional(false) +} + +func (m *_ClockAndTimekeepingDataUpdateDate) GetLengthInBitsConditional(lastItem bool) uint16 { + lengthInBits := uint16(m.GetParentLengthInBits()) + + // Simple field (yearHigh) + lengthInBits += 8 + + // Simple field (yearLow) + lengthInBits += 8 + + // Simple field (month) + lengthInBits += 8 + + // Simple field (day) + lengthInBits += 8 + + // Simple field (dayOfWeek) + lengthInBits += 8 + + return lengthInBits +} + +func (m *_ClockAndTimekeepingDataUpdateDate) GetLengthInBytes() uint16 { + return m.GetLengthInBits() / 8 +} + +func ClockAndTimekeepingDataUpdateDateParse(readBuffer utils.ReadBuffer) (ClockAndTimekeepingDataUpdateDate, error) { + positionAware := readBuffer + _ = positionAware + if pullErr := readBuffer.PullContext("ClockAndTimekeepingDataUpdateDate"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for ClockAndTimekeepingDataUpdateDate") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Simple Field (yearHigh) + _yearHigh, _yearHighErr := readBuffer.ReadByte("yearHigh") + if _yearHighErr != nil { + return nil, errors.Wrap(_yearHighErr, "Error parsing 'yearHigh' field of ClockAndTimekeepingDataUpdateDate") + } + yearHigh := _yearHigh + + // Simple Field (yearLow) + _yearLow, _yearLowErr := readBuffer.ReadByte("yearLow") + if _yearLowErr != nil { + return nil, errors.Wrap(_yearLowErr, "Error parsing 'yearLow' field of ClockAndTimekeepingDataUpdateDate") + } + yearLow := _yearLow + + // Simple Field (month) + _month, _monthErr := readBuffer.ReadUint8("month", 8) + if _monthErr != nil { + return nil, errors.Wrap(_monthErr, "Error parsing 'month' field of ClockAndTimekeepingDataUpdateDate") + } + month := _month + + // Simple Field (day) + _day, _dayErr := readBuffer.ReadUint8("day", 8) + if _dayErr != nil { + return nil, errors.Wrap(_dayErr, "Error parsing 'day' field of ClockAndTimekeepingDataUpdateDate") + } + day := _day + + // Simple Field (dayOfWeek) + _dayOfWeek, _dayOfWeekErr := readBuffer.ReadUint8("dayOfWeek", 8) + if _dayOfWeekErr != nil { + return nil, errors.Wrap(_dayOfWeekErr, "Error parsing 'dayOfWeek' field of ClockAndTimekeepingDataUpdateDate") + } + dayOfWeek := _dayOfWeek + + if closeErr := readBuffer.CloseContext("ClockAndTimekeepingDataUpdateDate"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for ClockAndTimekeepingDataUpdateDate") + } + + // Create a partially initialized instance + _child := &_ClockAndTimekeepingDataUpdateDate{ + YearHigh: yearHigh, + YearLow: yearLow, + Month: month, + Day: day, + DayOfWeek: dayOfWeek, + _ClockAndTimekeepingData: &_ClockAndTimekeepingData{}, + } + _child._ClockAndTimekeepingData._ClockAndTimekeepingDataChildRequirements = _child + return _child, nil +} + +func (m *_ClockAndTimekeepingDataUpdateDate) Serialize(writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + ser := func() error { + if pushErr := writeBuffer.PushContext("ClockAndTimekeepingDataUpdateDate"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for ClockAndTimekeepingDataUpdateDate") + } + + // Simple Field (yearHigh) + yearHigh := byte(m.GetYearHigh()) + _yearHighErr := writeBuffer.WriteByte("yearHigh", (yearHigh)) + if _yearHighErr != nil { + return errors.Wrap(_yearHighErr, "Error serializing 'yearHigh' field") + } + + // Simple Field (yearLow) + yearLow := byte(m.GetYearLow()) + _yearLowErr := writeBuffer.WriteByte("yearLow", (yearLow)) + if _yearLowErr != nil { + return errors.Wrap(_yearLowErr, "Error serializing 'yearLow' field") + } + + // Simple Field (month) + month := uint8(m.GetMonth()) + _monthErr := writeBuffer.WriteUint8("month", 8, (month)) + if _monthErr != nil { + return errors.Wrap(_monthErr, "Error serializing 'month' field") + } + + // Simple Field (day) + day := uint8(m.GetDay()) + _dayErr := writeBuffer.WriteUint8("day", 8, (day)) + if _dayErr != nil { + return errors.Wrap(_dayErr, "Error serializing 'day' field") + } + + // Simple Field (dayOfWeek) + dayOfWeek := uint8(m.GetDayOfWeek()) + _dayOfWeekErr := writeBuffer.WriteUint8("dayOfWeek", 8, (dayOfWeek)) + if _dayOfWeekErr != nil { + return errors.Wrap(_dayOfWeekErr, "Error serializing 'dayOfWeek' field") + } + + if popErr := writeBuffer.PopContext("ClockAndTimekeepingDataUpdateDate"); popErr != nil { + return errors.Wrap(popErr, "Error popping for ClockAndTimekeepingDataUpdateDate") + } + return nil + } + return m.SerializeParent(writeBuffer, m, ser) +} + +func (m *_ClockAndTimekeepingDataUpdateDate) isClockAndTimekeepingDataUpdateDate() bool { + return true +} + +func (m *_ClockAndTimekeepingDataUpdateDate) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewBoxedWriteBufferWithOptions(true, true) + if err := writeBuffer.WriteSerializable(m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataUpdateTime.go b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataUpdateTime.go new file mode 100644 index 00000000000..b10fb74db2e --- /dev/null +++ b/plc4go/protocols/cbus/readwrite/model/ClockAndTimekeepingDataUpdateTime.go @@ -0,0 +1,346 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package model + +import ( + "github.com/apache/plc4x/plc4go/internal/spi/utils" + "github.com/pkg/errors" +) + +// Code generated by code-generation. DO NOT EDIT. + +// ClockAndTimekeepingDataUpdateTime is the corresponding interface of ClockAndTimekeepingDataUpdateTime +type ClockAndTimekeepingDataUpdateTime interface { + utils.LengthAware + utils.Serializable + ClockAndTimekeepingData + // GetHours returns Hours (property field) + GetHours() uint8 + // GetMinute returns Minute (property field) + GetMinute() uint8 + // GetSecond returns Second (property field) + GetSecond() uint8 + // GetDaylightSaving returns DaylightSaving (property field) + GetDaylightSaving() byte + // GetIsNoDaylightSavings returns IsNoDaylightSavings (virtual field) + GetIsNoDaylightSavings() bool + // GetIsAdvancedBy1Hour returns IsAdvancedBy1Hour (virtual field) + GetIsAdvancedBy1Hour() bool + // GetIsReserved returns IsReserved (virtual field) + GetIsReserved() bool + // GetIsUnknown returns IsUnknown (virtual field) + GetIsUnknown() bool +} + +// ClockAndTimekeepingDataUpdateTimeExactly can be used when we want exactly this type and not a type which fulfills ClockAndTimekeepingDataUpdateTime. +// This is useful for switch cases. +type ClockAndTimekeepingDataUpdateTimeExactly interface { + ClockAndTimekeepingDataUpdateTime + isClockAndTimekeepingDataUpdateTime() bool +} + +// _ClockAndTimekeepingDataUpdateTime is the data-structure of this message +type _ClockAndTimekeepingDataUpdateTime struct { + *_ClockAndTimekeepingData + Hours uint8 + Minute uint8 + Second uint8 + DaylightSaving byte +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for discriminator values. +/////////////////////// + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +func (m *_ClockAndTimekeepingDataUpdateTime) InitializeParent(parent ClockAndTimekeepingData, commandTypeContainer ClockAndTimekeepingCommandTypeContainer, argument byte) { + m.CommandTypeContainer = commandTypeContainer + m.Argument = argument +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetParent() ClockAndTimekeepingData { + return m._ClockAndTimekeepingData +} + +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_ClockAndTimekeepingDataUpdateTime) GetHours() uint8 { + return m.Hours +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetMinute() uint8 { + return m.Minute +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetSecond() uint8 { + return m.Second +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetDaylightSaving() byte { + return m.DaylightSaving +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for virtual fields. +/////////////////////// + +func (m *_ClockAndTimekeepingDataUpdateTime) GetIsNoDaylightSavings() bool { + return bool(bool((m.GetDaylightSaving()) == (0x00))) +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetIsAdvancedBy1Hour() bool { + return bool(bool((m.GetDaylightSaving()) == (0x01))) +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetIsReserved() bool { + return bool(bool(bool((m.GetDaylightSaving()) > (0x01))) && bool(bool((m.GetDaylightSaving()) <= (0xFE)))) +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetIsUnknown() bool { + return bool(bool((m.GetDaylightSaving()) > (0xFE))) +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +// NewClockAndTimekeepingDataUpdateTime factory function for _ClockAndTimekeepingDataUpdateTime +func NewClockAndTimekeepingDataUpdateTime(hours uint8, minute uint8, second uint8, daylightSaving byte, commandTypeContainer ClockAndTimekeepingCommandTypeContainer, argument byte) *_ClockAndTimekeepingDataUpdateTime { + _result := &_ClockAndTimekeepingDataUpdateTime{ + Hours: hours, + Minute: minute, + Second: second, + DaylightSaving: daylightSaving, + _ClockAndTimekeepingData: NewClockAndTimekeepingData(commandTypeContainer, argument), + } + _result._ClockAndTimekeepingData._ClockAndTimekeepingDataChildRequirements = _result + return _result +} + +// Deprecated: use the interface for direct cast +func CastClockAndTimekeepingDataUpdateTime(structType interface{}) ClockAndTimekeepingDataUpdateTime { + if casted, ok := structType.(ClockAndTimekeepingDataUpdateTime); ok { + return casted + } + if casted, ok := structType.(*ClockAndTimekeepingDataUpdateTime); ok { + return *casted + } + return nil +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetTypeName() string { + return "ClockAndTimekeepingDataUpdateTime" +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetLengthInBits() uint16 { + return m.GetLengthInBitsConditional(false) +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetLengthInBitsConditional(lastItem bool) uint16 { + lengthInBits := uint16(m.GetParentLengthInBits()) + + // Simple field (hours) + lengthInBits += 8 + + // Simple field (minute) + lengthInBits += 8 + + // Simple field (second) + lengthInBits += 8 + + // Simple field (daylightSaving) + lengthInBits += 8 + + // A virtual field doesn't have any in- or output. + + // A virtual field doesn't have any in- or output. + + // A virtual field doesn't have any in- or output. + + // A virtual field doesn't have any in- or output. + + return lengthInBits +} + +func (m *_ClockAndTimekeepingDataUpdateTime) GetLengthInBytes() uint16 { + return m.GetLengthInBits() / 8 +} + +func ClockAndTimekeepingDataUpdateTimeParse(readBuffer utils.ReadBuffer) (ClockAndTimekeepingDataUpdateTime, error) { + positionAware := readBuffer + _ = positionAware + if pullErr := readBuffer.PullContext("ClockAndTimekeepingDataUpdateTime"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for ClockAndTimekeepingDataUpdateTime") + } + currentPos := positionAware.GetPos() + _ = currentPos + + // Simple Field (hours) + _hours, _hoursErr := readBuffer.ReadUint8("hours", 8) + if _hoursErr != nil { + return nil, errors.Wrap(_hoursErr, "Error parsing 'hours' field of ClockAndTimekeepingDataUpdateTime") + } + hours := _hours + + // Simple Field (minute) + _minute, _minuteErr := readBuffer.ReadUint8("minute", 8) + if _minuteErr != nil { + return nil, errors.Wrap(_minuteErr, "Error parsing 'minute' field of ClockAndTimekeepingDataUpdateTime") + } + minute := _minute + + // Simple Field (second) + _second, _secondErr := readBuffer.ReadUint8("second", 8) + if _secondErr != nil { + return nil, errors.Wrap(_secondErr, "Error parsing 'second' field of ClockAndTimekeepingDataUpdateTime") + } + second := _second + + // Simple Field (daylightSaving) + _daylightSaving, _daylightSavingErr := readBuffer.ReadByte("daylightSaving") + if _daylightSavingErr != nil { + return nil, errors.Wrap(_daylightSavingErr, "Error parsing 'daylightSaving' field of ClockAndTimekeepingDataUpdateTime") + } + daylightSaving := _daylightSaving + + // Virtual field + _isNoDaylightSavings := bool((daylightSaving) == (0x00)) + isNoDaylightSavings := bool(_isNoDaylightSavings) + _ = isNoDaylightSavings + + // Virtual field + _isAdvancedBy1Hour := bool((daylightSaving) == (0x01)) + isAdvancedBy1Hour := bool(_isAdvancedBy1Hour) + _ = isAdvancedBy1Hour + + // Virtual field + _isReserved := bool(bool((daylightSaving) > (0x01))) && bool(bool((daylightSaving) <= (0xFE))) + isReserved := bool(_isReserved) + _ = isReserved + + // Virtual field + _isUnknown := bool((daylightSaving) > (0xFE)) + isUnknown := bool(_isUnknown) + _ = isUnknown + + if closeErr := readBuffer.CloseContext("ClockAndTimekeepingDataUpdateTime"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for ClockAndTimekeepingDataUpdateTime") + } + + // Create a partially initialized instance + _child := &_ClockAndTimekeepingDataUpdateTime{ + Hours: hours, + Minute: minute, + Second: second, + DaylightSaving: daylightSaving, + _ClockAndTimekeepingData: &_ClockAndTimekeepingData{}, + } + _child._ClockAndTimekeepingData._ClockAndTimekeepingDataChildRequirements = _child + return _child, nil +} + +func (m *_ClockAndTimekeepingDataUpdateTime) Serialize(writeBuffer utils.WriteBuffer) error { + positionAware := writeBuffer + _ = positionAware + ser := func() error { + if pushErr := writeBuffer.PushContext("ClockAndTimekeepingDataUpdateTime"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for ClockAndTimekeepingDataUpdateTime") + } + + // Simple Field (hours) + hours := uint8(m.GetHours()) + _hoursErr := writeBuffer.WriteUint8("hours", 8, (hours)) + if _hoursErr != nil { + return errors.Wrap(_hoursErr, "Error serializing 'hours' field") + } + + // Simple Field (minute) + minute := uint8(m.GetMinute()) + _minuteErr := writeBuffer.WriteUint8("minute", 8, (minute)) + if _minuteErr != nil { + return errors.Wrap(_minuteErr, "Error serializing 'minute' field") + } + + // Simple Field (second) + second := uint8(m.GetSecond()) + _secondErr := writeBuffer.WriteUint8("second", 8, (second)) + if _secondErr != nil { + return errors.Wrap(_secondErr, "Error serializing 'second' field") + } + + // Simple Field (daylightSaving) + daylightSaving := byte(m.GetDaylightSaving()) + _daylightSavingErr := writeBuffer.WriteByte("daylightSaving", (daylightSaving)) + if _daylightSavingErr != nil { + return errors.Wrap(_daylightSavingErr, "Error serializing 'daylightSaving' field") + } + // Virtual field + if _isNoDaylightSavingsErr := writeBuffer.WriteVirtual("isNoDaylightSavings", m.GetIsNoDaylightSavings()); _isNoDaylightSavingsErr != nil { + return errors.Wrap(_isNoDaylightSavingsErr, "Error serializing 'isNoDaylightSavings' field") + } + // Virtual field + if _isAdvancedBy1HourErr := writeBuffer.WriteVirtual("isAdvancedBy1Hour", m.GetIsAdvancedBy1Hour()); _isAdvancedBy1HourErr != nil { + return errors.Wrap(_isAdvancedBy1HourErr, "Error serializing 'isAdvancedBy1Hour' field") + } + // Virtual field + if _isReservedErr := writeBuffer.WriteVirtual("isReserved", m.GetIsReserved()); _isReservedErr != nil { + return errors.Wrap(_isReservedErr, "Error serializing 'isReserved' field") + } + // Virtual field + if _isUnknownErr := writeBuffer.WriteVirtual("isUnknown", m.GetIsUnknown()); _isUnknownErr != nil { + return errors.Wrap(_isUnknownErr, "Error serializing 'isUnknown' field") + } + + if popErr := writeBuffer.PopContext("ClockAndTimekeepingDataUpdateTime"); popErr != nil { + return errors.Wrap(popErr, "Error popping for ClockAndTimekeepingDataUpdateTime") + } + return nil + } + return m.SerializeParent(writeBuffer, m, ser) +} + +func (m *_ClockAndTimekeepingDataUpdateTime) isClockAndTimekeepingDataUpdateTime() bool { + return true +} + +func (m *_ClockAndTimekeepingDataUpdateTime) String() string { + if m == nil { + return "" + } + writeBuffer := utils.NewBoxedWriteBufferWithOptions(true, true) + if err := writeBuffer.WriteSerializable(m); err != nil { + return err.Error() + } + return writeBuffer.GetBox().String() +} diff --git a/plc4go/protocols/cbus/readwrite/model/SALDataClockAndTimekeeping.go b/plc4go/protocols/cbus/readwrite/model/SALDataClockAndTimekeeping.go index 7ab9e4a9258..9c403893785 100644 --- a/plc4go/protocols/cbus/readwrite/model/SALDataClockAndTimekeeping.go +++ b/plc4go/protocols/cbus/readwrite/model/SALDataClockAndTimekeeping.go @@ -31,6 +31,8 @@ type SALDataClockAndTimekeeping interface { utils.LengthAware utils.Serializable SALData + // GetClockAndTimekeepingData returns ClockAndTimekeepingData (property field) + GetClockAndTimekeepingData() ClockAndTimekeepingData } // SALDataClockAndTimekeepingExactly can be used when we want exactly this type and not a type which fulfills SALDataClockAndTimekeeping. @@ -43,6 +45,7 @@ type SALDataClockAndTimekeepingExactly interface { // _SALDataClockAndTimekeeping is the data-structure of this message type _SALDataClockAndTimekeeping struct { *_SALData + ClockAndTimekeepingData ClockAndTimekeepingData } /////////////////////////////////////////////////////////// @@ -67,10 +70,25 @@ func (m *_SALDataClockAndTimekeeping) GetParent() SALData { return m._SALData } +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////// Accessors for property fields. +/////////////////////// + +func (m *_SALDataClockAndTimekeeping) GetClockAndTimekeepingData() ClockAndTimekeepingData { + return m.ClockAndTimekeepingData +} + +/////////////////////// +/////////////////////// +/////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////// + // NewSALDataClockAndTimekeeping factory function for _SALDataClockAndTimekeeping -func NewSALDataClockAndTimekeeping(salData SALData) *_SALDataClockAndTimekeeping { +func NewSALDataClockAndTimekeeping(clockAndTimekeepingData ClockAndTimekeepingData, salData SALData) *_SALDataClockAndTimekeeping { _result := &_SALDataClockAndTimekeeping{ - _SALData: NewSALData(salData), + ClockAndTimekeepingData: clockAndTimekeepingData, + _SALData: NewSALData(salData), } _result._SALData._SALDataChildRequirements = _result return _result @@ -98,6 +116,9 @@ func (m *_SALDataClockAndTimekeeping) GetLengthInBits() uint16 { func (m *_SALDataClockAndTimekeeping) GetLengthInBitsConditional(lastItem bool) uint16 { lengthInBits := uint16(m.GetParentLengthInBits()) + // Simple field (clockAndTimekeepingData) + lengthInBits += m.ClockAndTimekeepingData.GetLengthInBits() + return lengthInBits } @@ -114,9 +135,17 @@ func SALDataClockAndTimekeepingParse(readBuffer utils.ReadBuffer, applicationId currentPos := positionAware.GetPos() _ = currentPos - // Validation - if !(bool((1) == (2))) { - return nil, errors.WithStack(utils.ParseValidationError{"CLOCK_AND_TIMEKEEPING Not yet implemented"}) + // Simple Field (clockAndTimekeepingData) + if pullErr := readBuffer.PullContext("clockAndTimekeepingData"); pullErr != nil { + return nil, errors.Wrap(pullErr, "Error pulling for clockAndTimekeepingData") + } + _clockAndTimekeepingData, _clockAndTimekeepingDataErr := ClockAndTimekeepingDataParse(readBuffer) + if _clockAndTimekeepingDataErr != nil { + return nil, errors.Wrap(_clockAndTimekeepingDataErr, "Error parsing 'clockAndTimekeepingData' field of SALDataClockAndTimekeeping") + } + clockAndTimekeepingData := _clockAndTimekeepingData.(ClockAndTimekeepingData) + if closeErr := readBuffer.CloseContext("clockAndTimekeepingData"); closeErr != nil { + return nil, errors.Wrap(closeErr, "Error closing for clockAndTimekeepingData") } if closeErr := readBuffer.CloseContext("SALDataClockAndTimekeeping"); closeErr != nil { @@ -125,7 +154,8 @@ func SALDataClockAndTimekeepingParse(readBuffer utils.ReadBuffer, applicationId // Create a partially initialized instance _child := &_SALDataClockAndTimekeeping{ - _SALData: &_SALData{}, + ClockAndTimekeepingData: clockAndTimekeepingData, + _SALData: &_SALData{}, } _child._SALData._SALDataChildRequirements = _child return _child, nil @@ -139,6 +169,18 @@ func (m *_SALDataClockAndTimekeeping) Serialize(writeBuffer utils.WriteBuffer) e return errors.Wrap(pushErr, "Error pushing for SALDataClockAndTimekeeping") } + // Simple Field (clockAndTimekeepingData) + if pushErr := writeBuffer.PushContext("clockAndTimekeepingData"); pushErr != nil { + return errors.Wrap(pushErr, "Error pushing for clockAndTimekeepingData") + } + _clockAndTimekeepingDataErr := writeBuffer.WriteSerializable(m.GetClockAndTimekeepingData()) + if popErr := writeBuffer.PopContext("clockAndTimekeepingData"); popErr != nil { + return errors.Wrap(popErr, "Error popping for clockAndTimekeepingData") + } + if _clockAndTimekeepingDataErr != nil { + return errors.Wrap(_clockAndTimekeepingDataErr, "Error serializing 'clockAndTimekeepingData' field") + } + if popErr := writeBuffer.PopContext("SALDataClockAndTimekeeping"); popErr != nil { return errors.Wrap(popErr, "Error popping for SALDataClockAndTimekeeping") } diff --git a/plc4go/protocols/cbus/readwrite/model/StaticHelper.go b/plc4go/protocols/cbus/readwrite/model/StaticHelper.go index 475ee7cbfd9..a1ada507529 100644 --- a/plc4go/protocols/cbus/readwrite/model/StaticHelper.go +++ b/plc4go/protocols/cbus/readwrite/model/StaticHelper.go @@ -201,3 +201,13 @@ func KnowsMediaTransportControlCommandTypeContainer(readBuffer utils.ReadBuffer) } return MediaTransportControlCommandTypeContainerKnows(readUint8) } + +func KnowsClockAndTimekeepingCommandTypeContainer(readBuffer utils.ReadBuffer) bool { + oldPos := readBuffer.GetPos() + defer readBuffer.Reset(oldPos) + readUint8, err := readBuffer.ReadUint8("", 8) + if err != nil { + return false + } + return ClockAndTimekeepingCommandTypeContainerKnows(readUint8) +} diff --git a/plc4j/drivers/c-bus/src/main/java/org/apache/plc4x/java/cbus/readwrite/utils/StaticHelper.java b/plc4j/drivers/c-bus/src/main/java/org/apache/plc4x/java/cbus/readwrite/utils/StaticHelper.java index 6e8131fab51..3148f675ba3 100644 --- a/plc4j/drivers/c-bus/src/main/java/org/apache/plc4x/java/cbus/readwrite/utils/StaticHelper.java +++ b/plc4j/drivers/c-bus/src/main/java/org/apache/plc4x/java/cbus/readwrite/utils/StaticHelper.java @@ -183,4 +183,15 @@ public static boolean knowsMediaTransportControlCommandTypeContainer(ReadBuffer } } + public static boolean knowsClockAndTimekeepingCommandTypeContainer(ReadBuffer readBuffer) { + int oldPos = readBuffer.getPos(); + try { + return ClockAndTimekeepingCommandTypeContainer.isDefined(readBuffer.readUnsignedShort(8)); + } catch (ParseException ignore) { + return false; + } finally { + readBuffer.reset(oldPos); + } + } + } diff --git a/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/ReferenceTest.java b/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/ReferenceTest.java index f5ea8954c63..ca3504545e3 100644 --- a/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/ReferenceTest.java +++ b/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/ReferenceTest.java @@ -1092,14 +1092,57 @@ void lockAccessPointRemote() throws Exception { // from: https://updates.clipsal.com/ClipsalSoftwareDownload/DL/downloads/OpenCBus/Chapter%2021%20-%20C-Bus%20Media%20Transport%20Control%20Application.pdf @Nested class MediaTransportControlApplicationsTest{ + // TODO: no tests described here + } - //9.11 + // from: https://updates.clipsal.com/ClipsalSoftwareDownload/DL/downloads/OpenCBus/Chapter%2023%20-%20C-Bus%20Clock%20and%20Timekeeping%20Application.pdf + @Nested + class ClockAndTimekeeping{ + + //23.13 @Nested class Examples{ @Test - void tbd() throws Exception { - byte[] bytes = "\\05D500A4010300017D\r".getBytes(StandardCharsets.UTF_8); + void outputATimeCommand() throws Exception { + byte[] bytes = "\\05DF000D010A2B1700C2\r".getBytes(StandardCharsets.UTF_8); + ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes); + cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true); + CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length); + assertThat(msg).isNotNull(); + System.out.println(msg); + System.out.println(((RequestCommand) ((CBusMessageToServer) msg).getRequest()).getCbusCommand()); + assertMessageMatches(bytes, msg); + } + + @Test + void outputADateCommand() throws Exception { + byte[] bytes = "\\05DF000E0207D502190411\r".getBytes(StandardCharsets.UTF_8); + ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes); + cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true); + CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length); + assertThat(msg).isNotNull(); + System.out.println(msg); + System.out.println(((RequestCommand) ((CBusMessageToServer) msg).getRequest()).getCbusCommand()); + assertMessageMatches(bytes, msg); + } + + @Disabled("This example just seems plain wrong... First of all there is no command for 0x10 defined and the argument which should be it 0x11 requires a argument of 0x03... So either documenation wrong or the example") + @Test + void outputARequestRefreshCommand() throws Exception { + byte[] bytes = "\\05DF00100C\r".getBytes(StandardCharsets.UTF_8); + ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes); + cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true); + CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length); + assertThat(msg).isNotNull(); + System.out.println(msg); + System.out.println(((RequestCommand) ((CBusMessageToServer) msg).getRequest()).getCbusCommand()); + assertMessageMatches(bytes, msg); + } + + @Test + void outputARequestRefreshCommandFixedQuestionMark() throws Exception { + byte[] bytes = "\\05DF001103\r".getBytes(StandardCharsets.UTF_8); ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes); cBusOptions = new CBusOptions(false, false, false, false, false, false, false, false, true); CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, false, requestContext, cBusOptions, bytes.length); diff --git a/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec b/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec index f0311debe04..cb0ad9d2341 100644 --- a/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec +++ b/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec @@ -1349,7 +1349,7 @@ [simple AccessControlData accessControlData] ] ['CLOCK_AND_TIMEKEEPING' *ClockAndTimekeeping - [validation '1==2' "CLOCK_AND_TIMEKEEPING Not yet implemented"] // TODO: implement me + [simple ClockAndTimekeepingData clockAndTimekeepingData] ] ['TELEPHONY_STATUS_AND_CONTROL' *TelephonyStatusAndControl [validation '1==2' "TELEPHONY_STATUS_AND_CONTROL Not yet implemented"] // TODO: implement me @@ -2481,6 +2481,52 @@ ['0x0D' CATEGORY_NAME ] ] +[type ClockAndTimekeepingData + //TODO: golang doesn't like checking for null so we use that static call to check that the enum is known + [validation 'STATIC_CALL("knowsClockAndTimekeepingCommandTypeContainer", readBuffer)' "no command type could be found" shouldFail=false] + [simple ClockAndTimekeepingCommandTypeContainer commandTypeContainer ] + [virtual ClockAndTimekeepingCommandType commandType 'commandTypeContainer.commandType'] + [simple byte argument] + [typeSwitch commandType, argument + ['UPDATE_NETWORK_VARIABLE', '0x01' *UpdateTime + [simple uint 8 hours ] + [simple uint 8 minute ] + [simple uint 8 second ] + [simple byte daylightSaving ] + [virtual bit isNoDaylightSavings 'daylightSaving == 0x00'] + [virtual bit isAdvancedBy1Hour 'daylightSaving == 0x01'] + [virtual bit isReserved 'daylightSaving > 0x01 && daylightSaving <= 0xFE'] + [virtual bit isUnknown 'daylightSaving > 0xFE'] + ] + ['UPDATE_NETWORK_VARIABLE', '0x02' *UpdateDate + [simple byte yearHigh ] + [simple byte yearLow ] + [simple uint 8 month ] + [simple uint 8 day ] + [simple uint 8 dayOfWeek ] + ] + ['REQUEST_REFRESH', '0x03' *RequestRefresh + ] + ] +] + +[enum uint 8 ClockAndTimekeepingCommandTypeContainer(ClockAndTimekeepingCommandType commandType, uint 5 numBytes) + ['0x08' MediaTransportControlCommandUpdateNetworkVariable_0Bytes ['UPDATE_NETWORK_VARIABLE', '0']] + ['0x09' MediaTransportControlCommandUpdateNetworkVariable_1Bytes ['UPDATE_NETWORK_VARIABLE', '1']] + ['0x0A' MediaTransportControlCommandUpdateNetworkVariable_2Bytes ['UPDATE_NETWORK_VARIABLE', '2']] + ['0x0B' MediaTransportControlCommandUpdateNetworkVariable_3Bytes ['UPDATE_NETWORK_VARIABLE', '3']] + ['0x0C' MediaTransportControlCommandUpdateNetworkVariable_4Bytes ['UPDATE_NETWORK_VARIABLE', '4']] + ['0x0D' MediaTransportControlCommandUpdateNetworkVariable_5Bytes ['UPDATE_NETWORK_VARIABLE', '5']] + ['0x0E' MediaTransportControlCommandUpdateNetworkVariable_6Bytes ['UPDATE_NETWORK_VARIABLE', '6']] + ['0x0F' MediaTransportControlCommandUpdateNetworkVariable_7Bytes ['UPDATE_NETWORK_VARIABLE', '7']] + ['0x11' MediaTransportControlCommandRequestRefresh ['REQUEST_REFRESH', '1']] +] + +[enum uint 4 ClockAndTimekeepingCommandType + ['0x00' UPDATE_NETWORK_VARIABLE ] + ['0x01' REQUEST_REFRESH ] +] + [type ReplyOrConfirmation(CBusOptions cBusOptions, uint 16 messageLength, RequestContext requestContext) [peek byte peekedByte ] [virtual bit isAlpha '(peekedByte >= 0x67) && (peekedByte <= 0x7A)' ]