Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
samsamfire committed Dec 29, 2023
1 parent ddba6e5 commit 268a8dd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
Binary file modified README.md
Binary file not shown.
2 changes: 1 addition & 1 deletion http_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func createGateway() *HTTPGatewayServer {
if e != nil {
panic(e)
}
e = network.AddNode(NODE_ID_TEST, "testdata/base.eds")
_, e = network.AddNode(NODE_ID_TEST, "testdata/base.eds")
if e != nil {
panic(e)
}
Expand Down
19 changes: 9 additions & 10 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,9 @@ func (network *Network) Command(nodeId uint8, nmtCommand NMTCommand) error {
return network.busManager.Send(frame)
}

// Create a local node with a given OD
// Can be either a string : path to OD
// Or it can be an OD object
func (network *Network) CreateNode(nodeId uint8, od any) (Node, error) {
// Create a local CANopen compliant node with a given OD
// Can be either a string : path to OD or OD object
func (network *Network) CreateNode(nodeId uint8, od any) (*LocalNode, error) {
var odNode *ObjectDictionary
var err error
switch odType := od.(type) {
Expand Down Expand Up @@ -229,32 +228,32 @@ func (network *Network) CreateNode(nodeId uint8, od any) (Node, error) {
}

// Add a remote node with a given OD
// OD can be a path, ObjectDictionary or nil
// Can be either a string : path to OD or OD object
// This function will load and parse Object dictionnary (OD) into memory
// If already present, OD will be overwritten
// User can then access the node via OD naming
// A same OD can be used for multiple nodes
func (network *Network) AddNode(nodeId uint8, od any) error {
func (network *Network) AddNode(nodeId uint8, od any) (*RemoteNode, error) {
var odNode *ObjectDictionary
var err error
if nodeId < 1 || nodeId > 127 {
return fmt.Errorf("nodeId should be between 1 and 127, value given : %v", nodeId)
return nil, fmt.Errorf("nodeId should be between 1 and 127, value given : %v", nodeId)
}
switch odType := od.(type) {
case string:
odNode, err = ParseEDSFromFile(odType, nodeId)
if err != nil {
return err
return nil, err
}
network.odMap[nodeId] = &ObjectDictionaryInformation{nodeId: nodeId, od: odNode, edsPath: odType}
case ObjectDictionary:
odNode = &odType
network.odMap[nodeId] = &ObjectDictionaryInformation{nodeId: nodeId, od: odNode, edsPath: ""}
default:
return fmt.Errorf("expecting string or ObjectDictionary got : %T", od)
return nil, fmt.Errorf("expecting string or ObjectDictionary got : %T", od)
}

return nil
return NewRemoteNode(network.busManager, odNode, nodeId)

}

Expand Down
10 changes: 5 additions & 5 deletions sdo_client_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func TestSDOReadExpedited(t *testing.T) {
func TestSDOReadWriteLocal(t *testing.T) {
network := createNetwork()
defer network.Disconnect()
node, err := network.CreateNode(0x55, "testdata/base.eds")
localNode, err := network.CreateNode(0x55, "testdata/base.eds")
assert.Nil(t, err)
localNode := node.(*LocalNode)
_, err = localNode.SDOclients[0].ReadUint32(0x55, 0x2007, 0x0)
client := localNode.SDOclients[0]
_, err = client.ReadUint32(0x55, 0x2007, 0x0)
assert.Nil(t, err)
err = localNode.SDOclients[0].WriteRaw(0x55, 0x2007, 0x0, uint32(5656), false)
err = client.WriteRaw(0x55, 0x2007, 0x0, uint32(5656), false)
assert.Nil(t, err)
val, err := localNode.SDOclients[0].ReadUint32(0x55, 0x2007, 0x0)
val, err := client.ReadUint32(0x55, 0x2007, 0x0)
assert.Nil(t, err)
assert.Equal(t, uint32(5656), val)
}
Expand Down

0 comments on commit 268a8dd

Please sign in to comment.