Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating from master and slave words #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions DeviceAPI/API_rtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def getDataFromDevice(self):
devicedata = dict()
client = connection(self.address, port=502)
client.connect()
result = client.read_input_registers(0, 26, unit=self.slave_id)
result = client.read_input_registers(0, 26, unit=self.subordinate_id)
if int(result.registers[18]) == 32767:
devicedata['temperature'] = None
else:
Expand Down Expand Up @@ -123,12 +123,12 @@ def getDataFromDevice(self):
devicedata['fan_state'] = 'ON'
else:
devicedata['fan_state'] = 'OFF'
result = client.read_holding_registers(129, 1, unit=self.slave_id)
result = client.read_holding_registers(129, 1, unit=self.subordinate_id)
if int(result.registers[0]) > 100:
devicedata['heating'] = 0
else:
devicedata['heating'] = int(result.registers[0])
result = client.read_holding_registers(10, 1, unit=self.slave_id)
result = client.read_holding_registers(10, 1, unit=self.subordinate_id)
if int(result.registers[0]) == 0:
devicedata['cooling_mode'] = 'None'
devicedata['cooling_status'] = 'OFF'
Expand Down Expand Up @@ -170,39 +170,39 @@ def setDeviceData(self, postmsg):
client.connect()
if BEMOSS_ONTOLOGY.HEAT_SETPOINT.NAME in postmsg.keys():
client.write_register(187, int(self.far2cel(float(postmsg.get('heat_setpoint'))) * 100.0),
unit=self.slave_id)
unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.COOL_SETPOINT.NAME in postmsg.keys():
client.write_register(188, int(self.far2cel(float(postmsg.get('cool_setpoint'))) * 100.0),
unit=self.slave_id)
unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.OUTSIDE_DAMPER.NAME in postmsg.keys():
client.write_register(274, int(postmsg.get('outside_damper_position')),
unit=self.slave_id)
unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.DAMPER.NAME in postmsg.keys():
client.write_register(275, int(postmsg.get('bypass_damper_position')),
unit=self.slave_id)
unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.FAN_STATE.NAME in postmsg.keys():
if postmsg.get('fan_state') == 'ON' or postmsg.get('fan_state') == True:
client.write_register(130, 2, unit=self.slave_id)
client.write_register(130, 2, unit=self.subordinate_id)
elif postmsg.get('fan_state') == 'OFF' or postmsg.get('fan_state') == False:
client.write_register(130, 1, unit=self.slave_id)
client.write_register(130, 1, unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.COOLING_STATUS.NAME in postmsg.keys():
if postmsg.get('cooling_status') == 'ON':
client.write_registers(124, [1, 2, 2, 2], unit=self.slave_id)
client.write_registers(124, [1, 2, 2, 2], unit=self.subordinate_id)
elif postmsg.get('cooling_status') == 'OFF':
client.write_registers(124, [0, 1, 1, 1], unit=self.slave_id)
client.write_registers(124, [0, 1, 1, 1], unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.COOLING.NAME in postmsg.keys():
if postmsg.get('cooling_mode') == 'None':
client.write_register(10, 0, unit=self.slave_id)
client.write_register(10, 0, unit=self.subordinate_id)
elif postmsg.get('cooling_mode') == 'STG1':
client.write_register(10, 1, unit=self.slave_id)
client.write_register(10, 1, unit=self.subordinate_id)
elif postmsg.get('cooling_mode') == 'STG2':
client.write_register(10, 2, unit=self.slave_id)
client.write_register(10, 2, unit=self.subordinate_id)
elif postmsg.get('cooling_mode') == 'STG3':
client.write_register(10, 3, unit=self.slave_id)
client.write_register(10, 3, unit=self.subordinate_id)
elif postmsg.get('cooling_mode') == 'STG4':
client.write_register(10, 4, unit=self.slave_id)
client.write_register(10, 4, unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.HEATING.NAME in postmsg.keys():
client.write_register(129, int(postmsg.get('heating')), unit=self.slave_id)
client.write_register(129, int(postmsg.get('heating')), unit=self.subordinate_id)
client.close()
return True
except:
Expand Down
14 changes: 7 additions & 7 deletions DeviceAPI/API_vav.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def getDataFromDevice(self):
devicedata=dict()
client = connection(self.address, port=502)
client.connect()
result = client.read_input_registers(0,8,unit=self.slave_id)
result = client.read_input_registers(0,8,unit=self.subordinate_id)
if int(result.registers[0])==32767:
devicedata["temperature"] = None
else:
Expand All @@ -100,7 +100,7 @@ def getDataFromDevice(self):
devicedata['supply_temperature'] =None
else:
devicedata['supply_temperature']=round(float(self.cel2far(float(int(result.registers[7]))/100.0)),1)
result = client.read_holding_registers(159,2,unit=self.slave_id)
result = client.read_holding_registers(159,2,unit=self.subordinate_id)
if (int(result.registers[0])==1):
devicedata['override']='ON'
else:
Expand All @@ -118,16 +118,16 @@ def setDeviceData(self, postmsg):
client = connection(self.address,port=502)
client.connect()
if BEMOSS_ONTOLOGY.HEAT_SETPOINT.NAME in postmsg.keys():
result=client.write_register(6,int(self.far2cel(float(postmsg.get('heat_setpoint'))* 100.0)),unit=self.slave_id)
result=client.write_register(6,int(self.far2cel(float(postmsg.get('heat_setpoint'))* 100.0)),unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.COOL_SETPOINT.NAME in postmsg.keys():
result2=client.write_register(6,int(self.far2cel(float(postmsg.get('cool_setpoint'))* 100.0)),unit=self.slave_id)
result2=client.write_register(6,int(self.far2cel(float(postmsg.get('cool_setpoint'))* 100.0)),unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.OVERRIDE.NAME in postmsg.keys():
if postmsg.get('override') == 'ON' or postmsg.get('override') == True:
client.write_register(159,1,unit=self.slave_id)
client.write_register(159,1,unit=self.subordinate_id)
elif postmsg.get('override') == 'OFF' or postmsg.get('override') == False:
client.write_register(159,0,unit=self.slave_id)
client.write_register(159,0,unit=self.subordinate_id)
if BEMOSS_ONTOLOGY.FLAP.NAME in postmsg.keys():
client.write_register(160,int(postmsg.get('flap_position')),unit=self.slave_id)
client.write_register(160,int(postmsg.get('flap_position')),unit=self.subordinate_id)
client.close()
return True
except:
Expand Down
2 changes: 1 addition & 1 deletion DeviceAPI/BACnetAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import os
import gevent
from DeviceAPI.BaseAPI import baseAPI
from services.core.MasterDriverAgent.master_driver.driver import DriverAgent
from services.core.MainDriverAgent.main_driver.driver import DriverAgent
from csv import DictWriter
from bacpypes.object import get_datatype
from bacpypes.primitivedata import Enumerated, Unsigned, Boolean, Integer, Real, Double
Expand Down
10 changes: 5 additions & 5 deletions DeviceAPI/ModbusAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self,**kwargs):
if 'address' in self.variables.keys():
address_parts = self.get_variable("address").split(':')
self.address = address_parts[0]
self.slave_id =int(address_parts[1])
self.subordinate_id =int(address_parts[1])
self._debug = True

def discover(self):
Expand All @@ -77,15 +77,15 @@ def discover(self):
data[header].append(value)
except KeyError:
data[header] = [value]
client.slavelist=data["Slave_id"]
client.subordinatelist=data["Subordinate_id"]
device_list=client.discovery()
for address in device_list:
if isinstance(address, dict):
break
else:
slave_id=address.split(':')[1]
for idx, val in enumerate(data["Slave_id"]):
if slave_id==val:
subordinate_id=address.split(':')[1]
for idx, val in enumerate(data["Subordinate_id"]):
if subordinate_id==val:
macaddress = data["MacAddress"][idx]
model = data["ModelName"][idx]
vendor = data["VendorName"][idx]
Expand Down
44 changes: 22 additions & 22 deletions bemoss_lib/protocols/Modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,46 +58,46 @@ def discovery(self):
client = connection(ip, port=502)
client.connect()
result2=None
possible_slave_ids = self.slavelist
for slave_id in possible_slave_ids:
slave_id=int(slave_id)
result = client.read_device_info(slave_id, object_id=0x00)
possible_subordinate_ids = self.subordinatelist
for subordinate_id in possible_subordinate_ids:
subordinate_id=int(subordinate_id)
result = client.read_device_info(subordinate_id, object_id=0x00)
if result is None:
result2 = client.read_input_registers(0, 10, unit=slave_id)
result2 = client.read_input_registers(0, 10, unit=subordinate_id)
if result2 is None:
result2 = client.read_holding_registers(999, 1, unit=slave_id)
result2 = client.read_holding_registers(999, 1, unit=subordinate_id)
if result2 is None:
result2=client.read_discrete_inputs(0,10, unit=slave_id)
result2=client.read_discrete_inputs(0,10, unit=subordinate_id)
if result2 is None:
result2 = client.read_coils(0, 10, unit=slave_id)
result2 = client.read_coils(0, 10, unit=subordinate_id)
if result or result2 is not None:
str_Result = str(result)
str_Result2=str(result2)
try:
match=re.search('Response', str_Result2)
match2 = re.search('IllegalFunction', str_Result)
if match2 or match:
device_list.append(ip + ':' + str(slave_id))
device_list.append(ip + ':' + str(subordinate_id))
continue
else:##reading registers of Result
try:
Vendor=result.information[0]
except:
Vendor="unknown device"
mac=client.read_device_info(slave_id, object_id=0x01)
mac=client.read_device_info(subordinate_id, object_id=0x01)
if mac is not None:
mac=mac.information[0]
else:
mac=slave_id
ModelName= client.read_device_info(slave_id, object_id=0x05)
mac=subordinate_id
ModelName= client.read_device_info(subordinate_id, object_id=0x05)
if ModelName is not None:
ModelName=ModelName.information[0]
else:
ModelName="unknown device"
device_list.append({'address': ip + ':' + str(slave_id), 'mac': mac,
device_list.append({'address': ip + ':' + str(subordinate_id), 'mac': mac,
'model': ModelName, 'vendor': Vendor})
except Exception as er:
print ("problem with slave id " + str(slave_id))
print ("problem with subordinate id " + str(subordinate_id))
print er
else:
pass
Expand All @@ -111,26 +111,26 @@ def discovery(self):
print "Modbus discovery failed: Couldn't find IP subnet of network!"
return device_list

def getDevicedetails(self, slave_id):
def getDevicedetails(self, subordinate_id):

deviceinfo = list()
if slave_id == 7:
if subordinate_id == 7:
macaddress = '30168D000129'
model='VC1000'
vendor='Prolon'
elif slave_id == 1:
elif subordinate_id == 1:
macaddress = '30168D000262'
model = 'VC1000'
vendor = 'Prolon'
elif slave_id == 2:
elif subordinate_id == 2:
macaddress = '30168D000263'
model = 'VC1000'
vendor = 'Prolon'
elif slave_id == 15:
elif subordinate_id == 15:
macaddress = '30168D000130'
model='M1000'
vendor='Prolon'
elif slave_id == 20:
elif subordinate_id == 20:
macaddress = '30168D000264'
model = 'M1000'
vendor = 'Prolon'
Expand All @@ -143,8 +143,8 @@ def getDevicedetails(self, slave_id):

class connection(ModbusTcpClient):

def read_device_info(self,slave,object_id):
def read_device_info(self,subordinate,object_id):

request = ReadDeviceInformationRequest(object_id)
request.unit_id = slave
request.unit_id = subordinate
return self.execute(request)
16 changes: 8 additions & 8 deletions scripts/scalability-testing/config_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import argparse
import itertools
from test_settings import (virtual_device_host, device_types, config_dir,
volttron_install, master_driver_file,
volttron_install, main_driver_file,
host_config_location)

class DeviceConfig(object):
Expand Down Expand Up @@ -195,15 +195,15 @@ def build_all_configs(agent_config, device_type, host_address, count, reg_config

config_list, command_lines = build_device_configs(device_type, host_address, count, reg_config, config_dir, interval, publish_only_depth_all, campus, building)

build_master_config(agent_config, config_dir, config_list,
build_main_config(agent_config, config_dir, config_list,
scalability_test, scalability_test_iterations,
stagger_driver_startup)


def build_master_config(agent_config, config_dir, config_list,
def build_main_config(agent_config, config_dir, config_list,
scalability_test, scalability_test_iterations,
stagger_driver_startup):
"""Takes the input from multiple called to build_device_configs and create the master config."""
"""Takes the input from multiple called to build_device_configs and create the main config."""
configuration = {"driver_config_list": config_list}
configuration['scalability_test'] = scalability_test
configuration['scalability_test_iterations'] = scalability_test_iterations
Expand All @@ -219,20 +219,20 @@ def build_master_config(agent_config, config_dir, config_list,
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Create driver configuration files for scalability test.")
parser.add_argument('--agent-config', metavar='CONFIG_NAME',
help='name of the master driver config file',
default=master_driver_file)
help='name of the main driver config file',
default=main_driver_file)

parser.add_argument('--count', type=int, default=1,
help='number of devices to configure')

parser.add_argument('--scalability-test', action='store_true',
help='Configure master driver for a scalability test')
help='Configure main driver for a scalability test')

parser.add_argument('--publish-only-depth-all', action='store_true',
help='Configure drivers to only publish depth first all.')

parser.add_argument('--stagger-driver-startup', type=float,
help='Configure master driver to stagger driver startup over N seconds.')
help='Configure main driver to stagger driver startup over N seconds.')

parser.add_argument('--scalability-test-iterations', type=int, default=5,
help='Scalability test iterations')
Expand Down
4 changes: 2 additions & 2 deletions scripts/scalability-testing/fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def build_configs():
config_paths.extend(configs)
command_lines.extend(commands)

#config_builder.build_master_config(test_settings.master_driver_file, config_dir, config_paths)
config_builder.build_master_config(test_settings.master_driver_file,
#config_builder.build_main_config(test_settings.main_driver_file, config_dir, config_paths)
config_builder.build_main_config(test_settings.main_driver_file,
config_full_path,
config_paths,
True,
Expand Down
6 changes: 3 additions & 3 deletions scripts/scalability-testing/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@
device_types = {'bacnet': (1, 'device-configs/bacnet_lab.csv'),
'modbus': (1, 'device-configs/catalyst371.csv')}

#Output directory for configurations for the master driver agent
#Output directory for configurations for the main driver agent
# and individual drivers on the local host.
#Directory will be created if it does not exist.
config_dir = "configs"

#Volttron installation directory on virtua_device_host.
volttron_install = "~/volttron"

#Master driver config file name
master_driver_file = "master-driver.agent"
#Main driver config file name
main_driver_file = "main-driver.agent"

#Location of virtual device config files on virtual device host.
#Directory will be created if it does not exist and will
Expand Down
Loading