Example #1
0
    def __init__(self):

        self.addr = tools.get_random_uuid()
        #print("My UUID is : %s" % self.addr)

        self.engine = Engine()
        self.dev = Device("cli.experimental", self.addr)
        self.engine.add_device(self.dev)
Example #2
0
def run():
    print("Monitor test")
    eng = Engine()
    mon = monitor_example(eng)
    try:
        eng.run()
    except KeyboardInterrupt:
        import pdb
        pdb.set_trace()
Example #3
0
class xAALProxy:
    def __init__(self):

        self.addr = tools.get_random_uuid()
        #print("My UUID is : %s" % self.addr)

        self.engine = Engine()
        self.dev = Device("cli.experimental", self.addr)
        self.engine.add_device(self.dev)
        #self.eng.add_rx_handler(self.parse_answer)

    def sendmsg(self, target, action, key=None, value=None):

        addr = config.getConfigInfo(target,
                                    "xaaladdr")  #hdrware addr of the equpmt
        print addr

        self.engine.send_request(self.dev, [addr], action, None)

        #addr 224.0.29.200, port 1235
        #self.engine.get_network_connector().send(data)

    def recvmsg(self):
        data = self.engine.receive_msg()
        return data

    def filtmsg(self):
        self.engine.add_rx_handler(getalerte)
        self.engine.run()
Example #4
0
 def __init__(self):
     self.addr = tools.get_random_uuid()
     self.engine = Engine()
     self.dev = Device("cli.experimental", self.addr)
     self.dev.vendor_id = 'IHSEV'
     self.dev.info = 'chute'
     self.engine.add_device(self.dev)
     self.threadlist = []
     self.fallEvent = threading.Event()
     self.pepper = Pepper(self)
     self.kinect = Kinect()
     self.sensfloor = Sensfloor(self.engine)
Example #5
0
def main():
    if len(sys.argv) == 2:
        addr = sys.argv[1]
        if tools.is_valid_addr(addr):
            t0 = time.time()
            eng = Engine()
            eng.start()
            dev = QueryDB(eng)
            dev.query(addr)
            print("Time : %0.3f sec" % (time.time() - t0))
        else:
            print("Invalid addr")

    else:
        usage()
Example #6
0
def setup():
    """ setup xAAL Engine & Device. And start it in a Greenlet"""
    helpers.setup_console_logger()
    global monitor
    engine = Engine()
    cfg = tools.load_cfg(PACKAGE_NAME)
    if not cfg:
        logger.info('Missing config file, building a new one')
        cfg = tools.new_cfg(PACKAGE_NAME)
        cfg.write()

    dev = Device("hmi.basic")
    dev.address = cfg['config']['addr']
    dev.vendor_id = "IHSEV"
    dev.product_id = "WEB Interface"
    dev.version = 0.1
    dev.info = "%s@%s" % (PACKAGE_NAME, platform.node())

    engine.add_device(dev)
    db_server = None
    if 'db_server' in cfg['config']:
        db_server = cfg['config']['db_server']
    else:
        logger.info('You can set "db_server" in the config file')
    monitor = Monitor(dev, filter_func=monitor_filter, db_server=db_server)
    monitor.subscribe(event_handler)

    engine.start()
    green_let = Greenlet(xaal_loop, engine)
    green_let.start()
Example #7
0
def main(addr):
    if addr == None:
        addr = tools.get_random_uuid()
    dev = Device("switch.basic",addr)
    dev.product_id = 'One Simple test of Switch'
    dev.url = 'http://www.acme.org'

    # attributes
    state = dev.new_attribute('state')

    dev.dump()

    # methods
    def on():
        state.value = True
        print("%s ON" % dev)

    def off():
        state.value = False
        print("%s OFF" %dev)

    dev.add_method('on',on)
    dev.add_method('off',off)

    eng = Engine()
    eng.add_device(dev)
    #eng.run()
    eng.start()
Example #8
0
def main(addr):
    if addr == None:
        addr = tools.get_random_uuid()
    dev = Device("lamp.dimmer", addr)
    dev.product_id = 'Dummy Dimming Lamp'
    dev.url = 'http://www.acme.org'

    # attributes
    light = dev.new_attribute('light')
    dimmer = dev.new_attribute('dimmer', 50)

    dev.dump()

    # methods
    def on():
        light.value = True
        print("%s ON" % dev)

    def off():
        light.value = False
        print("%s OFF" % dev)

    def dim(_target):
        dimmer.value = _target
        print("Dimming to %d" % _target)

    dev.add_method('on', on)
    dev.add_method('off', off)
    dev.add_method('dim', dim)

    eng = Engine()
    eng.add_device(dev)
    eng.run()
Example #9
0
def main(addr):
    if addr == None:
        addr = tools.get_random_uuid()
    dev = Device("powerrelay.basic", addr)
    dev.product_id = 'Dummy Power Relay'
    dev.url = 'http://www.acme.org'

    # attributes
    power = dev.new_attribute('power')

    dev.dump()

    # methods
    def on():
        power.value = True
        print("%s ON" % dev)

    def off():
        power.value = False
        print("%s OFF" % dev)

    dev.add_method('on', on)
    dev.add_method('off', off)

    eng = Engine()
    eng.add_device(dev)
    eng.run()
Example #10
0
def setup_xaal():
    """ setup xAAL Engine & Device. And start it in a Greenlet"""
    global monitor
    engine = Engine()
    cfg = tools.load_cfg_or_die(PACKAGE_NAME)

    dev = Device("hmi.basic")
    dev.address = cfg['config']['addr']
    dev.vendor_id = "IHSEV"
    dev.product_id = "REST API"
    dev.version = 0.1
    dev.info = "%s@%s" % (PACKAGE_NAME, platform.node())

    engine.add_device(dev)
    monitor = Monitor(dev, filter_func=monitor_filter)
    engine.start()
    green_let = Greenlet(xaal_loop, engine)
    green_let.start()
Example #11
0
def run():
    eng = Engine()
    log = MQTTLogger(eng)
    eng.run()
Example #12
0
import time, random, sys
from xaal.lib import Engine, Device, tools

target = sys.argv[-1]
dev = Device("switch.basic", tools.get_random_uuid())

eng = Engine()
eng.start()

while 1:

    eng.send_request(dev, [
        target,
    ], 'dim', {'target': random.randint(0, 100)})
    eng.loop()
    time.sleep(5)

    eng.send_request(dev, [
        target,
    ], 'on')
    print('ON')
    eng.loop()
    time.sleep(3)

    eng.send_request(dev, [
        target,
    ], 'off')
    print('OFF')
    eng.loop()
    time.sleep(3)
Example #13
0
def run():
    eng = Engine()
    log = WARP10Logger(eng)
    eng.run()
Example #14
0
def run():
    eng = Engine()
    gw = GW(eng)
    eng.run()
Example #15
0
class Controller:
    def __init__(self):
        self.addr = tools.get_random_uuid()
        self.engine = Engine()
        self.dev = Device("cli.experimental", self.addr)
        self.dev.vendor_id = 'IHSEV'
        self.dev.info = 'chute'
        self.engine.add_device(self.dev)
        self.threadlist = []
        self.fallEvent = threading.Event()
        self.pepper = Pepper(self)
        self.kinect = Kinect()
        self.sensfloor = Sensfloor(self.engine)

    # thread to receive/send the xaal message
    def engineLoop(self, event):
        print "Sensfloor engine start->"
        while (not event.is_set()):  #not self.sensfloor.falldetected:
            self.engine.loop()
            if self.sensfloor.falldetected:
                event.set()
                print "[Sensfloor] fallEvent set by sensfloor"

    def run(self):

        # start falling detection with sensfloor
        if True:
            engineRun = threading.Thread(target=self.engineLoop,
                                         args=(self.fallEvent, ),
                                         name="sensfloor")
            engineRun.start()
            self.threadlist.append(engineRun)

        # start falling detection with kinect
        if True:
            self.kinect.setEvent(self.fallEvent)
            self.kinect.start()
            self.threadlist.append(self.kinect)

        # wait the two thread to be finished
        for thread in self.threadlist:
            thread.join()

            if (self.sensfloor.cpos != [] and self.sensfloor.spos != []):
                fallPosition = self.sensfloor.spos
                print "[Sensfloor] x : %f, y : %f distance %f, direction %f" % (
                    self.sensfloor.cpos[0], self.sensfloor.cpos[1],
                    self.sensfloor.spos[0], self.sensfloor.spos[1])
            elif (self.kinect.pos_c != []):
                # mapping from the sensfloor position to robot cmd (distance, direction)
                fallPosition = self.sensfloor.transformCartesianToPolar(
                    3.5, 7, self.kinect.pos_c[0], self.kinect.pos_c[1])
                print "[Kinect] x : %f, y : %f" % (self.kinect.pos_c[0],
                                                   self.kinect.pos_c[1])

        print "[Controller INFO] All fall detection finished"

        # the robot reach to the position and communicate with the person
        if self.fallEvent.is_set() and True:
            self.pepper.postureInit()
            self.pepper.say("I have detected that a person fell down")

            self.pepper.moveToPerson(fallPosition)

            # start searching the face of the person and dialogue face to face
            self.headposition = self.pepper.searchFace(
                15)  # search face time_out 15s
            if self.headposition == []:
                print "No position"
            else:
                print "[Face Detection INFO] Average pitch %f, yaw %f" % (
                    self.headposition[0], self.headposition[1])

            # verify the state of the of the person
            if self.pepper.dialogue():
                self.pepper.speakToPersonDetected("All right")
            else:
                self.pepper.speakToPersonDetected("Don't worry")
                self.scenario()
            self.pepper.postureInit()
            self.pepper.returnToInitPosition(fallPosition)

    def sendMail(self):
        #link = self.webRTCaddress()
        topic = "nao_robot/camera/top/camera/image_raw"
        text = "The assistance robot and smart house has detected a fall. To check, please see the video from this address "  #+ link
        text = text + "/stream_viewer?topic=" + topic
        mail = Mail(text)
        mail.sendMail()

    def webRTCaddress(self):
        ni.ifaddresses('wlan0')
        ip = ni.ifaddresses('wlan0')[2][0]['addr'] + ":8080"
        print "HostIP : ", ip
        return ip

    def scenario(self):
        self.smartDeviceAction("shutterleft", "up")
        self.smartDeviceAction("shutterright", "up")
        self.smartDeviceAction("lamp1", "on")
        self.smartDeviceAction("lamp2", "on")
        self.smartDeviceAction("lamp3", "on")
        self.smartDeviceAction("lamp4", "on")
        self.smartDeviceAction("lamp5", "on")
        self.smartDeviceAction("lamp6", "on")
        self.pepper.say("I turn the lights on")
        print "lampes allumeees"
        try:
            self.sendMail()
            self.pepper.say("I sent an email to your contact list")
        except:
            print "mail send failed"
        self.engine.loop()

    def smartDeviceAction(self, device, action):
        addr = config.getConfigInfo(device,
                                    "xaaladdr")  #hdrware addr of the equpmt
        print addr
        self.engine.send_request(self.dev, [addr], action, None)
Example #16
0
def run():
    eng = Engine()
    log = GW(eng)
    eng.run()
Example #17
0
def run():
    eng = Engine()    
    log = InfluxDBLogger(eng)
    eng.run()
Example #18
0
def run():
    eng = Engine()
    ipx = GW.spawn(eng)
    eng.run()
Example #19
0
def run():
    eng = Engine()
    net = GW.spawn(eng)
    eng.run()
Example #20
0
def main(addr):
    if addr == None:
        addr = tools.get_random_uuid()
    dev = Device("controlerMedia.basic", addr)
    dev.product_id = 'Controler DLNA'
    dev.url = 'http://www.acme.org'

    # attributes
    destination_media = dev.new_attribute('destination_media')
    source_media = dev.new_attribute('source_media')
    state_media = dev.new_attribute('state_media')
    position_media = dev.new_attribute('position_media')

    dev.dump()

    # methods
    def get_attributes():
        print("Attributs")

    ########### Ensemble des methodes liees a la mise en place du media ##########
    def set_destination(_dest):
        # Met la valeur du media player a utiliser dans la variable "destination_media"
        destination_media.value = _dest
        print("Destination \"" + _dest + "\" is set")

    def get_destinations():
        # Interroge le dBus pour connaitre les media renderer en DLNA
        # Envoie à l'utilisateur les destinations sous forme de liste
        available_dest = {"renderer1": "salon", "renderer2": "cuisine"}
        print("Display destinations")
        return available_dest

    def set_source(_src):
        # Met la valeur du media server a utiliser dans la variable "source_media"
        source_media.value = _src
        print("Source \"" + _src + "\" is set")

    def get_sources():
        # Interroge le dBus pour connaitre les media server en DLNA
        # Envoie à l'utilisateur les medias sous forme de liste
        available_media = {"media1": "NAS\\video1", "media2": "NAS\\video2"}
        print("Display sources")
        return available_media

    ########## Ensemble des methodes liees a l'etat du media lorsqu'il est en cours de lecture #########
    def play():
        state_media.value = True
        # Commande DLNA pour lancer le media
        print("%s Play" % dev)

    def pause():
        state_media.value = False
        # Commande DLNA pour mettre le media sur pause
        print("%s Pause" % dev)

    def stop():
        print("Media is stop")

    def next():
        print("Next media is play")

    def prev():
        print("Previous media is play")

    def moving_forward():
        print("Media is forwarding of 10 secondes")

    def moving_back():
        print("Media is backing of 10 secondes")

    dev.add_method('get_attributes', get_attributes)
    dev.add_method('set_destination', set_destination)
    dev.add_method('get_destinations', get_destinations)
    dev.add_method('set_source', set_source)
    dev.add_method('get_sources', get_sources)
    dev.add_method('play', play)
    dev.add_method('pause', pause)
    dev.add_method('stop', stop)
    dev.add_method('next', next)
    dev.add_method('prev', prev)
    dev.add_method('moving_forward', moving_forward)
    dev.add_method('moving_back', moving_back)

    eng = Engine()
    eng.add_device(dev)
    eng.run()
Example #21
0
def run():
    eng = Engine()
    mdb = MetaDB(eng)
    eng.run()
    print("Welcome,\n")
    
    print("Please choose the action (n°):")
    print("1. play")
    print("2. pause")
    print("3. destination")
    print("4. source")
    print("\n0. Quit")
    choice = input(" >>  ")
    exec_menu(choice)


# Main definition
addr = "f2fc6dac-4ffb-11ea-a473-0800276d39fa"
dev = Device("basic.basic", addr)
eng = Engine()
eng.add_device(dev)
addrMedia = ""
compteur_attente_dest = 0
compteur_attente_src = 0

# Menu definition
menu_actions = {
    'main_menu': main,
    '1': play,
    '2': pause,
    '3': set_destination,
    '4': set_source,
    '9': back,
    '0': exit,
}