def senddata(self): if (self.sock is not None): currentstr = "" # isbegin=False self.handler = outputHandler() while (1): try: #print "wait for send" msg=self.handler.readdatapipe() self.sock.sendto(msg,self.server_address) except Exception as a: print a," error" break else: print "Sorry output deamon socket has an error"
def __init__(self, registerCallbackFunc, args = {}, stapLabModulesDir = "stapLabModules", stapModulesDir = "gather", generatorModulesDir = "generatorModules" ): self.log = print if 'logStream' not in args else args['logStream'] self.registerCallback = registerCallbackFunc self.stapLabModulesDir = stapLabModulesDir self.stapModulesDir = stapModulesDir self.generatorModulesDir = generatorModulesDir self.stapLabModules = {} # {stapLabModule.id:stapLabModule} self.stapModules = {} # {stapModule.id:stapModule} self.generatorModules = {} self.args = args self.outputHandler = outputHandler(args=self.args) self.thread = Thread(target=self.run) self.thread.daemon = True self.thread.running = True self.thread.start()
def handleLink(self,address): print 'Connection address outputdeamon server udp :', address logging.debug('59 output server serve udp first while loop (TRY) ') # while(1): print "in main Loop" if (self.sock is not None): # ToDO Remove this if or refactor currentstr = "" # isbegin=False # break logging.debug('66 output server udp serve first while loop (TRY) Socket not None') self.handler = outputHandler() while (1): logging.debug('69 output server udp serve first while loop (TRY) Socket not None While') try: logging.debug('71 output server udp serve first while loop (TRY) Socket not None While (TRY)') msg = self.handler.readdatapipe() ln = len(msg) sent = 0 while (ln > 0): self.sock.sendto(msg[sent:min(sent + 10000, ln)], address) #print msg[sent:min(sent + 10000, ln - sent)] sent = sent + 10000 ln = ln - 10000 # time.sleep(1) print "send Done" except Exception as a: print a, " error" # time.sleep(5) logging.debug( '78 output server udp serve first while loop (TRY) Socket not None While (EXCEPT) ' + a.message) self.sock.close() break else: logging.debug('82 output server udp serve first while loop (TRY) Socket is None') print "Sorry input deamon udp socket has an error"
def serve(self): logging.debug('37 output server serve with ip port buffer') s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((self.ip, self.port)) s.listen(1) self.socket = s while (1): logging.debug('44 output server serve first while loop') try: logging.debug('46 output server serve first while loop (TRY)') try: logging.debug( '48 output server serve first while loop (TRY/TRY)') conn, addr = s.accept() except Exception as e: print "@ accept", e logging.debug( '52 output server serve first while loop (TRY/EXCEPT)' + e.message) s.shutdown() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((self.ip, self.port)) s.listen(1) self.socket = s print 'Connection address outputdeamon server:', addr logging.debug('59 output server serve first while loop (TRY) ') #while(1): print "in main Loop" if (self.socket is not None): # ToDO Remove this if or refactor currentstr = "" # isbegin=False #break logging.debug( '66 output server serve first while loop (TRY) Socket not None' ) self.handler = outputHandler() while (1): logging.debug( '69 output server serve first while loop (TRY) Socket not None While' ) try: logging.debug( '71 output server serve first while loop (TRY) Socket not None While (TRY)' ) msg = self.handler.readdatapipe() conn.send(msg) #time.sleep(1) print "send Done" except Exception as a: print a, " error" logging.debug( '78 output server serve first while loop (TRY) Socket not None While (EXCEPT) ' + a.message) conn.close() break else: logging.debug( '82 output server serve first while loop (TRY) Socket is None' ) print "Sorry input deamon socket has an error" except Exception as e: #if(s.) print e #exc_type, exc_obj, exc_tb = sys.exc_info() logging.debug( '89 output server serve first while loop (EXCEPT) ' + str(e.message)) time.sleep(5) break
def __init(): import logging # our own logging module import outputHandler import tokenHandler # our ouwn token hangling module import settingsHandler import pinDef # our own pin definition module import systemHandler import inputHandler # our own input handling module try: import pigpio except ImportError: print( "*** PiGPIO not found - please run the following command to install it ***" ) print( "sudo apt-get update && sudo apt-get install pigpio python-pigpio python3-pigpio\n" ) exit() # exit flag global __flagExit __flagExit = False # get our run mode - find out if daemon global runMode # Assume runMode is normal runMode = "normal" # Confirm if it's actually running as a daemon for i in sys.argv: if i == "--daemon": runMode = "daemon" break if os.environ.get("LAUNCHED_BY_SYSTEMD") == "1": runMode = "daemon" # start logging global l l = logging.logger(runMode=runMode) del logging l.log("NOTE", "DIYAC starting") # systemHandler global sysH sysH = systemHandler.systemHandler(l) del systemHandler sysH.setup("sigInt", runQuit=True) sysH.setup("sigTerm", runQuit=True) sysH.setup("sigHup", sigHup_callback, runQuit=False) sysH.setup("quit", cleanup) # get all the settings s = settingsHandler.settingsHandler(sysH, l) del settingsHandler # update the logger with new settings l.loadSettings(s) # see if pigpiod is running # if not running # try to start # check again # if not running # exit # pigpiod.pi() # if not connected # exit stat = subprocess.call("systemctl status pigpiod > /dev/null", shell=True) if stat != 0: l.log("WARN", "PIGPIOD is not running, will try to start") subprocess.call("sudo systemctl start pigpiod > /dev/null", shell=True) stat = subprocess.call("service pigpiod status > /dev/null", shell=True) if stat != 0: l.log("ERRR", "Unable to start pigpiod daemon") sysH.quit(code=1, status="Fail - PIGPIO not started and unable to start") else: l.log("INFO", "Starting pigpiod daemon successful") global pi pi = pigpio.pi() if not pi.connected: l.log("ERRR", "PiGPIO - Unable to connect") sysH.quit(code=1, status="Failed - unable to connect to PIGPIOD") # set tokens global tokens tokens = tokenHandler.tokenHandler(sysH, s, l) del tokenHandler # pin definitions global p p = pinDef.pinDef(sysH, s, l) del pinDef # output handler (settings, logger, gpio, pins global outH outH = outputHandler.outputHandler(sysH, s, l, pi, p) del outputHandler # Input handler global inH inH = inputHandler.inputHandler(sysH, s, l, tokens, outH, pi, p) del inputHandler time.sleep(0.1) # register these GPI pins to run __cbf on rising or falling edge for pin in p.pins["input"]: pi.callback(p.pins[pin], pigpio.EITHER_EDGE, __callbackInput) # register these GPO pins to run __cbf on rising or falling edge for pin in p.pins["output"]: pi.callback(p.pins[pin], pigpio.EITHER_EDGE, __callbackOutput) # state ready sysH.notifyUp("READY=1") sysH.notifyUp("STATUS=Running") l.log("NOTE", "DIYAC running", runMode) import getpass l.log("DBUG", "Running program as user", getpass.getuser())