Skip to content

Commit

Permalink
feat(plc4go/bacnet): partial port of application layer, application m…
Browse files Browse the repository at this point in the history
…odule
  • Loading branch information
sruehl committed Nov 11, 2022
1 parent 9b2e27f commit 94e73b0
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 5 deletions.
48 changes: 43 additions & 5 deletions plc4go/internal/bacnetip/ApplicationLayer.go
Expand Up @@ -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:
Expand All @@ -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)
}
107 changes: 107 additions & 0 deletions 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
}
28 changes: 28 additions & 0 deletions 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 {
}
28 changes: 28 additions & 0 deletions 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
}
38 changes: 38 additions & 0 deletions 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
}
28 changes: 28 additions & 0 deletions 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
}

0 comments on commit 94e73b0

Please sign in to comment.