diff options
| author | fisherxu <xufei40@huawei.com> | 2021-04-14 12:06:56 +0800 |
|---|---|---|
| committer | fisherxu <xufei40@huawei.com> | 2021-04-14 12:12:35 +0800 |
| commit | 29490d5a37b3053722c57a37c9cfa0b97c99cc2c (patch) | |
| tree | 7fe8cdf88d0f6b20cfae5a1304a20eb4f8438d79 /mappers | |
| parent | Merge pull request #2758 from majoyz/imagegc_disable (diff) | |
| download | kubeedge-29490d5a37b3053722c57a37c9cfa0b97c99cc2c.tar.gz | |
remove mappers from kubeedge/kubeedge repo
Signed-off-by: fisherxu <xufei40@huawei.com>
Diffstat (limited to 'mappers')
55 files changed, 1 insertions, 5672 deletions
diff --git a/mappers/README.md b/mappers/README.md index 13d95bb9e..6c2e0ecdf 100644 --- a/mappers/README.md +++ b/mappers/README.md @@ -1,4 +1,3 @@ # Mappers -There're two folders for modbus mapper. "modbus-go" is written by go language, "modbus_mapper" is by JavaScript. -Note, the modbus-go could work for KubeEdge 1.4 version and later. modbus_mapper is only for KubeEdge 1.3 and before. +All mappers have been moved to [mappers-go](https://github.com/kubeedge/mappers-go). diff --git a/mappers/bluetooth_mapper/Dockerfile b/mappers/bluetooth_mapper/Dockerfile deleted file mode 100644 index 0b1a79663..000000000 --- a/mappers/bluetooth_mapper/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM ubuntu:16.04 - -RUN mkdir -p kubeedge - -COPY . kubeedge/ - -WORKDIR kubeedge - -ENTRYPOINT ["/kubeedge/main","--logtostderr=true"] diff --git a/mappers/bluetooth_mapper/OWNERS b/mappers/bluetooth_mapper/OWNERS deleted file mode 100644 index c12e59ce4..000000000 --- a/mappers/bluetooth_mapper/OWNERS +++ /dev/null @@ -1,10 +0,0 @@ -approvers: - - edisonxiang - - sids-b - - sujithsimon22 -reviewers: - - chendave - - edisonxiang - - rohitsardesai83 - - sids-b - - sujithsimon22 diff --git a/mappers/bluetooth_mapper/README.md b/mappers/bluetooth_mapper/README.md deleted file mode 100644 index c473f0740..000000000 --- a/mappers/bluetooth_mapper/README.md +++ /dev/null @@ -1,4 +0,0 @@ - -# Bluetooth Mapper - -- Click [here](../../docs/components/mappers/bluetooth_mapper.md#bluetooth-mapper) for detailed documentation of the bluetooth mapper. diff --git a/mappers/bluetooth_mapper/action_manager/action_manager.go b/mappers/bluetooth_mapper/action_manager/action_manager.go deleted file mode 100644 index ea739bc9d..000000000 --- a/mappers/bluetooth_mapper/action_manager/action_manager.go +++ /dev/null @@ -1,133 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package actionmanager - -import ( - "errors" - "fmt" - "strings" - - "github.com/paypal/gatt" - "k8s.io/klog/v2" - - dataconverter "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/data_converter" -) - -const ( - ActionWrite = "WRITE" - ActionRead = "READ" -) - -// GattPeripheral represents the remote gatt peripheral device -var GattPeripheral gatt.Peripheral - -// CharacteristicsList contains the set of characteristics exposed by the device -var CharacteristicsList = make([]*gatt.Characteristic, 0) - -// Operation is structure to define device operation -type Operation struct { - // Action can be one of read/write corresponding to get/set respectively - Action string `yaml:"action" json:"action"` - // Characteristic refers to the characteristic on which the operation needs to be performed - CharacteristicUUID string `yaml:"characteristic-uuid" json:"characteristic-uuid"` - // Value is the value to be written in case of write action and value read from the device in case of read action - Value []byte `yaml:"value" json:"value"` -} - -// Action is structure to define a device action -type Action struct { - // PerformImmediately indicates whether the action is to be performed immediately or not - PerformImmediately bool `yaml:"perform-immediately" json:"perform-immediately"` - // Name is the name of the Action - Name string `yaml:"name" json:"name"` - // Operation specifies the operation to be performed for this action - Operation Operation `yaml:"operation" json:"operation"` -} - -//ActionManager is a structure that contains a list of actions -type ActionManager struct { - Actions []Action `yaml:"actions"` -} - -//PerformOperation executes the operation -func (action *Action) PerformOperation(readConverter ...dataconverter.DataRead) { - klog.Infof("Performing operations associated with action: %s", action.Name) - characteristic, err := FindCharacteristic(action.Operation.CharacteristicUUID) - if err != nil { - klog.Errorf("Error in finding characteristics: %s", err) - } - if strings.ToUpper(action.Operation.Action) == ActionRead { - readValue, err := ReadCharacteristic(GattPeripheral, characteristic) - if err != nil { - klog.Errorf("Error in reading characteristic: %s", err) - return - } - converted := false - for _, conversionAction := range readConverter[0].Actions { - if strings.EqualFold(conversionAction.ActionName, action.Name) { - convertedValue := fmt.Sprintf("%f", conversionAction.ConversionOperation.ConvertReadData(readValue)) - action.Operation.Value = []byte(convertedValue) - converted = true - } - } - if !converted { - action.Operation.Value = readValue - } - klog.Info("Read Successful") - } else if strings.ToUpper(action.Operation.Action) == ActionWrite { - if action.Operation.Value == nil { - klog.Errorf("Please provide a value to be written") - return - } - err := WriteCharacteristic(GattPeripheral, characteristic, action.Operation.Value) - if err != nil { - klog.Errorf("Error in writing characteristic: %s", err) - return - } - klog.Info("Write Successful") - } -} - -//FindCharacteristic is used to find the bluetooth characteristic -func FindCharacteristic(characteristicUUID string) (*gatt.Characteristic, error) { - for _, c := range CharacteristicsList { - if c.UUID().String() == characteristicUUID { - return c, nil - } - } - return nil, errors.New("unable to find the specified characteristic: " + characteristicUUID) -} - -//ReadCharacteristic is used to read the value of the characteristic -func ReadCharacteristic(p gatt.Peripheral, c *gatt.Characteristic) ([]byte, error) { - value, err := p.ReadCharacteristic(c) - if err != nil { - klog.Errorf("Error in reading characteristic, err: %s\n", err) - return nil, err - } - return value, nil -} - -//WriteCharacteristic is used to write some value into the characteristic -func WriteCharacteristic(p gatt.Peripheral, c *gatt.Characteristic, b []byte) error { - err := p.WriteCharacteristic(c, b, false) - if err != nil { - klog.Errorf("Error in writing characteristic, err: %s\n", err) - return err - } - return nil -} diff --git a/mappers/bluetooth_mapper/configuration/config.go b/mappers/bluetooth_mapper/configuration/config.go deleted file mode 100644 index 7e281aa7f..000000000 --- a/mappers/bluetooth_mapper/configuration/config.go +++ /dev/null @@ -1,221 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package configuration - -import ( - "encoding/json" - "errors" - "io/ioutil" - "reflect" - "strings" - - "gopkg.in/yaml.v2" - - "github.com/kubeedge/kubeedge/cloud/pkg/apis/devices/v1alpha2" - "github.com/kubeedge/kubeedge/cloud/pkg/devicecontroller/types" - actionmanager "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/action_manager" - dataconverter "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/data_converter" - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/scheduler" - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/watcher" -) - -//ConfigFilePath contains the location of the configuration file -var ConfigFilePath = "configuration/config.yaml" - -//ConfigMapPath contains the location of the configuration file -var ConfigMapPath = "/opt/kubeedge/deviceProfile.json" - -//Config is the global configuration used by all the modules of the mapper -var Config *BLEConfig - -//Blutooth protocol name -const ( - ProtocolName string = "BLUETOOTH" - READWRITE string = "ReadWrite" - READ string = "ReadOnly" -) - -//BLEConfig is the main structure that stores the configuration information read from both the config file as well as the config map -type BLEConfig struct { - Mqtt Mqtt `yaml:"mqtt"` - Device Device `yaml:"device"` - Watcher watcher.Watcher `yaml:"watcher"` - Scheduler scheduler.Scheduler `yaml:"scheduler"` - ActionManager actionmanager.ActionManager `yaml:"action-manager"` - Converter dataconverter.Converter `yaml:"data-converter"` -} - -//ReadConfigFile is the structure that is used to read the config file to get configuration information from the user -type ReadConfigFile struct { - Mqtt Mqtt `yaml:"mqtt"` - DeviceModelName string `yaml:"device-model-name"` - ActionManager ActionManagerConfig `yaml:"action-manager"` - Watcher watcher.Watcher `yaml:"watcher"` - Scheduler scheduler.Scheduler `yaml:"scheduler"` -} - -//ActionManagerConfig is a structure that contains a list of actions -type ActionManagerConfig struct { - Actions []Action `yaml:"actions"` -} - -//Action is structure to define a device action -type Action struct { - //PerformImmediately signifies whether the action is to be performed by the action-manager immediately or not - PerformImmediately bool `yaml:"perform-immediately" json:"perform-immediately"` - //Name is the name of the Action - Name string `yaml:"name" json:"name"` - //PropertyName is the name of the property defined in the device CRD - PropertyName string `yaml:"device-property-name" json:"device-property-name"` -} - -//Mqtt structure contains the MQTT specific configurations -type Mqtt struct { - Mode int `yaml:"mode"` - InternalServer string `yaml:"internal-server"` - Server string `yaml:"server"` -} - -//Device structure contains the device specific configurations -type Device struct { - ID string `yaml:"id"` - Name string `yaml:"name"` -} - -//ReadFromConfigFile is used to load the information from the configuration file -func (readConfigFile *ReadConfigFile) ReadFromConfigFile() error { - yamlFile, err := ioutil.ReadFile(ConfigFilePath) - if err != nil { - return err - } - err = yaml.Unmarshal(yamlFile, readConfigFile) - if err != nil { - return err - } - return nil -} - -//Load is used to consolidate the information loaded from the configuration file and the configmaps -func (b *BLEConfig) Load() error { - readConfigFile := ReadConfigFile{} - readConfigMap := &types.DeviceProfile{} - err := readConfigFile.ReadFromConfigFile() - if err != nil { - return errors.New("Error while reading from configuration file " + err.Error()) - } - err = ReadFromConfigMap(readConfigMap) - if err != nil { - return errors.New("Error while reading from config map " + err.Error()) - } - b.Mqtt = readConfigFile.Mqtt - b.Scheduler = readConfigFile.Scheduler - b.Watcher = readConfigFile.Watcher - propertyVisitors := make([]*types.PropertyVisitor, 0) - // Assign device information obtained from config file - for _, device := range readConfigMap.DeviceInstances { - if strings.EqualFold(device.Model, readConfigFile.DeviceModelName) { - b.Device.ID = device.ID - b.Device.Name = device.Model - propertyVisitors = device.PropertyVisitors - } - } - // Assign information required by action manager - for _, actionConfig := range readConfigFile.ActionManager.Actions { - action := actionmanager.Action{} - action.Name = actionConfig.Name - action.PerformImmediately = actionConfig.PerformImmediately - - for _, propertyVisitor := range propertyVisitors { - if strings.EqualFold(propertyVisitor.ModelName, b.Device.Name) && strings.EqualFold(propertyVisitor.PropertyName, actionConfig.PropertyName) && strings.ToUpper(propertyVisitor.Protocol) == ProtocolName { - propertyVisitorBytes, err := json.Marshal(propertyVisitor.VisitorConfig) - if err != nil { - return errors.New("Error in marshalling data property visitor configuration: " + err.Error()) - } - bluetoothPropertyVisitor := v1alpha2.VisitorConfigBluetooth{} - err = json.Unmarshal(propertyVisitorBytes, &bluetoothPropertyVisitor) - if err != nil { - return errors.New("Error in unmarshalling data property visitor configuration: " + err.Error()) - } - action.Operation.CharacteristicUUID = bluetoothPropertyVisitor.CharacteristicUUID - newBluetoothVisitorConfig := v1alpha2.VisitorConfigBluetooth{} - if !reflect.DeepEqual(bluetoothPropertyVisitor.BluetoothDataConverter, newBluetoothVisitorConfig.BluetoothDataConverter) { - readAction := dataconverter.ReadAction{} - readAction.ActionName = actionConfig.Name - readAction.ConversionOperation.StartIndex = bluetoothPropertyVisitor.BluetoothDataConverter.StartIndex - readAction.ConversionOperation.EndIndex = bluetoothPropertyVisitor.BluetoothDataConverter.EndIndex - readAction.ConversionOperation.ShiftRight = bluetoothPropertyVisitor.BluetoothDataConverter.ShiftRight - readAction.ConversionOperation.ShiftLeft = bluetoothPropertyVisitor.BluetoothDataConverter.ShiftLeft - for _, readOperations := range bluetoothPropertyVisitor.BluetoothDataConverter.OrderOfOperations { - readAction.ConversionOperation.OrderOfExecution = append(readAction.ConversionOperation.OrderOfExecution, string(readOperations.BluetoothOperationType)) - switch strings.ToUpper(string(readOperations.BluetoothOperationType)) { - case strings.ToUpper(string(v1alpha2.BluetoothAdd)): - readAction.ConversionOperation.Add = readOperations.BluetoothOperationValue - case strings.ToUpper(string(v1alpha2.BluetoothSubtract)): - readAction.ConversionOperation.Subtract = readOperations.BluetoothOperationValue - case strings.ToUpper(string(v1alpha2.BluetoothMultiply)): - readAction.ConversionOperation.Multiply = readOperations.BluetoothOperationValue - case strings.ToUpper(string(v1alpha2.BluetoothDivide)): - readAction.ConversionOperation.Divide = readOperations.BluetoothOperationValue - } - } - b.Converter.DataRead.Actions = append(b.Converter.DataRead.Actions, readAction) - } - if bluetoothPropertyVisitor.DataWriteToBluetooth != nil { - writeAttribute := dataconverter.WriteAttribute{} - writeAttribute.Operations = make(map[string]dataconverter.DataMap, 1) - dataMap := dataconverter.DataMap{} - dataMap.DataMapping = bluetoothPropertyVisitor.DataWriteToBluetooth - writeAttribute.Operations[actionConfig.Name] = dataMap - writeAttribute.Name = propertyVisitor.PropertyName - b.Converter.DataWrite.Attributes = append(b.Converter.DataWrite.Attributes, writeAttribute) - } - } - } - for _, deviceModel := range readConfigMap.DeviceModels { - if strings.EqualFold(deviceModel.Name, b.Device.Name) { - for _, property := range deviceModel.Properties { - if strings.EqualFold(property.Name, actionConfig.PropertyName) { - if property.AccessMode == READWRITE { - action.Operation.Action = "Write" - if strings.ToUpper(property.DataType) == "INT" { - value := string(int(property.DefaultValue.(float64))) - action.Operation.Value = []byte(value) - } else if strings.ToUpper(property.DataType) == "STRING" { - for _, converterAttribute := range b.Converter.DataWrite.Attributes { - if strings.EqualFold(converterAttribute.Name, actionConfig.PropertyName) { - for operationName, dataMap := range converterAttribute.Operations { - if action.Name == operationName { - if _, ok := dataMap.DataMapping[property.DefaultValue.(string)]; ok { - action.Operation.Value = dataMap.DataMapping[property.DefaultValue.(string)] - } - } - } - } - } - } - } else if property.AccessMode == READ { - action.Operation.Action = "Read" - } - } - } - } - } - b.ActionManager.Actions = append(b.ActionManager.Actions, action) - } - Config = b - return nil -} diff --git a/mappers/bluetooth_mapper/configuration/config.yaml b/mappers/bluetooth_mapper/configuration/config.yaml deleted file mode 100644 index b536bcf44..000000000 --- a/mappers/bluetooth_mapper/configuration/config.yaml +++ /dev/null @@ -1,40 +0,0 @@ -mqtt: - mode: 0 # 0 -internal mqtt broker 1 - external mqtt broker - server: tcp://127.0.0.1:1883 # external mqtt broker url. - internal-server: tcp://127.0.0.1:1884 # internal mqtt broker url. -device-model-name: cc2650-sensortag -action-manager: - actions: - - name: IRTemperatureConfiguration - perform-immediately: true - device-property-name: temperature-enable #property-name defined in the device model - - name: IRTemperatureData - perform-immediately: false - device-property-name: temperature #property-name defined in the device model - - name: IOConfigurationInitialize - perform-immediately: true - device-property-name: io-config-initialize #property-name defined in the device model - - name: IODataInitialize - perform-immediately: true - device-property-name: io-data-initialize #property-name defined in the device model - - name: IOConfiguration - perform-immediately: true - device-property-name: io-config #property-name defined in the device model - - name: IOData - perform-immediately: false - device-property-name: io-data #property-name defined in the device model -scheduler: - schedules: - - name: temperature - interval: 3000 - occurrence-limit: 10 # if it is 0, then the event will execute infinitely - actions: - - IRTemperatureData # Action name defined in the action-manager section -watcher: - device-twin-attributes : - - device-property-name: io-data # the twin attribute name defined while creating device - actions: # list of action names, defined in the action-manager section, to be executed on the device - - IOConfigurationInitialize - - IODataInitialize - - IOConfiguration - - IOData diff --git a/mappers/bluetooth_mapper/configuration/config_map_types.go b/mappers/bluetooth_mapper/configuration/config_map_types.go deleted file mode 100644 index 0f0499a15..000000000 --- a/mappers/bluetooth_mapper/configuration/config_map_types.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package configuration - -import ( - "encoding/json" - "io/ioutil" - - "github.com/kubeedge/kubeedge/cloud/pkg/devicecontroller/types" -) - -//ReadFromConfigMap is used to load the information from the configmaps that are provided from the cloud -func ReadFromConfigMap(deviceProfile *types.DeviceProfile) error { - jsonFile, err := ioutil.ReadFile(ConfigMapPath) - if err != nil { - return err - } - err = json.Unmarshal(jsonFile, deviceProfile) - if err != nil { - return err - } - return nil -} diff --git a/mappers/bluetooth_mapper/controller/controller.go b/mappers/bluetooth_mapper/controller/controller.go deleted file mode 100644 index 56504ca88..000000000 --- a/mappers/bluetooth_mapper/controller/controller.go +++ /dev/null @@ -1,228 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controller - -import ( - "encoding/json" - "strings" - - MQTT "github.com/eclipse/paho.mqtt.golang" - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/option" - "k8s.io/klog/v2" - - actionmanager "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/action_manager" - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/configuration" - dataconverter "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/data_converter" - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/helper" - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/scheduler" - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/watcher" -) - -// constants which can be used to convey topic information -const ( - MapperTopicPrefix = "$ke/device/bluetooth-mapper/" - WatcherTopicSuffix = "/watcher/create" - SchedulerCreateTopicSuffix = "/scheduler/create" - SchedulerDeleteTopicSuffix = "/scheduler/delete" - ActionManagerCreateTopicSuffix = "/action-manager/create" - ActionManagerDeleteTopicSuffix = "/action-manager/delete" -) - -var topicMap = make(map[string]MQTT.MessageHandler) - -//Config contains the configuration used by the controller -type Config struct { - Mqtt configuration.Mqtt `yaml:"mqtt"` - Device configuration.Device `yaml:"device"` - Watcher watcher.Watcher `yaml:"watcher"` - Scheduler scheduler.Scheduler `yaml:"scheduler"` - ActionManager actionmanager.ActionManager `yaml:"action-manager"` - Converter dataconverter.Converter `yaml:"data-converter"` -} - -// initTopicMap initializes topics to their respective handler functions -func (c *Config) initTopicMap() { - topicMap[MapperTopicPrefix+c.Device.ID+WatcherTopicSuffix] = c.handleWatchMessage - topicMap[MapperTopicPrefix+c.Device.ID+SchedulerCreateTopicSuffix] = c.handleScheduleCreateMessage - topicMap[MapperTopicPrefix+c.Device.ID+SchedulerDeleteTopicSuffix] = c.handleScheduleDeleteMessage - topicMap[MapperTopicPrefix+c.Device.ID+ActionManagerCreateTopicSuffix] = c.handleActionCreateMessage - topicMap[MapperTopicPrefix+c.Device.ID+ActionManagerDeleteTopicSuffix] = c.handleActionDeleteMessage -} - -//Start starts the controller of the mapper -func (c *Config) Start() { - c.initTopicMap() - helper.MqttConnect(c.Mqtt.Mode, c.Mqtt.InternalServer, c.Mqtt.Server) - subscribeAllTopics() - helper.ControllerWg.Add(1) - device, err := gatt.NewDevice(option.DefaultClientOptions...) - if err != nil { - klog.Fatalf("Failed to open device, err: %s\n", err) - return - } - go c.Watcher.Initiate(device, c.Device.Name, c.Device.ID, c.ActionManager.Actions, c.Converter) - - <-watcher.DeviceConnected - for _, action := range c.ActionManager.Actions { - if action.PerformImmediately { - action.PerformOperation(c.Converter.DataRead) - } - } - - for _, schedule := range c.Scheduler.Schedules { - helper.ControllerWg.Add(1) - go schedule.ExecuteSchedule(c.ActionManager.Actions, c.Converter.DataRead, c.Device.ID) - } - helper.ControllerWg.Wait() -} - -//subscribeAllTopics subscribes to mqtt topics associated with mapper -func subscribeAllTopics() { - for key, value := range topicMap { - helper.TokenClient = helper.Client.Subscribe(key, 0, value) - if helper.TokenClient.Wait() && helper.TokenClient.Error() != nil { - klog.Errorf("subscribe() Error in topic: %s is: %s", key, helper.TokenClient.Error()) - } - } -} - -//handleWatchMessage is the MQTT handler function for changing watcher configuration at runtime -func (c *Config) handleWatchMessage(client MQTT.Client, message MQTT.Message) { - newWatch := watcher.Watcher{} - err := json.Unmarshal(message.Payload(), &newWatch) - if err != nil { - klog.Errorf("Error in unmarshalling: %s", err) - } - c.Watcher = newWatch - configuration.Config.Watcher = c.Watcher - klog.Infof("New watcher has been started") - klog.Infof("New Watcher: %v", c.Watcher) -} - -//handleScheduleCreateMessage is the MQTT handler function for adding schedules at runtime -func (c *Config) handleScheduleCreateMessage(client MQTT.Client, message MQTT.Message) { - newSchedules := []scheduler.Schedule{} - err := json.Unmarshal(message.Payload(), &newSchedules) - if err != nil { - klog.Errorf("Error in unmarshalling: %s", err) - } - for _, newSchedule := range newSchedules { - scheduleExists := false - for scheduleIndex, schedule := range c.Scheduler.Schedules { - if schedule.Name == newSchedule.Name { - c.Scheduler.Schedules[scheduleIndex] = newSchedule - scheduleExists = true - break - } - } - if scheduleExists { - klog.Infof("Schedule: %s has been updated", newSchedule.Name) - klog.Infof("Updated Schedule: %v", newSchedule) - } else { - c.Scheduler.Schedules = append(c.Scheduler.Schedules, newSchedule) - klog.Infof("Schedule: %s has been added", newSchedule.Name) - klog.Infof("New Schedule: %v", newSchedule) - } - configuration.Config.Scheduler = c.Scheduler - helper.ControllerWg.Add(1) - newSchedule.ExecuteSchedule(c.ActionManager.Actions, c.Converter.DataRead, c.Device.ID) - } -} - -//handleScheduleDeleteMessage is the MQTT handler function for deleting schedules at runtime -func (c *Config) handleScheduleDeleteMessage(client MQTT.Client, message MQTT.Message) { - schedulesToBeDeleted := []scheduler.Schedule{} - err := json.Unmarshal(message.Payload(), &schedulesToBeDeleted) - if err != nil { - klog.Errorf("Error in unmarshalling: %s", err) - } - for _, scheduleToBeDeleted := range schedulesToBeDeleted { - scheduleExists := false - for index, schedule := range c.Scheduler.Schedules { - if strings.EqualFold(schedule.Name, scheduleToBeDeleted.Name) { - scheduleExists = true - copy(c.Scheduler.Schedules[index:], c.Scheduler.Schedules[index+1:]) - c.Scheduler.Schedules = c.Scheduler.Schedules[:len(c.Scheduler.Schedules)-1] - break - } - } - configuration.Config.Scheduler = c.Scheduler - if !scheduleExists { - klog.Errorf("Schedule: %s does not exist", scheduleToBeDeleted.Name) - } else { - klog.Infof("Schedule: %s has been deleted ", scheduleToBeDeleted.Name) - } - } -} - -//handleActionCreateMessage MQTT handler function for adding actions at runtime -func (c *Config) handleActionCreateMessage(client MQTT.Client, message MQTT.Message) { - newActions := []actionmanager.Action{} - err := json.Unmarshal(message.Payload(), &newActions) - if err != nil { - klog.Errorf("Error in unmarshalling: %s", err) - } - for _, newAction := range newActions { - actionExists := false - for actionIndex, action := range c.ActionManager.Actions { - if action.Name == newAction.Name { - c.ActionManager.Actions[actionIndex] = newAction - actionExists = true - break - } - } - if actionExists { - klog.Infof("Action: %s has been updated", newAction.Name) - klog.Infof("Updated Action: %v", newAction) - } else { - c.ActionManager.Actions = append(c.ActionManager.Actions, newAction) - klog.Infof("Action: %s has been added ", newAction.Name) - klog.Infof("New Action: %v", newAction) - } - configuration.Config.ActionManager = c.ActionManager - if newAction.PerformImmediately { - newAction.PerformOperation(c.Converter.DataRead) - } - } -} - -//handleActionDeleteMessage MQTT handler function for deleting actions at runtime -func (c *Config) handleActionDeleteMessage(client MQTT.Client, message MQTT.Message) { - actionsToBeDeleted := []actionmanager.Action{} - err := json.Unmarshal(message.Payload(), &actionsToBeDeleted) - if err != nil { - klog.Errorf("Error in unmarshalling: %s", err) - } - for _, actionToBeDeleted := range actionsToBeDeleted { - actionExists := false - for index, action := range c.ActionManager.Actions { - if strings.EqualFold(action.Name, actionToBeDeleted.Name) { - actionExists = true - copy(c.ActionManager.Actions[index:], c.ActionManager.Actions[index+1:]) - c.ActionManager.Actions = c.ActionManager.Actions[:len(c.ActionManager.Actions)-1] - break - } - } - configuration.Config.ActionManager = c.ActionManager - if !actionExists { - klog.Errorf("Action: %s did not exist", actionToBeDeleted.Name) - } else { - klog.Infof("Action: %s has been deleted ", actionToBeDeleted.Name) - } - } -} diff --git a/mappers/bluetooth_mapper/data_converter/data_converter.go b/mappers/bluetooth_mapper/data_converter/data_converter.go deleted file mode 100644 index 6fe01a16e..000000000 --- a/mappers/bluetooth_mapper/data_converter/data_converter.go +++ /dev/null @@ -1,111 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package dataconverter - -import ( - "strconv" - "strings" - - "github.com/kubeedge/kubeedge/cloud/pkg/apis/devices/v1alpha2" -) - -//Converter is the structure that contains data conversion specific configuration -type Converter struct { - DataWrite DataWrite `yaml:"write"` - DataRead DataRead `yaml:"read"` -} - -//dataWrite structure contains configuration information specific to data-writes -type DataWrite struct { - Attributes []WriteAttribute `yaml:"attributes"` -} - -//WriteAttribute structure contains the name of the attribute as well as a data-map of values to be written -type WriteAttribute struct { - Name string `yaml:"name"` - Operations map[string]DataMap `yaml:"operations"` -} - -//DataMap structure contains a mapping between the value that arrives from the platform (expected value) and -// the byte value to be written into the device -type DataMap struct { - DataMapping map[string][]byte `yaml:"data-map"` -} - -//dataRead structure contains configuration information specific to data-read -type DataRead struct { - Actions []ReadAction `yaml:"actions"` -} - -//ReadAction specifies the name of the action along with the conversion operations to be performed in case of data-read -type ReadAction struct { - ActionName string `yaml:"action-name"` - ConversionOperation ReadOperation `yaml:"conversion-operation"` -} - -//ReadOperation specifies how to convert the data received from the device into meaningful data -type ReadOperation struct { - StartIndex int `yaml:"start-index"` - EndIndex int `yaml:"end-index"` - ShiftLeft uint `yaml:"shift-left"` - ShiftRight uint `yaml:"shift-right"` - Multiply float64 `yaml:"multiply"` - Divide float64 `yaml:"divide"` - Add float64 `yaml:"add"` - Subtract float64 `yaml:"subtract"` - OrderOfExecution []string `yaml:"order-of-execution"` -} - -//ConvertReadData is the function responsible to convert the data read from the device into meaningful data -func (operation *ReadOperation) ConvertReadData(data []byte) float64 { - var intermediateResult uint64 - var initialValue []byte - var initialStringValue = "" - if operation.StartIndex <= operation.EndIndex { - for index := operation.StartIndex; index <= operation.EndIndex; index++ { - initialValue = append(initialValue, data[index]) - } - } else { - for index := operation.StartIndex; index >= operation.EndIndex; index-- { - initialValue = append(initialValue, data[index]) - } - } - for _, value := range initialValue { - initialStringValue = initialStringValue + strconv.Itoa(int(value)) - } - initialByteValue, _ := strconv.ParseUint(initialStringValue, 16, 16) - - if operation.ShiftLeft != 0 { - intermediateResult = initialByteValue << operation.ShiftLeft - } else if operation.ShiftRight != 0 { - intermediateResult = initialByteValue >> operation.ShiftRight - } - finalResult := float64(intermediateResult) - for _, executeOperation := range operation.OrderOfExecution { - switch strings.ToUpper(executeOperation) { - case strings.ToUpper(string(v1alpha2.BluetoothAdd)): - finalResult = finalResult + operation.Add - case strings.ToUpper(string(v1alpha2.BluetoothSubtract)): - finalResult = finalResult - operation.Subtract - case strings.ToUpper(string(v1alpha2.BluetoothMultiply)): - finalResult = finalResult * operation.Multiply - case strings.ToUpper(string(v1alpha2.BluetoothDivide)): - finalResult = finalResult / operation.Divide - } - } - return finalResult -} diff --git a/mappers/bluetooth_mapper/deployment.yaml b/mappers/bluetooth_mapper/deployment.yaml deleted file mode 100644 index 883b78dbe..000000000 --- a/mappers/bluetooth_mapper/deployment.yaml +++ /dev/null @@ -1,31 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: bluetooth-device-mapper-deployment -spec: - replicas: 1 - selector: - matchLabels: - app: bluetooth-mapper - template: - metadata: - labels: - app: bluetooth-mapper - spec: - hostNetwork: true - containers: - - name: bluetooth-mapper-container - image: <your_dockerhub_username>/bluetooth_mapper:v1.0 - imagePullPolicy: Always - securityContext: - privileged: true - volumeMounts: - - name: config-volume - mountPath: /opt/kubeedge/ - nodeSelector: - bluetooth: "true" - volumes: - - name: config-volume - configMap: - name: device-profile-config-<edge_node_name> - restartPolicy: Always diff --git a/mappers/bluetooth_mapper/helper/helper.go b/mappers/bluetooth_mapper/helper/helper.go deleted file mode 100644 index 8ce782778..000000000 --- a/mappers/bluetooth_mapper/helper/helper.go +++ /dev/null @@ -1,215 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package helper - -import ( - "crypto/tls" - "encoding/json" - "sync" - "time" - - MQTT "github.com/eclipse/paho.mqtt.golang" - "k8s.io/klog/v2" -) - -var ( - DeviceETPrefix = "$hw/events/device/" - DeviceETStateUpdateSuffix = "/state/update" - TwinETUpdateSuffix = "/twin/update" - TwinETCloudSyncSuffix = "/twin/cloud_updated" - TwinETGetSuffix = "/twin/get" - TwinETGetResultSuffix = "/twin/get/result" -) - -var TwinResult DeviceTwinResult -var Wg sync.WaitGroup -var ControllerWg sync.WaitGroup -var TwinAttributes []string - -var TokenClient Token -var ClientOpts *MQTT.ClientOptions -var Client MQTT.Client - -//Token interface to validate the MQTT connection. -type Token interface { - Wait() bool - WaitTimeout(time.Duration) bool - Error() error -} - -//DeviceStateUpdate is the structure used in updating the device state -type DeviceStateUpdate struct { - State string `json:"state,omitempty"` -} - -//BaseMessage the base struct of event message -type BaseMessage struct { - EventID string `json:"event_id"` - Timestamp int64 `json:"timestamp"` -} - -//TwinValue the struct of twin value -type TwinValue struct { - Value *string `json:"value,omitempty"` - Metadata *ValueMetadata `json:"metadata,omitempty"` -} - -//ValueMetadata the meta of value -type ValueMetadata struct { - Timestamp int64 `json:"timestamp,omitempty"` -} - -//TypeMetadata the meta of value type -type TypeMetadata struct { - Type string `json:"type,omitempty"` -} - -//TwinVersion twin version -type TwinVersion struct { - CloudVersion int64 `json:"cloud"` - EdgeVersion int64 `json:"edge"` -} - -//MsgTwin the struct of device twin -type MsgTwin struct { - Expected *TwinValue `json:"expected,omitempty"` - Actual *TwinValue `json:"actual,omitempty"` - Optional *bool `json:"optional,omitempty"` - Metadata *TypeMetadata `json:"metadata,omitempty"` - ExpectedVersion *TwinVersion `json:"expected_version,omitempty"` - ActualVersion *TwinVersion `json:"actual_version,omitempty"` -} - -//DeviceTwinUpdate the struct of device twin update -type DeviceTwinUpdate struct { - BaseMessage - Twin map[string]*MsgTwin `json:"twin"` -} - -//DeviceTwinResult device get result -type DeviceTwinResult struct { - BaseMessage - Twin map[string]*MsgTwin `json:"twin"` -} - -// HubclientInit create mqtt client config -func HubClientInit(server, clientID, username, password string) *MQTT.ClientOptions { - opts := MQTT.NewClientOptions().AddBroker(server).SetClientID(clientID).SetCleanSession(true) - if username != "" { - opts.SetUsername(username) - if password != "" { - opts.SetPassword(password) - } - } - tlsConfig := &tls.Config{InsecureSkipVerify: true, ClientAuth: tls.NoClientCert} - opts.SetTLSConfig(tlsConfig) - return opts -} - -//MqttConnect function felicitates the MQTT connection -func MqttConnect(mqttMode int, mqttInternalServer, mqttServer string) { - // Initiate the MQTT connection - if mqttMode == 0 { - ClientOpts = HubClientInit(mqttInternalServer, "eventbus", "", "") - } else if mqttMode == 1 { - ClientOpts = HubClientInit(mqttServer, "eventbus", "", "") - } - Client = MQTT.NewClient(ClientOpts) - if TokenClient = Client.Connect(); TokenClient.Wait() && TokenClient.Error() != nil { - klog.Errorf("client.Connect() Error is %s", TokenClient.Error()) - } -} - -//ChangeTwinValue sends the updated twin value to the edge through the MQTT broker -func ChangeTwinValue(updateMessage DeviceTwinUpdate, deviceID string) { - twinUpdateBody, err := json.Marshal(updateMessage) - if err != nil { - klog.Errorf("Error in marshalling: %s", err) - } - deviceTwinUpdate := DeviceETPrefix + deviceID + TwinETUpdateSuffix - TokenClient = Client.Publish(deviceTwinUpdate, 0, false, twinUpdateBody) - if TokenClient.Wait() && TokenClient.Error() != nil { - klog.Errorf("client.publish() Error in device twin update is %s", TokenClient.Error()) - } -} - -//SyncToCloud function syncs the updated device twin information to the cloud -func SyncToCloud(updateMessage DeviceTwinUpdate, deviceID string) { - deviceTwinResultUpdate := DeviceETPrefix + deviceID + TwinETCloudSyncSuffix - twinUpdateBody, err := json.Marshal(updateMessage) - if err != nil { - klog.Errorf("Error in marshalling: %s", err) - } - TokenClient = Client.Publish(deviceTwinResultUpdate, 0, false, twinUpdateBody) - if TokenClient.Wait() && TokenClient.Error() != nil { - klog.Errorf("client.publish() Error in device twin update is: %s", TokenClient.Error()) - } -} - -//GetTwin function is used to get the device twin details from the edge -func GetTwin(updateMessage DeviceTwinUpdate, deviceID string) { - getTwin := DeviceETPrefix + deviceID + TwinETGetSuffix - twinUpdateBody, err := json.Marshal(updateMessage) - if err != nil { - klog.Errorf("Error in marshalling: %s", err) - } - TokenClient = Client.Publish(getTwin, 0, false, twinUpdateBody) - if TokenClient.Wait() && TokenClient.Error() != nil { - klog.Errorf("client.publish() Error in device twin get is: %s ", TokenClient.Error()) - } -} - -//subscribe function subscribes the device twin information through the MQTT broker -func TwinSubscribe(deviceID string) { - getTwinResult := DeviceETPrefix + deviceID + TwinETGetResultSuffix - TokenClient = Client.Subscribe(getTwinResult, 0, OnTwinMessageReceived) - if TokenClient.Wait() && TokenClient.Error() != nil { - klog.Errorf("subscribe() Error in device twin result get is: %s", TokenClient.Error()) - } - for { - time.Sleep(1 * time.Second) - if TwinResult.Twin != nil { - for k := range TwinResult.Twin { - TwinAttributes = append(TwinAttributes, k) - } - Wg.Done() - break - } - } -} - -// OnTwinMessageReceived callback function which is called when message is received -func OnTwinMessageReceived(client MQTT.Client, message MQTT.Message) { - err := json.Unmarshal(message.Payload(), &TwinResult) - if err != nil { - klog.Errorf("Error in unmarshalling: %s", err) - } -} - -//CreateActualUpdateMessage function is used to create the device twin update message -func CreateActualUpdateMessage(updatedTwinAttributes map[string]string) DeviceTwinUpdate { - var deviceTwinUpdateMessage DeviceTwinUpdate - deviceTwinUpdateMessage.Twin = map[string]*MsgTwin{} - for _, twinAttribute := range TwinAttributes { - if actualValue, ok := updatedTwinAttributes[twinAttribute]; ok { - deviceTwinUpdateMessage.Twin[twinAttribute] = &MsgTwin{} - deviceTwinUpdateMessage.Twin[twinAttribute].Actual = &TwinValue{Value: &actualValue} - deviceTwinUpdateMessage.Twin[twinAttribute].Metadata = &TypeMetadata{Type: "Updated"} - } - } - return deviceTwinUpdateMessage -} diff --git a/mappers/bluetooth_mapper/main.go b/mappers/bluetooth_mapper/main.go deleted file mode 100644 index c1e58c2f4..000000000 --- a/mappers/bluetooth_mapper/main.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "flag" - "os" - - "github.com/spf13/pflag" - "k8s.io/klog/v2" - - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/configuration" - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/controller" -) - -// main function -func main() { - klog.InitFlags(nil) - pflag.CommandLine.AddGoFlagSet(flag.CommandLine) - pflag.Parse() - - BleConfig := configuration.BLEConfig{} - // load config - err := BleConfig.Load() - if err != nil { - klog.Errorf("Error in loading configuration: %s", err) - os.Exit(1) - } - bleController := controller.Config{ - Watcher: BleConfig.Watcher, - ActionManager: BleConfig.ActionManager, - Scheduler: BleConfig.Scheduler, - Converter: BleConfig.Converter, - Device: BleConfig.Device, - Mqtt: BleConfig.Mqtt, - } - bleController.Start() -} diff --git a/mappers/bluetooth_mapper/scheduler/scheduler.go b/mappers/bluetooth_mapper/scheduler/scheduler.go deleted file mode 100644 index bdfcaf1ee..000000000 --- a/mappers/bluetooth_mapper/scheduler/scheduler.go +++ /dev/null @@ -1,117 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package scheduler - -import ( - "encoding/json" - "fmt" - "strings" - "time" - - "k8s.io/klog/v2" - - actionmanager "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/action_manager" - dataconverter "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/data_converter" - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/helper" -) - -const ( - MapperTopicPrefix = "$ke/device/bluetooth-mapper/" - SchedulerResultSuffix = "/scheduler/result" - defaultEventFrequency = 5000 -) - -// Schedule is structure to define a schedule -type Schedule struct { - // Name is name of the schedule. It should be unique so that a stop-chan - // can be made corresponding to name to stop the schedule. - Name string `yaml:"name" json:"name"` - // Interval is the time in milliseconds after which this action are to be performed - Interval int `yaml:"interval" json:"interval"` - //OccurrenceLimit refers to the number of time the action can occur, if it is 0, then the event will execute infinitely - OccurrenceLimit int `yaml:"occurrence-limit" json:"occurrence-limit"` - // Actions is list of Actions to be performed in this schedule - Actions []string `yaml:"actions"` -} - -//Scheduler structure contains the list of schedules to be scheduled -type Scheduler struct { - Schedules []Schedule `yaml:"schedules" json:"schedules"` -} - -//ScheduleResult structure contains the format in which telemetry data will be published on the MQTT topic -type ScheduleResult struct { - EventName string - TimeStamp int64 - EventResult string -} - -// ExecuteSchedule is responsible for scheduling the operations -func (schedule *Schedule) ExecuteSchedule(actionManager []actionmanager.Action, dataConverter dataconverter.DataRead, deviceID string) { - klog.Infof("Executing schedule: %s", schedule.Name) - if schedule.OccurrenceLimit != 0 { - for iteration := 0; iteration < schedule.OccurrenceLimit; iteration++ { - schedule.performScheduleOperation(actionManager, dataConverter, deviceID) - } - } else { - for { - schedule.performScheduleOperation(actionManager, dataConverter, deviceID) - } - } - helper.ControllerWg.Done() -} - -// performScheduleOperation is responsible for performing the operations associated with the schedule -func (schedule *Schedule) performScheduleOperation(actionManager []actionmanager.Action, dataConverter dataconverter.DataRead, deviceID string) { - var scheduleResult ScheduleResult - if schedule.Interval == 0 { - schedule.Interval = defaultEventFrequency - } - for _, actionName := range schedule.Actions { - actionExists := false - for _, action := range actionManager { - if strings.EqualFold(action.Name, actionName) { - actionExists = true - klog.Infof("Performing scheduled operation: %s", action.Name) - action.PerformOperation(dataConverter) - scheduleResult.EventName = actionName - scheduleResult.TimeStamp = time.Now().UnixNano() / 1e6 - scheduleResult.EventResult = fmt.Sprintf("%s", action.Operation.Value) - publishScheduleResult(scheduleResult, deviceID) - } - } - if !actionExists { - klog.Errorf("Action %s does not exist.", actionName) - continue - } - time.Sleep(time.Duration(time.Duration(schedule.Interval) * time.Millisecond)) - } -} - -//publishScheduleResult publishes the telemetry data on the given MQTT topic -func publishScheduleResult(scheduleResult ScheduleResult, deviceID string) { - scheduleResultTopic := MapperTopicPrefix + deviceID + SchedulerResultSuffix - klog.Infof("Publishing schedule: %s result on topic: %s", scheduleResult.EventName, scheduleResultTopic) - scheduleResultBody, err := json.Marshal(scheduleResult) - if err != nil { - klog.Errorf("Error: %s", err) - } - helper.TokenClient = helper.Client.Publish(scheduleResultTopic, 0, false, scheduleResultBody) - if helper.TokenClient.Wait() && helper.TokenClient.Error() != nil { - klog.Errorf("client.publish() Error in device twin get is %s", helper.TokenClient.Error()) - } -} diff --git a/mappers/bluetooth_mapper/watcher/watcher.go b/mappers/bluetooth_mapper/watcher/watcher.go deleted file mode 100644 index b7db3c000..000000000 --- a/mappers/bluetooth_mapper/watcher/watcher.go +++ /dev/null @@ -1,192 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package watcher - -import ( - "errors" - "os" - "reflect" - "strings" - "time" - - "github.com/paypal/gatt" - "k8s.io/klog/v2" - - actionmanager "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/action_manager" - dataconverter "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/data_converter" - "github.com/kubeedge/kubeedge/mappers/bluetooth_mapper/helper" -) - -var DeviceConnected = make(chan bool) -var done = make(chan struct{}) -var deviceName string -var deviceID string -var actionManager []actionmanager.Action -var dataConverter dataconverter.Converter - -//Watch structure contains the watcher specific configurations -type Watcher struct { - DeviceTwinAttributes []Attribute `yaml:"device-twin-attributes" json:"device-twin-attributes"` -} - -//Attribute structure contains the name of the attribute along with the actions to be performed for this attribute -type Attribute struct { - Name string `yaml:"device-property-name" json:"device-property-name"` - Actions []string `yaml:"actions" json:"actions"` -} - -//Initiate initiates the watcher module -func (w *Watcher) Initiate(device gatt.Device, nameOfDevice, idOfDevice string, actions []actionmanager.Action, converter dataconverter.Converter) { - deviceID = idOfDevice - deviceName = nameOfDevice - actionManager = actions - dataConverter = converter - // Register optional handlers. - device.Handle( - gatt.PeripheralConnected(w.onPeripheralConnected), - gatt.PeripheralDisconnected(onPeripheralDisconnected), - gatt.PeripheralDiscovered(onPeripheralDiscovered), - ) - if err := device.Init(onStateChanged); err != nil { - klog.Errorf("Init device failed with error: %v", err) - } - <-done - klog.Infof("Watcher Done") -} - -//onStateChanged contains the operations to be performed when the state of the peripheral device changes -func onStateChanged(device gatt.Device, s gatt.State) { - switch s { - case gatt.StatePoweredOn: - klog.Infof("Scanning for BLE device Broadcasts...") - device.Scan([]gatt.UUID{}, true) - return - default: - device.StopScanning() - } -} - -//onPeripheralDiscovered contains the operations to be performed as soon as the peripheral device is discovered -func onPeripheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) { - if strings.EqualFold(a.LocalName, strings.Replace(deviceName, "-", " ", -1)) { - klog.Infof("Device: %s found !!!! Stop Scanning for devices", deviceName) - // Stop scanning once we've got the peripheral we're looking for. - p.Device().StopScanning() - klog.Infof("Connecting to %s", deviceName) - p.Device().Connect(p) - } -} - -//onPeripheralDisconnected contains the operations to be performed as soon as the peripheral device is disconnected -func onPeripheralDisconnected(p gatt.Peripheral, err error) { - klog.Infof("Disconnecting from bluetooth device....") - DeviceConnected <- false - close(done) - p.Device().CancelConnection(p) -} - -//onPeripheralConnected contains the operations to be performed as soon as the peripheral device is connected -func (w *Watcher) onPeripheralConnected(p gatt.Peripheral, err error) { - actionmanager.GattPeripheral = p - ss, err := p.DiscoverServices(nil) - if err != nil { - klog.Errorf("Failed to discover services, err: %s\n", err) - os.Exit(1) - } - for _, s := range ss { - // Discovery characteristics - cs, err := p.DiscoverCharacteristics(nil, s) - if err != nil { - klog.Errorf("Failed to discover characteristics for service %s, err: %v\n", s.Name(), err) - continue - } - actionmanager.CharacteristicsList = append(actionmanager.CharacteristicsList, cs...) - } - DeviceConnected <- true - for { - newWatcher := &Watcher{} - if !reflect.DeepEqual(w, newWatcher) { - err := w.EquateTwinValue(deviceID) - if err != nil { - klog.Errorf("Error in watcher functionality: %s", err) - } - } - } -} - -//EquateTwinValue is responsible for equating the actual state of the device to the expected state that has been set and syncing back the result to the cloud -func (w *Watcher) EquateTwinValue(deviceID string) error { - var updateMessage helper.DeviceTwinUpdate - updatedActualValues := make(map[string]string) - helper.Wg.Add(1) - klog.Infof("Watching on the device twin values for device with deviceID: %s", deviceID) - go helper.TwinSubscribe(deviceID) - helper.GetTwin(updateMessage, deviceID) - helper.Wg.Wait() - twinUpdated := false - for _, twinAttribute := range w.DeviceTwinAttributes { - if helper.TwinResult.Twin[twinAttribute.Name] != nil { - if helper.TwinResult.Twin[twinAttribute.Name].Expected != nil && ((helper.TwinResult.Twin[twinAttribute.Name].Actual == nil) && helper.TwinResult.Twin[twinAttribute.Name].Expected != nil || (*helper.TwinResult.Twin[twinAttribute.Name].Expected.Value != *helper.TwinResult.Twin[twinAttribute.Name].Actual.Value)) { - klog.Infof("%s Expected Value : %s", twinAttribute.Name, *helper.TwinResult.Twin[twinAttribute.Name].Expected.Value) - if helper.TwinResult.Twin[twinAttribute.Name].Actual == nil { - klog.Infof("%s Actual Value: %v", twinAttribute.Name, helper.TwinResult.Twin[twinAttribute.Name].Actual) - } else { - klog.Infof("%s Actual Value: %s", twinAttribute.Name, *helper.TwinResult.Twin[twinAttribute.Name].Actual.Value) - } - klog.Infof("Equating the actual value to expected value for: %s", twinAttribute.Name) - for _, watcherAction := range twinAttribute.Actions { - actionExists := false - for _, action := range actionManager { - if strings.EqualFold(action.Name, watcherAction) { - actionExists = true - for _, converterAttribute := range dataConverter.DataWrite.Attributes { - if strings.EqualFold(converterAttribute.Name, twinAttribute.Name) { - for operationName, dataMap := range converterAttribute.Operations { - if action.Name == operationName { - expectedValue := helper.TwinResult.Twin[twinAttribute.Name].Expected.Value - if _, ok := dataMap.DataMapping[*expectedValue]; ok { - action.Operation.Value = dataMap.DataMapping[*expectedValue] - } - } - action.PerformOperation() - } - } - } - } - } - if !actionExists { - return errors.New("The action: " + watcherAction + " does not exist for this device") - } - } - updatedActualValues[twinAttribute.Name] = *helper.TwinResult.Twin[twinAttribute.Name].Expected.Value - twinUpdated = true - } - } else { - return errors.New("The attribute: " + twinAttribute.Name + " does not exist for this device") - } - } - if twinUpdated { - updateMessage = helper.CreateActualUpdateMessage(updatedActualValues) - helper.ChangeTwinValue(updateMessage, deviceID) - time.Sleep(2 * time.Second) - klog.Infof("Syncing to cloud.....") - helper.SyncToCloud(updateMessage, deviceID) - } else { - klog.Infof("Actual values are in sync with Expected value") - } - return nil -} diff --git a/mappers/common/configmaptype.go b/mappers/common/configmaptype.go deleted file mode 100644 index 67a9790f5..000000000 --- a/mappers/common/configmaptype.go +++ /dev/null @@ -1,121 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mappercommon - -import "encoding/json" - -// DeviceProfile is structure to store in configMap. -type DeviceProfile struct { - DeviceInstances []DeviceInstance `json:"deviceInstances,omitempty"` - DeviceModels []DeviceModel `json:"deviceModels,omitempty"` - Protocols []Protocol `json:"protocols,omitempty"` -} - -// DeviceInstance is structure to store device in deviceProfile.json in configmap. -type DeviceInstance struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - ProtocolName string `json:"protocol,omitempty"` - PProtocol Protocol - Model string `json:"model,omitempty"` - Twins []Twin `json:"twins,omitempty"` - Datas Data `json:"data,omitempty"` - PropertyVisitors []PropertyVisitor `json:"propertyVisitors,omitempty"` -} - -// DeviceModel is structure to store deviceModel in deviceProfile.json in configmap. -type DeviceModel struct { - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Properties []Property `json:"properties,omitempty"` -} - -// Property is structure to store deviceModel property. -type Property struct { - Name string `json:"name,omitempty"` - DataType string `json:"dataType,omitempty"` - Description string `json:"description,omitempty"` - AccessMode string `json:"accessMode,omitempty"` - DefaultValue interface{} `json:"defaultValue,omitempty"` - Minimum int64 `json:"minimum,omitempty"` - Maximum int64 `json:"maximum,omitempty"` - Unit string `json:"unit,omitempty"` -} - -// Protocol is structure to store protocol in deviceProfile.json in configmap. -type Protocol struct { - Name string `json:"name,omitempty"` - Protocol string `json:"protocol,omitempty"` - ProtocolConfigs ProtocolConfig `json:"protocolConfig,omitempty"` - ProtocolCommonConfig json.RawMessage `json:"protocolCommonConfig,omitempty"` -} - -// ProtocolConfig is the protocol configuration. -type ProtocolConfig struct { - SlaveID int16 `json:"slaveID,omitempty"` -} - -// PropertyVisitor is structure to store propertyVisitor in deviceProfile.json in configmap. -type PropertyVisitor struct { - Name string `json:"name,omitempty"` - PropertyName string `json:"propertyName,omitempty"` - ModelName string `json:"modelName,omitempty"` - CollectCycle int64 `json:"collectCycle"` - ReportCycle int64 `json:"reportcycle,omitempty"` - PProperty Property - Protocol string `json:"protocol,omitempty"` - VisitorConfig json.RawMessage `json:"visitorConfig"` -} - -// Data is data structure for the message that only be subscribed in edge node internal. -type Data struct { - Properties []DataProperty `json:"dataProperties,omitempty"` - Topic string `json:"datatopic,omitempty"` -} - -// DataProperty is data property. -type DataProperty struct { - Metadatas DataMetadata `json:"metadata,omitempty"` - PropertyName string `json:"propertyName,omitempty"` - PVisitor *PropertyVisitor -} - -// Metadata is the metadata for data. -type Metadata struct { - Timestamp string `json:"timestamp,omitempty"` - Type string `json:"type,omitempty"` -} - -// Twin is the set/get pair to one register. -type Twin struct { - PropertyName string `json:"propertyName,omitempty"` - PVisitor *PropertyVisitor - Desired DesiredData `json:"desired,omitempty"` - Reported ReportedData `json:"reported,omitempty"` -} - -// DesiredData is the desired data. -type DesiredData struct { - Value string `json:"value,omitempty"` - Metadatas Metadata `json:"metadata,omitempty"` -} - -// ReportedData is the reported data. -type ReportedData struct { - Value string `json:"value,omitempty"` - Metadatas Metadata `json:"metadata,omitempty"` -} diff --git a/mappers/common/data_converter.go b/mappers/common/data_converter.go deleted file mode 100644 index d5cb0c22f..000000000 --- a/mappers/common/data_converter.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mappercommon - -import ( - "errors" - "strconv" -) - -// Convert string to other types -func Convert(valueType string, value string) (result interface{}, err error) { - switch valueType { - case "int": - return strconv.ParseInt(value, 10, 64) - case "float": - return strconv.ParseFloat(value, 32) - case "double": - return strconv.ParseFloat(value, 64) - case "boolean": - return strconv.ParseBool(value) - case "string": - return value, nil - default: - return nil, errors.New("Convert failed") - } -} diff --git a/mappers/common/event.go b/mappers/common/event.go deleted file mode 100644 index 4ee1d221c..000000000 --- a/mappers/common/event.go +++ /dev/null @@ -1,156 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mappercommon - -import ( - "crypto/tls" - "encoding/json" - "time" - - mqtt "github.com/eclipse/paho.mqtt.golang" -) - -// Joint the topic like topic := fmt.Sprintf(TopicTwinUpdateDelta, deviceID) -const ( - TopicTwinUpdateDelta = "$hw/events/device/%s/twin/update/delta" - TopicTwinUpdate = "$hw/events/device/%s/twin/update" - TopicStateUpdate = "$hw/events/device/%s/state/update" - TopicDataUpdate = "$ke/events/device/%s/data/update" -) - -// MqttClient is parameters for Mqtt client. -type MqttClient struct { - Qos byte - Retained bool - IP string - User string - Passwd string - Cert string - PrivateKey string - Client mqtt.Client -} - -// newTLSConfig new TLS configuration. -// Only one side check. Mqtt broker check the cert from client. -func newTLSConfig(certfile string, privateKey string) (*tls.Config, error) { - // Import client certificate/key pair - cert, err := tls.LoadX509KeyPair(certfile, privateKey) - if err != nil { - return nil, err - } - - // Create tls.Config with desired tls properties - return &tls.Config{ - // ClientAuth = whether to request cert from server. - // Since the server is set up for SSL, this happens - // anyways. - ClientAuth: tls.NoClientCert, - // ClientCAs = certs used to validate client cert. - ClientCAs: nil, - // InsecureSkipVerify = verify that cert contents - // match server. IP matches what is in cert etc. - InsecureSkipVerify: true, - // Certificates = list of certs client sends to server. - Certificates: []tls.Certificate{cert}, - }, nil -} - -// Connect connect to the Mqtt server. -func (mc *MqttClient) Connect() error { - opts := mqtt.NewClientOptions().AddBroker(mc.IP).SetClientID("").SetCleanSession(true) - if mc.Cert != "" { - tlsConfig, err := newTLSConfig(mc.Cert, mc.PrivateKey) - if err != nil { - return err - } - opts.SetTLSConfig(tlsConfig) - } else { - opts.SetUsername(mc.User) - opts.SetPassword(mc.Passwd) - } - - mc.Client = mqtt.NewClient(opts) - // The token is used to indicate when actions have completed. - if tc := mc.Client.Connect(); tc.Wait() && tc.Error() != nil { - return tc.Error() - } - - mc.Qos = 0 // At most 1 time - mc.Retained = false // Not retained - return nil -} - -// Publish publish Mqtt message. -func (mc *MqttClient) Publish(topic string, payload interface{}) error { - if tc := mc.Client.Publish(topic, mc.Qos, mc.Retained, payload); tc.Wait() && tc.Error() != nil { - return tc.Error() - } - return nil -} - -// Subscribe subsribe a Mqtt topic. -func (mc *MqttClient) Subscribe(topic string, onMessage mqtt.MessageHandler) error { - if tc := mc.Client.Subscribe(topic, mc.Qos, onMessage); tc.Wait() && tc.Error() != nil { - return tc.Error() - } - return nil -} - -// getTimestamp get current timestamp. -func getTimestamp() int64 { - return time.Now().UnixNano() / 1e6 -} - -// CreateMessageTwinUpdate create twin update message. -func CreateMessageTwinUpdate(name string, valueType string, value string) (msg []byte, err error) { - var updateMsg DeviceTwinUpdate - - updateMsg.BaseMessage.Timestamp = getTimestamp() - updateMsg.Twin = map[string]*MsgTwin{} - updateMsg.Twin[name] = &MsgTwin{} - updateMsg.Twin[name].Actual = &TwinValue{Value: &value} - updateMsg.Twin[name].Metadata = &TypeMetadata{Type: valueType} - - msg, err = json.Marshal(updateMsg) - return -} - -// CreateMessageData create data message. -func CreateMessageData(name string, valueType string, value string) (msg []byte, err error) { - var dataMsg DeviceData - - dataMsg.BaseMessage.Timestamp = getTimestamp() - dataMsg.Data = map[string]*DataValue{} - dataMsg.Data[name] = &DataValue{} - dataMsg.Data[name].Value = value - dataMsg.Data[name].Metadata.Type = valueType - dataMsg.Data[name].Metadata.Timestamp = getTimestamp() - - msg, err = json.Marshal(dataMsg) - return -} - -// CreateMessageState create device status message. -func CreateMessageState(state string) (msg []byte, err error) { - var stateMsg DeviceUpdate - - stateMsg.BaseMessage.Timestamp = getTimestamp() - stateMsg.State = state - - msg, err = json.Marshal(stateMsg) - return -} diff --git a/mappers/common/event_type.go b/mappers/common/event_type.go deleted file mode 100644 index 75142788f..000000000 --- a/mappers/common/event_type.go +++ /dev/null @@ -1,106 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mappercommon - -// BaseMessage the base structure of event message. -type BaseMessage struct { - EventID string `json:"event_id"` - Timestamp int64 `json:"timestamp"` -} - -// TwinValue the structure of twin value. -type TwinValue struct { - Value *string `json:"value,omitempty"` - Metadata ValueMetadata `json:"metadata,omitempty"` -} - -// ValueMetadata the meta of value. -type ValueMetadata struct { - Timestamp int64 `json:"timestamp,omitempty"` -} - -// TypeMetadata the meta of value type. -type TypeMetadata struct { - Type string `json:"type,omitempty"` -} - -// TwinVersion twin version. -type TwinVersion struct { - CloudVersion int64 `json:"cloud"` - EdgeVersion int64 `json:"edge"` -} - -// MsgTwin the structure of device twin. -type MsgTwin struct { - Expected *TwinValue `json:"expected,omitempty"` - Actual *TwinValue `json:"actual,omitempty"` - Optional *bool `json:"optional,omitempty"` - Metadata *TypeMetadata `json:"metadata,omitempty"` - ExpectedVersion *TwinVersion `json:"expected_version,omitempty"` - ActualVersion *TwinVersion `json:"actual_version,omitempty"` -} - -// DeviceTwinUpdate the structure of device twin update. -type DeviceTwinUpdate struct { - BaseMessage - Twin map[string]*MsgTwin `json:"twin"` -} - -// DeviceTwinResult device get result. -type DeviceTwinResult struct { - BaseMessage - Twin map[string]*MsgTwin `json:"twin"` -} - -// DeviceTwinDelta twin delta. -type DeviceTwinDelta struct { - BaseMessage - Twin map[string]*MsgTwin `json:"twin"` - Delta map[string]string `json:"delta"` -} - -// DataMetadata data metadata. -type DataMetadata struct { - Timestamp int64 `json:"timestamp"` - Type string `json:"type"` -} - -// DataValue data value. -type DataValue struct { - Value string `json:"value"` - Metadata DataMetadata `json:"metadata"` -} - -// DeviceData device data structure. -type DeviceData struct { - BaseMessage - Data map[string]*DataValue `json:"data"` -} - -//MsgAttr the struct of device attr -type MsgAttr struct { - Value string `json:"value"` - Optional *bool `json:"optional,omitempty"` - Metadata *TypeMetadata `json:"metadata,omitempty"` -} - -//DeviceUpdate device update. -type DeviceUpdate struct { - BaseMessage - State string `json:"state,omitempty"` - Attributes map[string]*MsgAttr `json:"attributes"` -} diff --git a/mappers/common/timer.go b/mappers/common/timer.go deleted file mode 100644 index 780202a16..000000000 --- a/mappers/common/timer.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package mappercommon - -import ( - "time" -) - -// Timer is to call a function periodically. -type Timer struct { - Function func() - Duration time.Duration - Times int -} - -// Start start a timer. -func (t *Timer) Start() { - ticker := time.NewTicker(t.Duration) - if t.Times > 0 { - for i := 0; i < t.Times; i++ { - select { - case <-ticker.C: - t.Function() - default: - } - } - } else { - for { - select { - case <-ticker.C: - t.Function() - default: - } - } - } -} diff --git a/mappers/modbus-go/Dockerfile b/mappers/modbus-go/Dockerfile deleted file mode 100644 index fe51aeefe..000000000 --- a/mappers/modbus-go/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM ubuntu:16.04 - -RUN mkdir -p kubeedge - -COPY ./modbus kubeedge/ -COPY ./config.yaml kubeedge/ - -WORKDIR kubeedge - -ENTRYPOINT ["/kubeedge/modbus", "--v", "5"] diff --git a/mappers/modbus-go/config.go b/mappers/modbus-go/config.go deleted file mode 100644 index 21ec1f0bf..000000000 --- a/mappers/modbus-go/config.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "errors" - "io/ioutil" - - "github.com/spf13/pflag" - "gopkg.in/yaml.v2" - "k8s.io/klog/v2" -) - -// Config is the modbus mapper configuration. -type Config struct { - Mqtt Mqtt `yaml:"mqtt,omitempty"` - Configmap string `yaml:"configmap"` -} - -// Mqtt is the Mqtt configuration. -type Mqtt struct { - ServerAddress string `yaml:"server,omitempty"` - Username string `yaml:"username,omitempty"` - Password string `yaml:"password,omitempty"` - Cert string `yaml:"certification,omitempty"` - PrivateKey string `yaml:"privatekey,omitempty"` -} - -// ErrConfigCert error of certification configuration. -var ErrConfigCert = errors.New("Both certification and private key must be provided") - -var defaultConfigFile = "./config.yaml" - -// Parse parse the configuration file. If failed, return error. -func (c *Config) Parse() error { - var level klog.Level - var loglevel string - var configFile string - - pflag.StringVar(&loglevel, "v", "1", "log level") - pflag.StringVar(&configFile, "config-file", defaultConfigFile, "Config file name") - pflag.Parse() - cf, err := ioutil.ReadFile(configFile) - if err != nil { - return err - } - if err = yaml.Unmarshal(cf, c); err != nil { - return err - } - if err = level.Set(loglevel); err != nil { - return err - } - - return c.parseFlags() -} - -// parseFlags parse flags. Certification and Private key must be provided at the same time. -func (c *Config) parseFlags() error { - pflag.StringVar(&c.Mqtt.ServerAddress, "mqtt-address", c.Mqtt.ServerAddress, "MQTT broker address") - pflag.StringVar(&c.Mqtt.Username, "mqtt-username", c.Mqtt.Username, "username") - pflag.StringVar(&c.Mqtt.Password, "mqtt-password", c.Mqtt.Password, "password") - pflag.StringVar(&c.Mqtt.Cert, "mqtt-certification", c.Mqtt.Cert, "certification file path") - pflag.StringVar(&c.Mqtt.PrivateKey, "mqtt-priviatekey", c.Mqtt.PrivateKey, "private key file path") - pflag.Parse() - - if (c.Mqtt.Cert != "" && c.Mqtt.PrivateKey == "") || - (c.Mqtt.Cert == "" && c.Mqtt.PrivateKey != "") { - return ErrConfigCert - } - return nil -} diff --git a/mappers/modbus-go/config.yaml b/mappers/modbus-go/config.yaml deleted file mode 100644 index 0ddb6b33c..000000000 --- a/mappers/modbus-go/config.yaml +++ /dev/null @@ -1,6 +0,0 @@ -mqtt: - server: tcp://127.0.0.1:1883 - username: "" - password: "" - certification: "" -configmap: /opt/kubeedge/deviceProfile.json diff --git a/mappers/modbus-go/config_test.go b/mappers/modbus-go/config_test.go deleted file mode 100644 index dedf1b160..000000000 --- a/mappers/modbus-go/config_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestParse(t *testing.T) { - config := Config{} - if err := config.Parse(); err != nil { - t.Log(err) - t.FailNow() - } - - assert.Equal(t, "tcp://127.0.0.1:1883", config.Mqtt.ServerAddress) - assert.Equal(t, "/opt/kubeedge/deviceProfile.json", config.Configmap) -} diff --git a/mappers/modbus-go/configmap/configmap_negtest.json b/mappers/modbus-go/configmap/configmap_negtest.json deleted file mode 100644 index cf94b6c95..000000000 --- a/mappers/modbus-go/configmap/configmap_negtest.json +++ /dev/null @@ -1,90 +0,0 @@ - - "deviceInstances": [{ - "id": "sensor-tag-instance-01", - "name": "sensor-tag-instance-01", - "protocol": "modbus-sensor-tag-instance-01", - "model": "sensor-tag-model", - "twins": [{ - "propertyName": "temperature-enable", - "desired": { - "value": "OFF", - "metadata": { - "timestamp": "1550049403598", - "type": "string" - } - }, - "reported": { - "value": "OFF", - "metadata": { - "timestamp": "1550049403598", - "type": "string" - } - } - }], - "propertyVisitors": [{ - "name": "temperature", - "propertyName": "temperature", - "modelName": "sensor-tag-model", - "protocol": "modbus", - "visitorConfig": { - "register": "CoilRegister", - "offset": 2, - "limit": 1, - "scale": 1, - "isSwap": true, - "isRegisterSwap": true - } - }, { - "name": "temperature-enable", - "propertyName": "temperature-enable", - "modelName": "sensor-tag-model", - "protocol": "modbus", - "visitorConfig": { - "register": "DiscreteInputRegister", - "offset": 3, - "limit": 1, - "scale": 1, - "isSwap": true, - "isRegisterSwap": true - } - }] - }], - "deviceModels": [{ - "name": "sensor-tag-model", - "properties": [{ - "name": "temperature", - "dataType": "int", - "description": "temperature in degree celsius", - "accessMode": "ReadWrite", - "defaultValue": 0, - "minimum": 0, - "maximum": 100, - "unit": "degree celsius" - }, { - "name": "temperature-enable", - "dataType": "string", - "description": "enable data collection of temperature sensor", - "accessMode": "ReadWrite", - "defaultValue": "OFF" - }] - }], - "protocols": [{ - "name": "modbus-sensor-tag-instance-01", - "protocol": "modbus", - "protocolConfig": { - "slaveID": 1 - }, - "protocolCommonConfig": { - "com": { - "serialPort": "1", - "baudRate": 115200, - "dataBits": 8, - "parity": "even", - "stopBits": 1 - }, - "customizedValues": { - "serialType": "RS485" - } - } - }] -} diff --git a/mappers/modbus-go/configmap/configmap_test.json b/mappers/modbus-go/configmap/configmap_test.json deleted file mode 100644 index a163a77a7..000000000 --- a/mappers/modbus-go/configmap/configmap_test.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "deviceInstances": [{ - "id": "sensor-tag-instance-01", - "name": "sensor-tag-instance-01", - "protocol": "modbus-sensor-tag-instance-01", - "model": "sensor-tag-model", - "twins": [{ - "propertyName": "temperature-enable", - "desired": { - "value": "OFF", - "metadata": { - "timestamp": "1550049403598", - "type": "string" - } - }, - "reported": { - "value": "OFF", - "metadata": { - "timestamp": "1550049403598", - "type": "string" - } - } - }], - "propertyVisitors": [{ - "name": "temperature", - "propertyName": "temperature", - "modelName": "sensor-tag-model", - "protocol": "modbus", - "visitorConfig": { - "register": "CoilRegister", - "offset": 2, - "limit": 1, - "scale": 1, - "isSwap": true, - "isRegisterSwap": true - } - }, { - "name": "temperature-enable", - "propertyName": "temperature-enable", - "modelName": "sensor-tag-model", - "protocol": "modbus", - "visitorConfig": { - "register": "DiscreteInputRegister", - "offset": 3, - "limit": 1, - "scale": 1, - "isSwap": true, - "isRegisterSwap": true - } - }] - }], - "deviceModels": [{ - "name": "sensor-tag-model", - "properties": [{ - "name": "temperature", - "dataType": "int", - "description": "temperature in degree celsius", - "accessMode": "ReadWrite", - "defaultValue": 0, - "minimum": 0, - "maximum": 100, - "unit": "degree celsius" - }, { - "name": "temperature-enable", - "dataType": "string", - "description": "enable data collection of temperature sensor", - "accessMode": "ReadWrite", - "defaultValue": "OFF" - }] - }], - "protocols": [{ - "name": "modbus-sensor-tag-instance-01", - "protocol": "modbus", - "protocolConfig": { - "slaveID": 1 - }, - "protocolCommonConfig": { - "com": { - "serialPort": "1", - "baudRate": 115200, - "dataBits": 8, - "parity": "even", - "stopBits": 1 - }, - "customizedValues": { - "serialType": "RS485" - } - } - }] -} diff --git a/mappers/modbus-go/configmap/parse.go b/mappers/modbus-go/configmap/parse.go deleted file mode 100644 index c84b0faf5..000000000 --- a/mappers/modbus-go/configmap/parse.go +++ /dev/null @@ -1,132 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package configmap - -import ( - "encoding/json" - "errors" - "io/ioutil" - - "k8s.io/klog/v2" - - mappercommon "github.com/kubeedge/kubeedge/mappers/common" - "github.com/kubeedge/kubeedge/mappers/modbus-go/globals" -) - -// Parse parse the configmap. -func Parse(path string, - devices map[string]*globals.ModbusDev, - dms map[string]mappercommon.DeviceModel, - protocols map[string]mappercommon.Protocol) error { - var deviceProfile mappercommon.DeviceProfile - - jsonFile, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - if err = json.Unmarshal(jsonFile, &deviceProfile); err != nil { - return err - } - - for i := 0; i < len(deviceProfile.DeviceInstances); i++ { - instance := deviceProfile.DeviceInstances[i] - j := 0 - for j = 0; j < len(deviceProfile.Protocols); j++ { - if instance.ProtocolName == deviceProfile.Protocols[j].Name { - instance.PProtocol = deviceProfile.Protocols[j] - break - } - } - if j == len(deviceProfile.Protocols) { - err = errors.New("Protocol not found") - return err - } - - if instance.PProtocol.Protocol != "modbus" { - continue - } - - for k := 0; k < len(instance.PropertyVisitors); k++ { - modelName := instance.PropertyVisitors[k].ModelName - propertyName := instance.PropertyVisitors[k].PropertyName - l := 0 - for l = 0; l < len(deviceProfile.DeviceModels); l++ { - if modelName == deviceProfile.DeviceModels[l].Name { - m := 0 - for m = 0; m < len(deviceProfile.DeviceModels[l].Properties); m++ { - if propertyName == deviceProfile.DeviceModels[l].Properties[m].Name { - instance.PropertyVisitors[k].PProperty = deviceProfile.DeviceModels[l].Properties[m] - break - } - } - - if m == len(deviceProfile.DeviceModels[l].Properties) { - err = errors.New("Property not found") - return err - } - break - } - } - if l == len(deviceProfile.DeviceModels) { - err = errors.New("Device model not found") - return err - } - } - - for k := 0; k < len(instance.Twins); k++ { - name := instance.Twins[k].PropertyName - l := 0 - for l = 0; l < len(instance.PropertyVisitors); l++ { - if name == instance.PropertyVisitors[l].PropertyName { - instance.Twins[k].PVisitor = &instance.PropertyVisitors[l] - break - } - } - if l == len(instance.PropertyVisitors) { - return errors.New("PropertyVisitor not found") - } - } - - for k := 0; k < len(instance.Datas.Properties); k++ { - name := instance.Datas.Properties[k].PropertyName - l := 0 - for l = 0; l < len(instance.PropertyVisitors); l++ { - if name == instance.PropertyVisitors[l].PropertyName { - instance.Datas.Properties[k].PVisitor = &instance.PropertyVisitors[l] - break - } - } - if l == len(instance.PropertyVisitors) { - return errors.New("PropertyVisitor not found") - } - } - - devices[instance.ID] = new(globals.ModbusDev) - devices[instance.ID].Instance = instance - klog.V(4).Info("Instance: ", instance.ID, instance) - } - - for i := 0; i < len(deviceProfile.DeviceModels); i++ { - dms[deviceProfile.DeviceModels[i].Name] = deviceProfile.DeviceModels[i] - } - - for i := 0; i < len(deviceProfile.Protocols); i++ { - protocols[deviceProfile.Protocols[i].Name] = deviceProfile.Protocols[i] - } - return nil -} diff --git a/mappers/modbus-go/configmap/parse_test.go b/mappers/modbus-go/configmap/parse_test.go deleted file mode 100644 index 0c0afae7b..000000000 --- a/mappers/modbus-go/configmap/parse_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package configmap - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" - - mappercommon "github.com/kubeedge/kubeedge/mappers/common" - . "github.com/kubeedge/kubeedge/mappers/modbus-go/globals" -) - -func TestParse(t *testing.T) { - var devices map[string]*ModbusDev - var models map[string]mappercommon.DeviceModel - var protocols map[string]mappercommon.Protocol - - devices = make(map[string]*ModbusDev) - models = make(map[string]mappercommon.DeviceModel) - protocols = make(map[string]mappercommon.Protocol) - - assert.Nil(t, Parse("./configmap_test.json", devices, models, protocols)) - for _, device := range devices { - var pcc ModbusProtocolCommonConfig - assert.Nil(t, json.Unmarshal([]byte(device.Instance.PProtocol.ProtocolCommonConfig), &pcc)) - assert.Equal(t, "RS485", pcc.CustomizedValues["serialType"]) - } -} - -func TestParseNeg(t *testing.T) { - var devices map[string]*ModbusDev - var models map[string]mappercommon.DeviceModel - var protocols map[string]mappercommon.Protocol - - devices = make(map[string]*ModbusDev) - models = make(map[string]mappercommon.DeviceModel) - protocols = make(map[string]mappercommon.Protocol) - - assert.NotNil(t, Parse("./configmap_negtest.json", devices, models, protocols)) -} diff --git a/mappers/modbus-go/configmap/type.go b/mappers/modbus-go/configmap/type.go deleted file mode 100644 index b166932cb..000000000 --- a/mappers/modbus-go/configmap/type.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package configmap - -// ModbusVisitorConfig is the modbus register configuration. -type ModbusVisitorConfig struct { - Register string `json:"register"` - Offset uint16 `json:"offset"` - Limit int `json:"limit"` - Scale int `json:"scale,omitempty"` - IsSwap bool `json:"isSwap,omitempty"` - IsRegisterSwap bool `json:"isRegisterSwap,omitempty"` -} - -// ModbusProtocolCommonConfig is the modbus protocol configuration. -type ModbusProtocolCommonConfig struct { - COM COMStruct `json:"com,omitempty"` - TCP TCPStruct `json:"tcp,omitempty"` - CustomizedValues CustomizedValue `json:"customizedValues,omitempty"` -} - -// CustomizedValue is the customized part for modbus protocol. -type CustomizedValue map[string]interface{} - -// COMStruct is the serial configuration. -type COMStruct struct { - SerialPort string `json:"serialPort"` - BaudRate int64 `json:"baudRate"` - DataBits int64 `json:"dataBits"` - Parity string `json:"parity"` - StopBits int64 `json:"stopBits"` -} - -// TCPStruct is the TCP configuation. -type TCPStruct struct { - IP string `json:"ip"` - Port int64 `json:"port"` -} diff --git a/mappers/modbus-go/deployment.yaml b/mappers/modbus-go/deployment.yaml deleted file mode 100644 index 8a3e7c621..000000000 --- a/mappers/modbus-go/deployment.yaml +++ /dev/null @@ -1,41 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: modbus-mapper -spec: - replicas: 1 - selector: - matchLabels: - app: modbusmapper - template: - metadata: - labels: - app: modbusmapper - spec: - hostNetwork: true - containers: - - name: modbus-mapper-container - image: modbusmapper:v1.0 - imagePullPolicy: IfNotPresent - securityContext: - privileged: true - volumeMounts: - - name: config-volume - mountPath: /opt/kubeedge/ - - mountPath: /dev/ttyS0 - name: modbus-dev0 - - mountPath: /dev/ttyS1 - name: modbus-dev1 - nodeSelector: - modbus: "true" - volumes: - - name: config-volume - configMap: - name: device-profile-config-test - - name: modbus-dev0 - hostPath: - path: /dev/ttyS0 - - name: modbus-dev1 - hostPath: - path: /dev/ttyS1 - restartPolicy: Always diff --git a/mappers/modbus-go/device/device.go b/mappers/modbus-go/device/device.go deleted file mode 100644 index b7516caa2..000000000 --- a/mappers/modbus-go/device/device.go +++ /dev/null @@ -1,276 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package device - -import ( - "encoding/json" - "errors" - "fmt" - "regexp" - "strconv" - "sync" - "time" - - mqtt "github.com/eclipse/paho.mqtt.golang" - "k8s.io/klog/v2" - - mappercommon "github.com/kubeedge/kubeedge/mappers/common" - "github.com/kubeedge/kubeedge/mappers/modbus-go/configmap" - "github.com/kubeedge/kubeedge/mappers/modbus-go/driver" - "github.com/kubeedge/kubeedge/mappers/modbus-go/globals" -) - -var devices map[string]*globals.ModbusDev -var models map[string]mappercommon.DeviceModel -var protocols map[string]mappercommon.Protocol -var wg sync.WaitGroup - -// setVisitor check if visitory is readonly, if not then set it. -func setVisitor(visitorConfig *configmap.ModbusVisitorConfig, twin *mappercommon.Twin, client *driver.ModbusClient) { - if twin.PVisitor.PProperty.AccessMode == "ReadOnly" { - klog.V(1).Info("Visit readonly register: ", visitorConfig.Offset) - return - } - - klog.V(2).Infof("Convert type: %s, value: %s ", twin.PVisitor.PProperty.DataType, twin.Desired.Value) - value, err := mappercommon.Convert(twin.PVisitor.PProperty.DataType, twin.Desired.Value) - if err != nil { - klog.Error(err) - return - } - - valueInt, _ := value.(int64) - _, err = client.Set(visitorConfig.Register, visitorConfig.Offset, uint16(valueInt)) - if err != nil { - klog.Error(err, visitorConfig) - return - } -} - -// getDeviceID extract the device ID from Mqtt topic. -func getDeviceID(topic string) (id string) { - re := regexp.MustCompile(`hw/events/device/(.+)/twin/update/delta`) - return re.FindStringSubmatch(topic)[1] -} - -// onMessage callback function of Mqtt subscribe message. -func onMessage(client mqtt.Client, message mqtt.Message) { - klog.V(2).Info("Receive message", message.Topic()) - // Get device ID and get device instance - id := getDeviceID(message.Topic()) - if id == "" { - klog.Error("Wrong topic") - return - } - klog.V(2).Info("Device id: ", id) - - var dev *globals.ModbusDev - var ok bool - if dev, ok = devices[id]; !ok { - klog.Error("Device not exist") - return - } - - // Get twin map key as the propertyName - var delta mappercommon.DeviceTwinDelta - if err := json.Unmarshal(message.Payload(), &delta); err != nil { - klog.Error("Unmarshal message failed: ", err) - return - } - for twinName, twinValue := range delta.Delta { - i := 0 - for i = 0; i < len(dev.Instance.Twins); i++ { - if twinName == dev.Instance.Twins[i].PropertyName { - break - } - } - if i == len(dev.Instance.Twins) { - klog.Error("Twin not found: ", twinName) - continue - } - // Desired value is not changed. - if dev.Instance.Twins[i].Desired.Value == twinValue { - continue - } - dev.Instance.Twins[i].Desired.Value = twinValue - var visitorConfig configmap.ModbusVisitorConfig - if err := json.Unmarshal([]byte(dev.Instance.Twins[i].PVisitor.VisitorConfig), &visitorConfig); err != nil { - klog.Error("Unmarshal visitor config failed") - } - setVisitor(&visitorConfig, &dev.Instance.Twins[i], dev.ModbusClient) - } -} - -// isRS485Enabled is RS485 feature enabled for RTU. -func isRS485Enabled(customizedValue configmap.CustomizedValue) bool { - isEnabled := false - - if len(customizedValue) != 0 { - if value, ok := customizedValue["serialType"]; ok { - if value == "RS485" { - isEnabled = true - } - } - } - return isEnabled -} - -// initModbus initialize modbus client -func initModbus(protocolConfig configmap.ModbusProtocolCommonConfig, slaveID int16) (client *driver.ModbusClient, err error) { - if protocolConfig.COM.SerialPort != "" { - modbusRTU := driver.ModbusRTU{SlaveID: byte(slaveID), - SerialName: protocolConfig.COM.SerialPort, - BaudRate: int(protocolConfig.COM.BaudRate), - DataBits: int(protocolConfig.COM.DataBits), - StopBits: int(protocolConfig.COM.StopBits), - Parity: protocolConfig.COM.Parity, - RS485Enabled: isRS485Enabled(protocolConfig.CustomizedValues), - Timeout: 5 * time.Second} - client, _ = driver.NewClient(modbusRTU) - } else if protocolConfig.TCP.IP != "" { - modbusTCP := driver.ModbusTCP{ - SlaveID: byte(slaveID), - DeviceIP: protocolConfig.TCP.IP, - TCPPort: strconv.FormatInt(protocolConfig.TCP.Port, 10), - Timeout: 5 * time.Second} - client, _ = driver.NewClient(modbusTCP) - } else { - return nil, errors.New("No protocol found") - } - return client, nil -} - -// initTwin initialize the timer to get twin value. -func initTwin(dev *globals.ModbusDev) { - for i := 0; i < len(dev.Instance.Twins); i++ { - var visitorConfig configmap.ModbusVisitorConfig - if err := json.Unmarshal([]byte(dev.Instance.Twins[i].PVisitor.VisitorConfig), &visitorConfig); err != nil { - klog.Error(err) - continue - } - setVisitor(&visitorConfig, &dev.Instance.Twins[i], dev.ModbusClient) - - twinData := TwinData{Client: dev.ModbusClient, - Name: dev.Instance.Twins[i].PropertyName, - Type: dev.Instance.Twins[i].Desired.Metadatas.Type, - RegisterType: visitorConfig.Register, - Address: visitorConfig.Offset, - Quantity: uint16(visitorConfig.Limit), - Topic: fmt.Sprintf(mappercommon.TopicTwinUpdate, dev.Instance.ID)} - collectCycle := time.Duration(dev.Instance.Twins[i].PVisitor.CollectCycle) - // If the collect cycle is not set, set it to 1 second. - if collectCycle == 0 { - collectCycle = 1 * time.Second - } - timer := mappercommon.Timer{Function: twinData.Run, Duration: collectCycle, Times: 0} - wg.Add(1) - go func() { - defer wg.Done() - timer.Start() - }() - } -} - -// initData initialize the timer to get data. -func initData(dev *globals.ModbusDev) { - for i := 0; i < len(dev.Instance.Datas.Properties); i++ { - var visitorConfig configmap.ModbusVisitorConfig - if err := json.Unmarshal([]byte(dev.Instance.Datas.Properties[i].PVisitor.VisitorConfig), &visitorConfig); err != nil { - klog.Error("Unmarshal visitor config failed") - } - twinData := TwinData{Client: dev.ModbusClient, - Name: dev.Instance.Datas.Properties[i].PropertyName, - Type: dev.Instance.Datas.Properties[i].Metadatas.Type, - RegisterType: visitorConfig.Register, - Address: visitorConfig.Offset, - Quantity: uint16(visitorConfig.Limit), - Topic: fmt.Sprintf(mappercommon.TopicDataUpdate, dev.Instance.ID)} - collectCycle := time.Duration(dev.Instance.Datas.Properties[i].PVisitor.CollectCycle) - // If the collect cycle is not set, set it to 1 second. - if collectCycle == 0 { - collectCycle = 1 * time.Second - } - timer := mappercommon.Timer{Function: twinData.Run, Duration: collectCycle, Times: 0} - wg.Add(1) - go func() { - defer wg.Done() - timer.Start() - }() - } -} - -// initSubscribeMqtt subscribe Mqtt topics. -func initSubscribeMqtt(instanceID string) error { - topic := fmt.Sprintf(mappercommon.TopicTwinUpdateDelta, instanceID) - klog.V(1).Info("Subscribe topic: ", topic) - return globals.MqttClient.Subscribe(topic, onMessage) -} - -// initGetStatus start timer to get device status and send to eventbus. -func initGetStatus(dev *globals.ModbusDev) { - getStatus := GetStatus{Client: dev.ModbusClient, - topic: fmt.Sprintf(mappercommon.TopicStateUpdate, dev.Instance.ID)} - timer := mappercommon.Timer{Function: getStatus.Run, Duration: 1 * time.Second, Times: 0} - wg.Add(1) - go func() { - defer wg.Done() - timer.Start() - }() -} - -// start start the device. -func start(dev *globals.ModbusDev) { - var protocolConfig configmap.ModbusProtocolCommonConfig - if err := json.Unmarshal([]byte(dev.Instance.PProtocol.ProtocolCommonConfig), &protocolConfig); err != nil { - klog.Error(err) - return - } - - client, err := initModbus(protocolConfig, dev.Instance.PProtocol.ProtocolConfigs.SlaveID) - if err != nil { - klog.Error(err) - return - } - dev.ModbusClient = client - - initTwin(dev) - initData(dev) - - if err := initSubscribeMqtt(dev.Instance.ID); err != nil { - klog.Error(err) - return - } - - initGetStatus(dev) -} - -// DevInit initialize the device datas. -func DevInit(configmapPath string) error { - devices = make(map[string]*globals.ModbusDev) - models = make(map[string]mappercommon.DeviceModel) - protocols = make(map[string]mappercommon.Protocol) - return configmap.Parse(configmapPath, devices, models, protocols) -} - -// DevStart start all devices. -func DevStart() { - for id, dev := range devices { - klog.V(4).Info("Dev: ", id, dev) - start(dev) - } - wg.Wait() -} diff --git a/mappers/modbus-go/device/devstatus.go b/mappers/modbus-go/device/devstatus.go deleted file mode 100644 index d6dda5703..000000000 --- a/mappers/modbus-go/device/devstatus.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package device - -import ( - "k8s.io/klog/v2" - - mappercommon "github.com/kubeedge/kubeedge/mappers/common" - "github.com/kubeedge/kubeedge/mappers/modbus-go/driver" - "github.com/kubeedge/kubeedge/mappers/modbus-go/globals" -) - -// GetStatus is the timer structure for getting device status. -type GetStatus struct { - Client *driver.ModbusClient - Status string - topic string -} - -// Run timer function. -func (gs *GetStatus) Run() { - gs.Status = gs.Client.GetStatus() - - var payload []byte - var err error - if payload, err = mappercommon.CreateMessageState(gs.Status); err != nil { - klog.Error("Create message state failed: ", err) - return - } - if err = globals.MqttClient.Publish(gs.topic, payload); err != nil { - klog.Error("Publish failed: ", err) - return - } -} diff --git a/mappers/modbus-go/device/twindata.go b/mappers/modbus-go/device/twindata.go deleted file mode 100644 index db964b164..000000000 --- a/mappers/modbus-go/device/twindata.go +++ /dev/null @@ -1,68 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package device - -import ( - "strconv" - "strings" - - "k8s.io/klog/v2" - - mappercommon "github.com/kubeedge/kubeedge/mappers/common" - "github.com/kubeedge/kubeedge/mappers/modbus-go/driver" - "github.com/kubeedge/kubeedge/mappers/modbus-go/globals" -) - -// TwinData is the timer structure for getting twin/data. -type TwinData struct { - Client *driver.ModbusClient - Name string - Type string - RegisterType string - Address uint16 - Quantity uint16 - Results []byte - Topic string -} - -// Run timer function. -func (td *TwinData) Run() { - var err error - td.Results, err = td.Client.Get(td.RegisterType, td.Address, td.Quantity) - if err != nil { - klog.Error("Get register failed: ", err) - return - } - // construct payload - var payload []byte - if strings.Contains(td.Topic, "$hw") { - if payload, err = mappercommon.CreateMessageTwinUpdate(td.Name, td.Type, strconv.Itoa(int(td.Results[0]))); err != nil { - klog.Error("Create message twin update failed") - return - } - } else { - if payload, err = mappercommon.CreateMessageData(td.Name, td.Type, strconv.Itoa(int(td.Results[0]))); err != nil { - klog.Error("Create message data failed") - return - } - } - if err = globals.MqttClient.Publish(td.Topic, payload); err != nil { - klog.Error(err) - } - - klog.V(2).Infof("Update value: %s, topic: %s", strconv.Itoa(int(td.Results[0])), td.Topic) -} diff --git a/mappers/modbus-go/driver/client.go b/mappers/modbus-go/driver/client.go deleted file mode 100644 index ae33d1fac..000000000 --- a/mappers/modbus-go/driver/client.go +++ /dev/null @@ -1,194 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package driver - -import ( - "errors" - "sync" - "time" - - "github.com/sailorvii/modbus" - "k8s.io/klog/v2" -) - -// ModbusTCP is the configurations of modbus TCP. -type ModbusTCP struct { - SlaveID byte - DeviceIP string - TCPPort string - Timeout time.Duration -} - -// ModbusRTU is the configurations of modbus RTU. -type ModbusRTU struct { - SlaveID byte - SerialName string - BaudRate int - DataBits int - StopBits int - Parity string - RS485Enabled bool - Timeout time.Duration -} - -// ModbusClient is the structure for modbus client. -type ModbusClient struct { - Client modbus.Client - Handler interface{} - Config interface{} - - mu sync.Mutex -} - -/* -* In modbus RTU mode, devices could connect to one serial port on RS485. However, -* the serial port doesn't support paralleled visit, and for one tcp device, it also doesn't support -* paralleled visit, so we expect one client for one port. - */ -var clients map[string]*ModbusClient - -func newTCPClient(config ModbusTCP) *ModbusClient { - addr := config.DeviceIP + ":" + config.TCPPort - - if client, ok := clients[addr]; ok { - return client - } - - if clients == nil { - clients = make(map[string]*ModbusClient) - } - - handler := modbus.NewTCPClientHandler(addr) - handler.Timeout = config.Timeout - handler.IdleTimeout = config.Timeout - handler.SlaveId = config.SlaveID - client := ModbusClient{Client: modbus.NewClient(handler), Handler: handler, Config: config} - clients[addr] = &client - return &client -} - -func newRTUClient(config ModbusRTU) *ModbusClient { - if client, ok := clients[config.SerialName]; ok { - return client - } - - if clients == nil { - clients = make(map[string]*ModbusClient) - } - - handler := modbus.NewRTUClientHandler(config.SerialName) - handler.BaudRate = config.BaudRate - handler.DataBits = config.DataBits - handler.Parity = parity(config.Parity) - handler.StopBits = config.StopBits - handler.SlaveId = config.SlaveID - handler.Timeout = config.Timeout - handler.IdleTimeout = config.Timeout - handler.RS485.Enabled = config.RS485Enabled - client := ModbusClient{Client: modbus.NewClient(handler), Handler: handler, Config: config} - clients[config.SerialName] = &client - return &client -} - -// NewClient allocate and return a modbus client. -// Client type includes TCP and RTU. -func NewClient(config interface{}) (*ModbusClient, error) { - switch c := config.(type) { - case ModbusTCP: - return newTCPClient(c), nil - case ModbusRTU: - return newRTUClient(c), nil - default: - return &ModbusClient{}, errors.New("Wrong modbus type") - } -} - -// GetStatus get device status. -// Now we could only get the connection status. -func (c *ModbusClient) GetStatus() string { - c.mu.Lock() - defer c.mu.Unlock() - - err := c.Client.Connect() - if err == nil { - return DEVSTOK - } - return DEVSTDISCONN -} - -// Get get register. -func (c *ModbusClient) Get(registerType string, addr uint16, quantity uint16) (results []byte, err error) { - c.mu.Lock() - defer c.mu.Unlock() - - switch registerType { - case "CoilRegister": - results, err = c.Client.ReadCoils(addr, quantity) - case "DiscreteInputRegister": - results, err = c.Client.ReadDiscreteInputs(addr, quantity) - case "HoldingRegister": - results, err = c.Client.ReadHoldingRegisters(addr, quantity) - case "InputRegister": - results, err = c.Client.ReadInputRegisters(addr, quantity) - default: - return nil, errors.New("Bad register type") - } - klog.V(2).Info("Get result: ", results) - return results, err -} - -// Set set register. -func (c *ModbusClient) Set(registerType string, addr uint16, value uint16) (results []byte, err error) { - c.mu.Lock() - defer c.mu.Unlock() - - klog.V(1).Info("Set:", registerType, addr, value) - - switch registerType { - case "CoilRegister": - var valueSet uint16 - switch value { - case 0: - valueSet = 0x0000 - case 1: - valueSet = 0xFF00 - default: - return nil, errors.New("Wrong value") - } - results, err = c.Client.WriteSingleCoil(addr, valueSet) - case "HoldingRegister": - results, err = c.Client.WriteSingleRegister(addr, value) - default: - return nil, errors.New("Bad register type") - } - klog.V(1).Info("Set result:", err, results) - return results, err -} - -// parity convert into the format that modbus drvier requires. -func parity(ori string) string { - var p string - switch ori { - case "even": - p = "E" - case "odd": - p = "O" - default: - p = "N" - } - return p -} diff --git a/mappers/modbus-go/driver/client_test.go b/mappers/modbus-go/driver/client_test.go deleted file mode 100644 index d960df240..000000000 --- a/mappers/modbus-go/driver/client_test.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// This application needs physical devices. -// Please edit by demand for testing. - -package driver - -import ( - "fmt" - "os" - "time" -) - -func tdriver() { - var modbusrtu ModbusRTU - - modbusrtu.SerialName = "/dev/ttyS0" - modbusrtu.BaudRate = 9600 - modbusrtu.DataBits = 8 - modbusrtu.StopBits = 1 - modbusrtu.SlaveID = 1 - modbusrtu.Parity = "N" - modbusrtu.Timeout = 2 * time.Second - - client, err := NewClient(modbusrtu) - if err != nil { - fmt.Println("New client error") - os.Exit(1) - } - - results, err := client.Set("DiscreteInputRegister", 2, 1) - if err != nil { - fmt.Println(err) - } - fmt.Println(results) - results, err = client.Set("CoilRegister", 2, 1) - if err != nil { - fmt.Println(err) - } - fmt.Println(results) - os.Exit(0) -} - -func main() { - /* - var modbustcp ModbusTCP - - modbustcp.DeviceIp = "192.168.56.1" - modbustcp.TcpPort = "502" - modbustcp.SlaveId = 0x1 - client := NewClient(modbustcp) - if client == nil { - fmt.Println("New client error") - os.Exit(1) - } - fmt.Println("status: ", client.GetStatus()) - - results, err := client.Client.ReadDiscreteInputs(0, 1) - if err != nil { - fmt.Println("Read error: ", err) - os.Exit(1) - } - fmt.Println("result: ", results) - */ - tdriver() - os.Exit(0) -} diff --git a/mappers/modbus-go/driver/const.go b/mappers/modbus-go/driver/const.go deleted file mode 100644 index a5e1fb581..000000000 --- a/mappers/modbus-go/driver/const.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package driver - -// Device status definition. -const ( - DEVSTOK = "OK" - DEVSTERR = "ERROR" /* Expected value is not equal as setting */ - DEVSTDISCONN = "DISCONNECTED" /* Disconnected */ - DEVSTUNHEALTHY = "UNHEALTHY" /* Unhealthy status from device */ - DEVSTUNKNOWN = "UNKNOWN" -) diff --git a/mappers/modbus-go/globals/globals.go b/mappers/modbus-go/globals/globals.go deleted file mode 100644 index 11c5f1079..000000000 --- a/mappers/modbus-go/globals/globals.go +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package globals - -import ( - mappercommon "github.com/kubeedge/kubeedge/mappers/common" - "github.com/kubeedge/kubeedge/mappers/modbus-go/driver" -) - -// ModbusDev is the modbus device configuration and client information. -type ModbusDev struct { - Instance mappercommon.DeviceInstance - ModbusClient *driver.ModbusClient -} - -var MqttClient mappercommon.MqttClient diff --git a/mappers/modbus-go/main.go b/mappers/modbus-go/main.go deleted file mode 100644 index ff6e84fc2..000000000 --- a/mappers/modbus-go/main.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright 2020 The KubeEdge Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "os" - - "k8s.io/klog/v2" - - mappercommon "github.com/kubeedge/kubeedge/mappers/common" - "github.com/kubeedge/kubeedge/mappers/modbus-go/device" - "github.com/kubeedge/kubeedge/mappers/modbus-go/globals" -) - -func main() { - var err error - var config Config - - klog.InitFlags(nil) - defer klog.Flush() - - if err = config.Parse(); err != nil { - klog.Fatal(err) - os.Exit(1) - } - klog.V(4).Info(config.Configmap) - - globals.MqttClient = mappercommon.MqttClient{IP: config.Mqtt.ServerAddress, - User: config.Mqtt.Username, - Passwd: config.Mqtt.Password, - Cert: config.Mqtt.Cert, - PrivateKey: config.Mqtt.PrivateKey} - if err = globals.MqttClient.Connect(); err != nil { - klog.Fatal(err) - os.Exit(1) - } - - if err = device.DevInit(config.Configmap); err != nil { - klog.Fatal(err) - os.Exit(1) - } - device.DevStart() -} diff --git a/mappers/modbus_mapper/Dockerfile b/mappers/modbus_mapper/Dockerfile deleted file mode 100644 index d62599bc0..000000000 --- a/mappers/modbus_mapper/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM alpine:latest - -COPY src/ /opt/src -COPY conf/ /opt/src/conf -COPY scripts/ /opt/scripts - -RUN chmod +x /opt/scripts/start_modbusmapper.sh -RUN apk add --update nodejs - -CMD sh /opt/scripts/start_modbusmapper.sh diff --git a/mappers/modbus_mapper/Makefile b/mappers/modbus_mapper/Makefile deleted file mode 100644 index 5b1fecffa..000000000 --- a/mappers/modbus_mapper/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -#make modbus_mapper -.PHONY: default modbus_mapper -modbus_mapper: - cd src && npm install --unsafe-perm=true - docker build -t modbus_mapper:v1.0 . diff --git a/mappers/modbus_mapper/OWNERS b/mappers/modbus_mapper/OWNERS deleted file mode 100644 index 4c7aa6d14..000000000 --- a/mappers/modbus_mapper/OWNERS +++ /dev/null @@ -1,10 +0,0 @@ -approvers: - - edisonxiang - - kevin-wangzefeng - - rohitsardesai83 -reviewers: - - edisonxiang - - fisherxu - - kevin-wangzefeng - - RicardoZPHuang - - rohitsardesai83 diff --git a/mappers/modbus_mapper/README.md b/mappers/modbus_mapper/README.md deleted file mode 100644 index 476e11948..000000000 --- a/mappers/modbus_mapper/README.md +++ /dev/null @@ -1,4 +0,0 @@ - -# Modbus Mapper - -- Click [here](../../docs/components/mappers/modbus_mapper.md#modbus-mapper) for detailed documentation of the modbus mapper. diff --git a/mappers/modbus_mapper/conf/conf.json b/mappers/modbus_mapper/conf/conf.json deleted file mode 100644 index 5d80341b8..000000000 --- a/mappers/modbus_mapper/conf/conf.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "mqtt_port": {CONNECTOR_MQTT_PORT}, - "mqtt_ip": "{CONNECTOR_MQTT_IP}", - "dpl_name": "{CONNECTOR_DPL_NAME}", - "log_level": "info" -} diff --git a/mappers/modbus_mapper/deployment.yaml b/mappers/modbus_mapper/deployment.yaml deleted file mode 100644 index a024235a7..000000000 --- a/mappers/modbus_mapper/deployment.yaml +++ /dev/null @@ -1,39 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: modbus-device-mapper-deployment -spec: - replicas: 1 - selector: - matchLabels: - app: modbus-mapper - template: - metadata: - labels: - app: modbus-mapper - spec: - hostNetwork: true - containers: - - name: modbus-mapper-container - image: <your_dockerhub_username>/modbus_mapper:v1.0 - env: - - name: CONNECTOR_MQTT_PORT - value: "1883" - - name: CONNECTOR_MQTT_IP - value: 127.0.0.1 - - name: CONNECTOR_DPL_NAME - value: dpl/deviceProfile.json - imagePullPolicy: IfNotPresent - securityContext: - privileged: true - volumeMounts: - - name: dpl-config-volume - mountPath: /opt/src/dpl - nodeSelector: - modbus: "true" - volumes: - - name: dpl-config-volume - configMap: - name: device-profile-config-<edge_node_name> - restartPolicy: Always - diff --git a/mappers/modbus_mapper/dpl/deviceProfile.json b/mappers/modbus_mapper/dpl/deviceProfile.json deleted file mode 100644 index 843024f1f..000000000 --- a/mappers/modbus_mapper/dpl/deviceProfile.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "deviceInstances": [{ - "id": "f81e1dce-8152-4f76-b673-d6728b46e395", - "name": "modbus-mock-instance-01", - "model": "modbus-mock-model", - "protocol": "modbus-tcp-01" - }], - "deviceModels": [{ - "properties": [{ - "name": "temperature", - "minimum": 0, - "maximum": 100, - "dataType": "int", - "accessMode": "rw" - }], - "name": "modbus-mock-model", - "description": null - }], - "propertyVisitors": [{ - "visitorConfig": { - "index": 0, - "scale": 1.0, - "isRegisterSwap": true, - "register": "HoldingRegister", - "offset": 1, - "isSwap": false, - "limit": 1 - }, - "propertyName": "temperature", - "modelName": "modbus-mock-model", - "protocol": "modbus", - "name": "temperature" - }], - "protocols": [{ - "protocol_config": { - "ip": "127.0.0.1", - "port": 5028, - "slaveID": 1 - }, - "protocol": "modbus-tcp", - "name": "modbus-tcp-01" - }] -} diff --git a/mappers/modbus_mapper/sample/sample_server.js b/mappers/modbus_mapper/sample/sample_server.js deleted file mode 100644 index 79341ab76..000000000 --- a/mappers/modbus_mapper/sample/sample_server.js +++ /dev/null @@ -1,33 +0,0 @@ -// create an empty modbus client -const ModbusRTU = require("modbus-serial"); -var holdingValue = 5 -var coilValue = false -var vector = { - getHoldingRegister: function() { - return holdingValue; - }, - getCoil: function() { - return coilValue; - }, - setRegister: function(addr, value, unitID) { - // Asynchronous handling supported also here - console.log("set register", addr, value, unitID); - holdingValue = value; - return; - }, - setCoil: function(addr, value, unitID) { - // Asynchronous handling supported also here - console.log("set coil", addr, value, unitID); - coilValue = Boolean(value); - return; - }, -}; - -// set the server to answer for modbus requests -console.log("ModbusTCP listening on modbus://127.0.0.1:5028"); -var serverTCP = new ModbusRTU.ServerTCP(vector, { host: "0.0.0.0", port: 5028, debug: true, unitID: 1 }); - -serverTCP.on("socketError", function(err){ - // Handle socket error if needed, can be ignored - console.error(err); -});
\ No newline at end of file diff --git a/mappers/modbus_mapper/scripts/start_modbusmapper.sh b/mappers/modbus_mapper/scripts/start_modbusmapper.sh deleted file mode 100755 index 80c0dd1b1..000000000 --- a/mappers/modbus_mapper/scripts/start_modbusmapper.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -CONFIG_DIR=/opt/src/conf - -for VAR in $(env) -do - if [[ ! -z "$(echo $VAR | grep -E '^CONNECTOR_')" ]]; then - VAR_NAME=$(echo "$VAR" | sed -r "s/([^=]*)=.*/\1/g") - echo "$VAR_NAME=$(eval echo \$$VAR_NAME)" - sed -i "s#{$VAR_NAME}#$(eval echo \$$VAR_NAME)#g" $CONFIG_DIR/conf.json - fi -done - -cd /opt/src -node index.js diff --git a/mappers/modbus_mapper/src/common.js b/mappers/modbus_mapper/src/common.js deleted file mode 100644 index 400848d62..000000000 --- a/mappers/modbus_mapper/src/common.js +++ /dev/null @@ -1,93 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const util = require('util'); -const mkdirp = require('mkdirp'); - -// bitArrayToInt change bit array to Int -function bitArrayToInt(bitArr, callback) { - let bitStr = ''; - if (bitArr.length > 0 && bitArr.length < 64) { - for (let i = 0; i < bitArr.length; i++){ - bitStr = bitStr + bitArr[i].toString(); - } - num = parseInt(bitStr,2); - callback(num); - } -} - -// byteArrayToInt change one byte array to Int -function byteArrayToInt(byteArr, callback) { - let bitArr = ''; - if (byteArr.length > 0 && byteArr.length < 5){ - for (let i = 0; i < byteArr.length; i++){ - bitArr = bitArr + (byteArr[i]).toString(2).padStart(8, '0'); - } - callback(parseInt(bitArr, 2)); - } -} - -// twoByteArrayToInt change two byte array to Int -function twoByteArrayToInt(byteArr, callback) { - let bitArr = ''; - if (byteArr.length > 0 && byteArr.length < 5){ - for (let i = 0; i < byteArr.length; i++){ - bitArr = bitArr + (byteArr[i]).toString(2).padStart(16, '0'); - } - callback(parseInt(bitArr, 2)); - } -} - -// IntToByteArray change Int to byte array -function IntToByteArray(value, callback) { - if ((value).toString(2).length > 32){ - let cs1 = (value).toString(2).slice(0,(value).toString(2).length-32); - let cs2 = (value).toString(2).slice((value).toString(2).length-32); - Int32ToByte(parseInt(cs1, 2), (arr1)=>{ - Int32ToByte(parseInt(cs2, 2), (arr2)=>{ - arr1 = arr1.concat(arr2); - callback(arr1); - }); - }); - } else { - Int32ToByte(value, (arr)=>{ - callback(arr); - }); - } -} - -// Int32ToByte change Int32 num to byte array -function Int32ToByte(value, callback) { - let byteArr = []; - for (let i = 16; i >= 0; i = i - 16) { - if((value >> i & 0xffff) != 0) { - byteArr.push(value >> i & 0xffff); - } - } - callback(byteArr); -} - -// switchRegister reverse the order of array -function switchRegister(data, callback) { - let switchData = []; - for (let i = 0; i < data.length/2; i++) { - switchData[i] = data[data.length-i-1]; - switchData[data.length-i-1] = data[i]; - } - callback(switchData) -} - -// switchByte exchange lower and higher byte value of two byte data -function switchByte(data, callback){ - let switchData = []; - let InternalData = []; - for (let i = 0; i < data.length; i++){ - InternalData[0] = data[i] & 0xff; - InternalData[1] = data[i] >> 8 & 0xff; - byteArrayToInt(InternalData, (bitarr)=>{ - switchData[i] = bitarr; - }); - } - callback(switchData) -} - -module.exports = {bitArrayToInt, byteArrayToInt, IntToByteArray, switchRegister, switchByte, twoByteArrayToInt}; diff --git a/mappers/modbus_mapper/src/constant.js b/mappers/modbus_mapper/src/constant.js deleted file mode 100644 index 39193fe85..000000000 --- a/mappers/modbus_mapper/src/constant.js +++ /dev/null @@ -1,17 +0,0 @@ -const defaultTopicPrefix = '$hw/events/device/'; -const defaultDirectTopicPrefix = '$hw/devices/'; -const twinDeltaTopic = defaultTopicPrefix + '+/twin/update/delta'; -const twinUpdateTopic = '/twin/update'; -const twinGetResTopic = defaultTopicPrefix + '+/twin/get/result'; -const twinGetTopic = '/twin/get'; -const directGetTopic = '/events/properties/get'; - -module.exports = { - twinDeltaTopic, - twinUpdateTopic, - defaultTopicPrefix, - defaultDirectTopicPrefix, - directGetTopic, - twinGetTopic, - twinGetResTopic -}; diff --git a/mappers/modbus_mapper/src/devicetwin.js b/mappers/modbus_mapper/src/devicetwin.js deleted file mode 100644 index 5f8dc3fc5..000000000 --- a/mappers/modbus_mapper/src/devicetwin.js +++ /dev/null @@ -1,230 +0,0 @@ -const constant = require('./constant'); -const common = require('./common'); -const Buffer = require('buffer').Buffer; -const uuidv4 = require('uuid/v4'); -const util = require('util'); -const async = require('async'); - -class DeviceTwin { - constructor(mqttClient) { - this.mqttClient = mqttClient; - } - - // transferType transfer data according to the dpl configuration - transferType(visitor, property, data, callback) { - let transData; - async.waterfall([ - function(callback) { - if (visitor.visitorConfig.isRegisterSwap) { - common.switchRegister(data, (switchedData)=>{ - callback(null, switchedData); - }); - } else { - callback(null, data); - } - }, - function(internalData, callback) { - if (visitor.visitorConfig.isSwap && (visitor.visitorConfig.register === 'HoldingRegister' || visitor.visitorConfig.register === 'InputRegister')) { - common.switchByte(internalData, (switchedData)=>{ - callback(null, switchedData); - }); - } else { - callback(null, internalData); - } - } - ], function(err, transedData) { - transData = transedData; - }); - this.transferDataType(visitor, property, transData, callback); - } - - // transferDataType transfer data according to the dpl configuration - transferDataType(visitor, property, data, callback) { - let transData; - switch(property.dataType) { - case 'int': - case 'float': - if (visitor.visitorConfig.register === 'DiscreteInputRegister' || visitor.visitorConfig.register === 'CoilRegister') { - common.bitArrayToInt(data, (num)=>{ - transData = num; - }); - } else if (visitor.visitorConfig.register === 'HoldingRegister' || visitor.visitorConfig.register === 'InputRegister') { - common.twoByteArrayToInt(data, (num)=>{ - transData = num; - }) - } - - if (visitor.visitorConfig.scale !=0 && transData != null) { - transData = transData * visitor.visitorConfig.scale; - } - - if (property.dataType === 'int') { - transData = parseInt(transData); - } - - if (property.maximum !== null && transData > parseFloat(property.maximum)) { - logger.info("read data is larger than max value, use max value") - transData = parseInt(property.maximum); - } else if (property.minimum !== null && transData < parseFloat(property.minimum)) { - logger.info("read data is smaller than min value, use min value") - transData = parseInt(property.minimum); - } - - callback(transData); - break; - case 'string': - let buf = new Buffer.from(data); - transData = buf.toString('utf8') - callback(transData); - break; - case 'boolean': - if (data[0] == 0 || data[0] == 1){ - transData = Boolean(data[0]); - } else { - transData = null; - } - callback(transData); - break; - default: - logger.error('unknown dataType: ', property.dataType); - callback(null); - break; - } - } - - // updateActual update actual value to edge mqtt - updateActual(deviceID, property, value) { - let reply_msg = { - event_id: "", - timestamp: new Date().getTime() - }; - let twin = {}; - twin[property.name] = { - actual: { - value: String(value), - metadata: { - timestamp: new Date().getTime() - } - }, - metadata: { - tyep: property.dataType - } - }; - reply_msg.twin = twin; - this.mqttClient.publish(constant.defaultTopicPrefix + deviceID + constant.twinUpdateTopic, JSON.stringify(reply_msg)); - } - - // dealUpdate set latest actual value of devicetwin into actualVal map - dealUpdate(transData, property, deviceID, actualVals) { - if (!actualVals.has(util.format("%s-%s", deviceID, property.name))) { - this.updateActual(deviceID, property, transData); - actualVals.set(util.format("%s-%s", deviceID, property.name), String(transData)); - logger.info("update devicetwin[%s] of device[%s] successfully", property.name, deviceID); - } else { - this.compareActuals(transData, actualVals.get(util.format("%s-%s", deviceID, property.name)), (changed)=>{ - if (changed) { - this.updateActual(deviceID, property, transData); - actualVals.set(util.format("%s-%s", deviceID, property.name), String(transData)); - logger.info("update devicetwin[%s] of device[%s] successfully", property.name, deviceID); - } - }); - } - } - - // getActuals publish get devicetwin msg to edge mqtt - getActuals(deviceID) { - let payload_msg = { - event_id: "", - timestamp: new Date().getTime() - }; - this.mqttClient.publish(constant.defaultTopicPrefix + deviceID + constant.twinGetTopic, JSON.stringify(payload_msg)); - } - - // setActuals set device property and actual value map - setActuals(getMsg, callback) { - let deviceTwin = getMsg.twin; - let PropActuals = new Map(); - Object.keys(deviceTwin).forEach(function(key){ - if (deviceTwin[key].hasOwnProperty('actual')) { - PropActuals.set(key, deviceTwin[key].actual.value); - } - }) - callback(PropActuals); - } - - // setExpecteds set device property and expected value map - setExpecteds(getMsg, callback) { - let deviceTwin = getMsg.twin; - let ProExpect = new Map(); - Object.keys(deviceTwin).forEach(function(key){ - if (deviceTwin[key].hasOwnProperty('expected') && !deviceTwin[key].hasOwnProperty('actual') || JSON.stringify(deviceTwin[key].actual) == '{}') { - ProExpect.set(key, deviceTwin[key].expected.value); - } - }) - callback(ProExpect); - } - - // compareActuals compare if data is changed - compareActuals(data, cachedActuals, callback) { - let changed = false; - if (data != cachedActuals) { - changed = true; - } - callback(changed); - } - - // UpdateDirectActuals update all devicetwin property to edge mqtt - UpdateDirectActuals(devIns, deviceID, actualVals) { - if (devIns.has(deviceID)) { - let deviceName = devIns.get(deviceID).name; - this.generateDirectGetMsg(deviceName, deviceID, actualVals, (directGetMsg)=>{ - this.mqttClient.publish(constant.defaultDirectTopicPrefix + deviceID + constant.directGetTopic, JSON.stringify(directGetMsg)); - }); - } - } - - // generateDirectGetMsg generate Direct Get Msg in message format - generateDirectGetMsg(deviceName, deviceID, actualVals, callback) { - let header = { - msg_id: uuidv4(), - parent_msg_id: "", - timestamp: new Date().getTime(), - sync: false - }; - let route = { - source: "eventbus", - group: "", - operation: "upload", - resource: util.format("%s%s%s", constant.defaultDirectTopicPrefix, deviceID, constant.directGetTopic) - }; - let content = { - data: actualVals, - device_name: deviceName, - device_id: deviceID, - timestamp: new Date().getTime() - }; - let directGetMsg = { - header: header, - route: route, - content: content - }; - callback(directGetMsg); - } - - // syncExpected check whether expected value should be update to device - static syncExpected(delta, key, callback) { - let deviceTwin = delta.twin[key]; - if (!delta.twin.hasOwnProperty(key)) { - logger.error("Invalid device twin ", key); - return; - } - if (!deviceTwin.hasOwnProperty('actual') || - (deviceTwin.hasOwnProperty('expected') && deviceTwin.expected.hasOwnProperty('metadata') && deviceTwin.actual.hasOwnProperty('metadata') && - deviceTwin.expected.metadata.timestamp > deviceTwin.actual.metadata.timestamp && - deviceTwin.expected.value !== deviceTwin.actual.value)) { - callback(deviceTwin.expected.value); - } - } -} - -module.exports = DeviceTwin; diff --git a/mappers/modbus_mapper/src/index.js b/mappers/modbus_mapper/src/index.js deleted file mode 100644 index 2edc685e0..000000000 --- a/mappers/modbus_mapper/src/index.js +++ /dev/null @@ -1,328 +0,0 @@ -const async = require('async'); -const log4js = require('log4js'); -const mqtt = require('mqtt'); -const path = require('path'); -const util = require('util'); - -const common = require('./common'); -const constant = require('./constant'); -const DeviceTwin = require('./devicetwin'); -const Modbus = require('./modbus'); -const WatchFiles = require('./watchfile'); - -//default logger options -log4js.configure({ - appenders: { - out: { type: 'stdout' }, - }, - categories: { - default: { appenders: ['out'], level: 'info' } - } -}); -logger = log4js.getLogger('appenders'); - -let options = { - port: 1883, - host: '127.0.0.1', - dpl_name: 'dpl/deviceProfile.json' -}; - -let mqtt_client, mqtt_client2, msg, mqtt_options, dt, devIns, devMod, devPro, modVistr; -let ActualVal = new Map(); - -async.series([ - //load conf.json - function(callback) { - WatchFiles.loadConfig('conf/conf.json', (err, configs)=>{ - if (err) { - logger.error('failed to load config, err: ', err); - } else { - options = { - port: configs.mqtt_port, - host: configs.mqtt_ip, - dpl_name: configs.dpl_name - }; - callback(err); - } - }); - }, - - //load dpl first time - function(callback) { - WatchFiles.loadDpl(options.dpl_name, (devInsMap, devModMap, devProMap, modVistrMap)=>{ - devIns = devInsMap; - devMod = devModMap; - devPro = devProMap; - modVistr = modVistrMap; - callback(); - }); - }, - - //first get twinget build map - function(callback) { - mqtt_options = { - port: options.port, - host: options.host, - }; - mqtt_client = mqtt.connect(mqtt_options); - dt = new DeviceTwin(mqtt_client); - mqtt_client.on('connect', ()=>{ - logger.info('connetced to edge mqtt with topic twinGet'); - mqtt_client.subscribe(constant.twinGetResTopic); - for (let instance of devIns) { - dt.getActuals(instance[0]); - } - }); - callback(); - }, - - //deal with twin get msg and set expected value into device - function(callback) { - mqtt_client.on('message', (topic, message)=>{ - try { - var msgGet = JSON.parse(message.toString()); - } catch (err) { - logger.error('unmarshal error'); - return; - } - let resources = topic.toString().split('/'); - let deviceID = resources[3]; - let dt = new DeviceTwin(mqtt_client); - let devProtocol, devInstance; - if (devPro.has(deviceID) && devIns.has(deviceID)) { - devProtocol = devPro.get(deviceID); - devInstance = devIns.get(deviceID); - } else { - logger.error('match visitor failed'); - } - logger.info('recieve twinGet msg, set properties actual value map'); - if (resources.length === 7 && resources[5] === 'get' && msgGet != null && msgGet.code != 404 && typeof(devProtocol) != 'undefined' && typeof(devInstance) != 'undefined') { - dt.setActuals(msgGet, (PropActuals)=>{ - for (let actual of PropActuals) { - ActualVal.set(util.format('%s-%s', deviceID, actual[0]), actual[1]); - } - }); - dt.setExpecteds(msgGet, (PropExpecteds)=>{ - for (let expected of PropExpecteds) { - modbusProtocolTransfer(devProtocol.protocol, (transferedProtocol)=>{ - if (modVistr.has(util.format('%s-%s-%s', devInstance.model, expected[0], transferedProtocol))) { - let visitor = modVistr.get(util.format('%s-%s-%s', devInstance.model, expected[0], transferedProtocol)); - dealDeltaMsg(msgGet, expected[0], visitor, devProtocol, expected[1]); - } - }); - } - }); - } - }); - callback(); - }, - - // start mqtt sub delta topic - function(callback) { - mqtt_options = { - port: options.port, - host: options.host, - }; - mqtt_client2 = mqtt.connect(mqtt_options); - mqtt_client2.on('connect', ()=>{ - logger.info('connetced to edge mqtt with topic twinDelta'); - mqtt_client2.subscribe(constant.twinDeltaTopic); - }); - callback(); - }, - - // on receive msg of delta topic - function(callback) { - logger.info('start to wait for devicetwin update'); - mqtt_client2.on('message', (topic, message)=>{ - try { - msg = JSON.parse(message.toString()); - } catch (err) { - logger.error('unmarshal error'); - callback(err); - return; - } - - //match visitors - let resources = topic.toString().split('/'); - let deviceID = resources[3]; - let devProtocol, devInstance; - if (devPro.has(deviceID) && devIns.has(deviceID)) { - devProtocol = devPro.get(deviceID); - devInstance = devIns.get(deviceID); - } else { - logger.error('match visitor failed'); - } - - try { - if (resources.length === 7 && resources[6] === 'delta' && typeof(devProtocol) != 'undefined' && typeof(devInstance) != 'undefined') { - logger.info('recieved twinDelta msg'); - Object.keys(msg.delta).forEach(function(key){ - modbusProtocolTransfer(devProtocol.protocol, (transferedProtocol)=>{ - if (modVistr.has(util.format('%s-%s-%s', devInstance.model, key, transferedProtocol))) { - let visitor = modVistr.get(util.format('%s-%s-%s', devInstance.model, key, transferedProtocol)); - DeviceTwin.syncExpected(msg, key, (value)=>{ - dealDeltaMsg(msg, key, visitor, devProtocol, value); - }); - } - }); - }); - } - } catch (err) { - logger.error('failed to change devicetwin of device[%s], err: ', deviceID, err); - } - }); - } -],function(err) { - if (err) { - logger.error(err); - } else { - logger.info('changed devicetwin successfully'); - } -}); - -let mqtt_client3; -logger.info('start to watch dpl config'); -WatchFiles.watchChange(path.join(__dirname, 'dpl'), ()=>{ - async.series([ - function(callback) { - WatchFiles.loadDpl(options.dpl_name, (devInsMap, devModMap, devProMap, modVistrMap)=>{ - devIns = devInsMap; - devMod = devModMap; - devPro = devProMap; - modVistr = modVistrMap; - callback(); - }); - }, - - function(callback) { - mqtt_options = { - port: options.port, - host: options.host, - }; - mqtt_client3 = mqtt.connect(mqtt_options); - let dt = new DeviceTwin(mqtt_client3); - mqtt_client3.on('connect', ()=>{ - logger.info('connetced to edge mqtt with topic twinGet'); - mqtt_client.subscribe(constant.twinGetResTopic); - for (let instance of devIns) { // let change from var - dt.getActuals(instance[0]); - } - }); - callback(); - }, - - function(callback) { - mqtt_client3.on('message', (topic, message)=>{ - try { - var msgGet = JSON.parse(message.toString()); - } catch (err) { - logger.error('unmarshal error'); - return; - } - let resources = topic.toString().split('/'); - let deviceID = resources[3]; - let devProtocol, devInstance; - if (devPro.has(deviceID) && devIns.has(deviceID)) { - devProtocol = devPro.get(deviceID); - devInstance = devIns.get(deviceID); - } else { - logger.error('match visitor failed'); - } - - let dt = new DeviceTwin(mqtt_client3); - if (resources.length === 7 && resources[5] === 'get' && msgGet != null && msgGet.code != 404 && typeof(devProtocol) != 'undefined' && typeof(devInstance) != 'undefined') { - logger.info('received twinGet message'); - dt.setExpecteds(msgGet, (PropExpecteds)=>{ - for (let expected of PropExpecteds) { - dt.compareActuals(expected[1], ActualVal.get(util.format('%s-%s', deviceID, expected[0])),(changed)=>{ - modbusProtocolTransfer(devProtocol.protocol, (transferedProtocol)=>{ - if (changed && modVistr.has(util.format('%s-%s-%s', devInstance.model, expected[0], transferedProtocol))) { - let visitor = modVistr.get(util.format('%s-%s-%s', devInstance.model, expected[0], transferedProtocol)); - dealDeltaMsg(msgGet, expected[0], visitor, devProtocol, expected[1]); - } - }); - }); - } - }); - } - }); - callback(); - } - ],function(err) { - if (err) { - logger.error('failed to load changed dpl config, err: ', err); - } else { - logger.info('load changed dpl config successfully'); - } - }); -}); - -logger.info('start to check devicetwin state'); -setInterval(()=>{ - let dt = new DeviceTwin(mqtt_client); - logger.info('chechking devicetwin state'); - for (let instance of devIns) { - if (devPro.has(instance[0])) { - let protocol = devPro.get(instance[0]); - let actuals = new Map(); - syncDeviceTwin(dt, instance[0], protocol, actuals); - } - } -}, 2000); - -// syncDeviceTwin check each property of each device according to the dpl configuration -function syncDeviceTwin(dt, key, protocol, actuals) { - async.eachSeries(devMod.get(key).properties, (property, callback)=>{ - let visitor; - if (typeof(protocol) != 'undefined') { - modbusProtocolTransfer(protocol.protocol, (transferedProtocol)=>{ - if (devIns.has(key) && modVistr.has(util.format('%s-%s-%s', devIns.get(key).model, property.name, transferedProtocol))) { - visitor = modVistr.get(util.format('%s-%s-%s', devIns.get(key).model, property.name, transferedProtocol)); - } else { - logger.error('failed to match visitor'); - } - }); - } - if (typeof(protocol) != 'undefined' && typeof(visitor) != 'undefined') { - let modbus = new Modbus(protocol, visitor); - modbus.ModbusUpdate((err, data)=>{ - if (err) { - logger.error('failed to update devicetwin[%s] of device[%s], err: ', property.name, key, err); - } else { - dt.transferType(visitor, property, data, (transData)=>{ - if (transData != null) { - actuals.set(property.name, String(transData)); - dt.dealUpdate(transData, property, key, ActualVal); - } - }); - callback(); - } - }); - } - },()=>{ - dt.UpdateDirectActuals(devIns, key, actuals); - }); -} - -// dealDeltaMsg deal with the devicetwin delta msg -function dealDeltaMsg(msg, key, visitor, protocol, value) { - let modbus = new Modbus(protocol, visitor); - modbus.ModbusDelta(msg.twin[key].metadata.type, value, (err, data)=>{ - if (err) { - logger.error('failed to modify register, err: ', err) - } else { - logger.info('modify register %s successfully', JSON.stringify(data)); - } - }) -} - -function modbusProtocolTransfer(protocol, callback) { - let transferedProtocol; - if (protocol === 'modbus-rtu' || protocol === 'modbus-tcp') { - transferedProtocol = 'modbus'; - } else { - transferedProtocol = protocol; - } - callback(transferedProtocol) -} diff --git a/mappers/modbus_mapper/src/modbus.js b/mappers/modbus_mapper/src/modbus.js deleted file mode 100644 index 5a7631a79..000000000 --- a/mappers/modbus_mapper/src/modbus.js +++ /dev/null @@ -1,204 +0,0 @@ -const ModbusRTU = require('modbus-serial'); -const Buffer = require('buffer').Buffer; -const async = require('async'); -const common = require('./common'); - -class Modbus { - constructor(protocol, visitor){ - this.protocol = protocol; - this.visitor = visitor; - this.client = new ModbusRTU(); - } - - // connect to device with modbus protocol - connect(callback) { - let protocol = this.protocol; - let client = this.client; - switch(protocol.protocol) { - case 'modbus-tcp': - client.connectTCP(protocol.protocolConfig.ip, { port: parseInt(protocol.protocolConfig.port) }, ()=>{ - client.setTimeout(500); - client.setID(parseInt(protocol.protocolConfig.slaveID)); - callback(client); - }); - break; - case 'modbus-rtu': - async.series([ - function(callback) { - setTimeout(function () { - callback(null, null); - }, 100); - }, - function (callback) { - client.connectRTUBuffered(protocol.protocolConfig.serialPort, { baudRate: parseInt(protocol.protocolConfig.baudRate) }, ()=>{ - client.setTimeout(500); - client.setID(parseInt(protocol.protocolConfig.slaveID)); - callback(null, client); - }); - }], (err, res) => {callback(res[1]); - }); - break; - default: - logger.info('unknwon modbus_type ', protocol.protocol); - break; - } - } - - // WriteAction write the value into device registers - WriteAction(value, callback) { - let visitor = this.visitor; - let client = this.client; - switch(visitor.visitorConfig.register){ - case 'CoilRegister': - client.writeCoils(parseInt(visitor.visitorConfig.offset), value, (err, data)=>{ - client.close(); - callback(err, data); - }); - break; - case 'HoldingRegister': - client.writeRegisters(parseInt(visitor.visitorConfig.offset), value, (err, data)=>{ - client.close(); - callback(err, data); - }); - break; - default: - client.close(); - logger.info('write action is not allowed on register type ', visitor.visitorConfig.register) - callback('unkown action', null); - break; - } - } - - // PreWriteAction transfer data before writing data to register - PreWriteAction(type, value, callback) { - let visitor = this.visitor; - let transData; - async.waterfall([ - function(callback) { - switch(type) { - case 'int': - case 'float': - value = parseInt(value); - if (visitor.visitorConfig.register === 'CoilRegister') { - transData = (value).toString(2).split('').map(function(s) { return parseInt(s); }); - } else if (visitor.visitorConfig.register === 'HoldingRegister') { - common.IntToByteArray(value, (byteArr)=>{ - if (byteArr.length < visitor.visitorConfig.limit) { - let zeroArr = new Array(visitor.visitorConfig.limit -byteArr.length).fill(0); - byteArr = zeroArr.concat(byteArr); - transData = byteArr; - } else { - transData = byteArr; - } - }); - } else { - transData = null; - } - callback(null, transData); - break; - case 'string': { - let buf = new Buffer.from(value); - transData = buf.toJSON().data; - callback(null, transData); - break; - } - case 'boolean': - if (value === 'true') { - transData = [1]; - } else if (value === 'false') { - transData = [0]; - } else { - transData = null; - } - callback(null, transData); - break; - default: - transData = null; - callback(null, transData); - break; - } - }, - function(transData, callback) { - if (visitor.visitorConfig.isRegisterSwap && transData != null) { - common.switchRegister(transData, (switchedData)=>{ - callback(null, switchedData); - }); - } else { - callback(null, transData); - } - }, - function(internalData, callback) { - if (visitor.visitorConfig.isSwap && internalData != null && (visitor.visitorConfig.register === 'HoldingRegisters' || visitor.visitorConfig.register === 'CoilsRegisters')) { - common.switchByte(internalData, (switchedData)=>{ - callback(null, switchedData); - }); - } else { - callback(null, internalData); - } - }], function(err, transData) { - callback(transData); - } - ); - } - - // ReadAction read register data from device - ReadAction(callback) { - let visitor = this.visitor; - let client = this.client; - switch (visitor.visitorConfig.register) { - case 'CoilRegister': - client.readCoils(parseInt(visitor.visitorConfig.offset), parseInt(visitor.visitorConfig.limit), (err, data)=>{ - client.close(); - callback(err, err?data:[data.data[0]]); - }); - break; - case 'DiscreteInputRegister': - client.readDiscreteInputs(parseInt(visitor.visitorConfig.offset), parseInt(visitor.visitorConfig.limit), (err, data)=>{ - client.close(); - callback(err, err?data:[data.data[0]]); - }); - break; - case 'HoldingRegister': - client.readHoldingRegisters(parseInt(visitor.visitorConfig.offset), parseInt(visitor.visitorConfig.limit), (err, data)=>{ - client.close(); - callback(err, err?data:data.data); - }); - break; - case 'InputRegister': - client.readInputRegisters(parseInt(visitor.visitorConfig.offset), parseInt(visitor.visitorConfig.limit), (err, data)=>{ - client.close(); - callback(err, err?data:data.data); - }); - break; - default: - client.close(); - logger.info('read action is not allowed on register type ', visitor.visitorConfig.register) - callback('unknown Registers type', null); - break; - } - } - - // ModbusDelta deal with the delta message to modify the register - ModbusDelta(type, value, callback) { - this.connect(()=>{ - this.PreWriteAction(type, value, (transData)=>{ - if (transData != null) { - this.WriteAction(transData, (err, data)=>{ - callback(err, data); - }); - } - }); - }); - } - - // ModbusUpdate deal with the update message to read the register - ModbusUpdate(callback) { - this.connect(()=>{ - this.ReadAction((err, data)=>{ - callback(err, data); - }); - }); - } -} - -module.exports = Modbus; diff --git a/mappers/modbus_mapper/src/package-lock.json b/mappers/modbus_mapper/src/package-lock.json deleted file mode 100644 index 021d58617..000000000 --- a/mappers/modbus_mapper/src/package-lock.json +++ /dev/null @@ -1,1281 +0,0 @@ -{ - "name": "modbus_mapper", - "version": "1.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "@serialport/binding-abstract": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@serialport/binding-abstract/-/binding-abstract-2.0.5.tgz", - "integrity": "sha512-oRg0QRsXJFKHQbQjmo0regKLZ9JhjLmTqc47ocJgYM5UtU9Q1VFrVPh0B2lr2pfm/tr3aNvTLX1eiVAvXyZ/bg==", - "requires": { - "debug": "^4.1.1" - } - }, - "@serialport/binding-mock": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@serialport/binding-mock/-/binding-mock-2.0.5.tgz", - "integrity": "sha512-1kD1qI686pIIolGZ6TPjAtvy8c3XIUlE4OXRZf7ZHaZgGaOUHAUMLKZt4tNTxsfedRTFyiYyHoe5QAbx82R9pQ==", - "requires": { - "@serialport/binding-abstract": "^2.0.5", - "debug": "^4.1.1" - } - }, - "@serialport/bindings": { - "version": "2.0.8", - "resolved": "https://registry.npmjs.org/@serialport/bindings/-/bindings-2.0.8.tgz", - "integrity": "sha512-paKLa9JkoH5FAy2sATTdXLCiKpuKn0pN15/etcCqzX8vi25fnQgJ8Yx9Z6zdbcKe1No7s/9PuH9yfjDR61fbOQ==", - "requires": { - "@serialport/binding-abstract": "^2.0.5", - "@serialport/parser-readline": "^2.0.2", - "bindings": "^1.3.0", - "debug": "^4.1.1", - "nan": "^2.13.2", - "prebuild-install": "^5.2.1" - } - }, - "@serialport/parser-byte-length": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@serialport/parser-byte-length/-/parser-byte-length-2.0.2.tgz", - "integrity": "sha512-cUOprk1uRLucCJy6m+wAM4pwdBaB5D4ySi6juwRScP9DTjKUvGWYj5jzuqvftFBvYFmFza89aLj5K23xiiqj7Q==" - }, - "@serialport/parser-cctalk": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@serialport/parser-cctalk/-/parser-cctalk-2.0.2.tgz", - "integrity": "sha512-5LMysRv7De+TeeoKzi4+sgouD4tqZEAn1agAVevw+7ILM0m30i1zgZLtchgxtCH7OoQRAkENEVEPc0OwhghKgw==" - }, - "@serialport/parser-delimiter": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@serialport/parser-delimiter/-/parser-delimiter-2.0.2.tgz", - "integrity": "sha512-zB02LahFfyZmJqak9l37vP/F1K+KCUxd1KQj35OhD1+0q/unMjVTZmsfkxFSM4gkaxP9j7+8USk+LQJ3V8U26Q==" - }, - "@serialport/parser-readline": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@serialport/parser-readline/-/parser-readline-2.0.2.tgz", - "integrity": "sha512-thL26dGEHB+eINNydJmzcLLhiqcBQkF+wNTbRaYblTP/6dm7JsfjYSud7bTkN63AgE0xpe9tKXBFqc8zgJ1VKg==", - "requires": { - "@serialport/parser-delimiter": "^2.0.2" - } - }, - "@serialport/parser-ready": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@serialport/parser-ready/-/parser-ready-2.0.2.tgz", - "integrity": "sha512-6ynQ+HIIkFQcEO2Hrq4Qmdz+hlJ7kjTHGQ1E7SRN7f70nnys1v3HSke8mjK3RzVw+SwL0rBYjftUdCTrU+7c+Q==" - }, - "@serialport/parser-regex": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@serialport/parser-regex/-/parser-regex-2.0.2.tgz", - "integrity": "sha512-7qjYd7AdHUK8fJOmHpXlMRipqRCVMMyDFyf/5TQQiOt6q+BiFjLOtSpVXhakHwgnXanzDYKeRSB8zM0pZZg+LA==" - }, - "@serialport/stream": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@serialport/stream/-/stream-2.0.5.tgz", - "integrity": "sha512-9gc3zPoAqs/04mvq8TdZ7GxtnacCDuw3/u0u18UXXHgC/5tNDYkY+hXFIJB1fQFnP5yyNB1L2XLfX974ySJg9Q==", - "requires": { - "@serialport/binding-mock": "^2.0.5", - "debug": "^4.1.1" - } - }, - "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" - }, - "anymatch": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.0.3.tgz", - "integrity": "sha512-c6IvoeBECQlMVuYUjSwimnhmztImpErfxJzWZhIQinIvQWoGOnB0dLIgifbPHQt5heS6mNlaZG16f06H3C8t1g==", - "requires": { - "normalize-path": "^3.0.0", - "picomatch": "^2.0.4" - } - }, - "aproba": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==" - }, - "are-we-there-yet": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", - "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", - "requires": { - "delegates": "^1.0.0", - "readable-stream": "^2.0.6" - } - }, - "async": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/async/-/async-3.1.0.tgz", - "integrity": "sha512-4vx/aaY6j/j3Lw3fbCHNWP0pPaTCew3F6F3hYyl/tHs/ndmV1q7NW9T5yuJ2XAGwdQrP+6Wu20x06U4APo/iQQ==" - }, - "async-limiter": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", - "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" - }, - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" - }, - "base64-js": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz", - "integrity": "sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==" - }, - "binary-extensions": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz", - "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==" - }, - "bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "requires": { - "file-uri-to-path": "1.0.0" - } - }, - "bl": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz", - "integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==", - "requires": { - "readable-stream": "^2.3.5", - "safe-buffer": "^5.1.1" - } - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "requires": { - "fill-range": "^7.0.1" - } - }, - "buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz", - "integrity": "sha512-c+Ko0loDaFfuPWiL02ls9Xd3GO3cPVmUobQ6t3rXNUk304u6hGq+8N/kFi+QEIKhzK3uwolVhLzszmfLmMLnqg==", - "requires": { - "base64-js": "^1.0.2", - "ieee754": "^1.1.4" - } - }, - "buffer-alloc": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz", - "integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==", - "requires": { - "buffer-alloc-unsafe": "^1.1.0", - "buffer-fill": "^1.0.0" - } - }, - "buffer-alloc-unsafe": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz", - "integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==" - }, - "buffer-fill": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", - "integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw=" - }, - "buffer-from": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" - }, - "callback-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/callback-stream/-/callback-stream-1.1.0.tgz", - "integrity": "sha1-RwGlEmbwbgbqpx/BcjOCLYdfSQg=", - "requires": { - "inherits": "^2.0.1", - "readable-stream": "> 1.0.0 < 3.0.0" - } - }, - "chokidar": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.0.2.tgz", - "integrity": "sha512-c4PR2egjNjI1um6bamCQ6bUNPDiyofNQruHvKgHQ4gDUP/ITSVSzNsiI5OWtHOsX323i5ha/kk4YmOZ1Ktg7KA==", - "requires": { - "anymatch": "^3.0.1", - "braces": "^3.0.2", - "fsevents": "^2.0.6", - "glob-parent": "^5.0.0", - "is-binary-path": "^2.1.0", - "is-glob": "^4.0.1", - "normalize-path": "^3.0.0", - "readdirp": "^3.1.1" - } - }, - "chownr": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.2.tgz", - "integrity": "sha512-GkfeAQh+QNy3wquu9oIZr6SS5x7wGdSgNQvD10X3r+AZr1Oys22HW8kAmDMvNg2+Dm0TeGaEuO8gFwdBXxwO8A==" - }, - "code-point-at": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" - }, - "commist": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/commist/-/commist-1.1.0.tgz", - "integrity": "sha512-rraC8NXWOEjhADbZe9QBNzLAN5Q3fsTPQtBV+fEVj6xKIgDgNiEVE6ZNfHpZOqfQ21YUzfVNUXLOEZquYvQPPg==", - "requires": { - "leven": "^2.1.0", - "minimist": "^1.1.0" - } - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "requires": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - } - }, - "console-control-strings": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" - }, - "d": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", - "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", - "requires": { - "es5-ext": "^0.10.50", - "type": "^1.0.1" - } - }, - "date-format": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/date-format/-/date-format-2.0.0.tgz", - "integrity": "sha512-M6UqVvZVgFYqZL1SfHsRGIQSz3ZL+qgbsV5Lp1Vj61LZVYuEwcMXYay7DRDtYs2HQQBK5hQtQ0fD9aEJ89V0LA==" - }, - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "requires": { - "ms": "^2.1.1" - } - }, - "decompress-response": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", - "integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=", - "requires": { - "mimic-response": "^1.0.0" - } - }, - "deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" - }, - "delegates": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" - }, - "detect-libc": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", - "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=" - }, - "duplexify": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.7.1.tgz", - "integrity": "sha512-07z8uv2wMyS51kKhD1KsdXJg5WQ6t93RneqRxUHnskXVtlYYkLqM0gqStQZ3pj073g687jPCHrqNfCzawLYh5g==", - "requires": { - "end-of-stream": "^1.0.0", - "inherits": "^2.0.1", - "readable-stream": "^2.0.0", - "stream-shift": "^1.0.0" - } - }, - "end-of-stream": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", - "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", - "requires": { - "once": "^1.4.0" - } - }, - "es5-ext": { - "version": "0.10.50", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.50.tgz", - "integrity": "sha512-KMzZTPBkeQV/JcSQhI5/z6d9VWJ3EnQ194USTUwIYZ2ZbpN8+SGXQKt1h68EX44+qt+Fzr8DO17vnxrw7c3agw==", - "requires": { - "es6-iterator": "~2.0.3", - "es6-symbol": "~3.1.1", - "next-tick": "^1.0.0" - } - }, - "es6-iterator": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", - "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", - "requires": { - "d": "1", - "es5-ext": "^0.10.35", - "es6-symbol": "^3.1.1" - } - }, - "es6-map": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/es6-map/-/es6-map-0.1.5.tgz", - "integrity": "sha1-kTbgUD3MBqMBaQ8LsU/042TpSfA=", - "requires": { - "d": "1", - "es5-ext": "~0.10.14", - "es6-iterator": "~2.0.1", - "es6-set": "~0.1.5", - "es6-symbol": "~3.1.1", - "event-emitter": "~0.3.5" - } - }, - "es6-set": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.5.tgz", - "integrity": "sha1-0rPsXU2ADO2BjbU40ol02wpzzLE=", - "requires": { - "d": "1", - "es5-ext": "~0.10.14", - "es6-iterator": "~2.0.1", - "es6-symbol": "3.1.1", - "event-emitter": "~0.3.5" - } - }, - "es6-symbol": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.1.tgz", - "integrity": "sha1-vwDvT9q2uhtG7Le2KbTH7VcVzHc=", - "requires": { - "d": "1", - "es5-ext": "~0.10.14" - } - }, - "event-emitter": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", - "integrity": "sha1-34xp7vFkeSPHFXuc6DhAYQsCzDk=", - "requires": { - "d": "1", - "es5-ext": "~0.10.14" - } - }, - "expand-template": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", - "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==" - }, - "extend": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" - }, - "file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" - }, - "fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "requires": { - "to-regex-range": "^5.0.1" - } - }, - "flatted": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.1.tgz", - "integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==" - }, - "fs": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", - "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" - }, - "fs-constants": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", - "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" - }, - "fs-extra": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", - "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", - "requires": { - "graceful-fs": "^4.1.2", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" - } - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "fsevents": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.0.7.tgz", - "integrity": "sha512-a7YT0SV3RB+DjYcppwVDLtn13UQnmg0SWZS7ezZD0UjnLwXmy8Zm21GMVGLaFGimIqcvyMQaOJBrop8MyOp1kQ==", - "optional": true - }, - "gauge": { - "version": "2.7.4", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", - "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", - "requires": { - "aproba": "^1.0.3", - "console-control-strings": "^1.0.0", - "has-unicode": "^2.0.0", - "object-assign": "^4.1.0", - "signal-exit": "^3.0.0", - "string-width": "^1.0.1", - "strip-ansi": "^3.0.1", - "wide-align": "^1.1.0" - } - }, - "github-from-package": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", - "integrity": "sha1-l/tdlr/eiXMxPyDoKI75oWf6ZM4=" - }, - "glob": { - "version": "7.1.4", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", - "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "glob-parent": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.0.0.tgz", - "integrity": "sha512-Z2RwiujPRGluePM6j699ktJYxmPpJKCfpGA13jz2hmFZC7gKetzrWvg5KN3+OsIFmydGyZ1AVwERCq1w/ZZwRg==", - "requires": { - "is-glob": "^4.0.1" - } - }, - "glob-stream": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/glob-stream/-/glob-stream-6.1.0.tgz", - "integrity": "sha1-cEXJlBOz65SIjYOrRtC0BMx73eQ=", - "requires": { - "extend": "^3.0.0", - "glob": "^7.1.1", - "glob-parent": "^3.1.0", - "is-negated-glob": "^1.0.0", - "ordered-read-streams": "^1.0.0", - "pumpify": "^1.3.5", - "readable-stream": "^2.1.5", - "remove-trailing-separator": "^1.0.1", - "to-absolute-glob": "^2.0.0", - "unique-stream": "^2.0.2" - }, - "dependencies": { - "glob-parent": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.0.tgz", - "integrity": "sha1-nmr2KZ2NO9K9QEMIMr0RPfkGxa4=", - "requires": { - "is-glob": "^3.1.0", - "path-dirname": "^1.0.0" - } - }, - "is-glob": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz", - "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", - "requires": { - "is-extglob": "^2.1.0" - } - } - } - }, - "graceful-fs": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.0.tgz", - "integrity": "sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==" - }, - "has-unicode": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" - }, - "help-me": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/help-me/-/help-me-1.1.0.tgz", - "integrity": "sha1-jy1QjQYAtKRW2i8IZVbn5cBWo8Y=", - "requires": { - "callback-stream": "^1.0.2", - "glob-stream": "^6.1.0", - "through2": "^2.0.1", - "xtend": "^4.0.0" - } - }, - "ieee754": { - "version": "1.1.13", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", - "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, - "ini": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" - }, - "is-absolute": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-absolute/-/is-absolute-1.0.0.tgz", - "integrity": "sha512-dOWoqflvcydARa360Gvv18DZ/gRuHKi2NU/wU5X1ZFzdYfH29nkiNZsF3mp4OJ3H4yo9Mx8A/uAGNzpzPN3yBA==", - "requires": { - "is-relative": "^1.0.0", - "is-windows": "^1.0.1" - } - }, - "is-binary-path": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", - "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "requires": { - "binary-extensions": "^2.0.0" - } - }, - "is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=" - }, - "is-fullwidth-code-point": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "requires": { - "number-is-nan": "^1.0.0" - } - }, - "is-glob": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", - "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", - "requires": { - "is-extglob": "^2.1.1" - } - }, - "is-negated-glob": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-negated-glob/-/is-negated-glob-1.0.0.tgz", - "integrity": "sha1-aRC8pdqMleeEtXUbl2z1oQ/uNtI=" - }, - "is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" - }, - "is-relative": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-relative/-/is-relative-1.0.0.tgz", - "integrity": "sha512-Kw/ReK0iqwKeu0MITLFuj0jbPAmEiOsIwyIXvvbfa6QfmN9pkD1M+8pdk7Rl/dTKbH34/XBFMbgD4iMJhLQbGA==", - "requires": { - "is-unc-path": "^1.0.0" - } - }, - "is-unc-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-unc-path/-/is-unc-path-1.0.0.tgz", - "integrity": "sha512-mrGpVd0fs7WWLfVsStvgF6iEJnbjDFZh9/emhRDcGWTduTfNHd9CHeUwH3gYIjdbwo4On6hunkztwOaAw0yllQ==", - "requires": { - "unc-path-regex": "^0.1.2" - } - }, - "is-windows": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", - "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==" - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" - }, - "json-stable-stringify-without-jsonify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", - "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=" - }, - "jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", - "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "requires": { - "graceful-fs": "^4.1.6" - } - }, - "leven": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/leven/-/leven-2.1.0.tgz", - "integrity": "sha1-wuep93IJTe6dNCAq6KzORoeHVYA=" - }, - "lodash": { - "version": "4.17.19", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", - "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==" - }, - "log4js": { - "version": "4.5.1", - "resolved": "https://registry.npmjs.org/log4js/-/log4js-4.5.1.tgz", - "integrity": "sha512-EEEgFcE9bLgaYUKuozyFfytQM2wDHtXn4tAN41pkaxpNjAykv11GVdeI4tHtmPWW4Xrgh9R/2d7XYghDVjbKKw==", - "requires": { - "date-format": "^2.0.0", - "debug": "^4.1.1", - "flatted": "^2.0.0", - "rfdc": "^1.1.4", - "streamroller": "^1.0.6" - } - }, - "mimic-response": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", - "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" - }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" - }, - "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" - } - } - }, - "modbus-serial": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/modbus-serial/-/modbus-serial-7.6.0.tgz", - "integrity": "sha512-6gEEdl2p2oVpFvfbjdxmCexPgo/0G8wAlobqwQo+8Zz/T5nqmcP1RhX0xqQuNx2r8SjTFipYNVkIiiFXRmi0Ew==", - "requires": { - "debug": "^4.1.1", - "serialport": "^7.1.3" - } - }, - "mqtt": { - "version": "2.18.8", - "resolved": "https://registry.npmjs.org/mqtt/-/mqtt-2.18.8.tgz", - "integrity": "sha512-3h6oHlPY/yWwtC2J3geraYRtVVoRM6wdI+uchF4nvSSafXPZnaKqF8xnX+S22SU/FcgEAgockVIlOaAX3fkMpA==", - "requires": { - "commist": "^1.0.0", - "concat-stream": "^1.6.2", - "end-of-stream": "^1.4.1", - "es6-map": "^0.1.5", - "help-me": "^1.0.1", - "inherits": "^2.0.3", - "minimist": "^1.2.0", - "mqtt-packet": "^5.6.0", - "pump": "^3.0.0", - "readable-stream": "^2.3.6", - "reinterval": "^1.1.0", - "split2": "^2.1.1", - "websocket-stream": "^5.1.2", - "xtend": "^4.0.1" - }, - "dependencies": { - "pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - } - } - }, - "mqtt-packet": { - "version": "5.6.1", - "resolved": "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-5.6.1.tgz", - "integrity": "sha512-eaF9rO2uFrIYEHomJxziuKTDkbWW5psLBaIGCazQSKqYsTaB3n4SpvJ1PexKaDBiPnMLPIFWBIiTYT3IfEJfww==", - "requires": { - "bl": "^1.2.1", - "inherits": "^2.0.3", - "process-nextick-args": "^2.0.0", - "safe-buffer": "^5.1.0" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - }, - "nan": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", - "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" - }, - "napi-build-utils": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.1.tgz", - "integrity": "sha512-boQj1WFgQH3v4clhu3mTNfP+vOBxorDlE8EKiMjUlLG3C4qAESnn9AxIOkFgTR2c9LtzNjPrjS60cT27ZKBhaA==" - }, - "next-tick": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", - "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" - }, - "node-abi": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.9.0.tgz", - "integrity": "sha512-jmEOvv0eanWjhX8dX1pmjb7oJl1U1oR4FOh0b2GnvALwSYoOdU7sj+kLDSAyjo4pfC9aj/IxkloxdLJQhSSQBA==", - "requires": { - "semver": "^5.4.1" - } - }, - "nodejs-base64": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/nodejs-base64/-/nodejs-base64-1.0.3.tgz", - "integrity": "sha512-6wLDv7N/MfV4wDsrBC2s8xVfx82iywopGLdAVYYTLmwOHTm6N463Dwr9tP4+GHhfTMPN4h9i2Z0LzMdFB2G5cw==" - }, - "noop-logger": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz", - "integrity": "sha1-lKKxYzxPExdVMAfYlm/Q6EG2pMI=" - }, - "normalize-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" - }, - "npmlog": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", - "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", - "requires": { - "are-we-there-yet": "~1.1.2", - "console-control-strings": "~1.1.0", - "gauge": "~2.7.3", - "set-blocking": "~2.0.0" - } - }, - "number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" - }, - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "requires": { - "wrappy": "1" - } - }, - "ordered-read-streams": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/ordered-read-streams/-/ordered-read-streams-1.0.1.tgz", - "integrity": "sha1-d8DLN8QVJdZBZtmQ/61+xqDhNj4=", - "requires": { - "readable-stream": "^2.0.1" - } - }, - "os-homedir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" - }, - "path-dirname": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", - "integrity": "sha1-zDPSTVJeCZpTiMAzbG4yuRYGCeA=" - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" - }, - "picomatch": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.0.7.tgz", - "integrity": "sha512-oLHIdio3tZ0qH76NybpeneBhYVj0QFTfXEFTc/B3zKQspYfYYkWYgFsmzo+4kvId/bQRcNkVeguI3y+CD22BtA==" - }, - "prebuild-install": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-5.3.0.tgz", - "integrity": "sha512-aaLVANlj4HgZweKttFNUVNRxDukytuIuxeK2boIMHjagNJCiVKWFsKF4tCE3ql3GbrD2tExPQ7/pwtEJcHNZeg==", - "requires": { - "detect-libc": "^1.0.3", - "expand-template": "^2.0.3", - "github-from-package": "0.0.0", - "minimist": "^1.2.0", - "mkdirp": "^0.5.1", - "napi-build-utils": "^1.0.1", - "node-abi": "^2.7.0", - "noop-logger": "^0.1.1", - "npmlog": "^4.0.1", - "os-homedir": "^1.0.1", - "pump": "^2.0.1", - "rc": "^1.2.7", - "simple-get": "^2.7.0", - "tar-fs": "^1.13.0", - "tunnel-agent": "^0.6.0", - "which-pm-runs": "^1.0.0" - } - }, - "process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" - }, - "pump": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/pump/-/pump-2.0.1.tgz", - "integrity": "sha512-ruPMNRkN3MHP1cWJc9OWr+T/xDP0jhXYCLfJcBuX54hhfIBnaQmAUMfDcG4DM5UMWByBbJY69QSphm3jtDKIkA==", - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, - "pumpify": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/pumpify/-/pumpify-1.5.1.tgz", - "integrity": "sha512-oClZI37HvuUJJxSKKrC17bZ9Cu0ZYhEAGPsPUy9KlMUmv9dKX2o77RUmq7f3XjIxbwyGwYzbzQ1L2Ks8sIradQ==", - "requires": { - "duplexify": "^3.6.0", - "inherits": "^2.0.3", - "pump": "^2.0.0" - } - }, - "rc": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", - "requires": { - "deep-extend": "^0.6.0", - "ini": "~1.3.0", - "minimist": "^1.2.0", - "strip-json-comments": "~2.0.1" - } - }, - "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "readdirp": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.1.1.tgz", - "integrity": "sha512-XXdSXZrQuvqoETj50+JAitxz1UPdt5dupjT6T5nVB+WvjMv2XKYj+s7hPeAVCXvmJrL36O4YYyWlIC3an2ePiQ==", - "requires": { - "picomatch": "^2.0.4" - } - }, - "reinterval": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/reinterval/-/reinterval-1.1.0.tgz", - "integrity": "sha1-M2Hs+jymwYKDOA3Qu5VG85D17Oc=" - }, - "remove-trailing-separator": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", - "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=" - }, - "rfdc": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.1.4.tgz", - "integrity": "sha512-5C9HXdzK8EAqN7JDif30jqsBzavB7wLpaubisuQIGHWf2gUXSpzy6ArX/+Da8RjFpagWsCn+pIgxTMAmKw9Zug==" - }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - }, - "semver": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==" - }, - "serialport": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/serialport/-/serialport-7.1.5.tgz", - "integrity": "sha512-NplGdqaY+ZL8t3t5egbT+3oqLW4d7WvDT/x1ACxAyWa1fSnx+KTAmlDHeCls39lXwu8voaOr3bPOW4bwM7PdAA==", - "requires": { - "@serialport/binding-mock": "^2.0.5", - "@serialport/bindings": "^2.0.8", - "@serialport/parser-byte-length": "^2.0.2", - "@serialport/parser-cctalk": "^2.0.2", - "@serialport/parser-delimiter": "^2.0.2", - "@serialport/parser-readline": "^2.0.2", - "@serialport/parser-ready": "^2.0.2", - "@serialport/parser-regex": "^2.0.2", - "@serialport/stream": "^2.0.5", - "debug": "^4.1.1" - } - }, - "set-blocking": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" - }, - "signal-exit": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" - }, - "simple-concat": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.0.tgz", - "integrity": "sha1-c0TLuLbib7J9ZrL8hvn21Zl1IcY=" - }, - "simple-get": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-2.8.1.tgz", - "integrity": "sha512-lSSHRSw3mQNUGPAYRqo7xy9dhKmxFXIjLjp4KHpf99GEH2VH7C3AM+Qfx6du6jhfUi6Vm7XnbEVEf7Wb6N8jRw==", - "requires": { - "decompress-response": "^3.3.0", - "once": "^1.3.1", - "simple-concat": "^1.0.0" - } - }, - "split2": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/split2/-/split2-2.2.0.tgz", - "integrity": "sha512-RAb22TG39LhI31MbreBgIuKiIKhVsawfTgEGqKHTK87aG+ul/PB8Sqoi3I7kVdRWiCfrKxK3uo4/YUkpNvhPbw==", - "requires": { - "through2": "^2.0.2" - } - }, - "stream-shift": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.0.tgz", - "integrity": "sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=" - }, - "streamroller": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-1.0.6.tgz", - "integrity": "sha512-3QC47Mhv3/aZNFpDDVO44qQb9gwB9QggMEE0sQmkTAwBVYdBRWISdsywlkfm5II1Q5y/pmrHflti/IgmIzdDBg==", - "requires": { - "async": "^2.6.2", - "date-format": "^2.0.0", - "debug": "^3.2.6", - "fs-extra": "^7.0.1", - "lodash": "^4.17.14" - }, - "dependencies": { - "async": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.2.tgz", - "integrity": "sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==", - "requires": { - "lodash": "^4.17.11" - } - }, - "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", - "requires": { - "ms": "^2.1.1" - } - } - } - }, - "string-width": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "requires": { - "code-point-at": "^1.0.0", - "is-fullwidth-code-point": "^1.0.0", - "strip-ansi": "^3.0.0" - } - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "requires": { - "safe-buffer": "~5.1.0" - } - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "requires": { - "ansi-regex": "^2.0.0" - } - }, - "strip-json-comments": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" - }, - "tar-fs": { - "version": "1.16.3", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-1.16.3.tgz", - "integrity": "sha512-NvCeXpYx7OsmOh8zIOP/ebG55zZmxLE0etfWRbWok+q2Qo8x/vOR/IJT1taADXPe+jsiu9axDb3X4B+iIgNlKw==", - "requires": { - "chownr": "^1.0.1", - "mkdirp": "^0.5.1", - "pump": "^1.0.0", - "tar-stream": "^1.1.2" - }, - "dependencies": { - "pump": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/pump/-/pump-1.0.3.tgz", - "integrity": "sha512-8k0JupWme55+9tCVE+FS5ULT3K6AbgqrGa58lTT49RpyfwwcGedHqaC5LlQNdEAumn/wFsu6aPwkuPMioy8kqw==", - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - } - } - }, - "tar-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.6.2.tgz", - "integrity": "sha512-rzS0heiNf8Xn7/mpdSVVSMAWAoy9bfb1WOTYC78Z0UQKeKa/CWS8FOq0lKGNa8DWKAn9gxjCvMLYc5PGXYlK2A==", - "requires": { - "bl": "^1.0.0", - "buffer-alloc": "^1.2.0", - "end-of-stream": "^1.0.0", - "fs-constants": "^1.0.0", - "readable-stream": "^2.3.0", - "to-buffer": "^1.1.1", - "xtend": "^4.0.0" - } - }, - "through2": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", - "integrity": "sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==", - "requires": { - "readable-stream": "~2.3.6", - "xtend": "~4.0.1" - } - }, - "through2-filter": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/through2-filter/-/through2-filter-3.0.0.tgz", - "integrity": "sha512-jaRjI2WxN3W1V8/FMZ9HKIBXixtiqs3SQSX4/YGIiP3gL6djW48VoZq9tDqeCWs3MT8YY5wb/zli8VW8snY1CA==", - "requires": { - "through2": "~2.0.0", - "xtend": "~4.0.0" - } - }, - "to-absolute-glob": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/to-absolute-glob/-/to-absolute-glob-2.0.2.tgz", - "integrity": "sha1-GGX0PZ50sIItufFFt4z/fQ98hJs=", - "requires": { - "is-absolute": "^1.0.0", - "is-negated-glob": "^1.0.0" - } - }, - "to-buffer": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", - "integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==" - }, - "to-regex-range": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", - "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "requires": { - "is-number": "^7.0.0" - } - }, - "tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", - "requires": { - "safe-buffer": "^5.0.1" - } - }, - "type": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/type/-/type-1.0.1.tgz", - "integrity": "sha512-MAM5dBMJCJNKs9E7JXo4CXRAansRfG0nlJxW7Wf6GZzSOvH31zClSaHdIMWLehe/EGMBkqeC55rrkaOr5Oo7Nw==" - }, - "typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" - }, - "ultron": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", - "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==" - }, - "unc-path-regex": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz", - "integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=" - }, - "unique-stream": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/unique-stream/-/unique-stream-2.3.1.tgz", - "integrity": "sha512-2nY4TnBE70yoxHkDli7DMazpWiP7xMdCYqU2nBRO0UB+ZpEkGsSija7MvmvnZFUeC+mrgiUfcHSr3LmRFIg4+A==", - "requires": { - "json-stable-stringify-without-jsonify": "^1.0.1", - "through2-filter": "^3.0.0" - } - }, - "universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" - }, - "util": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/util/-/util-0.11.1.tgz", - "integrity": "sha512-HShAsny+zS2TZfaXxD9tYj4HQGlBezXZMZuM/S5PKLLoZkShZiGk9o5CzukI1LVHZvjdvZ2Sj1aW/Ndn2NB/HQ==", - "requires": { - "inherits": "2.0.3" - }, - "dependencies": { - "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" - } - } - }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" - }, - "uuid": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", - "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==" - }, - "websocket-stream": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/websocket-stream/-/websocket-stream-5.5.0.tgz", - "integrity": "sha512-EXy/zXb9kNHI07TIMz1oIUIrPZxQRA8aeJ5XYg5ihV8K4kD1DuA+FY6R96HfdIHzlSzS8HiISAfrm+vVQkZBug==", - "requires": { - "duplexify": "^3.5.1", - "inherits": "^2.0.1", - "readable-stream": "^2.3.3", - "safe-buffer": "^5.1.2", - "ws": "^3.2.0", - "xtend": "^4.0.0" - } - }, - "which-pm-runs": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.0.0.tgz", - "integrity": "sha1-Zws6+8VS4LVd9rd4DKdGFfI60cs=" - }, - "wide-align": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", - "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", - "requires": { - "string-width": "^1.0.2 || 2" - } - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" - }, - "ws": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", - "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", - "requires": { - "async-limiter": "~1.0.0", - "safe-buffer": "~5.1.0", - "ultron": "~1.1.0" - } - }, - "xtend": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", - "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" - } - } -} diff --git a/mappers/modbus_mapper/src/package.json b/mappers/modbus_mapper/src/package.json deleted file mode 100644 index 3737905cd..000000000 --- a/mappers/modbus_mapper/src/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "modbus_mapper", - "version": "1.0.0", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "description": "", - "dependencies": { - "async": "3.1.0", - "buffer": "^5.2.1", - "chokidar": "3.0.2", - "fs": "^0.0.1-security", - "log4js": "4.5.1", - "modbus-serial": "^7.4.2", - "mqtt": "^2.18.8", - "nodejs-base64": "^1.0.3", - "util": "^0.11.1", - "uuid": "^3.3.2" - } -} diff --git a/mappers/modbus_mapper/src/watchfile.js b/mappers/modbus_mapper/src/watchfile.js deleted file mode 100644 index c951cca4e..000000000 --- a/mappers/modbus_mapper/src/watchfile.js +++ /dev/null @@ -1,113 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const chokidar = require('chokidar'); -const filename = 'dpl/deviceProfile.json'; -const util = require('util'); - -var devIns = new Map(); -var devMod = new Map(); -var devPro = new Map(); -var modVisitr = new Map(); - -// watchChange monitor dpl configuration file, reload if changed -function watchChange(paths, onChange) { - if (typeof onChange !== 'function') throw Error(`onChange (${onChange}) is not a function`); - - if (!Array.isArray(paths)) paths = [paths]; - - paths.forEach(path => { - if (!(path && fs.existsSync(path))) throw Error(`can't find path ${path}`); - }); - - let watcher = chokidar.watch(paths); - watcher.on('ready', ()=>{ - watcher.on('add', ()=>{ - logger.info('watched file added, load dpl config'); - setTimeout(() => { - onChange(filename); - }, 5000); - }).on('change', ()=> { - logger.info('watched file change, load dpl config'); - setTimeout(() => { - onChange(filename); - }, 5000); - }); - }); -} - -// loadDpl load dpl configuration file -function loadDpl(filename, callback) { - fs.readFile(filename, 'utf-8', (err, data)=>{ - if (err) { - logger.error('load dpl config error: ', err); - } else { - let dplConfigs = JSON.parse(data); - processData(dplConfigs, callback); - } - }); -} - -// loadConfig load mqtt configuration file -function loadConfig(filename, callback) { - fs.readFile(filename, 'utf-8', (err, data)=>{ - if (err) { - logger.error('load config error: ', err); - } else { - let configs = JSON.parse(data); - callback(null, configs); - } - }); -} - -// processData parse dpl config for each deviceInstance -function processData(dplConfigs, callback) { - for (let i = 0; i < dplConfigs.deviceInstances.length; i++) { - buildMaps(dplConfigs, i, (err)=>{ - if (err) { - logger.error('build devIns maps error: ', err) - } - }); - } - for (let i = 0; i < dplConfigs.deviceModels.length; i++) { - for (let j = 0; j < dplConfigs.deviceModels[i].properties.length; j++){ - buildVisitorMaps(dplConfigs, i, j); - } - } - callback(devIns, devMod, devPro, modVisitr); -} - -// buildMaps build three maps 1.map[deviceID]deviceInstance, 2.map[deviceID]deviceModel, 3.map[deviceID]protocol -function buildMaps(dplConfigs, i) { - devIns.set(dplConfigs.deviceInstances[i].id, dplConfigs.deviceInstances[i]); - let foundMod = dplConfigs.deviceModels.findIndex((element)=>{ - return element.name === dplConfigs.deviceInstances[i].model; - }); - if (foundMod != -1) { - devMod.set(dplConfigs.deviceInstances[i].id, dplConfigs.deviceModels[foundMod]); - } else { - logger.error('failed to find model[%s] for deviceid', dplConfigs.deviceModels[i].model); - } - - let foundPro = dplConfigs.protocols.findIndex((element)=>{ - return element.name === dplConfigs.deviceInstances[i].protocol; - }); - if (foundPro != -1) { - devPro.set(dplConfigs.deviceInstances[i].id, dplConfigs.protocols[foundPro]); - } else { - logger.error('failed to find protocol[%s] for deviceid', dplConfigs.deviceModels[i].protocol); - } -} - -// buildVisitorMaps build map[model-property-protocol]propertyVisitor -function buildVisitorMaps(dplConfigs, i, j) { - let foundVisitor = dplConfigs.propertyVisitors.findIndex((element)=>{ - return element.modelName === dplConfigs.deviceModels[i].name && element.propertyName === dplConfigs.deviceModels[i].properties[j].name; - }); - if (foundVisitor != -1) { - modVisitr.set(util.format('%s-%s-%s', dplConfigs.propertyVisitors[foundVisitor].modelName, dplConfigs.propertyVisitors[foundVisitor].propertyName, dplConfigs.propertyVisitors[foundVisitor].protocol), dplConfigs.propertyVisitors[foundVisitor]); - } else { - logger.error('failed to find visitor for model[%s], property[%s]', dplConfigs.deviceModels[i].name, dplConfigs.deviceModels[i].properties[j].name); - } -} - -module.exports = {watchChange, loadDpl, loadConfig}; |
