Esempio n. 1
0
def transform_value(command, value):
    if command == Commands.STATIC_IMG:
        return _pack_tuples_to_image(value)
    elif command == Commands.SET_RADIO:
        return freq_to_bytes(value)
    else:
        return value
Esempio n. 2
0
def main():
    r = redis.Redis(host='localhost', port=6379, db=0)
    p = r.pubsub()
    p.subscribe(replies=handle_replies)

    while True:
        b = Command(Commands.SET_RADIO, None, freq_to_bytes(random.randrange(890, 1079) / 10)).command
        r.publish('commands', bytes(b))
        p.get_message()
        time.sleep(1)
Esempio n. 3
0
def test_freq_to_bytes():
    assert protocol.freq_to_bytes(100.3) == [0x03, 0x0A]
    assert protocol.freq_to_bytes(100.9) == [0x09, 0x0A]
    assert protocol.freq_to_bytes(107.3) == [73, 0x0A]
    assert protocol.freq_to_bytes(90.3) == [0x03, 0x09]
    assert protocol.freq_to_bytes(90.9) == [0x09, 0x09]
    assert protocol.freq_to_bytes(97.3) == [73, 0x09]
Esempio n. 4
0
commands = [
            Command(Commands.BRIGHTNESS, Arguments.BR_HIGH),
            Command(Commands.STATIC_IMG, Arguments.NONE, extra_bytes=solid_color(0xf,0,0)),
            Command(Commands.BRIGHTNESS, Arguments.BR_OFF),
            Command(Commands.BRIGHTNESS, Arguments.BR_LOW),
            Command(Commands.BRIGHTNESS, Arguments.BR_HIGH),
           ]

commands = [
            Command(Commands.GET_VOL, None),
            Command(Commands.GET_VOL, None),
            Command(Commands.GET_VOL, None),
            Command(Commands.GET_RADIO, None),
            Command(Commands.GET_RADIO, None),
            Command(Commands.GET_RADIO, None),
            Command(Commands.SET_RADIO, None, freq_to_bytes(100.3)),
            Command(Commands.SET_RADIO, None, freq_to_bytes(100.5)),
            Command(Commands.SET_RADIO, None, freq_to_bytes(100.7)),
            Command(Commands.GET_RADIO, None),
            Command(Commands.GET_RADIO, None),
            Command(Commands.GET_RADIO, None),
           ]

def handle_replies(message):
    data = json.loads(message['data'].decode('ascii'))
    print(data)

def main():
    r = redis.Redis(host='localhost', port=6379, db=0)
    p = r.pubsub()
    p.subscribe(replies=handle_replies)
Esempio n. 5
0
def test_bytes_to_freq_to_bytes():
    assert protocol.freq_to_bytes(protocol.bytes_to_freq([73, 0x09
                                                          ])) == [73, 0x09]
Esempio n. 6
0
def test_freq_to_bytes_to_freq():
    assert protocol.bytes_to_freq(protocol.freq_to_bytes(100.3)) == 100.3
    assert protocol.bytes_to_freq(protocol.freq_to_bytes(90.3)) == 90.3
    assert protocol.bytes_to_freq(protocol.freq_to_bytes(88.3)) == 88.3