Skip to content

Commit

Permalink
Merge pull request #121 from percival-detector/fixtests
Browse files Browse the repository at this point in the history
Fixtests
  • Loading branch information
wnichols1 committed Sep 18, 2020
2 parents 017b716 + 6dab6ad commit aa14b53
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 577 deletions.
1 change: 1 addition & 0 deletions percival/carrier/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, txrx, channel_ini):
self._reg_command = UARTRegister(const.COMMAND)
self._reg_command.initialize_map([0,0,0])
self._reg_command.fields.device_type = self._device_family_features.function.value
# this renaming of channel_index to device_index is dubious.
self._reg_command.fields.device_index = self.channel_index

self._reg_echo = UARTRegister(const.READ_ECHO_WORD)
Expand Down
8 changes: 4 additions & 4 deletions percival/carrier/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def find_file(filename):
search_paths = os.getenv(env_config_dir, "")
if search_paths:
for path in search_paths.split(":"):
fn = os.path.abspath(str(os.path.join(path, filename)))
if os.path.isfile(fn):
return fn
fl = os.path.abspath(str(os.path.join(path, filename)))
if os.path.isfile(fl):
return fl

# All other searches failed. We cant find this file. Raise exception.
raise_with_traceback(IOError(errno.ENOENT, "%s: %s" % (os.strerror(errno.ENOENT), filename)))
Expand Down Expand Up @@ -1037,9 +1037,9 @@ def load_ini(self):

@property
def value_map(self):
# Read out the section General that describes the rest of the file
values = {}
desc = {}
# item will be a tuple (key , value) from the Debug section of the config file
for item in self._conf.items('Debug'):
values[item[0]] = item[1]

Expand Down
13 changes: 7 additions & 6 deletions percival/carrier/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(self, entries, words_per_entry, start_address):
def is_address_valid(self, address):
return self.start_address <= address < (self.start_address + self.words_per_entry * self.entries)


# note CONTROL_SETTINGS, MONITORING_SETTINGS are a misnomer, and should be called
# CONTROL_CHANNELS and MONITORING_CHANNELS
HEADER_SETTINGS_LEFT = UARTBlock(1, 1, 0x0000)
CONTROL_SETTINGS_LEFT = UARTBlock(1, 4, 0x0001)
MONITORING_SETTINGS_LEFT = UARTBlock(1, 4, 0x0005)
Expand Down Expand Up @@ -223,22 +224,22 @@ class DeviceCmd(Enum):
@unique
class DeviceFamily(Enum):
"""Enumeration of the available electronic component families"""
"""Digital potentiometer for control"""
AD5242 = 0
"""Digital potentiometer for control"""
AD5263 = 1
"""Digital potentiometer for control"""
"""DAC for control"""
AD5629 = 2
"""DAC for control"""
AD5669 = 3
"""DAC for control"""
"""ADC for monitoring"""
LTC2309 = 7
"""ADC for monitoring"""
LTC2497 = 4
"""ADC for monitoring"""
MAX31730 = 5
"""Temperature for monitoring"""
AT24CM01 = 6
MAX31730 = 5
"""EEPROM for on-board configuration storage"""
AT24CM01 = 6


@unique
Expand Down
8 changes: 5 additions & 3 deletions percival/carrier/registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def parse_map(self, words):
map_field.extract_field_value(words)

def parse_map_from_tuples(self, tuples):
words = [value for addr, value in tuples]
words = [value for (addr, value) in tuples]
self.parse_map(words)

def generate_map(self):
Expand Down Expand Up @@ -203,6 +203,7 @@ class MonitoringChannelMap(RegisterMap):

def __init__(self):
object.__setattr__(self, '_mem_map', {}) # This prevents infinite recursion when setting attributes
# word, num-bits, lowest-bit
self._mem_map = {"channel_id": MapField("channel_id", 0, 5, 27),
"board_type": MapField("board_type", 0, 3, 24),
"component_family_id": MapField("component_family_id", 0, 4, 20),
Expand Down Expand Up @@ -971,7 +972,8 @@ def generate_register_maps(registers):
"""Provides the connection between raw register maps: list of (addr, data) tuples and
:class:`percival.carrier.registers.RegisterMap` implementations.
:param registers: List of (addr, data) register tuples
:param registers: List of (addr, data) register tuples, consecutive by address,
describing whole registerblocks where they exist - As returned by READ_CONTROL_SOMETHING.
:type registers: list
:returns: A list of :class:`RegisterMap` objects
:rtype: list
Expand All @@ -991,7 +993,7 @@ def generate_register_maps(registers):
continue
(name, readback_addr_block, RegisterMapClass) = CarrierUARTRegisters[uart_block] # pylint: disable=W0612
block_map = RegisterMapClass()
block_words = registers[index:index + block_map.num_words]
block_words = registers[index:(index + block_map.num_words)]
try:
block_map.parse_map_from_tuples(block_words)
except IndexError as e:
Expand Down
90 changes: 7 additions & 83 deletions percival/carrier/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,6 @@ class could instead of taking the number of words, take the actual words and

import logging

class SensorDac(object):
"""
Represent a sensor DAC
"""
def __init__(self, dac_ini):
self._log = logging.getLogger(".".join([__name__, self.__class__.__name__]))
self._log.debug("Sensor DAC created %s", dac_ini)
self._config = dac_ini
self._raw_value = 0

@property
def name(self):
return self._config["Channel_name"]

@property
def buffer_index(self):
return self._config["Buffer_index"]

def set_value(self, value):
self._log.debug("DAC [%s] value set to %d", self._config["Channel_name"], value)
self._raw_value = value

def to_buffer_word(self):
# Raw value is ANDed with number of bits and offset
bit_mask = (2 ** self._config["Bit_size"]) - 1
buffer_value = self._raw_value & bit_mask
buffer_value = buffer_value << self._config["Bit_offset"]
self._log.debug("Buffer value returned %d", buffer_value)
return buffer_value


class Sensor(object):
"""
Expand All @@ -66,51 +36,6 @@ def __init__(self, buffer_cmd):
self._dacs_register_map.parse_map([0, 0, 0, 0, 0, 0, 0])
self._buffer_words = {}

# @property
# def dacs(self):
# return self._dacs

# def add_dac(self, dac_ini):
# """
# Add a DAC to the sensor set.
# :param dac_ini:
# :return:
# """
# # Create the SensorDAC object from the initialisation values
# dac = SensorDac(dac_ini)
# self._log.debug("Adding DAC [%s] to sensor", dac.name)
# self._dacs[dac.name] = dac
# # Keep a list of dac names for each buffer index
# if dac.buffer_index not in self._buffer_words:
# self._buffer_words[dac.buffer_index] = []
#
# # Append the name to the relevant buffer index store
# self._buffer_words[dac.buffer_index].append(dac.name)

# def set_dac(self, dac_name, value):
# """
# Set a DAC value ready for writing to the hardware.
# Sensor DAC values are written by buffer transfer so must all be set prior
# to a write
# :param dac_name:
# :param value:
# :return:
# """
# self._log.debug("Setting sensor DAC [%s] value: %d", dac_name, value)
# if dac_name in self._dacs:
# self._dacs[dac_name].set_value(value)

# def _generate_dac_words(self):
# # Create the set of words ready for the buffer write command
# words = []
# for index in sorted(self._buffer_words):
# word_value = 0
# for dac_name in self._buffer_words[index]:
# word_value += self._dacs[dac_name].to_buffer_word()
#
# words.append(word_value)
# return words

def configuration_values_to_word(self, size, values):
self._log.debug("Combining sensor values into 32 bit word")
# Check how many values can be combined
Expand All @@ -134,13 +59,6 @@ def configuration_values_to_word(self, size, values):
value <<= extra_shift
return value

# def apply_dac_values(self):
# # Generate the words and write to the buffer
# # Send the appropriate buffer command
# words = self._generate_dac_words()
# self._log.debug("Applying sensor DAC values: %s", words)
# self._buffer_cmd.send_dacs_setup_cmd(words)

def apply_dac_values(self, config):
self._log.debug("Sensor DAC configuration: %s", config)
for item in config:
Expand Down Expand Up @@ -217,6 +135,12 @@ def parse_debug_flag(self, flag):
return value

def apply_debug(self, debug):
"""
The documentation says nothing about this; info was gathered on the phone.
It seems that you create a 6-bitmask with
(CLKin, adcCPN, CPNI, sr7SC, SC, dmxSEL) which come from the ini file,
and this is put into all of the 9x5 H0, H1, G slots in the debug block.
"""
self._log.debug("Applying sensor debug: %s", debug)
debug_value = 0
if 'debug_dmxSEL' in debug:
Expand All @@ -231,7 +155,7 @@ def apply_debug(self, debug):
debug_value |= self.parse_debug_flag(debug['debug_adcCPN'])<<4
if 'debug_CLKin' in debug:
debug_value |= self.parse_debug_flag(debug['debug_CLKin'])<<5
self._log.debug("Debug value to set: %d", debug_value)
self._log.debug("Debug value to set: 0x%x", debug_value)
words = []
for index in range(0, 9):
words.append(self.configuration_values_to_word(6, [debug_value,
Expand Down
Loading

0 comments on commit aa14b53

Please sign in to comment.