def search_sinks():
    while True:
        if IS_WORKING == False:
            print("searching sinks...")
            p = subprocess.Popen(
                "sudo /home/respeaker/snipsAudio/./pulsemixer --get-volume",
                stdout=subprocess.PIPE,
                shell=True)
            (output, err) = p.communicate()
            p_status = p.wait()
            p = subprocess.Popen(
                "sudo /home/respeaker/snipsAudio/./pulsemixer --list",
                stdout=subprocess.PIPE,
                shell=True)
            (output, err) = p.communicate()
            p_status = p.wait()
            lines = output.splitlines()
            for line in lines:
                if line.startswith('Sink input:'):
                    if line.find("snips") == -1:
                        id = find_between(line, "ID: ", ",")
                        SINKS.add(Sink(id, 0))
            for sink in SINKS:
                p = subprocess.Popen(
                    "sudo /home/respeaker/snipsAudio/./pulsemixer --id " +
                    sink.id + " --get-volume",
                    stdout=subprocess.PIPE,
                    shell=True)
                (output, err) = p.communicate()
                p_status = p.wait()
                sink.volume = find_between(output, "", " ")
                print("Sink: " + sink.id + " has volume: " + sink.volume)
Beispiel #2
0
 def run2(self):
     trace('start')
     source = Source()
     translator = Translator(source)
     sink = Sink(translator)
     #exit()
     sink.run()
     trace('end')
Beispiel #3
0
    def run(self):

        address_used_internally = self.config['address_used_internally']
        range_port_init = self.config['internal_range_port']
        
        number_of_filter_scored = self.config['number_of_filter_scored']
        number_of_sum_up_players = self.config['number_of_sum_up_players']
        number_of_filters_columns = self.config['number_of_filters_columns']

        streamer_input = StreamerSubscriber(self.incoming_address, self.incoming_port, address_used_internally, range_port_init, 1, number_of_filters_columns)

        filters_columns = []        
        for i in range(number_of_filters_columns):
            filters_columns.append(FilterColumns(address_used_internally, range_port_init, address_used_internally, range_port_init + 1))
        streamer_filtered_columns = Streamer(address_used_internally, range_port_init + 1, address_used_internally, range_port_init + 2, number_of_filters_columns, number_of_filter_scored)
        
        filters_scored = []
        for i in range(number_of_filter_scored):
            filters_scored.append(FilterScored(address_used_internally, range_port_init + 2, address_used_internally, range_port_init + 3))
        streamer_scored_goals = StreamerPublisher(address_used_internally, range_port_init + 3, address_used_internally, range_port_init + 4, number_of_filter_scored, number_of_sum_up_players, lambda x: x[1])
        
        # Add subscriber here
        players_summers = []
        for i in range(number_of_sum_up_players):
            players_summers.append(SumUpPlayers(self.config['sum_up_players'], address_used_internally, range_port_init + 4, address_used_internally, range_port_init + 5, self.numerator_address, self.numerator_port))
        
        streamer_players  = Streamer(address_used_internally, range_port_init + 5, address_used_internally, range_port_init + 6, number_of_sum_up_players, 1)
      
        ranking_maker = RankingMaker(address_used_internally, range_port_init + 6, address_used_internally, range_port_init + 7)
        
        sink = Sink(address_used_internally, range_port_init + 7, self.config['output_filename'])
        
        streamer_input.start()
        for filter_columns in filters_columns:
            filter_columns.start()
        streamer_filtered_columns.start()
        for filter_scored in filters_scored:
            filter_scored.start()
        streamer_scored_goals.start()
        for players_summer in players_summers:
            players_summer.start()
        streamer_players.start()
        ranking_maker.start()
        sink.start()


        streamer_input.join()
        for filter_columns in filters_columns:    
            filter_columns.join()
        streamer_filtered_columns.join()
        for filter_scored in filters_scored:
            filter_scored.join()
        streamer_scored_goals.join()
        for player_summer in players_summers:
            players_summer.join()
        streamer_players.join()
        ranking_maker.join()
        sink.join()
Beispiel #4
0
 def __load_sinks(self):
     """Load sinks for this ruleset."""
     for root, _, files in os.walk(
             os.sep.join(['modules', self.module, 'sinks'])):
         for file_ in files:
             path = os.path.join(root, file_)
             ext = os.path.splitext(path)[1]
             if ext in ('.yaml', '.yml'):
                 Ruleset.logger.debug('Loading sink from file "%s".', path)
                 with open(path) as stream:
                     self.sinks.append(Sink(yaml.safe_load(stream)))
Beispiel #5
0
    def get_identifier_flow(self, identifier):
        if identifier in self.variable_flows:
            # get existing flow
            flow = self.variable_flows[identifier]
        else:
            # new variable: check if source/sink/sanitizer
            flows = []
            flows.append(Source(identifier, self.is_source(identifier)))
            flows.append(Sink(identifier, self.is_sink(identifier)))
            flows.append(Sanitizer(identifier, self.is_sanitizer(identifier)))
            flow = Flow(flows)

        return flow
    def run(self):

        address_used_internally = self.config['address_used_internally']
        range_port_init = self.config['internal_range_port']


        number_of_filters_columns = self.config['number_of_filters_columns']
        number_of_filters_by_score = self.config['number_of_filters_by_score']

        streamer_input = StreamerSubscriber(self.incoming_address, self.incoming_port, address_used_internally, range_port_init, 1, number_of_filters_columns)


        filters_columns = []        
        for i in range(number_of_filters_columns):
            filters_columns.append(FilterColumns(address_used_internally, range_port_init, address_used_internally, range_port_init + 1 ))

        streamer_filtered_columns = Streamer(address_used_internally,  range_port_init+ 1, address_used_internally, range_port_init + 2, number_of_filters_columns, number_of_filters_by_score )
        filters_by_score = []
        for i in range(number_of_filters_by_score):
            filters_by_score.append(FilterByScore(self.filter_points, address_used_internally,  range_port_init + 2, address_used_internally, range_port_init + 3))
        streamer_filtered_points = Streamer(address_used_internally,  range_port_init + 3, address_used_internally, range_port_init + 4, number_of_filters_by_score, 1)
        sum_up_points = SumUpPoints(address_used_internally, range_port_init + 4, address_used_internally, range_port_init + 5)
        sink = Sink(address_used_internally, range_port_init + 5, self.config['output_filename'])
        
        streamer_input.start()
        for filter_columns in filters_columns:
            filter_columns.start()
        streamer_filtered_columns.start()
        for filter_by_score in filters_by_score:
            filter_by_score.start()
        streamer_filtered_points.start()
        sum_up_points.start()
        sink.start()


        streamer_input.join()
        for filter_columns in filters_columns:
            filter_columns.join()
        streamer_filtered_columns.join()
        for filter_by_score in filters_by_score:
            filter_by_score.join()
        streamer_filtered_points.join()
        sum_up_points.join()
        sink.join()
 def connect(self, timeout=20):
     if not self.sink:
         self.sink = Sink(self.host, on_receive=self.track_sink_event)
     start = time.time()
     connected = False
     started = False
     error = None
     while time.time() - start < timeout and not self.is_ready():
         if not connected:
             try:
                 self.sink.connect(self._get_ace_port())
                 self.sink.send("HELLOBG")
                 connected = True
             except Error as error:
                 if not started:
                     self._start()
                     started = True
         self.on_poll(self.POLL_DELAY)
     if not self.is_ready():
         self.sink = None
         raise error
Beispiel #8
0
    def run(self):
        address_used_internally = self.config['address_used_internally']
        range_port_init = self.config['internal_range_port']

        input_streamer = StreamerSubscriber(self.incoming_address,
                                            self.incoming_port,
                                            address_used_internally,
                                            range_port_init, 1, 1)
        games_summarier = GamesSummarier(address_used_internally,
                                         range_port_init,
                                         address_used_internally,
                                         range_port_init + 1)
        sink = Sink(address_used_internally, range_port_init + 1,
                    '%home-wins.txt')

        input_streamer.start()
        games_summarier.start()
        sink.start()

        input_streamer.join()
        games_summarier.join()
        sink.join()
Beispiel #9
0
    def add_sink(self, method: Method, sink: dict):
        """Add a new sink to the list.
        New sinks are only relevant if a method's parameters are used in a sink.
        The same sanitizers are used from the original sink.

        Parameters
        ----------
        method : Method
            The method where the sink was added
        sink : dict
            A dictionary definition of the sink as defined in the ruleset
        """
        new_sink = Sink(sink)
        for existing_sink in self.sinks:
            if existing_sink.object_name != new_sink.object_name:
                continue
            if new_sink.methods == existing_sink.methods:
                break
        else:
            # Didn't break above, add new sink
            Ruleset.logger.debug('Added a new sink.  Notifying observers.')
            self.sinks.append(new_sink)
            self.notify_observers(method)
Beispiel #10
0
        # should only happen for audio channel
        print "I didn't get any samples; is your microphone or speaker OFF?"
        sys.exit(1)
#################################

    # process the received samples
    # make receiver
    r = Receiver(fc, opt.samplerate, opt.spb)
    demod_samples = r.demodulate(samples_rx)
    one, zero, thresh = r.detect_threshold(demod_samples)
    barker_start = r.detect_preamble(demod_samples, thresh, one)
    rcdbits = r.demap_and_check(demod_samples, barker_start)
    decoded_bits = r.decode(rcdbits)

    # push into sink
    sink = Sink()
    rcd_payload = sink.process(databits)#sink.process(decoded_bits)
    
    if len(rcd_payload) > 0:
        hd, err = common_srcsink.hamming(decoded_bits, databits)
        print 'Hamming distance for payload at frequency', fc,'Hz:', hd, 'BER:', err
    else:
        print 'Could not recover transmission.'

    if opt.graph:
                len_mod = len(mod_samples) - opt.spb*opt.silence 
                len_demod = len_mod - opt.spb*(len(src_payload) - len(rcd_payload))
                plot_graphs(mod_samples, samples_rx[barker_start:], demod_samples[barker_start:barker_start + len_demod], opt.spb, src.srctype, opt.silence)


Beispiel #11
0
def run(config):
    '''Primary Audiocom functionality.'''

    # Create the preamble to pre-pend to the transmission
    preamble = Preamble(config)

    # Create the sources
    sources = {}
    for i in range(len(config.channels)):
        frequency = config.channels[i]
        source = Source(config, i)
        print("Channel: %d Hz" % frequency)
        print("\n".join(["\t%s" % source]))
        sources[frequency] = source

    # Create a sender for each source, so we can process the bits to
    # get the modulated samples.  We combine all of the modulated
    # samples into a single array by adding them.

    baseband_samples = []
    modulated_samples = []

    for frequency in sources:
        src = sources[frequency]
        sender = Sender(frequency, preamble, config)
        sender.set_source(src)

        modulated_samples = util.add_arrays(sender.modulated_samples(),
                                            modulated_samples)
        baseband_samples = util.add_arrays(sender.bits_to_samples(src.payload),
                                           baseband_samples)
        print("sending %d samples" % len(modulated_samples))

    # Create the channel
    if config.bypass:
        channel = AbstractChannel(config.bypass_noise, config.bypass_h)
    else:
        channel = AudioChannel(config)

    # Transmit and receive data on the channel.  The received samples
    # (samples_rx) have not been processed in any way.
    samples_rx = channel.xmit_and_recv(modulated_samples)
    print('Received', len(samples_rx), 'samples')

    for frequency in config.channels:
        r = Receiver(frequency, preamble, config)
        try:
            # Call the main receiver function.  The returned array of bits
            # EXCLUDES the preamble.
            bits = r.process(samples_rx)

            # Push into a Sink so we can convert back to a useful payload
            # (this step will become more useful when we're transmitting
            # files or images instead of just bit arrays)
            src = sources[frequency]
            sink = Sink(src)
            received_payload = sink.process(bits)
            print("Received %d data bits" % len(received_payload))
            if src.type == Source.TEXT:
                print("Received text was:", sink.received_text)

            if len(received_payload) > 0:
                # Output BER
                hd = util.hamming(received_payload, src.payload)
                ber = float(hd) / len(received_payload)
                print('BER:', ber)
            else:
                print('Could not recover transmission.')

        except Exception as e:
            # In general, this is a fatal exception.  But we'd still like
            # to look at the graphs, so we'll continue with that output
            #            print('*** ERROR: Could not detect preamble. ***')
            print(repr(e))

        if config.graphs == "time":
            graphs.plot_samples(baseband_samples,
                                modulated_samples,
                                r.graph_info.received_samples,
                                stems=False)
        elif config.graphs == "freq":
            graphs.plot_sig_spectrum(modulated_samples,
                                     r.graph_info.demod_samples)
        elif config.graphs == "usr":
            graphs.plot_usr(r.graph_info.demod_samples)
Beispiel #12
0
 def run1(self):
     trace('start')
     source = Source()
     sink = Sink(source)
     sink.run()
     trace('end')
Beispiel #13
0
    # use Unicorn HAT when started without parameters
    from RealHat import RealHat
    hat = RealHat()
else:
    # just show the matrix status on the console when started with one parameter
    from FakeHat import FakeHat
    hat = FakeHat()

#################################################################################

app = Flask(__name__)
auth = HTTPBasicAuth()

app.debug = True
led = Matrix(hat)
sink = Sink(led)


# http post http://127.0.0.1:5500/update status:='["NONE","BUILDING","OK","ERROR","NONE","WHAT?"]' --auth giveme:someled
# win: http post http://giveme:[email protected]:5500/update  status:="[\"NONE\",\"BUILDING\",\"OK\",\"ERROR\",\"NONE\",\"WHAT?\"]"
@app.route("/update", methods=['POST'])
@auth.login_required
def update():
    content = request.get_json(silent=True)
    status = content['status']
    return str(sink.put(status))


@auth.verify_password
def verify_password(username, password):
    return username == 'giveme' and password == 'someled'
Beispiel #14
0
from bolt import Bolt
from sink import Sink
from spout import Spout
from splitBolt import SplitBolt

sp = Spout(paraNext=2)
blt = SplitBolt(parallelism=2, paraNext=[2, 2], grouping='key')
#blt = Bolt(parallelism=2, paraNext=2)
si = Sink(parallelism=2)
si2 = Sink(parallelism=2)

for i in range(0, 10):
    ret = blt.run(sp.run())
    si.run(ret[0])
    si2.run(ret[1])

si.getProcessed()
Beispiel #15
0
        sys.exit(1)
#################################

# process the received samples
# make receiver
    r = Receiver(fc, opt.samplerate, opt.spb)
    demod_samples = r.demodulate(samples_rx)

    one, zero, thresh = r.detect_threshold(demod_samples)
    barker_start = r.detect_preamble(demod_samples, thresh, one)
    rcdbits = r.demap_and_check(demod_samples, barker_start)
    if opt.cc_len != 0:
        rcdbits = r.decode(rcdbits)

    # push into sink
    sink = Sink(opt.compress, opt.encrypt)
    sink_bits = sink.process(rcdbits, pubkey)

    if len(sink_bits) > 0:
        hd, err = common_srcsink.hamming(sink_bits, src_bits)
        print 'Hamming distance for payload at frequency', fc, 'Hz:', hd, 'BER:', err
    else:
        print 'Could not recover transmission.'

    if opt.graph:
        len_mod = len(mod_samples) - opt.spb * opt.silence
        len_demod = len_mod - opt.spb * (len(src_payload) - len(rcd_payload))
        plot_graphs(mod_samples, samples_rx[barker_start:],
                    demod_samples[barker_start:barker_start + len_demod],
                    opt.spb, src.srctype, opt.silence)
Beispiel #16
0
def setSink(x,y):
    sinks.append( Sink())
    sinks[len(sinks) -1].set_dimensions(50,50) 
    sinks[len(sinks) -1].y_pos = y
    sinks[len(sinks) -1].x_pos = x