forked from angelodlfrtr/go-canopen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdic_object_dic.go
40 lines (31 loc) · 849 Bytes
/
dic_object_dic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package canopen
type DicObjectDic struct {
Baudrate int
NodeID int
// Map of Object ids to objects
Indexes map[uint16]DicObject
// Index to map objects names to objects indexs
NamesIndex map[string]uint16
}
func NewDicObjectDic() *DicObjectDic {
return &DicObjectDic{
Indexes: map[uint16]DicObject{},
NamesIndex: map[string]uint16{},
}
}
func (objectDic *DicObjectDic) AddObject(object DicObject) {
objectDic.Indexes[object.GetIndex()] = object
objectDic.NamesIndex[object.GetName()] = object.GetIndex()
}
func (objectDic *DicObjectDic) FindIndex(index uint16) DicObject {
if object, ok := objectDic.Indexes[index]; ok {
return object
}
return nil
}
func (objectDic *DicObjectDic) FindName(name string) DicObject {
if index, ok := objectDic.NamesIndex[name]; ok {
return objectDic.Indexes[index]
}
return nil
}