Пример #1
0
 def buildUp(self):
     self.output('Waiting for time to update...')
     # wait for time to come
     while not TimeUpdated.is_set() and not QuitinTime.is_set():
         TimeUpdated.wait(0.5)
     else:
         # if time never came and it's time to quit, skip tear down
         if QuitinTime.is_set():
             self.tearDown = lambda : None
             return
     self.output('Time updated... Starting')
     
     # setup sensors
     ADC.setup()
Пример #2
0
 def buildUp(self):
     self.output('Waiting for time to update...')
     # wait for time to come
     while not TimeUpdated.is_set() and not QuitinTime.is_set():
         TimeUpdated.wait(0.5)
     else:
         # if time never came and it's time to quit, skip tear down
         if QuitinTime.is_set():
             self.tearDown = lambda : None
             return
     self.output('Time updated... Starting')
     self.dbpath = '{0}/storage/{1}.db'.format(os.path.abspath(os.path.dirname(BeagleCommand.__file__)),datetime.now().strftime('%m.%d.%Y'))
     self.output('Using '+self.dbpath)
     self.conn = sqlite3.connect(self.dbpath)
     self.conn.execute('create table if not exists data (time real primary key, duration real, voltage real, used real, charged real);')
     self.cursor = self.conn.cursor()
     for row in self.cursor.execute('select time, duration, voltage, used, charged from data order by time;'):
         self.process(row)
Пример #3
0
 def run(self):
     self.output('started')
     self.buildUp()
     while True:
         # Check if main thread is ready to stop
         if QuitinTime.is_set():
             self.tearDown()
             self.output('Quitin\'')
             return
         self.loop()
Пример #4
0
 def loop(self):
     for col in ['time', 'voltage', 'used', 'charged', 'usedwhs', 'chargedwhs', 'totalwhs']:
         while True:
             if QuitinTime.is_set():
                 return
             self.send('get-'+col,0.0)
             time.sleep(1.0)
             self.readSerial()
             if col in self.rowdict:
                 break
         time.sleep(0.1)
     r = self.rowdict
     m = Message(to = ['storage'], msg = ['put', [r['time'], r['voltage'],
         r['used'], r['charged'], r['usedwhs'], r['chargedwhs'], r['totalwhs']]])
     self.MessageBox.put(m)
     self.rowdict.clear()
Пример #5
0
def run():
    """Run main server loop"""

    # create signal handler
    def signal_handler(sig, frame):
        print '\nCaught signal {0}... Quitin\' Time!'.format(str(sig))
        flaskProcess.terminate()
        flaskProcess.join()
        QuitinTime.set()
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    # create and start worker threads
    StorageThread = Storage(StorageIn,MessageBox)
    SerialThread = Serial(SerialIn,MessageBox)

    StorageThread.start()
    SerialThread.start()

    # start web server
    def f(MessageBox):
        from web import app
        app.MessageBox = MessageBox
        try:
            app.run(debug=True, use_reloader=False)
        except AttributeError:
            pass

    flaskProcess = Process(target=f, args=[MessageBox]) 
    flaskProcess.start()

    # pass messages until program is ended
    while True:
        # check to see if it's time to quit
        if QuitinTime.is_set():
            break
        try:
            # use timeout so that main thread can catch signals
            msg = MessageBox.get(timeout=0.5)
            for owner in msg.to:
                QueueOwners[owner].put(msg.msg)
        except Empty:
            pass
        except IOError:
            pass
Пример #6
0
    def run(self):
        """main worker loop"""
        self.output('started')
        self.buildUp()
        while True:
            # check for messages
            try: 
                msg = self.InQueue.get_nowait()
                if Debug:
                    self.output('received ' + str(msg))
                exec('self.{0}(*{1})'.format(msg[0],msg[1:]))
            except Queue.Empty:
                pass

            self.loop()

            # Check if main thread is ready to stop
            if QuitinTime.wait(2):
                self.tearDown()
                self.output('Quitin\'')
                return
Пример #7
0
 def run(self):
     """main worker loop"""
     self.output('started')
     self.buildUp()
     while True:
         # Check if main thread is ready to stop
         if QuitinTime.is_set():
             self.tearDown()
             self.output('Quitin\'')
             return
         # check for messages
         while True:
             try: 
                 msg = self.InQueue.get(block=self.messageBound,timeout=0.5)
                 if Debug:
                     self.output('received ' + str(msg))
                 exec('self.{0}(*{1})'.format(msg[0],msg[1:]))
             except Queue.Empty:
                 break
         if not self.messageBound:
             self.loop()
Пример #8
0
def run():
    """Run main server loop"""

    # create signal handler
    def signal_handler(sig, frame):
        print '\nCaught signal {0}... Quitin\' Time!'.format(str(sig))
        QuitinTime.set()
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    # create and start worker threads
    AcquireThread = Acquire(AcquireIn,MessageBox)
    StorageThread = Storage(StorageIn,MessageBox)
    SerialThread = Serial(SerialIn,MessageBox)

    AcquireThread.start()
    StorageThread.start()
    SerialThread.start()

    # pass messages until program is ended
    while True:
        # check to see if it's time to quit
        if QuitinTime.is_set():
            break
        try:
            # use timeout so that main thread can catch signals
            msg = MessageBox.get(timeout=0.5)
            for owner in msg.to:
                QueueOwners[owner].put(msg.msg)
        except Queue.Empty:
            pass

    if Reboot.is_set():
        os.system('reboot')
    if PowerOff.is_set():
        os.system('poweroff')
Пример #9
0
 def signal_handler(sig, frame):
     print '\nCaught signal {0}... Quitin\' Time!'.format(str(sig))
     flaskProcess.terminate()
     flaskProcess.join()
     QuitinTime.set()
Пример #10
0
 def poweroff(self, val):
     QuitinTime.set()
     PowerOff.set()
Пример #11
0
 def reboot(self, val):
     QuitinTime.set()
     Reboot.set()
Пример #12
0
 def signal_handler(sig, frame):
     print '\nCaught signal {0}... Quitin\' Time!'.format(str(sig))
     QuitinTime.set()