Exemple #1
0
class HumService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:HumService:1"
    serviceId = "urn:upnp-org:serviceId:HumService"

    actions = {'GetHum': [ServiceActionArgument('Hum', 'out', 'Hum')]}

    stateVariables = [
        # Variables
        ServiceStateVariable('Hum', 'string', sendEvents=True),
        ServiceStateVariable('ListeningHum', 'boolean', sendEvents=True)
    ]

    state = EventProperty('ListeningHum')
    hum = EventProperty('Hum')

    @register_action('GetHum')
    def getState(self):
        return {'Hum': str(read_hum())}

    def listen_to_hum_sensor(self, s):
        print "Listening for hum sensor values"
        tmp = 10
        tmp1 = 10
        while True:
            threadRead.mutex.acquire(1)
            print("Hum a pris le mutex\n")
            try:
                tmp1 = read_hum()
                print "J'entre dans le listen de hum\n"
                if tmp1 > 2000 or tmp1 == -1:
                    print "Valeur non changee erreur\n"

                if tmp1 > (tmp - 50) and tmp1 < (tmp + 50):
                    print "Valeur non changee trop proche\n"

                if (tmp1 < (tmp - 50) or tmp1 > (tmp + 50)) and tmp1 != -1:
                    self.hum = tmp1
                    tmp = tmp1

                #print read_lum()
                time.sleep(10)
                threadRead.mutex.release()
                print("Hum a rendu le mutex\n")
                time.sleep(3)
            except IOError as e:
                print "I/O error({0}): {1}".format(e.errno, e.strerror)
                time.sleep(0.5)
                threadRead.mutex.release()
                print("Hum a rendu le mutex\n")
        return

    def startListening(self):
        self.state = True
        self.thread = threading.Thread(target=HumService.listen_to_hum_sensor,
                                       args=(self, 0))
        self.thread.daemon = True
        self.thread.start()
        return {'ListeningHum': True}
Exemple #2
0
class DistanceService(Service):

	version = (1, 0)
	serviceType = "urn:schemas-upnp-org:service:DistanceService:1"
	serviceId = "urn:upnp-org:serviceId:DistanceService"

	actions = {
		'GetDistance': [
			ServiceActionArgument('Distance','out','Distance')
		]
	}
	
	stateVariables = [
		# Variables
		ServiceStateVariable('Distance','boolean',sendEvents=True)	,	
		ServiceStateVariable('ListeningDistance','boolean',sendEvents=True)

	]
		
	state=EventProperty('ListeningDistance')
	distance=EventProperty('Distance')

	@register_action('GetDistance')
	def getState(self):
		return {
			'Distance' : str(read_distance())
		}
		
	def listen_to_distance_sensor(self, s):
		print "Listening for distance sensor values"
		while True:
			threadRead.mutex1.acquire(1)
			print("Distance a pris le mutex\n");
			try:
				print "J'entre dans le listen de distance\n"
				self.distance = read_distance()
				time.sleep(5)
				threadRead.mutex1.release()
				print("Distance a rendu le mutex\n");
				time.sleep(5)
			except IOError as e:
				print "Erreur\n"
				print "I/O error({0}): {1}".format(e.errno, e.strerror)
				time.sleep(0.5)
				threadRead.mutex1.release()
				print("Distance a rendu le mutex\n");
		return
		
		
	def startListening(self):
		self.state=True
		
		self.thread = threading.Thread(target=DistanceService.listen_to_distance_sensor, args = (self,0))
		self.thread.daemon = True
		self.thread.start();
		return {
			'ListeningDistance':True
		}
Exemple #3
0
class PressionService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:PressionService:1"
    serviceId = "urn:upnp-org:serviceId:PressionService"

    actions = {
        'GetPression': [ServiceActionArgument('Pression', 'out', 'Pression')]
    }

    stateVariables = [
        # Variables
        ServiceStateVariable('Pression', 'string', sendEvents=True),
        ServiceStateVariable('ListeningPression', 'boolean', sendEvents=True)
    ]

    state = EventProperty('ListeningPression')
    pression = EventProperty('Pression')

    @register_action('GetPression')
    def getState(self):
        return {'Pression': str(read_pression())}

    def listen_to_pression_sensor(self, s):
        print "Listening for pression sensor values"
        tmp = 10
        tmp1 = 10
        while True:
            try:

                tmp1 = read_pression()
                print "J'entre dans le listen de pression\n"
                if tmp1 > 2000 or tmp1 == -1:
                    print "Valeur non changee erreur\n"

                if tmp1 > (tmp - 50) or tmp1 < (tmp + 50):
                    print "Valeur non changee trop proche\n"

                if tmp1 < (tmp - 50) or tmp1 > (tmp + 50):
                    self.pression = tmp1
                    tmp = tmp1

                time.sleep(5)
            except IOError as e:
                print "I/O error({0}): {1}".format(e.errno, e.strerror)
                time.sleep(0.5)
        return

    def startListening(self):
        self.state = True

        self.thread = threading.Thread(
            target=PressionService.listen_to_pression_sensor, args=(self, 0))
        self.thread.daemon = True
        self.thread.start()
        return {'ListeningPression': True}
class RemoteControlService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:RemoteControlService:1"
    serviceId = "urn:upnp-org:serviceId:RemoteControlService"

    subscription_timeout_range = (None, None)

    stateVariables = [
        # Arguments
        # ServiceStateVariable('button',                  'string', sendEvents=True),
        # ServiceStateVariable('beginRecognitionControl', 'ui4', sendEvents=True),
        ServiceStateVariable('tvCommandControl', 'string', sendEvents=True),
    ]

    actions = {
        # 'Click': [
        #     ServiceActionArgument('button',         'in',   'button'),
        # ],
        # 'SetTvCommand': [
        #     ServiceActionArgument('command',      'string',   'tvCommandControl'),
        # ],
    }

    # button                  = EventProperty('button')
    # beginRecognitionControl = EventProperty('beginRecognitionControl')
    tvCommandControl = EventProperty('tvCommandControl')
Exemple #5
0
class AccService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:Accelerometre:1"
    serviceId = "urn:upnp-org:serviceId:Accelerometre"

    subscription_timeout_range = (None, None)

    stateVariables = [
        # Arguments
        ServiceStateVariable('steps', 'string', sendEvents=True),
    ]

    actions = {
        'StartSuivi': [],
        'StopSuivi': [],
    }

    steps = EventProperty('steps')
    send = False

    @register_action('StartSuivi')
    def startSuivi(self):
        raise NotImplementedError()

    @register_action('StopSuivi')
    def stopSuivi(self):
        raise NotImplementedError()
Exemple #6
0
class DetectionService(Service):

    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:SensorService:1"
    serviceId = "urn:upnp-org:serviceId:SensorService"

    actions = {
        'setDetect':
        [ServiceActionArgument('detectOrNot', 'in', 'detectOrNot')]
    }

    stateVariables = [
        ServiceStateVariable('sensor1', 'boolean', sendEvents=True),
        ServiceStateVariable('sensor2', 'boolean', sendEvents=True),
        ServiceStateVariable('sensor3', 'boolean', sendEvents=True),
        ServiceStateVariable('detectOrNot', 'boolean', sendEvents=True),
        ServiceStateVariable('ListeningSensor', 'boolean', sendEvents=True)
    ]

    state = EventProperty('ListeningSensor')
    sen1 = EventProperty('sensor1', False)
    sen2 = EventProperty('sensor2', False)
    sen3 = EventProperty('sensor3', False)

    @register_action('setDetect')
    def setD(self, arg):
        print arg, type(arg), bool(int(arg))
        print "setDetect called"
        self.sen1 = False
        self.sen2 = False
        self.sen3 = False
        while bool(int(arg)):
            print "setDetect : in while"
            self.m1 = read_sensor(pir_sensor1)
            self.m2 = read_sensor(pir_sensor2)
            self.m3 = read_sensor(pir_sensor3)
            print self.m1, self.m2, self.m3
            if self.m1 == True:
                self.sen1 = self.m1
                break
            if self.m2 == True:
                self.sen2 = self.m2
                break
            if self.m3 == True:
                self.sen3 = self.m3
                break
        print "setDetect end"
Exemple #7
0
class MediaReceiverRegistrarService(Service):
    version = (1, 0)
    serviceType = "urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar:1"
    serviceId = "urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar"

    actions = {
        'IsAuthorized': [
            ServiceActionArgument('DeviceID', 'in', 'A_ARG_TYPE_DeviceID'),
            ServiceActionArgument('Result', 'out', 'A_ARG_TYPE_Result'),
        ],
        'RegisterDevice': [
            ServiceActionArgument('RegistrationReqMsg', 'in',
                                  'A_ARG_TYPE_RegistrationReqMsg'),
            ServiceActionArgument('RegistrationRespMsg', 'out',
                                  'A_ARG_TYPE_RegistrationRespMsg'),
        ],
        'IsValidated': [
            ServiceActionArgument('DeviceID', 'in', 'A_ARG_TYPE_DeviceID'),
            ServiceActionArgument('Result', 'out', 'A_ARG_TYPE_Result'),
        ],
    }
    stateVariables = [
        # Arguments
        ServiceStateVariable('A_ARG_TYPE_DeviceID', 'string'),
        ServiceStateVariable('A_ARG_TYPE_Result', 'int'),
        ServiceStateVariable('A_ARG_TYPE_RegistrationReqMsg', 'bin.base64'),
        ServiceStateVariable('A_ARG_TYPE_RegistrationRespMsg', 'bin.base64'),

        # Variables
        ServiceStateVariable('AuthorizationGrantedUpdateID',
                             'ui4',
                             sendEvents=True),
        ServiceStateVariable('AuthorizationDeniedUpdateID',
                             'ui4',
                             sendEvents=True),
        ServiceStateVariable('ValidationSucceededUpdateID',
                             'ui4',
                             sendEvents=True),
        ServiceStateVariable('ValidationRevokedUpdateID',
                             'ui4',
                             sendEvents=True),
    ]

    @register_action('IsAuthorized')
    def isAuthorized(self, device_id):
        raise NotImplementedError()

    @register_action('RegisterDevice')
    def registerDevice(self, request):
        raise NotImplementedError()

    @register_action('IsValidated')
    def isValidated(self, device_id):
        raise NotImplementedError()
Exemple #8
0
class FileManageService(Service):

    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:FileManageService:1"
    serviceId = "urn:upnp-org:serviceId:FileManageService"

    actions = {
        'ScanDir': [ServiceActionArgument('scan_ret', 'out', 'scan_ret')],
        'GetPicture': [
            ServiceActionArgument('path', 'in', 'path'),
            ServiceActionArgument('data', 'out', 'data')
        ],
        'DeleteFile':
        [ServiceActionArgument('fileToDelete', 'in', 'fileToDelete')]
    }

    stateVariables = [
        ServiceStateVariable('allFile', 'string', sendEvents=True),
        ServiceStateVariable('path', 'string', sendEvents=True),
        ServiceStateVariable('ListeningDir', 'string', sendEvents=True),
        ServiceStateVariable('data', 'string', sendEvents=True),
        ServiceStateVariable('scan_ret', 'string', sendEvents=True),
        ServiceStateVariable('fileToDelete', 'string', sendEvents=True)
    ]

    state = EventProperty('ListeningDir')
    string = EventProperty('allFile')
    data = EventProperty('data')
    deletedFile = EventProperty('fileToDelete')

    @register_action('ScanDir')
    def scanD(self):
        self.r = 1
        self.r += 1
        print "IN SCAN DIR"
        #self.string = str(read_dir("/home/pi/PICTURE_FROM_HIBOO/"))
        return {'scan_ret': str(read_dir("/home/pi/PICTURE_FROM_HIBOO/"))}

    @register_action('GetPicture')
    def getPicture(self, arg):
        print "IN GET PICTURE: " + str(arg)
        with open("/home/pi/PICTURE_FROM_HIBOO/" + str(arg),
                  "rb") as self.imageFile:
            #self.imageFile = open(str(arg), "rb")
            self.res = base64.b64encode(self.imageFile.read())
            print(len(self.res))
            print("decode done")
            self.fh = open("imageToSave.png", "wb")
            self.fh.write(base64.b64decode(self.res))
            self.fh.close()
        return {
            'data': self.res  # base64.b64encode(open(str(arg), "rb").read())
        }

    @register_action('DeleteFile')
    def empty(self, arg):
        print("IN DELETE FILE : " + str(arg))
        self.folder = "/home/pi/PICTURE_FROM_HIBOO"
        os.remove(self.folder + "/" + arg)
Exemple #9
0
class HeartRateService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:HeartRate:1"
    serviceId = "urn:upnp-org:serviceId:HeartRate"

    subscription_timeout_range = (None, None)

    stateVariables = [
        # Arguments
        ServiceStateVariable('heartrate', 'string', sendEvents=True),
    ]

    heartrate = EventProperty('heartrate')
Exemple #10
0
class ServoService(Service):

    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:ServoSercice:1"
    serviceId = "urn:upnp-org:serviceId:ServoSercice"

    actions = {
        'TurnServo': [
            ServiceActionArgument('angle', 'in', 'angle'),
            ServiceActionArgument('finished', 'out', 'finished')
        ]
    }

    stateVariables = [
        ServiceStateVariable('angle', 'string', sendEvents=True),
        ServiceStateVariable('ListeningServo', 'boolean', sendEvents=True),
        ServiceStateVariable('finished', 'boolean', sendEvents=True)
    ]

    state = EventProperty('ListeningServo')
    angle = EventProperty('angle')
    finished = EventProperty('finished', False)

    @register_action('TurnServo')
    def turnS(self, arg):
        if (int(arg) > 250 or int(arg) < 50):
            return
        if (int(arg) == 50):
            os.system("echo 0=" + str(arg) + " > /dev/servoblaster")
            time.sleep(1)
            os.system("echo 0=" + str(0) + " > /dev/servoblaster")
        else:
            os.system("echo 0=" + str(arg) + " > /dev/servoblaster")
        time.sleep(1)
        if self.finished == True:
            return {'finished': False}
        if self.finished == False:
            return {'finished': True}
Exemple #11
0
class CameraService(Service):

    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:CameraService:1"
    serviceId = "urn:upnp-org:serviceId:CameraService"

    actions = {'TakePicture': [ServiceActionArgument('take', 'out', 'take')]}

    stateVariables = [
        ServiceStateVariable('take', 'boolean', sendEvents=True),
        ServiceStateVariable('ListeningCamera', 'boolean', sendEvents=True)
    ]

    state = EventProperty('ListeningCamera')
    take = EventProperty('take', False)

    #camera = picamera.PiCamera()

    @register_action('TakePicture')
    def takeP(self):
        print "IN TAKE PICTURE"
        takePicture()
        return {'take': True}
Exemple #12
0
class GPSService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:GPS:1"
    serviceId = "urn:upnp-org:serviceId:GPS"

    subscription_timeout_range = (None, None)

    stateVariables = [
        # Arguments
        ServiceStateVariable('location', 'string', sendEvents=True),
    ]
    actions = {
        'SendLocation': [],
    }

    location = EventProperty('location')
    send = False

    @register_action('SendLocation')
    def sendLocation(self):
        raise NotImplementedError()
class SpeechToTextService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:SpeechToTextService:1"
    serviceId = "urn:upnp-org:serviceId:SpeechToTextService"

    subscription_timeout_range = (None, None)

    stateVariables = [
        # Arguments
        ServiceStateVariable('transcribedText', 'string', sendEvents=True),
    ]

    actions = {
        'BeginRecognition': [],
    }

    transcribedText = EventProperty('transcribedText')

    @register_action('BeginRecognition')
    def beginRecognition(self):
        raise NotImplementedError()
Exemple #14
0
class TmApplicationServer(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:TmApplicationServer:1"
    serviceId = "urn:upnp-org:serviceId:TmApplicationServer"

    actions = {
        'GetApplicationList': [
            ServiceActionArgument('AppListingFilter',       'in',   'A_ARG_TYPE_String'),
            ServiceActionArgument('ProfileID',              'in',   'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('AppListing',             'out',  'A_ARG_TYPE_AppList'),
        ],
        'LaunchApplication': [
            ServiceActionArgument('AppID',                  'in',   'A_ARG_TYPE_AppID'),
            ServiceActionArgument('ProfileID',              'in',   'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('AppURI',                 'out',  'A_ARG_TYPE_URI'),
        ],
        'TerminateApplication': [
            ServiceActionArgument('AppID',                  'in',   'A_ARG_TYPE_AppID'),
            ServiceActionArgument('ProfileID',              'in',   'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('TerminationResult',      'out',  'A_ARG_TYPE_Bool'),
        ],
        'GetApplicationStatus': [
            ServiceActionArgument('AppID',                  'in',   'A_ARG_TYPE_AppID'),
            ServiceActionArgument('AppStatus',              'out',  'A_ARG_TYPE_AppStatus'),
        ],
        'GetApplicationCertificateInfo': [
            ServiceActionArgument('AppID',                  'in',   'A_ARG_TYPE_AppID'),
            ServiceActionArgument('AppCertification',       'out',  'A_ARG_TYPE_AppCertificateInfo'),
        ],
        'GetCertifiedApplicationsList': [
            ServiceActionArgument('AppCertFilter',          'in',   'A_ARG_TYPE_String'),
            ServiceActionArgument('ProfileID',              'in',   'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('CertifiedAppList',       'out',  'A_ARG_TYPE_String'),
        ],
        'GetAppCertificationStatus': [
            ServiceActionArgument('AppID',                  'in',   'A_ARG_TYPE_AppID'),
            ServiceActionArgument('AppCertFilter',          'in',   'A_ARG_TYPE_String'),
            ServiceActionArgument('ProfileID',              'in',   'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('AppCertified',           'out',  'A_ARG_TYPE_Bool'),
        ],
        'SetAllowedApplicationsList': [
            ServiceActionArgument('AllowedAppListNonRestricted', 'in',   'A_ARG_TYPE_String'),
            ServiceActionArgument('AllowedAppListRestricted', 'in',   'A_ARG_TYPE_String'),
            ServiceActionArgument('ProfileID',              'in',   'A_ARG_TYPE_ProfileID'),
        ],
    }

    stateVariables = [
        # Variables
        ServiceStateVariable('AppStatusUpdate',                 'string',
                             sendEvents=True),
        ServiceStateVariable('AppListUpdate',                   'string',
                             sendEvents=True),

        # Arguments
        ServiceStateVariable('A_ARG_TYPE_AppStatus',            'string'),
        ServiceStateVariable('A_ARG_TYPE_AppList',              'string'),
        ServiceStateVariable('A_ARG_TYPE_AppID',                'string'),
        ServiceStateVariable('A_ARG_TYPE_ProfileID',            'ui4'),
        ServiceStateVariable('A_ARG_TYPE_URI',                  'URI'),
        ServiceStateVariable('A_ARG_TYPE_String',               'string'),
        ServiceStateVariable('A_ARG_TYPE_Bool',                 'string', [
            'false',
            'true'
        ]),
        ServiceStateVariable('A_ARG_TYPE_Int',                  'ui4'),
        ServiceStateVariable('A_ARG_TYPE_AppCertificateInfo',   'string'),
    ]

    # Events that can be registered to
    app_status_update = EventProperty('AppStatusUpdate')
    app_list_update = EventProperty('AppListUpdate')
    # TODO: How to handle the changes...?


    def __init__(self):
        Service.__init__(self)

        # Initialize D-BUS connection to the application server
        self.dbus = dbus.SessionBus()
        self.session = self.dbus.get_object('org.tmlink', '/org/tmlink')
        self.iface = dbus.Interface(self.session, 'org.tmlink.ApplicationServer')

    @register_action('GetApplicationList')
    def getApplicationList(self, appListingFilter, profileID):
        return {'AppListing': self.iface.ApplicationList()}

    @register_action('LaunchApplication')
    def launchApplication(self, appID, profileID):
        return {'AppURI': self.iface.LaunchApplication(appID)}

    @register_action('TerminateApplication')
    def terminateApplication(self, appID, profileID):
        return {'TerminationResult': self.iface.TerminateApplication(appID)}

    @register_action('GetApplicationStatus')
    def getApplicationStatus(self, appID):
        return {'AppStatus': self.iface.GetApplicationStatus(appID)}

    @register_action('GetApplicationCertificateInfo')
    def getApplicationCertificateInfo(self, appID):
        raise upnpError(815, 'Device Locked') # TODO: Implement

    @register_action('GetCertifiedApplicationsList')
    def getCertifiedApplicationsList(self, appCertFilter, profileID):
        raise upnpError(815, 'Device Locked') # TODO: Implement

    @register_action('GetAppCertificationStatus')
    def getAppCertificationStatus(self, appID, appCertFilter, profileID):
        raise upnpError(815, 'Device Locked') # TODO: Implement

    @register_action('SetAllowedApplicationsList')
    def setAllowedApplicationsList(self, allowedAppListNonRestricted, allowedAppListRestricted, profileID):
        raise upnpError(815, 'Device Locked') # TODO: Implement
Exemple #15
0
class ContentDirectoryService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:ContentDirectory:1"
    serviceId = "urn:upnp-org:serviceId:ContentDirectory"

    subscription_timeout_range = (None, None)

    actions = {
        'Browse': [
            ServiceActionArgument('ObjectID', 'in', 'A_ARG_TYPE_ObjectID'),
            ServiceActionArgument('BrowseFlag', 'in', 'A_ARG_TYPE_BrowseFlag'),
            ServiceActionArgument('Filter', 'in', 'A_ARG_TYPE_Filter'),
            ServiceActionArgument('StartingIndex', 'in', 'A_ARG_TYPE_Index'),
            ServiceActionArgument('RequestedCount', 'in', 'A_ARG_TYPE_Count'),
            ServiceActionArgument('SortCriteria', 'in',
                                  'A_ARG_TYPE_SortCriteria'),
            ServiceActionArgument('Result', 'out', 'A_ARG_TYPE_Result'),
            ServiceActionArgument('NumberReturned', 'out', 'A_ARG_TYPE_Count'),
            ServiceActionArgument('TotalMatches', 'out', 'A_ARG_TYPE_Count'),
            ServiceActionArgument('UpdateID', 'out', 'A_ARG_TYPE_UpdateID'),
        ],
        'GetSearchCapabilities': [
            ServiceActionArgument('SearchCaps', 'out', 'SearchCapabilities'),
        ],
        'GetSortCapabilities': [
            ServiceActionArgument('SortCaps', 'out', 'SortCapabilities'),
        ],
        'GetSystemUpdateID': [
            ServiceActionArgument('Id', 'out', 'SystemUpdateID'),
        ],
        'UpdateObject': [
            ServiceActionArgument('ObjectID', 'in', 'A_ARG_TYPE_ObjectID'),
            ServiceActionArgument('CurrentTagValue', 'in',
                                  'A_ARG_TYPE_TagValueList'),
            ServiceActionArgument('NewTagValue', 'in',
                                  'A_ARG_TYPE_TagValueList'),
        ],
        'Search': [
            ServiceActionArgument('ContainerID', 'in', 'A_ARG_TYPE_ObjectID'),
            ServiceActionArgument('SearchCriteria', 'in',
                                  'A_ARG_TYPE_SearchCriteria'),
            ServiceActionArgument('Filter', 'in', 'A_ARG_TYPE_Filter'),
            ServiceActionArgument('StartingIndex', 'in', 'A_ARG_TYPE_Index'),
            ServiceActionArgument('RequestedCount', 'in', 'A_ARG_TYPE_Count'),
            ServiceActionArgument('SortCriteria', 'in',
                                  'A_ARG_TYPE_SortCriteria'),
            ServiceActionArgument('Result', 'out', 'A_ARG_TYPE_Result'),
            ServiceActionArgument('NumberReturned', 'out', 'A_ARG_TYPE_Count'),
            ServiceActionArgument('TotalMatches', 'out', 'A_ARG_TYPE_Count'),
            ServiceActionArgument('UpdateID', 'out', 'A_ARG_TYPE_UpdateID'),
        ],
        'X_GetRemoteSharingStatus': [
            ServiceActionArgument('Status', 'out', 'X_RemoteSharingEnabled'),
        ],
    }
    stateVariables = [
        # Arguments
        ServiceStateVariable('A_ARG_TYPE_ObjectID', 'string'),
        ServiceStateVariable('A_ARG_TYPE_Result', 'string'),
        ServiceStateVariable('A_ARG_TYPE_SearchCriteria', 'string'),
        ServiceStateVariable('A_ARG_TYPE_BrowseFlag', 'string',
                             ['BrowseMetadata', 'BrowseDirectChildren']),
        ServiceStateVariable('A_ARG_TYPE_Filter', 'string'),
        ServiceStateVariable('A_ARG_TYPE_SortCriteria', 'string'),
        ServiceStateVariable('A_ARG_TYPE_Index', 'ui4'),
        ServiceStateVariable('A_ARG_TYPE_Count', 'ui4'),
        ServiceStateVariable('A_ARG_TYPE_UpdateID', 'ui4'),
        ServiceStateVariable('A_ARG_TYPE_TagValueList', 'string'),

        # Variables
        ServiceStateVariable('SearchCapabilities', 'string'),
        ServiceStateVariable('SortCapabilities', 'string'),
        ServiceStateVariable('SystemUpdateID', 'ui4', sendEvents=True),
        #ServiceStateVariable('ContainerUpdateIDs',          'string',
        #                     sendEvents=True),
        ServiceStateVariable('X_RemoteSharingEnabled',
                             'boolean',
                             sendEvents=True),
    ]

    system_update_id = EventProperty('SystemUpdateID')
    #container_update_ids = EventProperty('ContainerUpdateIDs')
    remote_sharing_enabled = EventProperty('X_RemoteSharingEnabled', 1)

    @register_action('Browse')
    def browse(self, objectID, browseFlag, browseFilter, startingIndex,
               requestedCount, sortCriteria):
        raise NotImplementedError()

    @register_action('GetSearchCapabilities')
    def getSearchCapabilities(self):
        raise NotImplementedError()

    @register_action('GetSortCapabilities')
    def getSortCapabilities(self):
        raise NotImplementedError()

    @register_action('GetSystemUpdateID')
    def getSystemUpdateID(self):
        raise NotImplementedError()

    @register_action('UpdateObject')
    def updateObject(self, objectID, currentTagValue, newTagValue):
        raise NotImplementedError()

    @register_action('Search')
    def search(self, containerID, searchCriteria, searchFilter, startingIndex,
               requestedCount, sortCriteria):
        raise NotImplementedError()

    @register_action('X_GetRemoteSharingStatus')
    def getRemoteSharingStatus(self):
        raise NotImplementedError()
Exemple #16
0
class TempHumService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:TempHumService:1"
    serviceId = "urn:upnp-org:serviceId:TempHumService"

    actions = {
        'GetTemp': [ServiceActionArgument('Temp', 'out', 'Temp')],
        'GetHumi': [ServiceActionArgument('Humi', 'out', 'Humi')]
    }

    stateVariables = [
        # Variables
        ServiceStateVariable('Temp', 'string', sendEvents=True),
        ServiceStateVariable('Humi', 'string', sendEvents=True),
        ServiceStateVariable('ListeningTempHum', 'boolean', sendEvents=True)
    ]

    state = EventProperty('ListeningTempHum')
    temp = EventProperty('Temp')
    humi = EventProperty('Humi')

    @register_action('GetTemp')
    def getState(self):
        return {'Temp': str(read_temp())}

    def listen_to_tempHum_sensor(self, s):
        print "Listening for tempHum sensor values"
        tmp = 10
        tmp1 = 10
        tmp2 = 10
        while True:
            threadRead.mutex1.acquire(1)
            print("temphum a pris le mutex\n")
            try:
                tmp1 = read_hum()
                tmp2 = read_temp()
                print "J'entre dans le listen de tempHum\n"
                #if tmp1 == -1 or tmp2 == -1 or tmp1 is None or tmp2 is None:
                #	print "NONEEEEEEEEEEEEE\n"

                #elif tmp1 > (tmp - 50) or tmp1 < (tmp + 50) :
                #	print "Valeur non changee trop proche\n"

                #elif tmp1 < (tmp - 50) or tmp1 > (tmp + 50) :
                self.humi = tmp1
                tmp = tmp1
                self.temp = tmp2

                time.sleep(5)
                threadRead.mutex1.release()
                print("Hum a rendu le mutex\n")
                time.sleep(3)
            except IOError as e:
                print "I/O error({0}): {1}".format(e.errno, e.strerror)
                time.sleep(0.5)
                print("temphum a rendu le mutex\n")
                threadRead.mutex1.release()
        return

    def startListening(self):
        self.state = True

        self.thread = threading.Thread(
            target=TempHumService.listen_to_tempHum_sensor, args=(self, 0))
        self.thread.daemon = True
        self.thread.start()
        return {'ListeningTempHum': True}

    @register_action('GetHumi')
    def getState(self):
        return {'Hum': str(read_hum())}
Exemple #17
0
class ReceptionService(Service):

    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:Reception:1"
    serviceId = "urn:upnp-org:serviceId:Reception"

    actions = {
        'GetMailReceivingStatus': [
            ServiceActionArgument('MailReceiving', 'out',
                                  'MailReceivingStatus'),
        ]
    }

    stateVariables = [
        ServiceStateVariable('MailReceivingStatus', 'string', sendEvents=True)
    ]

    mailStatus = EventProperty('MailReceivingStatus')

    @register_action('GetMailReceivingStatus')
    def getMailReceivingStatus(self):
        return {'MailReceiving': self.mailStatus}

    def listen_receiving_status(self, s):
        SECONDPAUSE = 3
        MAIL = False
        DOOR = False  #False = Close / True = Open
        CanReceive = True
        timerMail = 0
        while True:
            try:
                if CapteurService.stateDoor == 0:
                    DOOR = False
                #door close
                else:
                    DOOR = True
                #door open
                if (CapteurService.stateMailing == True):
                    MAIL = True
                if (CanReceive == False):
                    timerMail = timerMail + 1
                if (timerMail == 8 * SECONDPAUSE):
                    CanReceive = True
                if (MAIL == True and DOOR == False and CanReceive == True):
                    print("reception courrier : " +
                          str(datetime.datetime.now()))
                    self.mailStatus = str(datetime.datetime.now())
                    CanReceive = False
                    timerMail = 0

                time.sleep(.1)
                MAIL = False
            except IOError as e:
                print "I/O error({0}): {1}".format(e.errno, e.strerror)
                time.sleep(0.5)
        return

    def startListening(self):
        self.mailStatus = "Nothing"

        self.thread = threading.Thread(
            target=ReceptionService.listen_receiving_status, args=(self, 0))
        self.thread.daemon = True
        self.thread.start()
Exemple #18
0
class TmClientProfile(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:TmClientProfile:1"
    serviceId = "urn:upnp-org:serviceId:TmClientProfile"

    actions = {
        'GetMaxNumProfiles': [
            ServiceActionArgument('NumProfilesAllowed', 'out',
                                  'MaxNumProfiles'),
        ],
        'SetClientProfile': [
            ServiceActionArgument('ProfileID', 'in', 'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('ClientProfile', 'in',
                                  'A_ARG_TYPE_ClientProfile'),
            ServiceActionArgument('ResultProfile', 'out',
                                  'A_ARG_TYPE_ClientProfile'),
        ],
        'GetClientProfile': [
            ServiceActionArgument('ProfileID', 'in', 'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('ClientProfile', 'out',
                                  'A_ARG_TYPE_ClientProfile'),
        ],
    }
    stateVariables = [
        # Variables
        ServiceStateVariable('UnusedProfileIDs', 'string', sendEvents=True),
        # Arguments
        ServiceStateVariable('A_ARG_TYPE_ClientProfile', 'string'),
        ServiceStateVariable('A_ARG_TYPE_ProfileID', 'ui4'),
        ServiceStateVariable('A_ARG_TYPE_String', 'string'),
        ServiceStateVariable('A_ARG_TYPE_INT', 'integer'),
        ServiceStateVariable('A_ARG_TYPE_Bool', 'string', ['false', 'true']),
        ServiceStateVariable('MaxNumProfiles', 'ui2'),
    ]

    unused_profile_ids = EventProperty('UnusedProfileIDs')

    # Internal variables
    maxNumProfiles = 1

    @register_action('GetMaxNumProfiles')
    def getMaxNumProfiles(self):
        return self.maxNumProfiles

    @register_action('SetClientProfile')
    def setClientProfile(self, profileID, clientProfile):
        # TODO: Update the profile XML with the provided profile, return the new union
        if profileID < 0 or profileID >= self.maxNumProfiles:
            raise upnpError(830, 'Invalid Profile ID')
        # raise upnpError(825, 'Invalid Profile') # If profile did not match schema
        raise upnpError(
            701,
            'Operation Rejected')  # TODO: Change when function is implemented

    @register_action('GetClientProfile')
    def getClientProfile(self, profileID):
        # TODO: Return XML formatted profile
        if profileID < 0 or profileID >= self.maxNumProfiles:
            raise upnpError(830, 'Invalid Profile ID')
        raise upnpError(
            701,
            'Operation Rejected')  # TODO: Change when function is implemented
Exemple #19
0
class EnvoiService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:Envoi:1"
    serviceId = "urn:upnp-org:serviceId:Envoi"

    actions = {
        'GetPackageDepositeInMailBoxStatus': [
            ServiceActionArgument('PackageDepositeInMailBox', 'out',
                                  'PackageDepositeInMailBoxStatus'),
        ],
        'GetPackageTookOfMailBoxStatus': [
            ServiceActionArgument('PackageTookOfMailBox', 'out',
                                  'PackageTookOfMailBoxStatus'),
        ]
    }

    stateVariables = [
        ServiceStateVariable('PackageDepositeInMailBoxStatus',
                             'string',
                             sendEvents=True),
        ServiceStateVariable('PackageTookOfMailBoxStatus',
                             'string',
                             sendEvents=True)
    ]

    packDepositeInMBox = EventProperty('PackageDepositeInMailBoxStatus')
    packTookOfMBox = EventProperty('PackageTookOfMailBoxStatus')

    @register_action('GetPackageDepositeInMailBoxStatus')
    def getPackageDepositeInMailBoxStatus(self):
        return {'PackageDepositeInMailBox': self.packDepositeInMBox}

    @register_action('GetPackageTookOfMailBoxStatus')
    def getPackageTookOfMailBoxStatus(self):
        return {'PackageTookOfMailBox': self.packTookOfMBox}

    def listen_sending_status(self, s):
        DOOR = False  #False = Close / True = Open
        BUTTONSTATE = False
        SENDING = True

        DOOR1 = False
        DOORRESET = False
        pin = 7
        numleds = 4
        grovepi.pinMode(pin, "OUTPUT")

        testColorBlack = 0  # 0b000 #000000
        testColorRed = 4  # 0b100 #FF0000

        while True:
            try:
                if CapteurService.stateDoor == 0:
                    DOOR = False
                #door close
                else:
                    DOOR = True
                #door open
                BUTTONSTATE = CapteurService.stateButton
                if (DOOR == True and BUTTONSTATE == True and SENDING == True):
                    grovepi.chainableRgbLed_test(pin, numleds, testColorRed)
                    print("Colis posee dans la boite a : " +
                          str(datetime.datetime.now()))
                    self.packDepositeInMBox = str(datetime.datetime.now())
                    SENDING = False
                if (SENDING == False and DOOR == False):
                    DOOR1 = True
                if (DOOR1 == True and DOOR == True):
                    SENDING = True
                    grovepi.chainableRgbLed_test(pin, numleds, testColorBlack)
                    print("Colis pris par le facteur a : " +
                          str(datetime.datetime.now()))
                    self.packTookOfMBox = str(datetime.datetime.now())
                    DOOR1 = False
                    DOORRESET = False
                time.sleep(.1)
            except IOError as e:
                print "I/O error({0}): {1}".format(e.errno, e.strerror)
                time.sleep(0.5)
        return

    def startListening(self):
        self.packDepositeInMBox = "Nothing"
        self.packTookOfMBox = "Nothing"
        self.thread = threading.Thread(
            target=EnvoiService.listen_sending_status, args=(self, 0))
        self.thread.daemon = True
        self.thread.start()
Exemple #20
0
class ConnectionManagerService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:ConnectionManager:1"
    serviceId = "urn:upnp-org:serviceId:ConnectionManager"

    actions = {
        'GetProtocolInfo': [
            ServiceActionArgument('Source', 'out', 'SourceProtocolInfo'),
            ServiceActionArgument('Sink', 'out', 'SinkProtocolInfo'),
        ],
        'GetCurrentConnectionIDs': [
            ServiceActionArgument('ConnectionIDs', 'out',
                                  'CurrentConnectionIDs'),
        ],
        'GetCurrentConnectionInfo': [
            ServiceActionArgument('ConnectionID', 'in',
                                  'A_ARG_TYPE_ConnectionID'),
            ServiceActionArgument('RcsID', 'out', 'A_ARG_TYPE_RcsID'),
            ServiceActionArgument('AVTransportID', 'out',
                                  'A_ARG_TYPE_AVTransportID'),
            ServiceActionArgument('ProtocolInfo', 'out',
                                  'A_ARG_TYPE_ProtocolInfo'),
            ServiceActionArgument('PeerConnectionManager', 'out',
                                  'A_ARG_TYPE_ConnectionManager'),
            ServiceActionArgument('PeerConnectionID', 'out',
                                  'A_ARG_TYPE_ConnectionID'),
            ServiceActionArgument('Direction', 'out', 'A_ARG_TYPE_Direction'),
            ServiceActionArgument('Status', 'out',
                                  'A_ARG_TYPE_ConnectionStatus'),
        ],
    }
    stateVariables = [
        # Arguments
        ServiceStateVariable('A_ARG_TYPE_ConnectionStatus', 'string', [
            'OK', 'ContentFormatMismatch', 'InsufficientBandwidth',
            'UnreliableChannel', 'Unknown'
        ]),
        ServiceStateVariable('A_ARG_TYPE_ConnectionManager', 'string'),
        ServiceStateVariable('A_ARG_TYPE_Direction', 'string',
                             ['Input', 'Output']),
        ServiceStateVariable('A_ARG_TYPE_ProtocolInfo', 'string'),
        ServiceStateVariable('A_ARG_TYPE_ConnectionID', 'i4'),
        ServiceStateVariable('A_ARG_TYPE_AVTransportID', 'i4'),
        ServiceStateVariable('A_ARG_TYPE_RcsID', 'i4'),

        # Variables
        ServiceStateVariable('SourceProtocolInfo', 'string', sendEvents=True),
        ServiceStateVariable('SinkProtocolInfo', 'string', sendEvents=True),
        ServiceStateVariable('CurrentConnectionIDs', 'string',
                             sendEvents=True),
    ]

    source_protocol_info = EventProperty('SourceProtocolInfo')
    sink_protocol_info = EventProperty('SinkProtocolInfo')
    current_connection_ids = EventProperty('CurrentConnectionIDs')

    @register_action('GetProtocolInfo')
    def getProtocolInfo(self):
        raise NotImplementedError()

    @register_action('GetCurrentConnectionIDs')
    def getCurrentConnectionIDs(self):
        raise NotImplementedError()

    @register_action('GetCurrentConnectionInfo')
    def getCurrentConnectionInfo(self, connectionID):
        raise NotImplementedError()
Exemple #21
0
class TmNotificationServer(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:TmNotificationServer:1"
    serviceId = "urn:upnp-org:serviceId:TmNotificationServer"

    actions = {
        'GetNotification': [
            ServiceActionArgument('ProfileID', 'in', 'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('NotiID', 'in', 'A_ARG_TYPE_NotiID'),
            ServiceActionArgument('Notification', 'out',
                                  'A_ARG_TYPE_Notification'),
        ],
        'GetSupportedApplications': [
            ServiceActionArgument('ProfileID', 'in', 'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('AppIDs', 'out', 'A_ARG_TYPE_String'),
        ],
        'SetAllowedApplications': [
            ServiceActionArgument('ProfileID', 'in', 'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('AppIDs', 'in', 'A_ARG_TYPE_String'),
        ],
        'InvokeNotiAction': [
            ServiceActionArgument('ProfileID', 'in', 'A_ARG_TYPE_ProfileID'),
            ServiceActionArgument('NotiID', 'in', 'A_ARG_TYPE_NotiID'),
            ServiceActionArgument('ActionID', 'in', 'A_ARG_TYPE_ActionID'),
        ],
    }
    stateVariables = [
        # Variables
        ServiceStateVariable('ActiveNotiEvent', 'string', sendEvents=True),
        ServiceStateVariable('NotiAppListUpdate', 'string', sendEvents=True),

        # Arguments
        ServiceStateVariable('A_ARG_TYPE_Notification', 'string'),
        ServiceStateVariable('A_ARG_TYPE_AppID', 'string'),
        ServiceStateVariable('A_ARG_TYPE_ProfileID', 'ui4'),
        ServiceStateVariable('A_ARG_TYPE_ActionID', 'string'),
        ServiceStateVariable('A_ARG_TYPE_NotiID', 'string'),
        ServiceStateVariable('A_ARG_TYPE_String', 'string'),
        ServiceStateVariable('A_ARG_TYPE_URI', 'URI'),
        ServiceStateVariable('A_ARG_TYPE_INT', 'ui4'),
        ServiceStateVariable('A_ARG_TYPE_Bool', 'string', ['false', 'true']),
    ]

    active_noti_event = EventProperty('ActiveNotiEvent')
    noti_app_list_update = EventProperty('NotiAppListUpdate')

    @register_action('GetNotification')
    def getNotification(self, profileID, notiID):
        raise NotImplementedError()

    @register_action('GetSupportedApplications')
    def getSupportedApplications(self, profileID):
        raise NotImplementedError()

    @register_action('SetAllowedApplications')
    def setAllowedApplications(self, profileID, appIDs):
        raise NotImplementedError()

    @register_action('InvokeNotiAction')
    def setAllowedApplications(self, profileID, notiID, actionID):
        # actionID 0x00 shall clear any active notification
        raise NotImplementedError()
Exemple #22
0
class CapteurService(Service):
    version = (1, 0)
    serviceType = "urn:schemas-upnp-org:service:Capteur:1"
    serviceId = "urn:upnp-org:serviceId:Capteur"

    actions = {
        'GetDoorState': [
            ServiceActionArgument('Door', 'out', 'DoorState'),
        ],
        'GetButtonState': [
            ServiceActionArgument('Button', 'out', 'ButtonState'),
        ],
        'GetAccelerometerState': [
            ServiceActionArgument('Accelerometer', 'out',
                                  'AccelerometerState'),
        ],
        'SetColorLed': [ServiceActionArgument('Input', 'in', 'ColorLed')],
        'GetMailingState': [
            ServiceActionArgument('Mailing', 'out', 'Mailingtate'),
        ]
    }

    stateVariables = [
        # Variables
        ServiceStateVariable('ColorLed', 'int'),
        ServiceStateVariable('DoorState', 'boolean', sendEvents=True),
        ServiceStateVariable('ButtonState', 'boolean', sendEvents=True),
        ServiceStateVariable('AccelerometerState', 'string', sendEvents=True),
        ServiceStateVariable('Mailingtate', 'boolean', sendEvents=True)
    ]

    stateDoor = EventProperty('DoorState')
    stateButton = EventProperty('ButtonState')
    stateAccelerometer = EventProperty('AccelerometerState')
    stateMailing = EventProperty('Mailingtate')

    @register_action('GetDoorState')
    def getDoorState(self):
        return {'Door': self.stateDoor}

    @register_action('GetButtonState')
    def getButtonState(self):
        return {'Button': self.stateButton}

    @register_action('GetAccelerometerState')
    def getAccelerometerState(self):
        return {'Accelerometer': self.stateAccelerometer}

    @register_action('SetColorLed')
    def setColorLed(self, color):
        print(color)
        grovepi.chainableRgbLed_test(pin, numleds, int(color))

    @register_action('GetMailingState')
    def getMailingState(self):
        return {'Mailing': self.stateMailing}

    def listen_capteur(self, s):
        sensor = 4
        button = 3
        i = 0
        m = False
        while True:
            adxl345 = ADXL345()
            #print(CapteurService.getDoorState(self))
            #print(CapteurService.getAccelerometerState(self))
            #print(CapteurService.getButtonState(self))
            self.stateDoor = grovepi.digitalRead(sensor)
            axes = adxl345.getAxes(True)
            self.stateAccelerometer = axes['z']
            first = axes['z']
            self.stateButton = grovepi.digitalRead(button)

            time.sleep(.1)
            axes = adxl345.getAxes(True)
            second = axes['z']
            res = int(abs(first - second) * 100)
            if (res > 10):
                self.stateMailing = True
                m = True
            if (m == True):
                i = i + 1
            if (i >= 5):
                self.stateMailing = False
                m = False
                i = 0

    def startListening(self):
        self.stateDoor = True
        self.stateButton = True
        self.stateAccelerometer = "test"
        self.stateMailing = False

        self.thread = threading.Thread(target=CapteurService.listen_capteur,
                                       args=(self, 0))
        self.thread.daemon = True
        self.thread.start()