# Path: zircon/transceivers/dummy.py
# class DummyTransceiver(BaseTransceiver):
# 
#     def __init__(self, signal_name='dummy', data_gen=lambda t: sin(t), dt=0.1):
# 
#         self.dt = dt
#         self.signal_name = signal_name
#         self.data_gen = data_gen
# 
#         self.t = 0
#         self.last = time.time()
# 
#     def open(self):
#         return True
# 
#     def close(self):
#         return True
# 
#     def pause(self):
# 
#         now = time.time()
#         dt_real = now - self.last - self.dt
#         self.t += now - self.last
#         self.last = now
# 
#         to_wait = max(min(self.dt - dt_real, self.dt), 0)
#         time.sleep(to_wait)
# 
#     def read(self):
# 
#         self.pause()
# 
#         timestamp = int(time.time() * 1e6)
#         val = self.data_gen(self.t)
#         return timestamp, self.signal_name, val
# 
#     def write(self, data):
#         print('[WRITE] {}'.format(data))
#         return True
# 
# Path: zircon/publishers/zeromq.py
# class ZMQPublisher(BasePublisher):
# 
#     def __init__(self, host='*', port=8811, zmq_type=zmq.PUB):
# 
#         self.host = host
#         self.port = port
#         self.zmq_type = zmq_type
#         self.URI = 'tcp://{}:{}'.format(self.host, self.port)
# 
#         self.context = zmq.Context()
#         self.sock = self.context.socket(self.zmq_type)
# 
#         self.count = 0
# 
#     def open(self):
#         self.sock.bind(self.URI)
#         return True
# 
#     def close(self):
#         self.sock.close()
#         return True
# 
#     def send(self, msg):
# 
#         try:
#             self.sock.send(msg)
#             self.count += 1
#             print('[SENT] {}'.format(self.count))
#         except TypeError:
#             print('[ERROR] Message fed to Publisher must be serialized!')
#             return False
# 
#         return True
# 
# Path: zircon/reporters/base.py
# class Reporter():
#     """ A Reporter continuously reads data from a Transceiver, feeds it through
#     a row of Transformers, and broadcasts the result using a Publisher.
# 
#     When creating a Reporter, you supply instances of a Transceiver,
#     one or more Transformers, and a Publisher. If not specified,
#     a pickling Transformer and the default Publisher are used.
# 
#     **Usage**::
# 
#         reporter = Reporter(
#             transceiver=MyTransceiver(),
#             transformers=[MyDecoder(), MyCompressor(), ...],
#             publisher=MyPublisher()
#         )
# 
#     A Reporter can be run as its own process::
# 
#         reporter.run()
# 
#     Or stepped through by an external engine::
# 
#         reporter.open()
#         while not done:
#             reporter.step()
#     """
# 
#     def __init__(self, transceiver, transformers=None, publisher=None):
# 
#         self.transceiver = transceiver
# 
#         if transformers:
#             self.transformers = transformers
#         else:
#             self.transformers = [Pickler()]
# 
#         if publisher:
#             self.publisher = publisher
#         else:
#             self.publisher = ZMQPublisher()
# 
#         for i in range(len(self.transformers) - 1):
#             self.transformers[i].set_callback(self.transformers[i+1].push)
# 
#         self.transformers[-1].set_callback(self.publisher.send)
# 
#     def open(self):
#         """ Initialize the Transceiver and Publisher.
#         """
# 
#         success = self.transceiver.open()
#         if not success:
#             return False
# 
#         success = self.publisher.open()
#         if not success:
#             return False
# 
#         return True
# 
#     def step(self):
#         """ Read data and feed it into the first Transformer.
#         """
# 
#         raw_data = self.transceiver.read()
# 
#         if raw_data is not None:
#             self.transformers[0].push(raw_data)
# 
#     def run(self):
#         """ Initialize components and start broadcasting.
#         """
# 
#         success = self.open()
#         if not success:
#             print('Failed to initialize!')
#             return
# 
#         while True:
#             self.step()


from zircon.transceivers.dummy import DummyTransceiver
from zircon.publishers.zeromq import ZMQPublisher
from zircon.reporters.base import Reporter
from zircon.transformers.common import *
from math import sin, pi
"""

"""



# Generated signal
def sine_wave(t):
    return sin(2*pi*t/3.0)

# Sampling frequency
freq = 1000

reporter = Reporter(

# Path: zircon/transceivers/dummy.py
# class DummyTransceiver(BaseTransceiver):
# 
#     def __init__(self, signal_name='dummy', data_gen=lambda t: sin(t), dt=0.1):
# 
#         self.dt = dt
#         self.signal_name = signal_name
#         self.data_gen = data_gen
# 
#         self.t = 0
#         self.last = time.time()
# 
#     def open(self):
#         return True
# 
#     def close(self):
#         return True
# 
#     def pause(self):
# 
#         now = time.time()
#         dt_real = now - self.last - self.dt
#         self.t += now - self.last
#         self.last = now
# 
#         to_wait = max(min(self.dt - dt_real, self.dt), 0)
#         time.sleep(to_wait)
# 
#     def read(self):
# 
#         self.pause()
# 
#         timestamp = int(time.time() * 1e6)
#         val = self.data_gen(self.t)
#         return timestamp, self.signal_name, val
# 
#     def write(self, data):
#         print('[WRITE] {}'.format(data))
#         return True
# 
# Path: zircon/publishers/zeromq.py
# class ZMQPublisher(BasePublisher):
# 
#     def __init__(self, host='*', port=8811, zmq_type=zmq.PUB):
# 
#         self.host = host
#         self.port = port
#         self.zmq_type = zmq_type
#         self.URI = 'tcp://{}:{}'.format(self.host, self.port)
# 
#         self.context = zmq.Context()
#         self.sock = self.context.socket(self.zmq_type)
# 
#         self.count = 0
# 
#     def open(self):
#         self.sock.bind(self.URI)
#         return True
# 
#     def close(self):
#         self.sock.close()
#         return True
# 
#     def send(self, msg):
# 
#         try:
#             self.sock.send(msg)
#             self.count += 1
#             print('[SENT] {}'.format(self.count))
#         except TypeError:
#             print('[ERROR] Message fed to Publisher must be serialized!')
#             return False
# 
#         return True
# 
# Path: zircon/reporters/base.py
# class Reporter():
#     """ A Reporter continuously reads data from a Transceiver, feeds it through
#     a row of Transformers, and broadcasts the result using a Publisher.
# 
#     When creating a Reporter, you supply instances of a Transceiver,
#     one or more Transformers, and a Publisher. If not specified,
#     a pickling Transformer and the default Publisher are used.
# 
#     **Usage**::
# 
#         reporter = Reporter(
#             transceiver=MyTransceiver(),
#             transformers=[MyDecoder(), MyCompressor(), ...],
#             publisher=MyPublisher()
#         )
# 
#     A Reporter can be run as its own process::
# 
#         reporter.run()
# 
#     Or stepped through by an external engine::
# 
#         reporter.open()
#         while not done:
#             reporter.step()
#     """
# 
#     def __init__(self, transceiver, transformers=None, publisher=None):
# 
#         self.transceiver = transceiver
# 
#         if transformers:
#             self.transformers = transformers
#         else:
#             self.transformers = [Pickler()]
# 
#         if publisher:
#             self.publisher = publisher
#         else:
#             self.publisher = ZMQPublisher()
# 
#         for i in range(len(self.transformers) - 1):
#             self.transformers[i].set_callback(self.transformers[i+1].push)
# 
#         self.transformers[-1].set_callback(self.publisher.send)
# 
#     def open(self):
#         """ Initialize the Transceiver and Publisher.
#         """
# 
#         success = self.transceiver.open()
#         if not success:
#             return False
# 
#         success = self.publisher.open()
#         if not success:
#             return False
# 
#         return True
# 
#     def step(self):
#         """ Read data and feed it into the first Transformer.
#         """
# 
#         raw_data = self.transceiver.read()
# 
#         if raw_data is not None:
#             self.transformers[0].push(raw_data)
# 
#     def run(self):
#         """ Initialize components and start broadcasting.
#         """
# 
#         success = self.open()
#         if not success:
#             print('Failed to initialize!')
#             return
# 
#         while True:
#             self.step()


# Path: tests/sample_reporter.py
from zircon.transceivers.dummy import DummyTransceiver
from zircon.publishers.zeromq import ZMQPublisher
from zircon.reporters.base import Reporter
from zircon.transformers.common import *
from math import sin, pi

"""

"""



# Generated signal
def sine_wave(t):
    return sin(2*pi*t/3.0)

# Sampling frequency
freq = 1000

reporter = Reporter(

    transceiver=DummyTransceiver(