Skip to content

Commit

Permalink
Merge pull request #15 from vapor-ware/mhink-no-indirect-rs485
Browse files Browse the repository at this point in the history
Remove indirect reads from rs485 devices.
  • Loading branch information
MatthewHink committed Oct 16, 2017
2 parents 8403d15 + 7f604a4 commit 02e4e6d
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 150 deletions.
7 changes: 0 additions & 7 deletions synse/devicebus/devices/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ def __init__(self):
# lookups when routing commands to specific devices.
self.device_uuid = uuid()

# defines a flag that can be checked to see whether the device is configured
# to operate directly (e.g. via the synse application) or indirectly
# (e.g. via a background process). this flag is set on device registration
# if the device is configured with the "from_background" field (default
# False).
self.from_background = False

# the rack id for which the device resides on. initialized as None here, but
# when the subclasses are registered/initialized, they will provide the
# actual rack_id
Expand Down
7 changes: 0 additions & 7 deletions synse/devicebus/devices/i2c/i2c_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ def __init__(self, **kwargs):

self._lock = lockfile.LockFile(self.serial_lock)

# the device is read from a background process
self.from_background = kwargs.get('from_background', False)

# initialize board record -- all subclasses should implement their
# own board record.
self.board_record = None
Expand Down Expand Up @@ -119,10 +116,6 @@ def register(cls, devicebus_config, app_config, app_cache):
i2c_device['device_name'] = rack['device_name']
i2c_device['lockfile'] = rack['lockfile']

# check whether the device is controlled by a background process
# or if directly by the synse app.
i2c_device['from_background'] = rack.get('from_background', False)

# sensor configurations
i2c_device['altitude'] = _altitude_m

Expand Down
33 changes: 1 addition & 32 deletions synse/devicebus/devices/rs485/f660_airflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,38 +128,7 @@ def _read(self, command):
def _read_sensor(self):
""" Convenience method to return the sensor reading.
If the sensor is configured to be read indirectly (e.g. from background)
it will do so -- otherwise, we perform a direct read.
"""
if self.from_background:
return self._indirect_sensor_read()
return self._direct_sensor_read()

def _indirect_sensor_read(self):
"""Read the sensor data from the intermediary data file.
FIXME - reading from file is only for the POC. once we can
confirm that this works and have it stable for the short-term, we
will need to move on to the longer-term plan of having this done
via socket.
Returns:
dict: the thermistor reading value.
"""
logger.debug('indirect_sensor_read')

# If we are not the vec leader we need to redirect this call to the leader.
# The Synse configuration is supposed to be the same for all vecs in the chamber.
if not RS485Device.is_vec_leader():
response = RS485Device.redirect_call_to_vec_leader(request.url)
return {const.UOM_AIRFLOW: response[const.UOM_AIRFLOW]}

data_file = self._get_bg_read_file(str(self.unit), '{0:04x}'.format(self.register_base))
data = F660Airflow.read_sensor_data_file(data_file)
return {const.UOM_AIRFLOW: data[0]}

def _direct_sensor_read(self):
""" Internal method to get and convert the sensor reading.
Read the sensor by hitting the bus.
Returns:
dict: the sensor reading value.
Expand Down
60 changes: 2 additions & 58 deletions synse/devicebus/devices/rs485/gs3_2010_fan_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ def _fan_control(self, action='status', speed_rpm=None):
# Production
# Write speed.
if action == 'set_speed' and speed_rpm is not None:
if self.from_background:
self._write_indirect(speed_rpm)
return {const.UOM_VAPOR_FAN: speed_rpm}

speed_rpm = int(speed_rpm)
self._check_fan_speed_setting(speed_rpm)
self._set_rpm(speed_rpm)
Expand All @@ -269,66 +265,14 @@ def _fan_control(self, action='status', speed_rpm=None):
return {const.UOM_VAPOR_FAN: speed_rpm}

# Read speed.
if self.from_background:
rpm, direction = self._read_indirect()
else:
rpm, direction = self._read_direct()

return {
const.UOM_VAPOR_FAN: rpm,
const.UOM_DIRECTION: direction,
const.UOM_VAPOR_FAN: self._get_rpm(),
const.UOM_DIRECTION: self._get_direction(),
}

raise SynseException(RS485Device.HARDWARE_TYPE_UNKNOWN.format(
self.hardware_type))

def _write_indirect(self, speed_rpm):
""" Indirect write to set the speed on the fan controller.
Args:
speed_rpm: The speed to set in rpm.
"""
# If we are not the vec leader we need to redirect this call to the leader.
# The Synse configuration is supposed to be the same for all vecs in the chamber.
if not RS485Device.is_vec_leader():
RS485Device.redirect_call_to_vec_leader(request.url)
return

data_file = self._get_bg_write_file(str(self.unit), '{0:04x}'.format(self.register_base))
logger.debug('data_file: {}, speed_rpm: {}'.format(data_file, speed_rpm))

with open(data_file, 'w') as f:
f.write(str(speed_rpm))

def _read_indirect(self):
""" Indirect read of the fan controller.
Returns:
A set of (rpm, direction). rpm is an int. direction is forward or reverse.
"""
logger.debug('_read_indirect')

# If we are not the vec leader we need to redirect this call to the leader.
# The Synse configuration is supposed to be the same for all vecs in the chamber.
if not RS485Device.is_vec_leader():
response = RS485Device.redirect_call_to_vec_leader(request.url)
return response[const.UOM_VAPOR_FAN], response[const.UOM_DIRECTION]

data_file = self._get_bg_read_file(str(self.unit), '{0:04x}'.format(self.register_base))
data = GS32010Fan.read_sensor_data_file(data_file)
return (
int(data[0]), # rpm
data[1] # direction
)

def _read_direct(self):
""" Direct read of the fan controller. This read hits the bus.
Returns:
A set of (rpm, direction). rpm is an int. direction is forward or reverse.
"""
return self._get_rpm(), self._get_direction()

def _check_fan_speed_setting(self, speed_rpm):
""" Ensure that the caller's speed_rpm setting is valid.
Expand Down
7 changes: 0 additions & 7 deletions synse/devicebus/devices/rs485/rs485_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ def __init__(self, **kwargs):

self._lock = lockfile.LockFile(self.serial_lock)

# the device is read from a background process
self.from_background = kwargs.get('from_background', False)

# Common RS-485 commands.
self._command_map = {
cid.SCAN: self._scan,
Expand Down Expand Up @@ -125,10 +122,6 @@ def register(cls, devicebus_config, app_config, app_cache):
rs485_device['device_name'] = rack['device_name']
rs485_device['lockfile'] = rack['lockfile']

# check whether the device is controlled by a background process
# or if directly by the synse app.
rs485_device['from_background'] = rack.get('from_background', False)

# since we are unable to import subclasses (circular import), but
# we still need to initialize a subclassed device interface, we
# match the configured 'device_model' with the '_instance_name' of
Expand Down
40 changes: 1 addition & 39 deletions synse/devicebus/devices/rs485/sht31_humidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,45 +127,7 @@ def _read(self, command):
def _read_sensor(self):
""" Convenience method to return the sensor reading.
If the sensor is configured to be read indirectly (e.g. from background)
it will do so -- otherwise, we perform a direct read.
"""
if self.from_background:
return self._indirect_sensor_read()
return self._direct_sensor_read()

def _indirect_sensor_read(self):
"""Read the sensor data from the intermediary data file.
FIXME - reading from file is only for the POC. once we can
confirm that this works and have it stable for the short-term, we
will need to move on to the longer-term plan of having this done
via socket.
Returns:
dict: the thermistor reading value.
"""
logger.debug('indirect_sensor_read')

# If we are not the vec leader we need to redirect this call to the leader.
# The Synse configuration is supposed to be the same for all vecs in the chamber.
if not RS485Device.is_vec_leader():
response = RS485Device.redirect_call_to_vec_leader(request.url)
return {
const.UOM_HUMIDITY: response[const.UOM_HUMIDITY],
const.UOM_TEMPERATURE: response[const.UOM_TEMPERATURE],
}

data_file = self._get_bg_read_file(
str(self.unit), '{0:04x}'.format(self.register_base))
data = SHT31Humidity.read_sensor_data_file(data_file)
return {
const.UOM_TEMPERATURE: data[0],
const.UOM_HUMIDITY: data[1]
}

def _direct_sensor_read(self):
""" Internal method for reading data off of the SHT31 Humidity device.
Read the sensor by hitting the bus.
Returns:
dict: the temperature and humidity reading values.
Expand Down

0 comments on commit 02e4e6d

Please sign in to comment.