Exemple #1
0
 def __init__(
         self,
         table = '1110', # NAND table (a two bit address is expected)
         width = 1,      # data bus width, one bit output
         name  = None):  # device name: None, use generic
     # check if table is a path to the table data
     if not self.tableCheck(table):
         # if table is a path, import table
         table = self.tableImport(table)
     # call parent class constructor
     Device.__init__(self, name)
     # find number of words
     words = ceil(len(table)/width)
     # size in power of 2
     size = ceil(ln(words)/ln(2))
     # complete table up to 2^size
     table += 'U'*(2**size-words)*width
     # record configuration
     self.configuration = size, width, table
     # instantiate output port
     self.Q = outPort(width, "Q")
     # register port
     self.outports.append(self.Q)
     # set default output port value
     self.Q.set(table[0:width])
     # done
     return
Exemple #2
0
    def __init__(
            self,
            size = 4,     # counter width: 4bits, 0 to 15
            name = None): # device name  : None, use generic

        # call Device class constructor
        Device.__init__(self, name)
        # record configuration
        self.configuration = size
        # instantiate output port
        self.Q = outPort(size, "Q")
        # register port
        self.outports.append(self.Q)
        # set output ports value
        self.Q.set(self._randbits(size))
        # done
        return
Exemple #3
0
    def __init__(
        self,
        period=20,  # clock period: 20 ns, 50 MHz
        shift=10,  # phase shift : 10 ns, half period
        width=10,  # pulse width : 10 ns, symmetrical
        count=None,  # number of pulses: None is unlimited
        name=None):  # device name : None is use generic

        # call Device class constructor
        Device.__init__(self, name)
        # record configuration
        self.configuration = period, width, shift, count
        # instantiate output ports
        self.Q = outPort(1, "Q")
        # register port
        self.outports.append(self.Q)
        # compute clock phase
        phase = (0 - shift) % period
        # set output ports value
        self.Q.set(['0', '1'][phase < width])
        # done
        return
Exemple #4
0
def test_find_most_suitable_station() -> None:
    stations = [
        Station(Point(0, 0), 10),
        Station(Point(20, 20), 5),
        Station(Point(10, 0), 12)
    ]
    assert find_most_suitable_station(stations, Device(Point(0, 0))) == \
        StationPower(Station(Point(0, 0), 10), 100.0)

    assert find_most_suitable_station(stations, Device(Point(100,
                                                             100))) is None

    station, power = find_most_suitable_station(stations, Device(Point(15,
                                                                       10)))
    assert station.point == Point(x=10, y=0)
    assert station.reach == 12
    assert round(power, 2) == 0.67

    station, power = find_most_suitable_station(stations, Device(Point(18,
                                                                       18)))
    assert station.point == Point(x=20, y=20)
    assert station.reach == 5
    assert round(power, 2) == 4.72
Exemple #5
0
def parse_eumel_xml():
    #http_packet = requests.get(EUMEL_ENDPOINT, auth=('admin', 'aA123456!'))

    tree = ElementTree.parse(EUMEL_XML)
    tree_root = tree.getroot()
    tree_header = tree_root[0].attrib
    tree_leaves = {child.attrib['id']: child.text for child in tree_root[0][0]}
    parsed_device = Device(manufacturer=tree_header['man'],
                           model=tree_header['mod'],
                           serial_number=tree_header['sn'])
    time_format = '%Y-%m-%dT%H:%M:%SZ'
    converted_epoch_time = int(
        time.mktime(time.strptime(tree_header['t'], time_format)))
    accumulated_measurement_in_watts = int(tree_leaves['TotWhImp'].replace(
        '.', ''))
    parsed_log_entry = LogEntry(epoch=converted_epoch_time,
                                value=accumulated_measurement_in_watts)
    return parsed_device, parsed_log_entry
Exemple #6
0
def device_from_json(point: str) -> Device:
    return Device(Point(*json.loads(point)))
Exemple #7
0
def test_point_from_json():
    assert device_from_json('[0, 0]') == Device(Point(0, 0))
Exemple #8
0
import time
import cv2
# ----------------------------------------
from core import Device
# --------------------------------------------------

camera01 = Device('cap01', '192.168.0.65', 8000, 'admin', 'a1234567')
ret_flag, error_code = camera01.login()
if not ret_flag:
    print(f'{camera01.id} login failed: {error_code} !')
camera02 = Device('cap02', '192.168.0.66', 8000, 'admin', 'a1234567')
ret_flag, error_code = camera02.login()
if not ret_flag:
    print(f'{camera02.id} login failed: {error_code} !')

ret_flag01, error_code01 = camera01.open()
ret_flag02, error_code02 = camera02.open()
if not ret_flag01:
    print(f'{camera01.id} open failed: {error_code01} !')
    exit()
if not ret_flag02:
    print(f'{camera02.id} open failed: {error_code02} !')
    exit()

cv2.namedWindow(camera01.id)
cv2.namedWindow(camera02.id)

count = 0
while True:
    ret_flag01, frame01 = camera01.read()
    ret_flag02, frame02 = camera02.read()
Exemple #9
0
def test_enrich_stations_with_power() -> None:
    stations = [Station(Point(0, 0), 10)]
    device = Device(Point(0, 0))
    assert list(enrich_stations_with_power(
        stations, device)) == [StationPower(Station(Point(0, 0), 10), 100.0)]