def __init__(self): super(TestCase, self).__init__() # Notification service self.ns = NotifyService(config=self.config) self.error_code = 0
def __init__(self): super(TestCase, self).__init__() self.has_opened = False self.has_closed = False # Notification service self.ns = NotifyService(config=self.config) self.error_code = 0
def __init__(self): super(TestCase, self).__init__() self.red = False self.green = False self.blue = False # Notification service self.ns = NotifyService(config=self.config) self.error_code = 0
def main(): from ws4py.client.threadedclient import WebSocketClient from fabtotum.fabui.notify import NotifyService from fabtotum.utils.pyro.gcodeclient import GCodeServiceClient from fabtotum.fabui.config import ConfigService from fabtotum.os.paths import RUN_PATH import logging import argparse import os # Setup arguments parser = argparse.ArgumentParser() parser.add_argument("-L", "--log", help="Use logfile to store log messages.", default='/var/log/fabui/gpiomonitor.log') parser.add_argument("-p", "--pidfile", help="File to store process pid.", default=os.path.join(RUN_PATH, 'gpiomonitor.pid') ) # Get arguments args = parser.parse_args() pidfile = args.pidfile with open(pidfile, 'w') as f: f.write( str(os.getpid()) ) config = ConfigService() # Load configuration NOTIFY_FILE = config.get('general', 'notify_file') ################################################################## SOCKET_HOST = config.get('socket', 'host') SOCKET_PORT = config.get('socket', 'port') ################################################################## EVENT_PIN = config.get('totumduino', 'event_pin') # Pyro GCodeService wrapper gcs = GCodeServiceClient() ws = WebSocketClient('ws://'+SOCKET_HOST +':'+SOCKET_PORT+'/') ws.connect(); # Notification service ns = NotifyService(ws, NOTIFY_FILE, config) # Setup logger logger2 = logging.getLogger('GPIOMonitor') logger2.setLevel(logging.DEBUG) fh = logging.FileHandler(args.log, mode='w') #~ formatter = logging.Formatter("%(name)s - %(levelname)s : %(message)s") formatter = logging.Formatter("[%(asctime)s] %(levelname)s : %(message)s") fh.setFormatter(formatter) fh.setLevel(logging.DEBUG) logger2.addHandler(fh) gpioMonitor = GPIOMonitor(ns, gcs, logger2, EVENT_PIN) gpioMonitor.start() gpioMonitor.loop()
# Start gcode service gcservice = GCodeService(SERIAL_PORT, SERIAL_BAUD, logger=logger, fabid=FABID_ACTIVE) gcservice.start() # Pyro GCodeService wrapper gcserver = GCodeServiceServer(gcservice) ws = WebSocketClient('ws://' + SOCKET_HOST + ':' + SOCKET_PORT + '/') ws.connect() # Notification service ns = NotifyService(ws, NOTIFY_FILE, config) ## Folder temp monitor ftm = FolderTempMonitor(ns, gcservice, logger, TRACE, TASK_MONITOR) ## usb disk monitor um = UsbMonitor(ns, logger, USB_FILE) ## Configuration monitor cm = ConfigMonitor(gcservice, config, logger) ## The Observer ;) observer = Observer() observer.schedule(um, '/dev/', recursive=False) observer.schedule(cm, '/var/lib/fabui', recursive=True) observer.schedule(ftm, TEMP_PATH, recursive=False) observer.start()
class TestCase(GCodePusher): def __init__(self): super(TestCase, self).__init__() self.red = False self.green = False self.blue = False # Notification service self.ns = NotifyService(config=self.config) self.error_code = 0 def trace(self, log_msg): print log_msg self.trace_logger.info(log_msg) def exit(self, error_code): self.stop() # need to stop the loop first self.error_code = error_code exit(self.error_code) def custom_action_callback(self, action, data): if action == "custom": if data[0] == 'is_red_working': self.red = (data[1] == 'Yes') self.trace(_('Is RED working...{0}').format(data[1])) self.trace(_('Setting GREEN color')) self.send('M701 S0') self.send('M702 S255') self.send('M703 S0') data = { 'id': 'is_green_working', 'type': 'question', 'msg': _('Are the GREEN ambient lights glowing?'), 'buttons': '[Yes][No]' } self.ns.notify('selftest', data) elif data[0] == 'is_green_working': self.green = (data[1] == 'Yes') self.trace(_('Is GREEN working...{0}').format(data[1])) self.trace(_('Setting BLUE color')) self.send('M701 S0') self.send('M702 S0') self.send('M703 S255') data = { 'id': 'is_blue_working', 'type': 'question', 'msg': _('Are the BLUE ambient lights glowing?'), 'buttons': '[Yes][No]' } self.ns.notify('selftest', data) elif data[0] == 'is_blue_working': self.blue = (data[1] == 'Yes') self.trace(_('Is BLUE working...{0}').format(data[1])) self.trace(_('Setting WHITE color')) self.send('M701 S255') self.send('M702 S255') self.send('M703 S255') if self.red and self.green and self.blue: self.trace(_('All lights are working')) self.exit(0) else: self.trace(_('Some lights are not working')) self.exit(1) else: self.exit(1) else: self.trace(_('unknown action [{0}]').format(action)) self.exit(1) def run(self): self.resetTrace() self.trace(_("=== Starting ambient light test ===")) self.trace(_('Setting RED color')) self.send('M701 S255') self.send('M702 S0') self.send('M703 S0') data = { 'id': 'is_red_working', 'type': 'question', 'msg': _('Are the RED ambient lights glowing?'), 'buttons': '[Yes][No]' } self.ns.notify('selftest', data) self.loop() self.trace(_("=== Ambient light test finished ===")) self.exit(self.error_code)
class TestCase(GCodePusher): def __init__(self): super(TestCase, self).__init__() # Notification service self.ns = NotifyService(config=self.config) self.error_code = 0 def trace(self, log_msg): print log_msg self.trace_logger.info(log_msg) def exit(self, error_code): self.stop() # need to stop the loop first self.error_code = error_code exit(self.error_code) def __stress_test_thread(self): self.trace(_('=== Milling motor stress test started ===')) self.send('M3 S6000') self.trace(_('Waiting to start up...')) time.sleep(7) for rpm in range(7, 14): rpm *= 1000 self.send('M3 S{0}'.format(rpm)) time.sleep(2) self.send('M5') self.trace(_('Stopping motor')) time.sleep(2) data = { 'id': 'is_working_question', 'type': 'question', 'msg': _('Did the motor start and was changing speed?'), 'buttons': '[Yes][No]' } self.ns.notify('selftest', data) def custom_action_callback(self, action, data): if action == "custom": if data[0] == 'start_motor' and data[1] == 'OK': self.stress_test_thread = Thread( target=self.__stress_test_thread) self.stress_test_thread.start() elif data[0] == 'is_working_question': self.trace(_('Is the motor working...{0}').format(data[1])) if data[1] == 'Yes': self.exit(0) self.exit(1) else: self.exit(1) else: self.trace(_('unknown action [{0}]').format(action)) self.exit(1) def run(self): self.resetTrace() self.trace(_('=== Preparing test ===')) head_info = self.config.get_current_head_info() self.trace(_('Installed head: {0}').format(head_info['name'])) if "mill" not in head_info['capabilities']: self.trace(_('Head does not support milling.')) self.trace(_('Skipping test.')) self.stop() exit(200) data = { 'id': 'start_motor', 'type': 'confirm', 'msg': _('When ready click OK to start the motor.'), 'buttons': '[OK]' } self.ns.notify('selftest', data) self.loop() self.trace(_("=== Milling motor stress test finished ===")) self.exit(self.error_code)
class TestCase(GCodePusher): def __init__(self): super(TestCase, self).__init__() self.has_opened = False self.has_closed = False # Notification service self.ns = NotifyService(config=self.config) self.error_code = 0 def trace(self, log_msg): print log_msg self.trace_logger.info(log_msg) def exit(self, error_code): self.stop() # need to stop the loop first self.error_code = error_code exit(self.error_code) def custom_action_callback(self, action, data): if action == "custom": if data[0] == 'is_probe_opened': self.has_opened = ('Yes' == data[1]) self.trace('Is probe opened...{0}'.format(data[1])) self.trace("Closing probe") self.gcs.send('M402') data = { 'id' : 'is_probe_closed', 'type': 'question', 'msg': _('Is the probe closed?'), 'buttons' : '[Yes][No]' } self.ns.notify('selftest', data) elif data[0] == 'is_probe_closed': self.has_closed = ('Yes' == data[1]) self.trace(_('Is probe closed...{0}').format(data[1])) if self.has_opened and self.has_closed: self.exit(0) else: self.exit(1) else: self.exit(1) else: self.trace(_('unknown action [{0}]').format(action)) self.exit(1) def run(self): self.resetTrace() # Preparing self.send('M402') # Start self.trace(_("=== Starting probe test ===")) self.trace(_("Opening probe")) self.send('M401') data = { 'id' : 'is_probe_opened', 'type': 'question', 'msg': _('Is the probe extended?'), 'buttons' : '[Yes][No]' } self.ns.notify('selftest', data) self.loop() self.trace(_("=== Probe test finished ===")) self.exit(self.error_code)