Skip to content

Commit

Permalink
Moving HTTP gateway to a seperate package
Browse files Browse the repository at this point in the history
Big rework
  • Loading branch information
samsamfire committed Jan 31, 2024
1 parent 3e5f611 commit 535f7c6
Show file tree
Hide file tree
Showing 17 changed files with 663 additions and 707 deletions.
46 changes: 45 additions & 1 deletion gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ type BaseGateway struct {
network *Network
defaultNetwork uint16
defaultNodeId uint8
sdoBuffer []byte
}

func NewBaseGateway(network *Network, defaultNetwork uint16, defaultNodeId uint8, sdoUploadBufferSize int) *BaseGateway {
return &BaseGateway{
network: network,
defaultNetwork: defaultNetwork,
defaultNodeId: defaultNodeId,
sdoBuffer: make([]byte, sdoUploadBufferSize),
}
}

type GatewayVersion struct {
Expand All @@ -24,17 +34,27 @@ type GatewayVersion struct {
}

// Set default network to use
func (gw *BaseGateway) SetDefaultNetwork(id uint16) error {
func (gw *BaseGateway) SetDefaultNetworkId(id uint16) error {
gw.defaultNetwork = id
return nil
}

// Get the default network
func (gw *BaseGateway) DefaultNetworkId() uint16 {
return gw.defaultNetwork
}

// Set default node Id to use
func (gw *BaseGateway) SetDefaultNodeId(id uint8) error {
gw.defaultNodeId = id
return nil
}

// Get default node Id
func (gw *BaseGateway) DefaultNodeId() uint8 {
return gw.defaultNodeId
}

// Get gateway version information
func (gw *BaseGateway) GetVersion() (GatewayVersion, error) {
return GatewayVersion{}, nil
Expand All @@ -52,3 +72,27 @@ func (gw *BaseGateway) SetSDOTimeout(timeoutMs uint32) error {
gw.network.sdoClient.timeoutTimeBlockTransferUs = timeoutMs * 1000
return nil
}

// Access SDO read buffer
func (gw *BaseGateway) Buffer() []byte {
return gw.sdoBuffer
}

// Read SDO
func (gw *BaseGateway) ReadSDO(nodeId uint8, index uint16, subindex uint8) (int, error) {
return gw.network.ReadRaw(nodeId, index, subindex, gw.sdoBuffer)
}

// Write SDO
func (gw *BaseGateway) WriteSDO(nodeId uint8, index uint16, subindex uint8, value string, datatype uint8) error {
encodedValue, err := encode(value, datatype, 0)
if err != nil {
return SDO_ABORT_TYPE_MISMATCH
}
return gw.network.WriteRaw(nodeId, index, subindex, encodedValue)
}

// Disconnect from network
func (gw *BaseGateway) Disconnect() {
gw.network.Disconnect()
}
87 changes: 0 additions & 87 deletions gateway_http_client.go

This file was deleted.

152 changes: 0 additions & 152 deletions gateway_http_handlers.go

This file was deleted.

17 changes: 0 additions & 17 deletions gateway_http_schemas.go

This file was deleted.

Loading

0 comments on commit 535f7c6

Please sign in to comment.