Skip to content

Commit

Permalink
feat: add getendpoints, browse, read dto (#40)
Browse files Browse the repository at this point in the history
Signed-off-by: ZhangJian He <shoothzj@gmail.com>
  • Loading branch information
shoothzj authored Oct 16, 2024
1 parent cbe78d9 commit 4ca93c8
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 18 deletions.
4 changes: 2 additions & 2 deletions opcua/enc/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ func (d *bufferedDecoder) fillMessageBody(msg *uamsg.Message) error {
// TODO process more Identifier type
switch messageBody.TypeId.Identifier {
case uamsg.ObjectOpenSecureChannelRequest_Encoding_DefaultBinary.Identifier:
service := &uamsg.OpenSecureChannelServiceRequest{}
service := &uamsg.OpenSecureChannelRequest{}
err = d.readTo(reflect.ValueOf(service).Elem())
if err != nil {
return err
}
messageBody.Service = service
case uamsg.ObjectOpenSecureChannelResponse_Encoding_DefaultBinary.Identifier:
service := &uamsg.OpenSecureChannelServiceResponse{}
service := &uamsg.OpenSecureChannelResponse{}
err = d.readTo(reflect.ValueOf(service).Elem())
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions opcua/enc/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func getOpenSecureChannelRequestMsgTestCase() *encodeTestCase {
TypeId: &uamsg.ExpandedNodeId{
NodeId: &uamsg.ObjectOpenSecureChannelRequest_Encoding_DefaultBinary,
},
Service: &uamsg.OpenSecureChannelServiceRequest{
Service: &uamsg.OpenSecureChannelRequest{
Header: &uamsg.RequestHeader{
AuthenticationToken: &uamsg.NodeId{
EncodingType: uamsg.TwoByte,
Expand Down Expand Up @@ -203,7 +203,7 @@ func getOpenSecureChannelResponseMsgTestCase() *encodeTestCase {
TypeId: &uamsg.ExpandedNodeId{
NodeId: &uamsg.ObjectOpenSecureChannelResponse_Encoding_DefaultBinary,
},
Service: &uamsg.OpenSecureChannelServiceResponse{
Service: &uamsg.OpenSecureChannelResponse{
Header: &uamsg.ResponseHeader{
Timestamp: 0,
RequestHandle: 1,
Expand Down
18 changes: 11 additions & 7 deletions opcua/secure_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func (secChan *SecureChannel) handleOpenSecureChannel() error {
return errors.New("invalid message body, expected GenericBody")
}

openSecChanBody, ok := genericBody.Service.(*uamsg.OpenSecureChannelServiceRequest)
openSecChanBody, ok := genericBody.Service.(*uamsg.OpenSecureChannelRequest)
if !ok {
return errors.New("invalid service, expected OpenSecureChannelServiceRequest")
return errors.New("invalid service, expected OpenSecureChannelRequest")
}

// TODO only support NONE mode yet
Expand Down Expand Up @@ -176,7 +176,7 @@ func (secChan *SecureChannel) handleOpenSecureChannel() error {
TypeId: &uamsg.ExpandedNodeId{
NodeId: &uamsg.ObjectOpenSecureChannelResponse_Encoding_DefaultBinary,
},
Service: &uamsg.OpenSecureChannelServiceResponse{
Service: &uamsg.OpenSecureChannelResponse{
Header: &uamsg.ResponseHeader{
Timestamp: util.GetCurrentUaTimestamp(),
RequestHandle: openSecChanBody.Header.RequestHandle,
Expand Down Expand Up @@ -231,18 +231,22 @@ func (secChan *SecureChannel) handleRequest(req *uamsg.Message) error {
var rsp *uamsg.Message
var err error
switch generic.Service.(type) {
case *uamsg.OpenSecureChannelServiceRequest:
rsp, err = secChan.handleOpenSecureChannelServiceRequest(req)
case *uamsg.OpenSecureChannelRequest:
rsp, err = secChan.handleOpenSecureChannelRequest(req)
case *uamsg.CloseSecureChannelRequest:
rsp, err = secChan.handleCloseSecureChannelRequest(req)
case *uamsg.ReadRequest:
rsp, err = secChan.handleReadRequest(req)
case *uamsg.CreateSessionRequest:
rsp, err = secChan.handleCreateSessionRequest(req)
case *uamsg.ActivateSessionRequest:
rsp, err = secChan.handleActivateSessionRequest(req)
case *uamsg.CloseSessionRequest:
rsp, err = secChan.handleCloseSessionRequest(req)
case *uamsg.GetEndpointsRequest:
rsp, err = secChan.handleGetEndpoints(req)
case *uamsg.BrowseRequest:
rsp, err = secChan.handleBrowseRequest(req)
case *uamsg.ReadRequest:
rsp, err = secChan.handleReadRequest(req)
default:
secChan.logger.Error("unsupported an service", "service", generic.Service)
rsp = secChan.createErrorMessage(req.RequestId, 0, uamsg.ErrorCodeBadServiceUnsupported)
Expand Down
18 changes: 13 additions & 5 deletions opcua/service_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ package opcua

import "github.com/protocol-laboratory/opcua-go/opcua/uamsg"

func (secChan *SecureChannel) handleOpenSecureChannelServiceRequest(req *uamsg.Message) (*uamsg.Message, error) {
func (secChan *SecureChannel) handleOpenSecureChannelRequest(req *uamsg.Message) (*uamsg.Message, error) {
return nil, nil
}

func (secChan *SecureChannel) handleCloseSecureChannelRequest(req *uamsg.Message) (*uamsg.Message, error) {
return nil, nil
}

func (secChan *SecureChannel) handleReadRequest(req *uamsg.Message) (*uamsg.Message, error) {
return nil, nil
}

func (secChan *SecureChannel) handleCreateSessionRequest(req *uamsg.Message) (*uamsg.Message, error) {
return nil, nil
}
Expand All @@ -25,3 +21,15 @@ func (secChan *SecureChannel) handleActivateSessionRequest(req *uamsg.Message) (
func (secChan *SecureChannel) handleCloseSessionRequest(req *uamsg.Message) (*uamsg.Message, error) {
return nil, nil
}

func (secChan *SecureChannel) handleGetEndpoints(req *uamsg.Message) (*uamsg.Message, error) {
return nil, nil
}

func (secChan *SecureChannel) handleBrowseRequest(req *uamsg.Message) (*uamsg.Message, error) {
return nil, nil
}

func (secChan *SecureChannel) handleReadRequest(req *uamsg.Message) (*uamsg.Message, error) {
return nil, nil
}
45 changes: 45 additions & 0 deletions opcua/uamsg/browse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uamsg

type BrowseRequest struct {
Header *RequestHeader
View *ViewDescription
RequestedMaxReferencesPerNode uint32
NodesToBrowse []*BrowseDescription
}

type ViewDescription struct {
ViewId *NodeId
Timestamp uint64
ViewVersion uint32
}

type BrowseDescription struct {
NodeId *NodeId
BrowseDirection uint32
ReferenceTypeId *NodeId
IncludeSubtypes bool
NodeClassMask uint32
ResultMask uint32
}

type BrowseResponse struct {
Header *ResponseHeader
Results []*BrowseResult
}

type BrowseResult struct {
StatusCode *StatusCode
ContinuationPoint []byte
References []*ReferenceDescription
DiagnosticInfos []*DiagnosticInfo
}

type ReferenceDescription struct {
ReferenceTypeId *NodeId
IsForward bool
NodeId *ExpandedNodeId
BrowseName *QualifiedName
DisplayName *LocalizedText
NodeClass uint32
TypeDefinition *ExpandedNodeId
}
13 changes: 13 additions & 0 deletions opcua/uamsg/endpoints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package uamsg

type GetEndpointsRequest struct {
Header *RequestHeader
EndpointUrl string
LocaleIds []string
ProfileUris []string
}

type GetEndpointsResponse struct {
Header *ResponseHeader
Endpoints []EndpointDescription
}
4 changes: 2 additions & 2 deletions opcua/uamsg/secure_channel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package uamsg

type OpenSecureChannelServiceRequest struct {
type OpenSecureChannelRequest struct {
Header *RequestHeader
ClientProtocolVersion uint32
RequestType SecurityTokenRequestType
Expand All @@ -9,7 +9,7 @@ type OpenSecureChannelServiceRequest struct {
RequestedLifetime uint32
}

type OpenSecureChannelServiceResponse struct {
type OpenSecureChannelResponse struct {
Header *ResponseHeader
ServerProtocolVersion uint32
SecurityToken *ChannelSecurityToken
Expand Down

0 comments on commit 4ca93c8

Please sign in to comment.