github.com/midokura/kubeedge@v1.2.0-mido.0/tests/e2e/utils/device.go (about)

     1  package utils
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	v12 "k8s.io/api/core/v1"
     7  	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     8  
     9  	"github.com/kubeedge/kubeedge/cloud/pkg/apis/devices/v1alpha1"
    10  	"github.com/kubeedge/kubeedge/cloud/pkg/devicecontroller/types"
    11  )
    12  
    13  func NewLedDeviceModel() v1alpha1.DeviceModel {
    14  	deviceProperty1 := v1alpha1.DeviceProperty{
    15  		Name:        "power-status",
    16  		Description: "Indicates whether the led light is ON/OFF",
    17  		Type: v1alpha1.PropertyType{String: &v1alpha1.PropertyTypeString{
    18  			AccessMode:   "ReadWrite",
    19  			DefaultValue: "OFF",
    20  		}},
    21  	}
    22  	deviceProperty2 := v1alpha1.DeviceProperty{
    23  		Name:        "gpio-pin-number",
    24  		Description: "Indicates the GPIO pin to which LED is connected",
    25  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
    26  			AccessMode:   "ReadOnly",
    27  			DefaultValue: 18,
    28  		}},
    29  	}
    30  	properties := []v1alpha1.DeviceProperty{deviceProperty1, deviceProperty2}
    31  	newDeviceModel := v1alpha1.DeviceModel{
    32  		TypeMeta: v1.TypeMeta{
    33  			Kind:       "DeviceModel",
    34  			APIVersion: "devices.kubeedge.io/v1alpha1",
    35  		},
    36  		ObjectMeta: v1.ObjectMeta{
    37  			Name:      "led-light",
    38  			Namespace: Namespace,
    39  		},
    40  		Spec: v1alpha1.DeviceModelSpec{
    41  			Properties: properties,
    42  		},
    43  	}
    44  	return newDeviceModel
    45  }
    46  
    47  func NewModbusDeviceModel() v1alpha1.DeviceModel {
    48  	deviceProperty1 := v1alpha1.DeviceProperty{
    49  		Name:        "temperature",
    50  		Description: "temperature in degree celsius",
    51  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
    52  			AccessMode: "ReadWrite",
    53  			Maximum:    100,
    54  			Unit:       "degree celsius",
    55  		}},
    56  	}
    57  	deviceProperty2 := v1alpha1.DeviceProperty{
    58  		Name:        "temperature-enable",
    59  		Description: "enable data collection of temperature sensor",
    60  		Type: v1alpha1.PropertyType{String: &v1alpha1.PropertyTypeString{
    61  			AccessMode:   "ReadWrite",
    62  			DefaultValue: "OFF",
    63  		}},
    64  	}
    65  	properties := []v1alpha1.DeviceProperty{deviceProperty1, deviceProperty2}
    66  	devicePropertyVisitor1 := v1alpha1.DevicePropertyVisitor{
    67  		PropertyName: "temperature",
    68  		VisitorConfig: v1alpha1.VisitorConfig{
    69  			Modbus: &v1alpha1.VisitorConfigModbus{
    70  				Register:       "CoilRegister",
    71  				Offset:         2,
    72  				Limit:          1,
    73  				Scale:          1,
    74  				IsSwap:         true,
    75  				IsRegisterSwap: true,
    76  			},
    77  		},
    78  	}
    79  	devicePropertyVisitor2 := v1alpha1.DevicePropertyVisitor{
    80  		PropertyName: "temperature-enable",
    81  		VisitorConfig: v1alpha1.VisitorConfig{
    82  			Modbus: &v1alpha1.VisitorConfigModbus{
    83  				Register:       "DiscreteInputRegister",
    84  				Offset:         3,
    85  				Limit:          1,
    86  				Scale:          1.0,
    87  				IsSwap:         true,
    88  				IsRegisterSwap: true,
    89  			},
    90  		},
    91  	}
    92  	propertyVisitors := []v1alpha1.DevicePropertyVisitor{devicePropertyVisitor1, devicePropertyVisitor2}
    93  	newDeviceModel := v1alpha1.DeviceModel{
    94  		TypeMeta: v1.TypeMeta{
    95  			Kind:       "DeviceModel",
    96  			APIVersion: "devices.kubeedge.io/v1alpha1",
    97  		},
    98  		ObjectMeta: v1.ObjectMeta{
    99  			Name:      "sensor-tag-model",
   100  			Namespace: Namespace,
   101  		},
   102  		Spec: v1alpha1.DeviceModelSpec{
   103  			Properties:       properties,
   104  			PropertyVisitors: propertyVisitors,
   105  		},
   106  	}
   107  	return newDeviceModel
   108  }
   109  
   110  func NewBluetoothDeviceModel() v1alpha1.DeviceModel {
   111  	deviceProperty1 := v1alpha1.DeviceProperty{
   112  		Name:        "temperature",
   113  		Description: "temperature in degree celsius",
   114  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   115  			AccessMode: "ReadOnly",
   116  			Maximum:    100,
   117  			Unit:       "degree celsius",
   118  		}},
   119  	}
   120  	deviceProperty2 := v1alpha1.DeviceProperty{
   121  		Name:        "temperature-enable",
   122  		Description: "enable data collection of temperature sensor",
   123  		Type: v1alpha1.PropertyType{String: &v1alpha1.PropertyTypeString{
   124  			AccessMode:   "ReadWrite",
   125  			DefaultValue: "ON",
   126  		}},
   127  	}
   128  	deviceProperty3 := v1alpha1.DeviceProperty{
   129  		Name:        "io-config-initialize",
   130  		Description: "initialize io-config with value 0",
   131  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   132  			AccessMode:   "ReadWrite",
   133  			DefaultValue: 0,
   134  		}},
   135  	}
   136  	deviceProperty4 := v1alpha1.DeviceProperty{
   137  		Name:        "io-data-initialize",
   138  		Description: "initialize io-data with value 0",
   139  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   140  			AccessMode:   "ReadWrite",
   141  			DefaultValue: 0,
   142  		}},
   143  	}
   144  	deviceProperty5 := v1alpha1.DeviceProperty{
   145  		Name:        "io-config",
   146  		Description: "register activation of io-config",
   147  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   148  			AccessMode:   "ReadWrite",
   149  			DefaultValue: 1,
   150  		}},
   151  	}
   152  	deviceProperty6 := v1alpha1.DeviceProperty{
   153  		Name:        "io-data",
   154  		Description: "data field to control io-control",
   155  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   156  			AccessMode:   "ReadWrite",
   157  			DefaultValue: 0,
   158  		}},
   159  	}
   160  	properties := []v1alpha1.DeviceProperty{deviceProperty1, deviceProperty2, deviceProperty3, deviceProperty4, deviceProperty5, deviceProperty6}
   161  	devicePropertyVisitor1 := v1alpha1.DevicePropertyVisitor{
   162  		PropertyName: "temperature",
   163  		VisitorConfig: v1alpha1.VisitorConfig{
   164  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   165  				CharacteristicUUID: "f000aa0104514000b000000000000000",
   166  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   167  					StartIndex: 2,
   168  					EndIndex:   1,
   169  					ShiftRight: 2,
   170  					OrderOfOperations: []v1alpha1.BluetoothOperations{
   171  						{
   172  							BluetoothOperationType:  "Multiply",
   173  							BluetoothOperationValue: 0.03125,
   174  						},
   175  					},
   176  				},
   177  			},
   178  		},
   179  	}
   180  	devicePropertyVisitor2 := v1alpha1.DevicePropertyVisitor{
   181  		PropertyName: "temperature-enable",
   182  		VisitorConfig: v1alpha1.VisitorConfig{
   183  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   184  				CharacteristicUUID: "f000aa0204514000b000000000000000",
   185  				DataWriteToBluetooth: map[string][]byte{
   186  					"ON":  {1},
   187  					"OFF": {0},
   188  				},
   189  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   190  					StartIndex: 1,
   191  					EndIndex:   1,
   192  				},
   193  			},
   194  		},
   195  	}
   196  	devicePropertyVisitor3 := v1alpha1.DevicePropertyVisitor{
   197  		PropertyName: "io-config-initialize",
   198  		VisitorConfig: v1alpha1.VisitorConfig{
   199  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   200  				CharacteristicUUID: "f000aa6604514000b000000000000000",
   201  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   202  					StartIndex: 1,
   203  					EndIndex:   1,
   204  				},
   205  			},
   206  		},
   207  	}
   208  	devicePropertyVisitor4 := v1alpha1.DevicePropertyVisitor{
   209  		PropertyName: "io-data-initialize",
   210  		VisitorConfig: v1alpha1.VisitorConfig{
   211  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   212  				CharacteristicUUID: "f000aa6504514000b000000000000000",
   213  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   214  					StartIndex: 1,
   215  					EndIndex:   1,
   216  				},
   217  			},
   218  		},
   219  	}
   220  	devicePropertyVisitor5 := v1alpha1.DevicePropertyVisitor{
   221  		PropertyName: "io-config",
   222  		VisitorConfig: v1alpha1.VisitorConfig{
   223  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   224  				CharacteristicUUID: "f000aa6604514000b000000000000000",
   225  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   226  					StartIndex: 1,
   227  					EndIndex:   1,
   228  				},
   229  			},
   230  		},
   231  	}
   232  	devicePropertyVisitor6 := v1alpha1.DevicePropertyVisitor{
   233  		PropertyName: "io-data",
   234  		VisitorConfig: v1alpha1.VisitorConfig{
   235  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   236  				CharacteristicUUID: "f000aa6504514000b000000000000000",
   237  				DataWriteToBluetooth: map[string][]byte{
   238  					"Red":            {1},
   239  					"Green":          {2},
   240  					"RedGreen":       {3},
   241  					"Buzzer":         {4},
   242  					"BuzzerRed":      {5},
   243  					"BuzzerGreen":    {6},
   244  					"BuzzerRedGreen": {7},
   245  				},
   246  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   247  					StartIndex: 1,
   248  					EndIndex:   1,
   249  				},
   250  			},
   251  		},
   252  	}
   253  	propertyVisitors := []v1alpha1.DevicePropertyVisitor{devicePropertyVisitor1, devicePropertyVisitor2, devicePropertyVisitor3, devicePropertyVisitor4, devicePropertyVisitor5, devicePropertyVisitor6}
   254  	newDeviceModel := v1alpha1.DeviceModel{
   255  		TypeMeta: v1.TypeMeta{
   256  			Kind:       "DeviceModel",
   257  			APIVersion: "devices.kubeedge.io/v1alpha1",
   258  		},
   259  		ObjectMeta: v1.ObjectMeta{
   260  			Name:      "cc2650-sensortag",
   261  			Namespace: Namespace,
   262  		},
   263  		Spec: v1alpha1.DeviceModelSpec{
   264  			Properties:       properties,
   265  			PropertyVisitors: propertyVisitors,
   266  		},
   267  	}
   268  	return newDeviceModel
   269  }
   270  
   271  func UpdatedLedDeviceModel() v1alpha1.DeviceModel {
   272  	deviceProperty1 := v1alpha1.DeviceProperty{
   273  		Name:        "power-status",
   274  		Description: "Indicates whether the led light is ON/OFF",
   275  		Type: v1alpha1.PropertyType{String: &v1alpha1.PropertyTypeString{
   276  			AccessMode:   "ReadWrite",
   277  			DefaultValue: "ON",
   278  		}},
   279  	}
   280  	deviceProperty2 := v1alpha1.DeviceProperty{
   281  		Name:        "gpio-pin-number",
   282  		Description: "Indicates the GPIO pin to which LED is connected",
   283  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   284  			AccessMode:   "ReadWrite",
   285  			DefaultValue: 17,
   286  		}},
   287  	}
   288  	properties := []v1alpha1.DeviceProperty{deviceProperty1, deviceProperty2}
   289  	updatedDeviceModel := v1alpha1.DeviceModel{
   290  		TypeMeta: v1.TypeMeta{
   291  			Kind:       "DeviceModel",
   292  			APIVersion: "devices.kubeedge.io/v1alpha1",
   293  		},
   294  		ObjectMeta: v1.ObjectMeta{
   295  			Name:      "led-light",
   296  			Namespace: Namespace,
   297  		},
   298  		Spec: v1alpha1.DeviceModelSpec{
   299  			Properties: properties,
   300  		},
   301  	}
   302  	return updatedDeviceModel
   303  }
   304  
   305  func UpdatedModbusDeviceModel() v1alpha1.DeviceModel {
   306  	deviceProperty1 := v1alpha1.DeviceProperty{
   307  		Name:        "temperature",
   308  		Description: "temperature in degree",
   309  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   310  			AccessMode: "ReadOnly",
   311  			Maximum:    200,
   312  			Unit:       "celsius",
   313  		}},
   314  	}
   315  	deviceProperty2 := v1alpha1.DeviceProperty{
   316  		Name:        "temperature-enable",
   317  		Description: "enable data collection of temperature sensor",
   318  		Type: v1alpha1.PropertyType{String: &v1alpha1.PropertyTypeString{
   319  			AccessMode:   "ReadWrite",
   320  			DefaultValue: "ON",
   321  		}},
   322  	}
   323  	properties := []v1alpha1.DeviceProperty{deviceProperty1, deviceProperty2}
   324  	devicePropertyVisitor1 := v1alpha1.DevicePropertyVisitor{
   325  		PropertyName: "temperature",
   326  		VisitorConfig: v1alpha1.VisitorConfig{
   327  			Modbus: &v1alpha1.VisitorConfigModbus{
   328  				Register:       "CoilRegister",
   329  				Offset:         2,
   330  				Limit:          1,
   331  				Scale:          2,
   332  				IsSwap:         false,
   333  				IsRegisterSwap: true,
   334  			},
   335  		},
   336  	}
   337  	devicePropertyVisitor2 := v1alpha1.DevicePropertyVisitor{
   338  		PropertyName: "temperature-enable",
   339  		VisitorConfig: v1alpha1.VisitorConfig{
   340  			Modbus: &v1alpha1.VisitorConfigModbus{
   341  				Register:       "DiscreteInputRegister",
   342  				Offset:         1,
   343  				Limit:          1,
   344  				Scale:          1.0,
   345  				IsSwap:         true,
   346  				IsRegisterSwap: false,
   347  			},
   348  		},
   349  	}
   350  	propertyVisitors := []v1alpha1.DevicePropertyVisitor{devicePropertyVisitor1, devicePropertyVisitor2}
   351  	newDeviceModel := v1alpha1.DeviceModel{
   352  		TypeMeta: v1.TypeMeta{
   353  			Kind:       "DeviceModel",
   354  			APIVersion: "devices.kubeedge.io/v1alpha1",
   355  		},
   356  		ObjectMeta: v1.ObjectMeta{
   357  			Name:      "sensor-tag-model",
   358  			Namespace: Namespace,
   359  		},
   360  		Spec: v1alpha1.DeviceModelSpec{
   361  			Properties:       properties,
   362  			PropertyVisitors: propertyVisitors,
   363  		},
   364  	}
   365  	return newDeviceModel
   366  }
   367  
   368  func UpdatedBluetoothDeviceModel() v1alpha1.DeviceModel {
   369  	deviceProperty1 := v1alpha1.DeviceProperty{
   370  		Name:        "temperature",
   371  		Description: "temperature in degree",
   372  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   373  			AccessMode: "ReadOnly",
   374  			Maximum:    200,
   375  			Unit:       "degree",
   376  		}},
   377  	}
   378  	deviceProperty2 := v1alpha1.DeviceProperty{
   379  		Name:        "temperature-enable",
   380  		Description: "enable data collection of temperature sensor",
   381  		Type: v1alpha1.PropertyType{String: &v1alpha1.PropertyTypeString{
   382  			AccessMode:   "ReadWrite",
   383  			DefaultValue: "OFF",
   384  		}},
   385  	}
   386  	deviceProperty3 := v1alpha1.DeviceProperty{
   387  		Name:        "io-config-initialize",
   388  		Description: "initialize io-config with value 0",
   389  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   390  			AccessMode:   "ReadWrite",
   391  			DefaultValue: 0,
   392  		}},
   393  	}
   394  	deviceProperty4 := v1alpha1.DeviceProperty{
   395  		Name:        "io-data-initialize",
   396  		Description: "initialize io-data with value 0",
   397  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   398  			AccessMode:   "ReadWrite",
   399  			DefaultValue: 0,
   400  		}},
   401  	}
   402  	deviceProperty5 := v1alpha1.DeviceProperty{
   403  		Name:        "io-config",
   404  		Description: "register activation of io-config",
   405  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   406  			AccessMode:   "ReadWrite",
   407  			DefaultValue: 1,
   408  		}},
   409  	}
   410  	deviceProperty6 := v1alpha1.DeviceProperty{
   411  		Name:        "io-data",
   412  		Description: "data field to control io-control",
   413  		Type: v1alpha1.PropertyType{Int: &v1alpha1.PropertyTypeInt64{
   414  			AccessMode:   "ReadWrite",
   415  			DefaultValue: 0,
   416  		}},
   417  	}
   418  	properties := []v1alpha1.DeviceProperty{deviceProperty1, deviceProperty2, deviceProperty3, deviceProperty4, deviceProperty5, deviceProperty6}
   419  	devicePropertyVisitor1 := v1alpha1.DevicePropertyVisitor{
   420  		PropertyName: "temperature",
   421  		VisitorConfig: v1alpha1.VisitorConfig{
   422  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   423  				CharacteristicUUID: "f000aa0104514000b000000000000000",
   424  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   425  					StartIndex: 1,
   426  					EndIndex:   3,
   427  					ShiftRight: 1,
   428  					OrderOfOperations: []v1alpha1.BluetoothOperations{
   429  						{
   430  							BluetoothOperationType:  "Multiply",
   431  							BluetoothOperationValue: 0.05,
   432  						},
   433  					},
   434  				},
   435  			},
   436  		},
   437  	}
   438  	devicePropertyVisitor2 := v1alpha1.DevicePropertyVisitor{
   439  		PropertyName: "temperature-enable",
   440  		VisitorConfig: v1alpha1.VisitorConfig{
   441  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   442  				CharacteristicUUID: "f000aa0204514000b000000000000000",
   443  				DataWriteToBluetooth: map[string][]byte{
   444  					"On":  {1},
   445  					"OFF": {0},
   446  				},
   447  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   448  					StartIndex: 1,
   449  					EndIndex:   1,
   450  				},
   451  			},
   452  		},
   453  	}
   454  	devicePropertyVisitor3 := v1alpha1.DevicePropertyVisitor{
   455  		PropertyName: "io-config-initialize",
   456  		VisitorConfig: v1alpha1.VisitorConfig{
   457  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   458  				CharacteristicUUID: "f000aa6604514000b000000000000000",
   459  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   460  					StartIndex: 1,
   461  					EndIndex:   1,
   462  				},
   463  			},
   464  		},
   465  	}
   466  	devicePropertyVisitor4 := v1alpha1.DevicePropertyVisitor{
   467  		PropertyName: "io-data-initialize",
   468  		VisitorConfig: v1alpha1.VisitorConfig{
   469  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   470  				CharacteristicUUID: "f000aa6504514000b000000000000001",
   471  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   472  					StartIndex: 1,
   473  					EndIndex:   1,
   474  				},
   475  			},
   476  		},
   477  	}
   478  	devicePropertyVisitor5 := v1alpha1.DevicePropertyVisitor{
   479  		PropertyName: "io-config",
   480  		VisitorConfig: v1alpha1.VisitorConfig{
   481  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   482  				CharacteristicUUID: "f000aa6604514000b000000000000000",
   483  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   484  					StartIndex: 1,
   485  					EndIndex:   1,
   486  				},
   487  			},
   488  		},
   489  	}
   490  	devicePropertyVisitor6 := v1alpha1.DevicePropertyVisitor{
   491  		PropertyName: "io-data",
   492  		VisitorConfig: v1alpha1.VisitorConfig{
   493  			Bluetooth: &v1alpha1.VisitorConfigBluetooth{
   494  				CharacteristicUUID: "f000aa6504514000b000000000000000",
   495  				DataWriteToBluetooth: map[string][]byte{
   496  					"Red":            {2},
   497  					"Green":          {3},
   498  					"RedGreen":       {4},
   499  					"Buzzer":         {5},
   500  					"BuzzerRed":      {6},
   501  					"BuzzerGreen":    {7},
   502  					"BuzzerRedGreen": {8},
   503  				},
   504  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
   505  					StartIndex: 1,
   506  					EndIndex:   1,
   507  				},
   508  			},
   509  		},
   510  	}
   511  	propertyVisitors := []v1alpha1.DevicePropertyVisitor{devicePropertyVisitor1, devicePropertyVisitor2, devicePropertyVisitor3, devicePropertyVisitor4, devicePropertyVisitor5, devicePropertyVisitor6}
   512  	newDeviceModel := v1alpha1.DeviceModel{
   513  		TypeMeta: v1.TypeMeta{
   514  			Kind:       "DeviceModel",
   515  			APIVersion: "devices.kubeedge.io/v1alpha1",
   516  		},
   517  		ObjectMeta: v1.ObjectMeta{
   518  			Name:      "cc2650-sensortag",
   519  			Namespace: Namespace,
   520  		},
   521  		Spec: v1alpha1.DeviceModelSpec{
   522  			Properties:       properties,
   523  			PropertyVisitors: propertyVisitors,
   524  		},
   525  	}
   526  	return newDeviceModel
   527  }
   528  
   529  func NewLedDeviceInstance(nodeSelector string) v1alpha1.Device {
   530  	deviceInstance := v1alpha1.Device{
   531  		TypeMeta: v1.TypeMeta{
   532  			Kind:       "Device",
   533  			APIVersion: "devices.kubeedge.io/v1alpha1",
   534  		},
   535  		ObjectMeta: v1.ObjectMeta{
   536  			Name:      "led-light-instance-01",
   537  			Namespace: Namespace,
   538  			Labels: map[string]string{
   539  				"description": "LEDLight",
   540  				"model":       "led-light",
   541  			},
   542  		},
   543  		Spec: v1alpha1.DeviceSpec{
   544  			DeviceModelRef: &v12.LocalObjectReference{
   545  				Name: "led-light",
   546  			},
   547  			NodeSelector: &v12.NodeSelector{
   548  				NodeSelectorTerms: []v12.NodeSelectorTerm{
   549  					{
   550  						MatchExpressions: []v12.NodeSelectorRequirement{
   551  							{
   552  								Key:      "",
   553  								Operator: v12.NodeSelectorOpIn,
   554  								Values:   []string{nodeSelector},
   555  							},
   556  						},
   557  					},
   558  				},
   559  			},
   560  		},
   561  		Status: v1alpha1.DeviceStatus{
   562  			Twins: []v1alpha1.Twin{
   563  				{
   564  					PropertyName: "power-status",
   565  					Desired: v1alpha1.TwinProperty{
   566  						Value: "ON",
   567  						Metadata: map[string]string{
   568  							"type": "string",
   569  						},
   570  					},
   571  					Reported: v1alpha1.TwinProperty{
   572  						Value: "unknown",
   573  					},
   574  				},
   575  			},
   576  		},
   577  	}
   578  
   579  	return deviceInstance
   580  }
   581  
   582  // NewMockInstance create an instance for mock bluetooth device.
   583  func NewMockInstance(nodeSelector string) v1alpha1.Device {
   584  	deviceInstance := v1alpha1.Device{
   585  		TypeMeta: v1.TypeMeta{
   586  			Kind:       "Device",
   587  			APIVersion: "devices.kubeedge.io/v1alpha1",
   588  		},
   589  		ObjectMeta: v1.ObjectMeta{
   590  			Name:      "mock-temp-sensor-instance",
   591  			Namespace: Namespace,
   592  			Labels: map[string]string{
   593  				"description":  "TemperatureSensor",
   594  				"manufacturer": "TemperatureInstruments",
   595  				"model":        "sensortagmock",
   596  			},
   597  		},
   598  		Spec: v1alpha1.DeviceSpec{
   599  			DeviceModelRef: &v12.LocalObjectReference{
   600  				Name: "mock-temp-sensor-model",
   601  			},
   602  			NodeSelector: &v12.NodeSelector{
   603  				NodeSelectorTerms: []v12.NodeSelectorTerm{
   604  					{
   605  						MatchExpressions: []v12.NodeSelectorRequirement{
   606  							{
   607  								Key:      "",
   608  								Operator: v12.NodeSelectorOpIn,
   609  								Values:   []string{nodeSelector},
   610  							},
   611  						},
   612  					},
   613  				},
   614  			},
   615  		},
   616  		Status: v1alpha1.DeviceStatus{
   617  			Twins: []v1alpha1.Twin{
   618  				{
   619  					PropertyName: "io-data",
   620  					Desired: v1alpha1.TwinProperty{
   621  						Value: "Red",
   622  						Metadata: map[string]string{
   623  							"type": "string",
   624  						},
   625  					},
   626  					Reported: v1alpha1.TwinProperty{
   627  						Value: "unknown",
   628  					},
   629  				},
   630  			},
   631  		},
   632  	}
   633  	return deviceInstance
   634  }
   635  
   636  func NewModbusDeviceInstance(nodeSelector string) v1alpha1.Device {
   637  	deviceInstance := v1alpha1.Device{
   638  		TypeMeta: v1.TypeMeta{
   639  			Kind:       "Device",
   640  			APIVersion: "devices.kubeedge.io/v1alpha1",
   641  		},
   642  		ObjectMeta: v1.ObjectMeta{
   643  			Name:      "sensor-tag-instance-02",
   644  			Namespace: Namespace,
   645  			Labels: map[string]string{
   646  				"description":  "TISimplelinkSensorTag",
   647  				"manufacturer": "TexasInstruments",
   648  				"model":        "CC2650",
   649  			},
   650  		},
   651  		Spec: v1alpha1.DeviceSpec{
   652  			DeviceModelRef: &v12.LocalObjectReference{
   653  				Name: "sensor-tag-model",
   654  			},
   655  			NodeSelector: &v12.NodeSelector{
   656  				NodeSelectorTerms: []v12.NodeSelectorTerm{
   657  					{
   658  						MatchExpressions: []v12.NodeSelectorRequirement{
   659  							{
   660  								Key:      "",
   661  								Operator: v12.NodeSelectorOpIn,
   662  								Values:   []string{nodeSelector},
   663  							},
   664  						},
   665  					},
   666  				},
   667  			},
   668  		},
   669  		Status: v1alpha1.DeviceStatus{
   670  			Twins: []v1alpha1.Twin{
   671  				{
   672  					PropertyName: "temperature-enable",
   673  					Desired: v1alpha1.TwinProperty{
   674  						Value: "OFF",
   675  						Metadata: map[string]string{
   676  							"type": "string",
   677  						},
   678  					},
   679  					Reported: v1alpha1.TwinProperty{
   680  						Value: "unknown",
   681  					},
   682  				},
   683  			},
   684  		},
   685  	}
   686  	return deviceInstance
   687  }
   688  
   689  func NewBluetoothDeviceInstance(nodeSelector string) v1alpha1.Device {
   690  	deviceInstance := v1alpha1.Device{
   691  		TypeMeta: v1.TypeMeta{
   692  			Kind:       "Device",
   693  			APIVersion: "devices.kubeedge.io/v1alpha1",
   694  		},
   695  		ObjectMeta: v1.ObjectMeta{
   696  			Name:      "sensor-tag-instance-01",
   697  			Namespace: Namespace,
   698  			Labels: map[string]string{
   699  				"description":  "TISimplelinkSensorTag",
   700  				"manufacturer": "TexasInstruments",
   701  				"model":        "cc2650-sensortag",
   702  			},
   703  		},
   704  		Spec: v1alpha1.DeviceSpec{
   705  			DeviceModelRef: &v12.LocalObjectReference{
   706  				Name: "cc2650-sensortag",
   707  			},
   708  			NodeSelector: &v12.NodeSelector{
   709  				NodeSelectorTerms: []v12.NodeSelectorTerm{
   710  					{
   711  						MatchExpressions: []v12.NodeSelectorRequirement{
   712  							{
   713  								Key:      "",
   714  								Operator: v12.NodeSelectorOpIn,
   715  								Values:   []string{nodeSelector},
   716  							},
   717  						},
   718  					},
   719  				},
   720  			},
   721  			Protocol: v1alpha1.ProtocolConfig{
   722  				Bluetooth: &v1alpha1.ProtocolConfigBluetooth{
   723  					MACAddress: "BC:6A:29:AE:CC:96",
   724  				},
   725  			},
   726  		},
   727  		Status: v1alpha1.DeviceStatus{
   728  			Twins: []v1alpha1.Twin{
   729  				{
   730  					PropertyName: "io-data",
   731  					Desired: v1alpha1.TwinProperty{
   732  						Value: "1",
   733  						Metadata: map[string]string{
   734  							"type": "int",
   735  						},
   736  					},
   737  					Reported: v1alpha1.TwinProperty{
   738  						Value: "unknown",
   739  					},
   740  				},
   741  			},
   742  		},
   743  	}
   744  	return deviceInstance
   745  }
   746  
   747  func UpdatedLedDeviceInstance(nodeSelector string) v1alpha1.Device {
   748  	deviceInstance := v1alpha1.Device{
   749  		TypeMeta: v1.TypeMeta{
   750  			Kind:       "Device",
   751  			APIVersion: "devices.kubeedge.io/v1alpha1",
   752  		},
   753  		ObjectMeta: v1.ObjectMeta{
   754  			Name:      "led-light-instance-01",
   755  			Namespace: Namespace,
   756  			Labels: map[string]string{
   757  				"description": "LEDLight-1",
   758  				"model":       "led-light-1",
   759  			},
   760  		},
   761  		Spec: v1alpha1.DeviceSpec{
   762  			DeviceModelRef: &v12.LocalObjectReference{
   763  				Name: "led-light",
   764  			},
   765  			NodeSelector: &v12.NodeSelector{
   766  				NodeSelectorTerms: []v12.NodeSelectorTerm{
   767  					{
   768  						MatchExpressions: []v12.NodeSelectorRequirement{
   769  							{
   770  								Key:      "",
   771  								Operator: v12.NodeSelectorOpIn,
   772  								Values:   []string{nodeSelector},
   773  							},
   774  						},
   775  					},
   776  				},
   777  			},
   778  		},
   779  		Status: v1alpha1.DeviceStatus{
   780  			Twins: []v1alpha1.Twin{
   781  				{
   782  					PropertyName: "power-status",
   783  					Desired: v1alpha1.TwinProperty{
   784  						Value: "OFF",
   785  						Metadata: map[string]string{
   786  							"type": "string",
   787  						},
   788  					},
   789  					Reported: v1alpha1.TwinProperty{
   790  						Value: "unknown",
   791  					},
   792  				},
   793  			},
   794  		},
   795  	}
   796  	return deviceInstance
   797  }
   798  
   799  func UpdatedModbusDeviceInstance(nodeSelector string) v1alpha1.Device {
   800  	deviceInstance := v1alpha1.Device{
   801  		TypeMeta: v1.TypeMeta{
   802  			Kind:       "Device",
   803  			APIVersion: "devices.kubeedge.io/v1alpha1",
   804  		},
   805  		ObjectMeta: v1.ObjectMeta{
   806  			Name:      "sensor-tag-instance-02",
   807  			Namespace: Namespace,
   808  			Labels: map[string]string{
   809  				"description":  "TISensorTag",
   810  				"manufacturer": "TexasInstruments-TI",
   811  				"model":        "CC2650-sensorTag",
   812  			},
   813  		},
   814  		Spec: v1alpha1.DeviceSpec{
   815  			DeviceModelRef: &v12.LocalObjectReference{
   816  				Name: "sensor-tag-model",
   817  			},
   818  			NodeSelector: &v12.NodeSelector{
   819  				NodeSelectorTerms: []v12.NodeSelectorTerm{
   820  					{
   821  						MatchExpressions: []v12.NodeSelectorRequirement{
   822  							{
   823  								Key:      "",
   824  								Operator: v12.NodeSelectorOpIn,
   825  								Values:   []string{nodeSelector},
   826  							},
   827  						},
   828  					},
   829  				},
   830  			},
   831  		},
   832  		Status: v1alpha1.DeviceStatus{
   833  			Twins: []v1alpha1.Twin{
   834  				{
   835  					PropertyName: "temperature-enable",
   836  					Desired: v1alpha1.TwinProperty{
   837  						Value: "ON",
   838  						Metadata: map[string]string{
   839  							"type": "string",
   840  						},
   841  					},
   842  					Reported: v1alpha1.TwinProperty{
   843  						Value: "unknown",
   844  					},
   845  				},
   846  			},
   847  		},
   848  	}
   849  	return deviceInstance
   850  }
   851  
   852  func UpdatedBluetoothDeviceInstance(nodeSelector string) v1alpha1.Device {
   853  	deviceInstance := v1alpha1.Device{
   854  		TypeMeta: v1.TypeMeta{
   855  			Kind:       "Device",
   856  			APIVersion: "devices.kubeedge.io/v1alpha1",
   857  		},
   858  		ObjectMeta: v1.ObjectMeta{
   859  			Name:      "sensor-tag-instance-01",
   860  			Namespace: Namespace,
   861  			Labels: map[string]string{
   862  				"description":  "TISensorTag",
   863  				"manufacturer": "TexasInstruments-TI",
   864  				"model":        "cc2650-sensor-tag",
   865  			},
   866  		},
   867  		Spec: v1alpha1.DeviceSpec{
   868  			DeviceModelRef: &v12.LocalObjectReference{
   869  				Name: "cc2650-sensortag",
   870  			},
   871  			NodeSelector: &v12.NodeSelector{
   872  				NodeSelectorTerms: []v12.NodeSelectorTerm{
   873  					{
   874  						MatchExpressions: []v12.NodeSelectorRequirement{
   875  							{
   876  								Key:      "",
   877  								Operator: v12.NodeSelectorOpIn,
   878  								Values:   []string{nodeSelector},
   879  							},
   880  						},
   881  					},
   882  				},
   883  			},
   884  			Protocol: v1alpha1.ProtocolConfig{
   885  				Bluetooth: &v1alpha1.ProtocolConfigBluetooth{
   886  					MACAddress: "BC:6A:29:AE:CC:69",
   887  				},
   888  			},
   889  		},
   890  		Status: v1alpha1.DeviceStatus{
   891  			Twins: []v1alpha1.Twin{
   892  				{
   893  					PropertyName: "io-data",
   894  					Desired: v1alpha1.TwinProperty{
   895  						Value: "1",
   896  						Metadata: map[string]string{
   897  							"type": "int",
   898  						},
   899  					},
   900  					Reported: v1alpha1.TwinProperty{
   901  						Value: "unknown",
   902  					},
   903  				},
   904  			},
   905  		},
   906  	}
   907  	return deviceInstance
   908  }
   909  
   910  func IncorrectDeviceModel() v1alpha1.DeviceModel {
   911  	newDeviceModel := v1alpha1.DeviceModel{
   912  		TypeMeta: v1.TypeMeta{
   913  			Kind:       "device-model",
   914  			APIVersion: "devices.kubeedge.io/v1alpha1",
   915  		},
   916  		ObjectMeta: v1.ObjectMeta{
   917  			Name:      "led-light",
   918  			Namespace: Namespace,
   919  		},
   920  	}
   921  	return newDeviceModel
   922  }
   923  
   924  func IncorrectDeviceInstance() v1alpha1.Device {
   925  	deviceInstance := v1alpha1.Device{
   926  		TypeMeta: v1.TypeMeta{
   927  			Kind:       "device",
   928  			APIVersion: "devices.kubeedge.io/v1alpha1",
   929  		},
   930  		ObjectMeta: v1.ObjectMeta{
   931  			Name:      "led-light-instance-01",
   932  			Namespace: Namespace,
   933  			Labels: map[string]string{
   934  				"description": "LEDLight",
   935  				"model":       "led-light",
   936  			},
   937  		},
   938  	}
   939  	return deviceInstance
   940  }
   941  
   942  func NewConfigMapLED(nodeSelector string) v12.ConfigMap {
   943  	configMap := v12.ConfigMap{
   944  		TypeMeta: v1.TypeMeta{
   945  			Kind:       "ConfigMap",
   946  			APIVersion: "v1",
   947  		},
   948  		ObjectMeta: v1.ObjectMeta{
   949  			Name:      "device-profile-config-" + nodeSelector,
   950  			Namespace: Namespace,
   951  		},
   952  	}
   953  	configMap.Data = make(map[string]string)
   954  
   955  	deviceProfile := &types.DeviceProfile{}
   956  	deviceProfile.DeviceInstances = []*types.DeviceInstance{
   957  		{
   958  			Name:  "led-light-instance-01",
   959  			ID:    "led-light-instance-01",
   960  			Model: "led-light",
   961  		},
   962  	}
   963  	deviceProfile.DeviceModels = []*types.DeviceModel{
   964  		{
   965  			Name: "led-light",
   966  			Properties: []*types.Property{
   967  				{
   968  					Name:         "power-status",
   969  					DataType:     "string",
   970  					Description:  "Indicates whether the led light is ON/OFF",
   971  					AccessMode:   "ReadWrite",
   972  					DefaultValue: "OFF",
   973  				},
   974  				{
   975  					Name:         "gpio-pin-number",
   976  					DataType:     "int",
   977  					Description:  "Indicates the GPIO pin to which LED is connected",
   978  					AccessMode:   "ReadOnly",
   979  					DefaultValue: 18,
   980  				},
   981  			},
   982  		},
   983  	}
   984  	deviceProfile.Protocols = []*types.Protocol{
   985  		{
   986  			ProtocolConfig: nil,
   987  		},
   988  	}
   989  
   990  	bytes, err := json.Marshal(deviceProfile)
   991  	if err != nil {
   992  		Errorf("Failed to marshal deviceprofile: %v", deviceProfile)
   993  	}
   994  	configMap.Data["deviceProfile.json"] = string(bytes)
   995  
   996  	return configMap
   997  }
   998  
   999  func NewConfigMapBluetooth(nodeSelector string) v12.ConfigMap {
  1000  	configMap := v12.ConfigMap{
  1001  		TypeMeta: v1.TypeMeta{
  1002  			Kind:       "ConfigMap",
  1003  			APIVersion: "v1",
  1004  		},
  1005  		ObjectMeta: v1.ObjectMeta{
  1006  			Name:      "device-profile-config-" + nodeSelector,
  1007  			Namespace: Namespace,
  1008  		},
  1009  	}
  1010  	configMap.Data = make(map[string]string)
  1011  
  1012  	deviceProfile := &types.DeviceProfile{}
  1013  	deviceProfile.DeviceInstances = []*types.DeviceInstance{
  1014  		{
  1015  			Name:     "sensor-tag-instance-01",
  1016  			ID:       "sensor-tag-instance-01",
  1017  			Protocol: "bluetooth-sensor-tag-instance-01",
  1018  			Model:    "cc2650-sensortag",
  1019  		},
  1020  	}
  1021  	deviceProfile.DeviceModels = []*types.DeviceModel{
  1022  		{
  1023  			Name: "cc2650-sensortag",
  1024  			Properties: []*types.Property{
  1025  				{
  1026  					Name:         "temperature",
  1027  					DataType:     "int",
  1028  					Description:  "temperature in degree celsius",
  1029  					AccessMode:   "ReadOnly",
  1030  					DefaultValue: 0,
  1031  					Maximum:      100,
  1032  					Unit:         "degree celsius",
  1033  				},
  1034  				{
  1035  					Name:         "temperature-enable",
  1036  					DataType:     "string",
  1037  					Description:  "enable data collection of temperature sensor",
  1038  					AccessMode:   "ReadWrite",
  1039  					DefaultValue: "ON",
  1040  				},
  1041  				{
  1042  					Name:         "io-config-initialize",
  1043  					DataType:     "int",
  1044  					Description:  "initialize io-config with value 0",
  1045  					AccessMode:   "ReadWrite",
  1046  					DefaultValue: 0,
  1047  				},
  1048  				{
  1049  					Name:         "io-data-initialize",
  1050  					DataType:     "int",
  1051  					Description:  "initialize io-data with value 0",
  1052  					AccessMode:   "ReadWrite",
  1053  					DefaultValue: 0,
  1054  				},
  1055  				{
  1056  					Name:         "io-config",
  1057  					DataType:     "int",
  1058  					Description:  "register activation of io-config",
  1059  					AccessMode:   "ReadWrite",
  1060  					DefaultValue: 1,
  1061  				}, {
  1062  					Name:         "io-data",
  1063  					DataType:     "int",
  1064  					Description:  "data field to control io-control",
  1065  					AccessMode:   "ReadWrite",
  1066  					DefaultValue: 0,
  1067  				},
  1068  			},
  1069  		},
  1070  	}
  1071  	deviceProfile.Protocols = []*types.Protocol{
  1072  		{
  1073  			Name:     "bluetooth-sensor-tag-instance-01",
  1074  			Protocol: "bluetooth",
  1075  			ProtocolConfig: v1alpha1.ProtocolConfigBluetooth{
  1076  				MACAddress: "BC:6A:29:AE:CC:96",
  1077  			},
  1078  		},
  1079  	}
  1080  
  1081  	deviceProfile.PropertyVisitors = []*types.PropertyVisitor{
  1082  		{
  1083  			Name:         "temperature",
  1084  			PropertyName: "temperature",
  1085  			ModelName:    "cc2650-sensortag",
  1086  			Protocol:     "bluetooth",
  1087  			VisitorConfig: v1alpha1.VisitorConfigBluetooth{
  1088  				CharacteristicUUID: "f000aa0104514000b000000000000000",
  1089  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
  1090  					OrderOfOperations: []v1alpha1.BluetoothOperations{
  1091  						{
  1092  							BluetoothOperationType:  "Multiply",
  1093  							BluetoothOperationValue: 0.03125,
  1094  						},
  1095  					},
  1096  					ShiftRight: 2,
  1097  					StartIndex: 2,
  1098  					EndIndex:   1,
  1099  				},
  1100  			},
  1101  		},
  1102  		{
  1103  			Name:         "temperature-enable",
  1104  			PropertyName: "temperature-enable",
  1105  			ModelName:    "cc2650-sensortag",
  1106  			Protocol:     "bluetooth",
  1107  			VisitorConfig: v1alpha1.VisitorConfigBluetooth{
  1108  				CharacteristicUUID: "f000aa0204514000b000000000000000",
  1109  				DataWriteToBluetooth: map[string][]byte{
  1110  					"ON":  {1},
  1111  					"OFF": {0},
  1112  				},
  1113  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
  1114  					StartIndex: 1,
  1115  					EndIndex:   1,
  1116  				},
  1117  			},
  1118  		},
  1119  		{
  1120  			Name:         "io-config-initialize",
  1121  			PropertyName: "io-config-initialize",
  1122  			ModelName:    "cc2650-sensortag",
  1123  			Protocol:     "bluetooth",
  1124  			VisitorConfig: v1alpha1.VisitorConfigBluetooth{
  1125  				CharacteristicUUID: "f000aa6604514000b000000000000000",
  1126  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
  1127  					StartIndex: 1,
  1128  					EndIndex:   1,
  1129  				},
  1130  			},
  1131  		},
  1132  		{
  1133  			Name:         "io-data-initialize",
  1134  			PropertyName: "io-data-initialize",
  1135  			ModelName:    "cc2650-sensortag",
  1136  			Protocol:     "bluetooth",
  1137  			VisitorConfig: v1alpha1.VisitorConfigBluetooth{
  1138  				CharacteristicUUID: "f000aa6504514000b000000000000000",
  1139  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
  1140  					StartIndex: 1,
  1141  					EndIndex:   1,
  1142  				},
  1143  			},
  1144  		},
  1145  		{
  1146  			Name:         "io-config",
  1147  			PropertyName: "io-config",
  1148  			ModelName:    "cc2650-sensortag",
  1149  			Protocol:     "bluetooth",
  1150  			VisitorConfig: v1alpha1.VisitorConfigBluetooth{
  1151  				CharacteristicUUID: "f000aa6604514000b000000000000000",
  1152  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
  1153  					StartIndex: 1,
  1154  					EndIndex:   1,
  1155  				},
  1156  			},
  1157  		},
  1158  		{
  1159  			Name:         "io-data",
  1160  			PropertyName: "io-data",
  1161  			ModelName:    "cc2650-sensortag",
  1162  			Protocol:     "bluetooth",
  1163  			VisitorConfig: v1alpha1.VisitorConfigBluetooth{
  1164  				CharacteristicUUID: "f000aa6504514000b000000000000000",
  1165  				DataWriteToBluetooth: map[string][]byte{
  1166  					"Red":            {1},
  1167  					"Green":          {2},
  1168  					"RedGreen":       {3},
  1169  					"Buzzer":         {4},
  1170  					"BuzzerRed":      {5},
  1171  					"BuzzerGreen":    {6},
  1172  					"BuzzerRedGreen": {7},
  1173  				},
  1174  				BluetoothDataConverter: v1alpha1.BluetoothReadConverter{
  1175  					StartIndex: 1,
  1176  					EndIndex:   1,
  1177  				},
  1178  			},
  1179  		},
  1180  	}
  1181  
  1182  	bytes, err := json.Marshal(deviceProfile)
  1183  	if err != nil {
  1184  		Errorf("Failed to marshal deviceprofile: %v", deviceProfile)
  1185  	}
  1186  	configMap.Data["deviceProfile.json"] = string(bytes)
  1187  
  1188  	return configMap
  1189  }
  1190  
  1191  func NewConfigMapModbus(nodeSelector string) v12.ConfigMap {
  1192  	configMap := v12.ConfigMap{
  1193  		TypeMeta: v1.TypeMeta{
  1194  			Kind:       "ConfigMap",
  1195  			APIVersion: "v1",
  1196  		},
  1197  		ObjectMeta: v1.ObjectMeta{
  1198  			Name:      "device-profile-config-" + nodeSelector,
  1199  			Namespace: Namespace,
  1200  		},
  1201  	}
  1202  	configMap.Data = make(map[string]string)
  1203  
  1204  	deviceProfile := &types.DeviceProfile{}
  1205  	deviceProfile.DeviceInstances = []*types.DeviceInstance{
  1206  		{
  1207  			Name:  "sensor-tag-instance-02",
  1208  			ID:    "sensor-tag-instance-02",
  1209  			Model: "sensor-tag-model",
  1210  		},
  1211  	}
  1212  	deviceProfile.DeviceModels = []*types.DeviceModel{
  1213  		{
  1214  			Name: "sensor-tag-model",
  1215  			Properties: []*types.Property{
  1216  
  1217  				{
  1218  					Name:         "temperature",
  1219  					DataType:     "int",
  1220  					Description:  "temperature in degree celsius",
  1221  					AccessMode:   "ReadWrite",
  1222  					DefaultValue: 0,
  1223  					Maximum:      100,
  1224  					Unit:         "degree celsius",
  1225  				},
  1226  				{
  1227  					Name:         "temperature-enable",
  1228  					DataType:     "string",
  1229  					Description:  "enable data collection of temperature sensor",
  1230  					AccessMode:   "ReadWrite",
  1231  					DefaultValue: "OFF",
  1232  				},
  1233  			},
  1234  		},
  1235  	}
  1236  	deviceProfile.Protocols = []*types.Protocol{
  1237  		{
  1238  			ProtocolConfig: nil,
  1239  		},
  1240  	}
  1241  	deviceProfile.PropertyVisitors = []*types.PropertyVisitor{
  1242  		{
  1243  			Name:         "temperature",
  1244  			PropertyName: "temperature",
  1245  			ModelName:    "sensor-tag-model",
  1246  			Protocol:     "modbus",
  1247  			VisitorConfig: v1alpha1.VisitorConfigModbus{
  1248  				Register:       "CoilRegister",
  1249  				Offset:         2,
  1250  				Limit:          1,
  1251  				Scale:          1,
  1252  				IsSwap:         true,
  1253  				IsRegisterSwap: true,
  1254  			},
  1255  		},
  1256  		{
  1257  			Name:         "temperature-enable",
  1258  			PropertyName: "temperature-enable",
  1259  			ModelName:    "sensor-tag-model",
  1260  			Protocol:     "modbus",
  1261  			VisitorConfig: v1alpha1.VisitorConfigModbus{
  1262  				Register:       "DiscreteInputRegister",
  1263  				Offset:         3,
  1264  				Limit:          1,
  1265  				Scale:          1,
  1266  				IsSwap:         true,
  1267  				IsRegisterSwap: true,
  1268  			},
  1269  		},
  1270  	}
  1271  
  1272  	bytes, err := json.Marshal(deviceProfile)
  1273  	if err != nil {
  1274  		Errorf("Failed to marshal deviceprofile: %v", deviceProfile)
  1275  	}
  1276  	configMap.Data["deviceProfile.json"] = string(bytes)
  1277  
  1278  	return configMap
  1279  }