Changeset 360 for powerbar


Ignore:
Timestamp:
Jan 31, 2012, 7:39:34 AM (13 years ago)
Author:
Rick van der Zwet
Message:

Allow port cycle for hard-reboot of UNIT.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • powerbar/npm2000.py

    r359 r360  
    2424MAX_PORTS = 8
    2525
     26# Wait a little while to allow device to turn off
     27CYCLE_WAIT = 1
     28
    2629# XOR all the 8bit values to get a checksum
    2730def checksum(s):
     
    168171        doCommand('portOn', port)
    169172
     173def cyclePort(port):
     174    raw_status= doCommand('status')
     175    if getPortState(port,raw_status):
     176        doCommand('portOff',port)
     177        time.sleep(CYCLE_WAIT)
     178        doCommand('portOn',port)
     179    else:
     180        doCommand('portOn', port)
     181        time.sleep(CYCLE_WAIT)
     182        doCommand('portOff',port)
     183
    170184
    171185def runTest():
     
    214228    try:
    215229        opts, args = getopt.getopt(sys.argv[1:],
    216             "hf:s:t:o:v", ["help","verbose","host=", "port=", "password=", "addresscode=","toggle=","off=", "on=", "status="])
     230            "c:hf:s:t:o:v", ["cycle=", "help","verbose","host=", "port=", "password=", "addresscode=","toggle=","off=", "on=", "status="])
    217231    except getopt.GetoptError, err:
    218232        # print help information and exit:
     
    243257            opt_action = "toggle"
    244258            opt_port = a
     259        elif o in ("-c","--cycle"):
     260            opt_action = "cycle"
     261            opt_port = a
    245262        elif o in ("-f","--off"):
    246263            opt_action = "off"
     
    280297
    281298    if opt_action == "toggle":
    282         if opt_port == "all":
    283             for i in range(1,MAX_PORTS+1):
    284                 togglePort(getPortHex(i))
    285         else:
    286                 togglePort(opt_port)
     299      if opt_port == "all":
     300        for i in range(1,MAX_PORTS+1):
     301          togglePort(getPortHex(i))
     302      else:
     303        togglePort(opt_port)
     304    elif opt_action == "cycle":
     305      if opt_port == "all":
     306        for i in range(1,MAX_PORTS+1):
     307          cyclePort(getPortHex(i))
     308      else:
     309        cyclePort(opt_port)
    287310    elif opt_action == "on":
    288311        if opt_port == "all":
Note: See TracChangeset for help on using the changeset viewer.