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 2022/11/11 17:32:48 UTC
[plc4x] 02/02: feat(plc4go/bacnet): partial port of application layer, application module
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
commit 94e73b0b5f4f0190e09cf1f1f8c4821f3cc807b2
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Nov 11 18:30:51 2022 +0100
feat(plc4go/bacnet): partial port of application layer, application module
---
plc4go/internal/bacnetip/ApplicationLayer.go | 48 ++++++++++--
plc4go/internal/bacnetip/ApplicationModule.go | 107 ++++++++++++++++++++++++++
plc4go/internal/bacnetip/Capability.go | 28 +++++++
plc4go/internal/bacnetip/Device.go | 28 +++++++
plc4go/internal/bacnetip/NetworkService.go | 38 +++++++++
plc4go/internal/bacnetip/Object.go | 28 +++++++
6 files changed, 272 insertions(+), 5 deletions(-)
diff --git a/plc4go/internal/bacnetip/ApplicationLayer.go b/plc4go/internal/bacnetip/ApplicationLayer.go
index 050c9ac96f..c2a1324adc 100644
--- a/plc4go/internal/bacnetip/ApplicationLayer.go
+++ b/plc4go/internal/bacnetip/ApplicationLayer.go
@@ -1834,7 +1834,7 @@ func NewApplicationServiceAccessPoint(aseID *int, sapID *int) (*ApplicationServi
// TODO: big WIP
func (a *ApplicationServiceAccessPoint) Indication(apdu readWriteModel.APDU) error {
- log.Debug().Msgf("indication\n%s", apdu)
+ log.Debug().Msgf("Indication\n%s", apdu)
switch apdu := apdu.(type) {
case readWriteModel.APDUConfirmedRequestExactly:
@@ -1850,26 +1850,64 @@ func (a *ApplicationServiceAccessPoint) Indication(apdu readWriteModel.APDU) err
// TODO: the handling here gets a bit different now... need to wrap the head around how to do this (error handling etc)
if errorFound == nil {
- if err := a.SapResponse(apdu); err != nil {
+ if err := a.SapRequest(apdu); err != nil {
return err
}
} else {
log.Debug().Err(errorFound).Msg("got error")
- }
+ // TODO: map it to a error... code temporary placeholder
+ a.Response(readWriteModel.NewAPDUReject(apdu.GetInvokeId(), nil, 0))
+ }
case readWriteModel.APDUUnconfirmedRequestExactly:
+ //assume no errors found
+ var errorFound error
+ if !readWriteModel.BACnetUnconfirmedServiceChoiceKnows(uint8(apdu.GetServiceRequest().GetServiceChoice())) {
+ errorFound = errors.New("unrecognized service")
+ }
+
+ if errorFound == nil {
+ errorFound = a.SapRequest(apdu)
+ }
+ // TODO: the handling here gets a bit different now... need to wrap the head around how to do this (error handling etc)
+
+ if errorFound == nil {
+ if err := a.SapRequest(apdu); err != nil {
+ return err
+ }
+ } else {
+ log.Debug().Err(errorFound).Msg("got error")
+ }
+
default:
return errors.Errorf("unknown PDU type %T", apdu)
}
return nil
}
+// TODO: big WIP
+func (a *ApplicationServiceAccessPoint) SapIndication(apdu readWriteModel.APDU, pduDestination []byte) error {
+ log.Debug().Msgf("SapIndication\n%s", apdu)
+
+ // TODO: check if we need to check apdu here
+
+ return a.Request(apdu)
+}
+
// TODO: big WIP
func (a *ApplicationServiceAccessPoint) Confirmation(apdu readWriteModel.APDU) error {
- panic("not yet implemented")
+ log.Debug().Msgf("Confirmation\n%s", apdu)
+
+ // TODO: check if we need to check apdu here
+
+ return a.SapResponse(apdu)
}
// TODO: big WIP
func (a *ApplicationServiceAccessPoint) SapConfirmation(apdu readWriteModel.APDU, pduDestination []byte) error {
- panic("not yet implemented")
+ log.Debug().Msgf("SapConfirmation\n%s", apdu)
+
+ // TODO: check if we need to check apdu here
+
+ return a.Response(apdu)
}
diff --git a/plc4go/internal/bacnetip/ApplicationModule.go b/plc4go/internal/bacnetip/ApplicationModule.go
new file mode 100644
index 0000000000..0371c83bbe
--- /dev/null
+++ b/plc4go/internal/bacnetip/ApplicationModule.go
@@ -0,0 +1,107 @@
+/*
+ * 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 bacnetip
+
+import "github.com/pkg/errors"
+
+// TODO: implement
+type Application struct {
+ ApplicationServiceElement
+ Collector
+}
+
+// TODO: implement
+type IOController struct {
+}
+
+// TODO: implement
+type ApplicationIOController struct {
+ IOController
+ Application
+}
+
+func NewApplicationIOController(interface{}, interface{}, interface{}, *int) (*ApplicationIOController, error) {
+ return &ApplicationIOController{}, nil
+}
+
+type BIPSimpleApplication struct {
+ *ApplicationIOController
+ *WhoIsIAmServices
+ *ReadWritePropertyServices
+ localAddress interface{}
+ asap *ApplicationServiceAccessPoint
+ smap *StateMachineAccessPoint
+ nsap *NetworkServiceAccessPoint
+ nse *NetworkServiceElement
+}
+
+func NewBIPSimpleApplication(localDevice DeviceEntry, localAddress, deviceInfoCache *DeviceInventory, aseID *int) (*BIPSimpleApplication, error) {
+ b := &BIPSimpleApplication{}
+ controller, err := NewApplicationIOController(localDevice, localAddress, deviceInfoCache, aseID)
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating io controller")
+ }
+ b.ApplicationIOController = controller
+
+ b.localAddress = localAddress
+
+ // include a application decoder
+ applicationServiceAccessPoint, err := NewApplicationServiceAccessPoint(nil, nil)
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating application service access point")
+ }
+ b.asap = applicationServiceAccessPoint
+
+ // pass the device object to the state machine access point, so it can know if it should support segmentation
+ stateMachineAccessPoint, err := NewStateMachineAccessPoint(localDevice, deviceInfoCache, nil, nil)
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating state machine access point")
+ }
+ b.smap = stateMachineAccessPoint
+
+ // pass the device object to the state machine access point so it # can know if it should support segmentation
+ // Note: deviceInfoCache already passed above so we don't need to do it again here
+
+ // a network service access point will be needed
+ networkServiceAccessPoint, err := NewNetworkServiceAccessPoint()
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating network service access point")
+ }
+ b.nsap = networkServiceAccessPoint
+
+ // give the NSAP a generic network layer service element
+ networkServiceElement, err := NewNetworkServiceElement()
+ if err != nil {
+ return nil, errors.Wrap(err, "error creating new network service element")
+ }
+ b.nse = networkServiceElement
+ if err := bind(b.nse, b.nsap); err != nil {
+ return nil, errors.New("error binding network stack")
+ }
+
+ // bind the top layers
+ if err := bind(b, b.asap, b.smap, b.nsap); err != nil {
+ return nil, errors.New("error binding top layers")
+ }
+
+ // TODO: BIP, etc... udp stack binding here
+
+ return b, nil
+}
diff --git a/plc4go/internal/bacnetip/Capability.go b/plc4go/internal/bacnetip/Capability.go
new file mode 100644
index 0000000000..e4dbecac74
--- /dev/null
+++ b/plc4go/internal/bacnetip/Capability.go
@@ -0,0 +1,28 @@
+/*
+ * 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 bacnetip
+
+// TODO: implement
+type Capability struct {
+}
+
+// TODO: implement
+type Collector struct {
+}
diff --git a/plc4go/internal/bacnetip/Device.go b/plc4go/internal/bacnetip/Device.go
new file mode 100644
index 0000000000..cbf38a66aa
--- /dev/null
+++ b/plc4go/internal/bacnetip/Device.go
@@ -0,0 +1,28 @@
+/*
+ * 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 bacnetip
+
+type WhoIsIAmServices struct {
+}
+
+func NewWhoIsIAmServices() (*WhoIsIAmServices, error) {
+ // TODO: implement me
+ return nil, nil
+}
diff --git a/plc4go/internal/bacnetip/NetworkService.go b/plc4go/internal/bacnetip/NetworkService.go
new file mode 100644
index 0000000000..b9c9b120a0
--- /dev/null
+++ b/plc4go/internal/bacnetip/NetworkService.go
@@ -0,0 +1,38 @@
+/*
+ * 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 bacnetip
+
+type NetworkServiceAccessPoint struct {
+ // TODO: implement me
+}
+
+func NewNetworkServiceAccessPoint() (*NetworkServiceAccessPoint, error) {
+ // TODO: implement me
+ return nil, nil
+}
+
+type NetworkServiceElement struct {
+ // TODO: implement me
+}
+
+func NewNetworkServiceElement() (*NetworkServiceElement, error) {
+ // TODO: implement me
+ return nil, nil
+}
diff --git a/plc4go/internal/bacnetip/Object.go b/plc4go/internal/bacnetip/Object.go
new file mode 100644
index 0000000000..742a16176a
--- /dev/null
+++ b/plc4go/internal/bacnetip/Object.go
@@ -0,0 +1,28 @@
+/*
+ * 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 bacnetip
+
+type ReadWritePropertyServices struct {
+}
+
+func NewReadWritePropertyServices() (*ReadWritePropertyServices, error) {
+ // TODO: implement me
+ return nil, nil
+}