Exemplo n.º 1
0
 def reader(self, reader):
     if reader is not self._reader:
         if self._reader is not None:
             pyons.remove_entity(self._reader)
         self._reader = reader
         if reader is not None:
             pyons.add_entity(reader)
Exemplo n.º 2
0
 def generator(self, generator):
     if generator is not self._generator:
         if self._generator is not None:
             pyons.remove_entity(self._generator)
         self._generator = generator
         if generator is not None:
             pyons.add_entity(generator)
Exemplo n.º 3
0
 def channel(self, channel):
     if channel is not self._channel:
         if self._channel is not None:
             pyons.remove_entity(self._channel)
         self._channel = channel
         if channel is not None:
             pyons.add_entity(channel)
Exemplo n.º 4
0
 def generate(self, event, source):
     assert source is self and event == "timeout"
     client_id = self.next_client_id
     pyons.info("building a new client #{}".format(client_id), self)
     client = Client(client_id, self.server, self.max_requests,
                     self.request_interval)
     pyons.add_entity(client)
     self.next_timeout_id = pyons.create_timeout(self.timeout, "timeout")
     self.next_client_id += 1
Exemplo n.º 5
0
    def _initialize(self):
        if len(self.antennas) == 0:
            raise RuntimeError("no antennas attached to the reader")
        self._antenna_index = 0
        self._round_index = 0
        self.power_on()
        pyons.add_entity(self.transceiver)

        reader_info = journal.ReaderInfoRecord()
        reader_info.n_antennas = len(self.antennas)
        reader_info.tx_power = self.max_tx_power
        reader_info.circulator_noise = self.circulator_noise
        reader_info.power_switch_enabled = self.switch_power
        reader_info.session_switch_enabled = (
            self.session_strategy == Reader.SessionStrategy.ALTER)
        reader_info.power_on_duration = self.power_on_interval
        reader_info.power_off_duration = self.power_off_interval
        reader_info.n_rounds_per_antenna = self.rounds_per_antenna
        reader_info.n_rounds_per_session = self.rounds_per_inventory_flag
        reader_info.n_slots = 2**self.q
        reader_info.q = self.q
        reader_info.m = self.m
        reader_info.trext = self.trext
        reader_info.dr = self.dr
        reader_info.blf = self.blf
        reader_info.data0 = self.data0
        reader_info.data1 = self.data1
        reader_info.rtcal = self.rtcal
        reader_info.trcal = self.trcal
        journal.Journal().write_reader_info(reader_info)

        for antenna_index in range(0, len(self.antennas)):
            antenna = self.antennas[antenna_index]
            assert isinstance(antenna, phy.ReaderAntenna)
            antenna_info = journal.ReaderAntennaInfoRecord()
            antenna_info.index = antenna_index
            antenna_info.side = antenna.side
            antenna_info.lane = antenna.lane
            antenna_info.position = antenna.position
            antenna_info.forward_dir = np.array(antenna.dir_forward)
            antenna_info.right_dir = np.array(antenna.dir_right)
            antenna_info.gain = antenna.gain
            antenna_info.rp = antenna.rp
            antenna_info.polarization = antenna.polarization
            antenna_info.cable_loss = antenna.cable_loss
            journal.Journal().write_reader_antenna_info(antenna_info)
Exemplo n.º 6
0
 def send(self, frame):
     assert isinstance(self.channel, Channel)
     if len(self._tx_signals) > 0:
         raise RuntimeError("send() while another TX is running")
     peers = self.channel.get_peers(self)
     for peer in peers:
         if peer.node.turned_on:
             signal = Signal(sender=self,
                             receiver=peer,
                             frame=frame,
                             power=self.power,
                             channel=self.channel)
             self._tx_signals.append(signal)
             pyons.add_entity(signal)
     self._tx_end_timeout = pyons.create_timeout(frame.duration, 'tx-end')
     # If start sending, nothing would be received anyway
     for signal in self._rx_signals:
         if signal.state != Signal.State.FINISHED:
             signal.broken = True
Exemplo n.º 7
0
    def _initialize(self):
        self._power_down()
        self.created_at = pyons.time()
        self._last_position_update = pyons.time()
        pyons.add_entity(self.transceiver)

        tag_info = journal.TagInfoRecord()
        tag_info.created_at = pyons.time()
        tag_info.vehicle_id = self.vehicle_id
        tag_info.epc = self.epc
        tag_info.tid = self.tid
        tag_info.location = self.location
        tag_info.antenna_forward_dir = np.array(self.antenna.dir_forward)
        tag_info.antenna_right_dir = np.array(self.antenna.dir_right)
        tag_info.antenna_gain = self.antenna.gain
        tag_info.antenna_polarization = self.antenna.polarization
        tag_info.antenna_rp = self.antenna.rp
        tag_info.sensitivity = self.sensitivity
        tag_info.lane = self.lane
        tag_info.n_epc_read = 0
        tag_info.n_tid_read = 0
        tag_info.modulation_loss = self.transceiver.modulation_loss
        journal.Journal().write_tag_created(tag_info)
Exemplo n.º 8
0
 def add_vehicle(self, vehicle):
     self.vehicles.append(vehicle)
     pyons.add_entity(vehicle)
Exemplo n.º 9
0
 def add_tag(self, tag):
     assert tag.epc not in self.tags
     self._tags[tag.epc] = tag
     pyons.add_entity(tag)
Exemplo n.º 10
0
    @pyons.Entity.finalizer()
    def finish(self):
        pyons.info("===== generator finished:"
                   "\n\t* clients generated: {}".format(self.next_client_id))

    def __str__(self):
        return "Generator"


@pyons.stop_condition()
def check_simulation_time():
    return pyons.time() >= 100


if __name__ == '__main__':
    generation_interval = 2.0
    request_interval = 1.0
    max_requests = 5
    max_clients = 20

    server = Server()
    generator = Generator(generation_interval, server, max_requests,
                          request_interval, max_clients)

    pyons.add_entity(server)
    pyons.add_entity(generator)

    pyons.setup_env(pyons.LogLevel.DEBUG)

    pyons.run(1000)