Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

support edgex 2.1 #30

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ generate: controller-gen
paths="./api/v1alpha1/device_types.go" \
paths="./api/v1alpha1/deviceservice_types.go" \
paths="./api/v1alpha1/deviceprofile_types.go" \
paths="./api/v1alpha1/valuedescriptor_types.go" \
paths="./api/v1alpha1/groupversion_info.go"

# Download controller-gen locally if necessary
Expand Down
13 changes: 8 additions & 5 deletions api/v1alpha1/device_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const (
type OperatingState string

const (
Enabled OperatingState = "ENABLED"
Disabled OperatingState = "DISABLED"
Unknown OperatingState = "UNKNOWN"
Up OperatingState = "UP"
Down OperatingState = "DOWN"
)

type ProtocolProperties map[string]string
Expand All @@ -59,11 +60,13 @@ type DeviceSpec struct {
Labels []string `json:"labels,omitempty"`
// Device service specific location (interface{} is an empty interface so
// it can be anything)
// TODO: location type in edgex is interface{}
Location string `json:"location,omitempty"`
// Associated Device Service - One per device
Service string `json:"service"`
Service string `json:"serviceName"`
// Associated Device Profile - Describes the device
Profile string `json:"profile"`
Profile string `json:"profileName"`
Notify bool `json:"notify"`
// True means device is managed by cloud, cloud can update the related fields
// False means cloud can't update the fields
Managed bool `json:"managed,omitempty"`
Expand Down Expand Up @@ -103,7 +106,7 @@ type DeviceStatus struct {
EdgeId string `json:"edgeId,omitempty"`
// Admin state (locked/unlocked)
AdminState AdminState `json:"adminState,omitempty"`
// Operating state (enabled/disabled)
// Operating state (up/down/unknown)
OperatingState OperatingState `json:"operatingState,omitempty"`
// current device state
// +optional
Expand Down
119 changes: 39 additions & 80 deletions api/v1alpha1/deviceprofile_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,107 +18,69 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

const (
DeviceProfileFinalizer = "v1alpha1.deviceProfile.finalizer"
)

type DeviceResource struct {
Description string `json:"description"`
Name string `json:"name"`
Tag string `json:"tag,omitempty"`
Properties ProfileProperty `json:"properties"`
Attributes map[string]string `json:"attributes,omitempty"`
Description string `json:"description"`
Name string `json:"name"`
Tag string `json:"tag,omitempty"`
IsHidden bool `json:"isHidden"`
Properties ResourceProperties `json:"properties"`
Attributes MapInterfaceValue `json:"attributes,omitempty"`
}

type ProfileProperty struct {
Value PropertyValue `json:"value"`
Units Units `json:"units,omitempty"`
// +k8s:deepcopy-gen=false
type MapInterfaceValue map[string]interface{}

func (in *MapInterfaceValue) DeepCopyInto(out *MapInterfaceValue) {
if in == nil {
*out = nil
} else {
*out = runtime.DeepCopyJSON(*in)
}
}

func (in *MapInterfaceValue) DeepCopy() *MapInterfaceValue {
if in == nil {
return nil
}
out := new(MapInterfaceValue)
in.DeepCopyInto(out)
return out
}

type PropertyValue struct {
Type string `json:"type,omitempty"` // ValueDescriptor Type of property after transformations
type ResourceProperties struct {
ReadWrite string `json:"readWrite,omitempty"` // Read/Write Permissions set for this property
Minimum string `json:"minimum,omitempty"` // Minimum value that can be get/set from this property
Maximum string `json:"maximum,omitempty"` // Maximum value that can be get/set from this property
DefaultValue string `json:"defaultValue,omitempty"` // Default value set to this property if no argument is passed
Size string `json:"size,omitempty"` // Size of this property in its type (i.e. bytes for numeric types, characters for string types)
Mask string `json:"mask,omitempty"` // Mask to be applied prior to get/set of property
Shift string `json:"shift,omitempty"` // Shift to be applied after masking, prior to get/set of property
Scale string `json:"scale,omitempty"` // Multiplicative factor to be applied after shifting, prior to get/set of property
Offset string `json:"offset,omitempty"` // Additive factor to be applied after multiplying, prior to get/set of property
Base string `json:"base,omitempty"` // Base for property to be applied to, leave 0 for no power operation (i.e. base ^ property: 2 ^ 10)
// Required value of the property, set for checking error state. Failing an
// assertion condition wil l mark the device with an error state
Assertion string `json:"assertion,omitempty"`
Precision string `json:"precision,omitempty"`
FloatEncoding string `json:"floatEncoding,omitempty"` // FloatEncoding indicates the representation of floating value of reading. It should be 'Base64' or 'eNotation'
MediaType string `json:"mediaType,omitempty"`
Assertion string `json:"assertion,omitempty"`
MediaType string `json:"mediaType,omitempty"`
Units string `json:"units,omitempty"`
ValueType string `json:"valueType,omitempty"`
}

type Units struct {
Type string `json:"type,omitempty"`
ReadWrite string `json:"readWrite,omitempty"`
DefaultValue string `json:"defaultValue,omitempty"`
}

type Command struct {
// EdgeId is a unique identifier used by EdgeX Foundry, such as a UUID
EdgeId string `json:"id,omitempty"`
// Command name (unique on the profile)
Name string `json:"name,omitempty"`
// Get Command
Get Get `json:"get,omitempty"`
// Put Command
Put Put `json:"put,omitempty"`
}

type Put struct {
Action `json:",inline"`
ParameterNames []string `json:"parameterNames,omitempty"`
}

type Get struct {
Action `json:",omitempty"`
}

type Action struct {
// Path used by service for action on a device or sensor
Path string `json:"path,omitempty"`
// Responses from get or put requests to service
Responses []Response `json:"responses,omitempty"`
// Url for requests from command service
URL string `json:"url,omitempty"`
}

// Response for a Get or Put request to a service
type Response struct {
Code string `json:"code,omitempty"`
Description string `json:"description,omitempty"`
ExpectedValues []string `json:"expectedValues,omitempty"`
}

type ProfileResource struct {
Name string `json:"name,omitempty"`
Get []ResourceOperation `json:"get,omitempty"`
Set []ResourceOperation `json:"set,omitempty"`
type DeviceCommand struct {
Name string `json:"name"`
IsHidden bool `json:"isHidden"`
ReadWrite string `json:"readWrite"`
ResourceOperations []ResourceOperation `json:"resourceOperations"`
}

type ResourceOperation struct {
Index string `json:"index,omitempty"`
Operation string `json:"operation,omitempty"`
// Deprecated
Object string `json:"object,omitempty"`
// The replacement of Object field
DeviceResource string `json:"deviceResource,omitempty"`
Parameter string `json:"parameter,omitempty"`
// Deprecated
Resource string `json:"resource,omitempty"`
// The replacement of Resource field
DeviceCommand string `json:"deviceCommand,omitempty"`
Secondary []string `json:"secondary,omitempty"`
Mappings map[string]string `json:"mappings,omitempty"`
DeviceResource string `json:"deviceResource,omitempty"`
Mappings map[string]string `json:"mappings,omitempty"`
DefaultValue string `json:"defaultValue"`
}

// DeviceProfileSpec defines the desired state of DeviceProfile
Expand All @@ -133,10 +95,7 @@ type DeviceProfileSpec struct {
// Labels used to search for groups of profiles on EdgeX Foundry
Labels []string `json:"labels,omitempty"`
DeviceResources []DeviceResource `json:"deviceResources,omitempty"`

// TODO support the following field
DeviceCommands []ProfileResource `json:"deviceCommands,omitempty"`
CoreCommands []Command `json:"coreCommands,omitempty"`
DeviceCommands []DeviceCommand `json:"deviceCommands,omitempty"`
}

// DeviceProfileStatus defines the observed state of DeviceProfile
Expand Down
31 changes: 1 addition & 30 deletions api/v1alpha1/deviceservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,14 @@ const (
DeviceServiceManagingCondition clusterv1.ConditionType = "DeviceServiceManaging"
)

type Addressable struct {
// ID is a unique identifier for the Addressable, such as a UUID
Id string `json:"id,omitempty"`
// Name is a unique name given to the Addressable
Name string `json:"name,omitempty"`
// Protocol for the address (HTTP/TCP)
Protocol string `json:"protocol,omitempty"`
// Method for connecting (i.e. POST)
HTTPMethod string `json:"method,omitempty"`
// Address of the addressable
Address string `json:"address,omitempty"`
// Port for the address
Port int `json:"port,omitempty"`
// Path for callbacks
Path string `json:"path,omitempty"`
// For message bus protocols
Publisher string `json:"publisher,omitempty"`
// User id for authentication
User string `json:"user,omitempty"`
// Password of the user for authentication for the addressable
Password string `json:"password,omitempty"`
// Topic for message bus addressables
Topic string `json:"topic,omitempty"`
}

// DeviceServiceSpec defines the desired state of DeviceService
type DeviceServiceSpec struct {
BaseAddress string `json:"baseAddress"`
// Information describing the device
Description string `json:"description,omitempty"`
// operational state - either enabled or disabled
OperatingState OperatingState `json:"operatingState,omitempty"`
// tags or other labels applied to the device service for search or other
// identification needs on the EdgeX Foundry
Labels []string `json:"labels,omitempty"`
// address (MQTT topic, HTTP address, serial bus, etc.) for reaching
// the service
Addressable Addressable `json:"addressable,omitempty"`
// Device Service Admin State
AdminState AdminState `json:"adminState,omitempty"`
// True means deviceService is managed by cloud, cloud can update the related fields
Expand Down
4 changes: 0 additions & 4 deletions api/v1alpha1/edgexobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ type EdgeXObject interface {
IsAddedToEdgeX() bool
}

func (vd *ValueDescriptor) IsAddedToEdgeX() bool {
return vd.Status.AddedToEdgeX
}

func (dp *DeviceProfile) IsAddedToEdgeX() bool {
return dp.Status.Synced
}
Expand Down
73 changes: 0 additions & 73 deletions api/v1alpha1/valuedescriptor_types.go

This file was deleted.

Loading