Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0bf36a4
Adds proposed GetDeviceByName to manageddevices. This enables Device …
tobiasmo1 Dec 5, 2018
e1d5c63
Merge remote-tracking branch 'upstream/master'
tobiasmo1 Dec 19, 2018
7b4a2f9
Updates to DeviceSDK to support decoupled edgex-go models (bson)
tobiasmo1 Dec 21, 2018
a73be14
Adds proposed GetDeviceByName to manageddevices. This enables Device …
tobiasmo1 Dec 5, 2018
26d1749
Updates to DeviceSDK to support decoupled edgex-go models (bson)
tobiasmo1 Dec 21, 2018
5a266d1
- Adds consistent of "e_models" to reference edgex-go/pkg/models; and…
tobiasmo1 Jan 14, 2019
06111ac
Ignore Sublime, VS Code and GoLand project and debug files.
tobiasmo1 Jan 14, 2019
9a8907d
(NOT FOR UPSTREAM)
tobiasmo1 Jan 14, 2019
ea7a660
Adds proposed GetDeviceByName to manageddevices. This enables Device …
tobiasmo1 Dec 5, 2018
d8920cd
Merge branch 'master' of https://github.com/tobiasmo1/device-sdk-go
tobiasmo1 Jan 14, 2019
1efa6a3
Merge branch 'master' of https://github.com/tobiasmo1/device-sdk-go i…
tobiasmo1 Jan 14, 2019
b6c9653
Adds proposed GetDeviceByName to manageddevices. This enables Device …
tobiasmo1 Dec 5, 2018
b2a1fb1
Merge branch 'master' of https://github.com/tobiasmo1/device-sdk-go
tobiasmo1 Jan 14, 2019
8b5ff97
Merge branch '954-decouple-mongo-types' of https://github.com/tobiasm…
tobiasmo1 Jan 15, 2019
e1be171
Remove local logging comments
tobiasmo1 Jan 20, 2019
400c831
Adds proposed GetDeviceByName to manageddevices. This enables Device …
tobiasmo1 Dec 5, 2018
7f3dd76
Merge branch 'master' of https://github.com/tobiasmo1/device-sdk-go
tobiasmo1 Jan 20, 2019
af0986e
Adds proposed GetDeviceByName to manageddevices. This enables Device …
tobiasmo1 Dec 5, 2018
76f78c3
Merge branch 'master' of https://github.com/tobiasmo1/device-sdk-go
tobiasmo1 Jan 20, 2019
57ca8a5
Merge branch 'master' of https://github.com/tobiasmo1/device-sdk-go i…
tobiasmo1 Jan 20, 2019
ecd29f2
Update glide and mock deviceclient
tobiasmo1 Jan 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*~
*.log
example/cmd/device-simple/device-simple
example/cmd/device-simple/device-simple/debug
glide.lock
vendor
.idea
/.project
.vscode/
6 changes: 3 additions & 3 deletions async.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/edgexfoundry/device-sdk-go/internal/common"
"github.com/edgexfoundry/device-sdk-go/internal/transformer"
ds_models "github.com/edgexfoundry/device-sdk-go/pkg/models"
"github.com/edgexfoundry/edgex-go/pkg/models"
e_models "github.com/edgexfoundry/edgex-go/pkg/models"
)

// processAsyncResults processes readings that are pushed from
Expand All @@ -23,7 +23,7 @@ import (
func processAsyncResults() {
for !svc.stopped {
acv := <-svc.asyncCh
readings := make([]models.Reading, 0, len(acv.CommandValues))
readings := make([]e_models.Reading, 0, len(acv.CommandValues))

device, ok := cache.Devices().ForName(acv.DeviceName)
if !ok {
Expand Down Expand Up @@ -67,7 +67,7 @@ func processAsyncResults() {
}

// push to Core Data
event := &models.Event{Device: acv.DeviceName, Readings: readings}
event := &e_models.Event{Device: acv.DeviceName, Readings: readings}
_, err := common.EventClient.Add(event)
if err != nil {
common.LoggingClient.Error(fmt.Sprintf("processAsyncResults - Failed to push event %v: %v", event, err))
Expand Down
10 changes: 5 additions & 5 deletions example/driver/simpledriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"time"

ds_models "github.com/edgexfoundry/device-sdk-go/pkg/models"
"github.com/edgexfoundry/edgex-go/pkg/clients/logging"
"github.com/edgexfoundry/edgex-go/pkg/models"
logger "github.com/edgexfoundry/edgex-go/pkg/clients/logging"
e_models "github.com/edgexfoundry/edgex-go/pkg/models"
)

type SimpleDriver struct {
Expand All @@ -27,7 +27,7 @@ type SimpleDriver struct {

// DisconnectDevice handles protocol-specific cleanup when a device
// is removed.
func (s *SimpleDriver) DisconnectDevice(address *models.Addressable) error {
func (s *SimpleDriver) DisconnectDevice(address *e_models.Addressable) error {
return nil
}

Expand All @@ -40,7 +40,7 @@ func (s *SimpleDriver) Initialize(lc logger.LoggingClient, asyncCh chan<- *ds_mo
}

// HandleReadCommands triggers a protocol Read operation for the specified device.
func (s *SimpleDriver) HandleReadCommands(addr *models.Addressable, reqs []ds_models.CommandRequest) (res []*ds_models.CommandValue, err error) {
func (s *SimpleDriver) HandleReadCommands(addr *e_models.Addressable, reqs []ds_models.CommandRequest) (res []*ds_models.CommandValue, err error) {

if len(reqs) != 1 {
err = fmt.Errorf("SimpleDriver.HandleReadCommands; too many command requests; only one supported")
Expand All @@ -61,7 +61,7 @@ func (s *SimpleDriver) HandleReadCommands(addr *models.Addressable, reqs []ds_mo
// a ResourceOperation for a specific device resource (aka DeviceObject).
// Since the commands are actuation commands, params provide parameters for the individual
// command.
func (s *SimpleDriver) HandleWriteCommands(addr *models.Addressable, reqs []ds_models.CommandRequest,
func (s *SimpleDriver) HandleWriteCommands(addr *e_models.Addressable, reqs []ds_models.CommandRequest,
params []*ds_models.CommandValue) error {

if len(reqs) != 1 {
Expand Down
57 changes: 28 additions & 29 deletions internal/cache/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,55 @@ package cache
import (
"fmt"

"github.com/edgexfoundry/edgex-go/pkg/models"
e_models "github.com/edgexfoundry/edgex-go/pkg/models"
)

var (
dc *deviceCache
)

// DeviceCache holds a set of devices
type DeviceCache interface {
ForName(name string) (models.Device, bool)
ForId(id string) (models.Device, bool)
All() []models.Device
Add(device models.Device) error
Update(device models.Device) error
UpdateAddressable(addressable models.Addressable) error
ForName(name string) (e_models.Device, bool)
ForId(id string) (e_models.Device, bool)
All() []e_models.Device
Add(device e_models.Device) error
Update(device e_models.Device) error
UpdateAddressable(addressable e_models.Addressable) error
Remove(id string) error
RemoveByName(name string) error
UpdateAdminState(id string, state models.AdminState) error
UpdateAdminState(id string, state e_models.AdminState) error
}

type deviceCache struct {
dMap map[string]*models.Device // key is Device name
nameMap map[string]string // key is id, and value is Device name
dMap map[string]*e_models.Device // key is Device name
nameMap map[string]string // key is id, and value is Device name
}

// ForName returns a Device with the given name.
func (d *deviceCache) ForName(name string) (models.Device, bool) {
func (d *deviceCache) ForName(name string) (e_models.Device, bool) {
if device, ok := d.dMap[name]; ok {
return *device, ok
} else {
return models.Device{}, ok
return e_models.Device{}, ok
}
}

// ForId returns a device with the given device id.
func (d *deviceCache) ForId(id string) (models.Device, bool) {
func (d *deviceCache) ForId(id string) (e_models.Device, bool) {
name, ok := d.nameMap[id]
if !ok {
return models.Device{}, ok
return e_models.Device{}, ok
}

if device, ok := d.dMap[name]; ok {
return *device, ok
} else {
return models.Device{}, ok
}
return e_models.Device{}, ok
}

// All() returns the current list of devices in the cache.
func (d *deviceCache) All() []models.Device {
devices := make([]models.Device, len(d.dMap))
func (d *deviceCache) All() []e_models.Device {
devices := make([]e_models.Device, len(d.dMap))
i := 0
for _, device := range d.dMap {
devices[i] = *device
Expand All @@ -71,25 +70,25 @@ func (d *deviceCache) All() []models.Device {
// Adds a new device to the cache. This method is used to populate the
// devices cache with pre-existing devices from Core Metadata, as well
// as create new devices returned in a ScanList during discovery.
func (d *deviceCache) Add(device models.Device) error {
func (d *deviceCache) Add(device e_models.Device) error {
if _, ok := d.dMap[device.Name]; ok {
return fmt.Errorf("device %s has already existed in cache", device.Name)
}
d.dMap[device.Name] = &device
d.nameMap[device.Id.Hex()] = device.Name
d.nameMap[device.Id] = device.Name
return nil
}

// Update updates the device in the cache
func (d *deviceCache) Update(device models.Device) error {
if err := d.Remove(device.Id.Hex()); err != nil {
func (d *deviceCache) Update(device e_models.Device) error {
if err := d.Remove(device.Id); err != nil {
return err
}
return d.Add(device)
}

// UpdateAddressable updates the device addressable in the cache
func (d *deviceCache) UpdateAddressable(add models.Addressable) error {
func (d *deviceCache) UpdateAddressable(add e_models.Addressable) error {
found := false
for _, device := range d.dMap {
if device.Addressable.Id == add.Id {
Expand Down Expand Up @@ -122,15 +121,15 @@ func (d *deviceCache) RemoveByName(name string) error {
return fmt.Errorf("device %s does not exist in cache", name)
}

delete(d.nameMap, device.Id.Hex())
delete(d.nameMap, device.Id)
delete(d.dMap, name)
return nil
}

// UpdateAdminState updates the device admin state in cache by id. This method
// is used by the UpdateHandler to trigger update device admin state that's been
// updated directly to Core Metadata.
func (d *deviceCache) UpdateAdminState(id string, state models.AdminState) error {
func (d *deviceCache) UpdateAdminState(id string, state e_models.AdminState) error {
name, ok := d.nameMap[id]
if !ok {
return fmt.Errorf("device %s cannot be found in cache", id)
Expand All @@ -140,13 +139,13 @@ func (d *deviceCache) UpdateAdminState(id string, state models.AdminState) error
return nil
}

func newDeviceCache(devices []models.Device) DeviceCache {
func newDeviceCache(devices []e_models.Device) DeviceCache {
defaultSize := len(devices) * 2
dMap := make(map[string]*models.Device, defaultSize)
dMap := make(map[string]*e_models.Device, defaultSize)
nameMap := make(map[string]string, defaultSize)
for i, d := range devices {
dMap[d.Name] = &devices[i]
nameMap[d.Id.Hex()] = d.Name
nameMap[d.Id] = d.Name
}
dc = &deviceCache{dMap: dMap, nameMap: nameMap}
return dc
Expand Down
14 changes: 7 additions & 7 deletions internal/cache/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ import (
"sync"

"github.com/edgexfoundry/device-sdk-go/internal/common"
"github.com/edgexfoundry/edgex-go/pkg/models"
e_models "github.com/edgexfoundry/edgex-go/pkg/models"
)

var (
initOnce sync.Once
)

// Init basic state for cache
// InitCache initializes the basic state of local caches
func InitCache() {
initOnce.Do(func() {
vds, err := common.ValueDescriptorClient.ValueDescriptors()
if err != nil {
common.LoggingClient.Error(fmt.Sprintf("Value Descriptor cache initialization failed: %v", err))
vds = make([]models.ValueDescriptor, 0)
vds = make([]e_models.ValueDescriptor, 0)
}
newValueDescriptorCache(vds)

ds, err := common.DeviceClient.DevicesForServiceByName(common.ServiceName)
if err != nil {
common.LoggingClient.Error(fmt.Sprintf("Device cache initialization failed: %v", err))
ds = make([]models.Device, 0)
ds = make([]e_models.Device, 0)
}
newDeviceCache(ds)

dps := make([]models.DeviceProfile, len(ds))
dps := make([]e_models.DeviceProfile, len(ds))
for i, d := range ds {
dps[i] = d.Profile
}
Expand All @@ -44,11 +44,11 @@ func InitCache() {
ses, err := common.ScheduleEventClient.ScheduleEventsForServiceByName(common.ServiceName)
if err != nil {
common.LoggingClient.Error(fmt.Sprintf("Schedule Event cache initialization failed: %v", err))
ses = make([]models.ScheduleEvent, 0)
ses = make([]e_models.ScheduleEvent, 0)
}
newScheduleEventCache(ses)

schMap := make(map[string]models.Schedule, len(ses))
schMap := make(map[string]e_models.Schedule, len(ses))
for _, se := range ses {
if _, ok := schMap[se.Schedule]; !ok {
sc, err := common.ScheduleClient.ScheduleForName(se.Schedule)
Expand Down
Loading