Changeset 0280387b4a7b139df25cf2a418e85037ea3d7b1b


Ignore:
Timestamp:
05/15/10 01:04:11 (21 months ago)
Author:
Luper Rouch <luper.rouch@…>
Children:
3d477f9e40ceaedf2ee58027d5e0a5c098150f62
Parents:
811533e58cd3e57fc04f2e7809d3f6ddd6198a82
git-committer:
Luper Rouch <luper.rouch@…> (05/15/10 01:04:11)
Message:

pompilop:

  • fixed base96() (needs testing on real hardware)
  • 'input' is now a keyword argument of Command
  • more tests
Location:
pompilop/pompilop
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pompilop/pompilop/bin/pompicontrol.py

    r811533e r0280387  
    2828 
    2929command, data = args 
    30 command_obj = Command.from_strings(command, options.input, options.channel,  
    31         data, aux=options.aux) 
     30command_obj = Command.from_strings(command, options.channel, data, 
     31        aux=options.aux, input=options.input) 
    3232if options.debug: 
    3333    print "Sending command to %s:" % options.dev 
  • pompilop/pompilop/serial/__init__.py

    r811533e r0280387  
    8989    AUX_MAX = 32 
    9090 
    91     def __init__(self, command, input, channel, data, aux=None, device=0): 
     91    def __init__(self, command, channel, data, aux=None, device=0, input=True): 
    9292        self.command = command 
    9393        if device < 0 or device >= self.DEVICES_MAX: 
     
    121121        ret.append(CHANNEL_HEADER) 
    122122        ret.append(chr(CHANNEL_VALUE_BASE + self.channel)) 
     123        # Aux bytes 
     124        if self.aux is not None: 
     125            ret.append(AUX_HEADER) 
     126            ret.append(chr(AUX_VALUE_BASE + self.aux)) 
    123127        # Data bytes 
    124128        dumped_data = base96(self.data) 
     
    141145        return "\x20" 
    142146    bytes = [] 
    143     while value: 
    144         byte = value & 0x5f 
    145         bytes.append(chr(byte + 0x20)) 
    146         value >>= 5 
    147     print bytes 
     147    while value > 0: 
     148        if value >= 0x60: 
     149            bytes.append("\x7f") 
     150        else: 
     151            bytes.append(chr(value + 0x20)) 
     152        value -= 0x60 
    148153    return "".join(reversed(bytes)) 
    149154 
  • pompilop/pompilop/tests/test_serial.py

    r9d933f3 r0280387  
    11from nose.tools import assert_equal 
    2 from pompilop.serial import checksum, format_commands, Command 
     2from pompilop.serial import checksum, format_commands, Command, base96 
    33 
    44 
     
    1717def test_format(): 
    1818    data = [ 
    19             (Command(Command.MUTE, False, 2, 1),  
     19            (Command(Command.MUTE, 2, 1, input=False),  
    2020                "\x01\x57\x7F\x03\x4D\x55\x54\x30\x08\x20\x09\x21\x0A" 
    2121                "\x22\x10\x21\x1F\x2E\x02"), 
    22             (Command(Command.EQ_FREQUENCY, True, 3, aux=5), 
     22            (Command(Command.EQ_FREQUENCY, 3, 1, aux=5, input=True), 
    2323                "\x01\x57\x7F\x03\x45\x51\x46\x30\x08\x20\x09\x20\x0A" 
    2424                "\x23\x0B\x25\x10\x21\x1F\x44\x02"), 
     
    2626    for cmd, expected in data: 
    2727        assert_equal(format_commands([cmd]), expected) 
     28 
     29 
     30def test_base96(): 
     31    assert_equal(base96(0), "\x20") 
     32    assert_equal(base96(1), "\x21") 
     33    assert_equal(base96(0x60), "\x7f") 
     34    assert_equal(base96(0x61), "\x21\x7f") 
     35 
Note: See TracChangeset for help on using the changeset viewer.