Changeset 75 for powerbar


Ignore:
Timestamp:
Feb 11, 2010, 8:10:33 PM (15 years ago)
Author:
Rick van der Zwet
Message:

Status hack

File:
1 edited

Legend:

Unmodified
Added
Removed
  • powerbar/npm4000.py

    r74 r75  
     1#!/usr/bin/env python
    12# NPM 4000 powerbar managment script, to be used instead of the windows
    23# application.
     4#
    35# XXX: Not all features are ported yet (like amp monitoring)
    46# XXX: Some dirty poking around with hex representations and numeric representations of ports
    5 #
     7# XXX: Make proper classes for use
     8# XXX: Documentation
     9#
    610# Licence: BSD
    711# Version: $Id: npm4000.py 750 2009-09-27 14:34:55Z rick $
    812# Rick van der Zwet <info@rickvanderzwet.nl>
     13
    914import socket, time
    1015import getopt, sys
     
    130135        return False
    131136
    132 def getPortStatus(port):
     137def getPortStatus(i):
    133138    raw_status = doCommand('status')
    134     retval = getPortState(port,raw_status)
    135     dprint("Port %i: %s" % (port, retval))
     139    print "Port %02i [%s]:" % (i, getPortName(i)),
     140    if getPortState(i,raw_status):
     141        print "1"
     142    else:
     143        print "0"
    136144    return(retval)
    137145
    138 def getStatus():
     146def getStatusAll():
    139147    raw_status= doCommand('status')
    140148    for i in range(1,25):
     
    146154
    147155def togglePort(port):
    148     portNumber = getPortNumber("%X" % port)
    149     if getPortStatus(portNumber):
     156    if getPortState(port):
    150157        doCommand('portOff',port)
    151158    else:
     
    198205    try:
    199206        opts, args = getopt.getopt(sys.argv[1:],
    200             "hf:st:o:v", ["help","verbose","host=", "port=", "password=", "addresscode=","toggle=","off=", "on=", "status"])
     207            "hf:s:t:o:v", ["help","verbose","host=", "port=", "password=", "addresscode=","toggle=","off=", "on=", "status="])
    201208    except getopt.GetoptError, err:
    202209        # print help information and exit:
     
    207214    opt_port = None
    208215    opt_action = None
    209     opt_status = None
    210216    for o, a in opts:
    211217        if o in ("-v", "--verbose"):
     
    223229            inet_port = a
    224230        elif o in ("-s", "--status"):
    225             opt_status = True
     231            opt_action = "status"
     232            opt_port = a
    226233        elif o in ("-t","--toggle"):
    227234            opt_action = "toggle"
     
    236243            assert False, "unhandled option"
    237244
    238     if (opt_status):
    239         getStatus()
    240         sys.exit(0)
    241     elif (opt_port == None or opt_action == None):
     245    if (opt_port == None or opt_action == None):
    242246        usage()
    243247        sys.exit(2)
    244248
    245249    dprint ('action: ' + opt_action + ' port: ' + opt_port)
     250
     251    s.connect((inet_addr, inet_port))
     252
     253    # Status needs real integers, hack
     254    if opt_action == "status":
     255        if opt_port == "all":
     256            getStatusAll()
     257        else:
     258            print "XXX: Implement"
     259        sys.exit(0)
    246260
    247261    # Resolve port to proper number
     
    256270        dprint('Hexcode of port: %i' % opt_port)
    257271
    258     s.connect((inet_addr, inet_port))
    259 
    260272    if opt_action == "toggle":
    261273        if opt_port == "all":
     
    275287            doCommand("portOn", opt_port)
    276288
     289
    277290if __name__ == "__main__":
    278291    main()
Note: See TracChangeset for help on using the changeset viewer.