#!/usr/bin/env python # power on/off an Alcatel Speedtouch 510 modem using some circuitry # controlled via RTS/DTR from os import open, O_RDONLY from sys import argv, stderr, exit from termios import TIOCMBIS, TIOCMBIC, TIOCM_RTS, TIOCM_DTR from fcntl import ioctl from select import select from struct import pack from time import sleep if argv[1:] == ['on']: time = 0.02 # >=0.01 elif argv[1:] == ['off']: time = 5.0 # >=4.0 else: print >>stderr, "Usage: st510 on|off" exit(1) rts = pack('I', TIOCM_RTS) dtr = pack('I', TIOCM_DTR) fd = open('/dev/ttyS2', O_RDONLY) # opening a serial line will assert RTS and DTR but we should not rely on that. ioctl(fd, TIOCMBIS, rts) # Charge up the capacitor. This mechanism avoids random resets when # pulling plugs or powering the system on- and off. # # 50 pulses - # 250 pulses 10 sec reset possible starting at 3mA # 500 pulses 15 sec reset possible starting at 4mA # 1000 pulses - 10.5V 18 sec reset possible starting ar 5mA # # 250 pulses will do, 500 works but to stay on the safe side... for i in range(1000): ioctl(fd, TIOCMBIC, dtr) select([], [], [], 0.001) ioctl(fd, TIOCMBIS, dtr) select([], [], [], 0.001) # Capacitor charged up, DTR is set. fire by clearing RTS ioctl(fd, TIOCMBIC, rts) select([], [], [], time) ioctl(fd, TIOCMBIS, rts) # if we close fd within 25 seconds then the remaining capacitor charge may generate # another reset pulse when RTS goes down. # This could switch the modem back on when we are supposed to switch it off. The other # way around it gets even worse: when the reset is pressed a number of times while # the modem has just been switched on it will reload the factory settings (consult the # manual about the exact reset sequence for this). So, we're anal and wait a full minute. sleep(60)