Ejemplo n.º 1
0
class BluetoothReader:
	
	def __init__(self, btGUI):
		self.resolver = AoResolver() # Bluetooth Reader
		self.count = 0
		self.cont = None
		self.myGUI = btGUI
		self.detected_locations_dic = [] #detected_locations_dictionary
		global inet_mode
		self.serverAPI = serverAPI.ServerAPI(inet_mode)

	def notifyMacAddress(self, macAddress): #For exposition, put filtering here
		flag = 0
		result = self.myGUI.location_cache.checkLocationsForBluetoothMAC(macAddress)
		if result == 0:
			loc = self.serverAPI.get_location_by_bluetooth_mac(macAddress)
			if loc is not None:
				self.myGUI.location_cache.appendLocation(loc)
				self.myGUI.notifyOfNewLocation(str(loc['name']) + " [" + str(loc['location_type']) + "]")	

								
	def __callback(self, error, mac, name, fp): #Different Thread
		global count
		global cont
		global detected_locations_list
		global macAddress
		if error == -25: #KErrEof (no more devices)
			#print "query done"
			cont = None
		elif error:
			raise
		else:
			count += 1
			macAddress = mac
			# filtering       #Jakob's phone    #Nokia Tablet                   #Dell Axim
			if macAddress == '001c623fa0b8' or macAddress == '00194fa4e262' or macAddress == '0010c65e9224':
				fp(macAddress)						
			cont = self.resolver.next
		
		myLock.signal()

	def btSearch(self):
		global macAddress
		try:
			self.resolver.open()
			#print "Bluetooth Search Start"
			GUI.drawLocationList()
			cont = lambda: self.resolver.discover(self.__callback, self.notifyMacAddress)
			while cont:
				cont()
				myLock.wait()
				if(self.myGUI.terminated == 1): #if this lock is resolved by the GUI
					break

		finally:
			self.resolver.close()
Ejemplo n.º 2
0
	def __init__(self, btGUI):
		self.resolver = AoResolver() # Bluetooth Reader
		self.count = 0
		self.cont = None
		self.myGUI = btGUI
		self.detected_locations_dic = [] #detected_locations_dictionary
		global inet_mode
		self.serverAPI = serverAPI.ServerAPI(inet_mode)
Ejemplo n.º 3
0
	def __init__(self, btGUI):
		self.resolver = AoResolver() # Bluetooth Reader
		self.count = 0
		self.myLock = e32.Ao_lock()
		self.cont = None
		self.myGUI = btGUI
		self.detected_locations_dic = {} #detected_locations_dictionary	
#		self.serverAPI = ServerAPI.ServerAPI()	
		self.server_host = "http://test.talking-points.org"
Ejemplo n.º 4
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import e32
from pyaosocket import AoResolver

myLock = e32.Ao_lock()
count = 0
cont = None
rsv = AoResolver()

def cb(error, mac, name, dummy):
    global count
    global cont
    if error == -25: # KErrEof (no more devices)
        print "no more"
        cont = None
    elif error:
        raise
    else:
        count += 1
        print repr([mac, name, count])
        cont = rsv.next
    myLock.signal()
Ejemplo n.º 5
0
class BluetoothReader:
	
	def __init__(self, btGUI):
		self.resolver = AoResolver() # Bluetooth Reader
		self.count = 0
		self.myLock = e32.Ao_lock()
		self.cont = None
		self.myGUI = btGUI
		self.detected_locations_dic = {} #detected_locations_dictionary	
#		self.serverAPI = ServerAPI.ServerAPI()	
		self.server_host = "http://test.talking-points.org"
	def notifyMacAddress(self, macAddress):
		flag = 0
#		if(macAddress == "001ff3b01a1e"): #for test
		#see if this mac address has been detected
		for i,v in self.detected_locations_dic.iteritems():
			if v['bluetooth_mac'] == str(macAddress): #if this has been detected
				flag = 1
				break
						
		if flag == 0 :
			try:
				request_url = self.server_host + "/locations/show/" + str(1) + ".json"
				print "here"
				response = urllib.urlopen(request_url).read()
				loc = json.read(response)	
			except:
				print "f****d up"
			if loc == null:
				return
			else: #if this is valid macaddress
				myGUI.location_cache.appendLocation(loc)
				myGUI.notifyOfNewLocation(loc['name'] + " [" + loc['type'] + "]")	
								
	def __callback(self, error, mac, name, fp): #Different Thread
		global count
		global cont
		global detected_locations_list
		if error == -25: #KErrEof (no more devices)
			#print "query done"
			cont = None
		elif error:
			raise
		else:
			count += 1
			macAddress = mac
			fp(macAddress)	
				
			cont = self.resolver.next
		myLock.signal()

	def btSearch(self):
		global macAddress
		try:
			self.resolver.open()
			print "Bluetooth Search Start"
			cont = lambda: self.resolver.discover(self.__callback, self.notifyMacAddress)
			while cont:
				cont()
				myLock.wait()

		finally:
			self.resolver.close()	
Ejemplo n.º 6
0
 def __init__(self):
     self.timer = e32.Ao_timer()
     self.resolver = AoResolver()
     self.resolver.open()
     self.active = False
Ejemplo n.º 7
0
class BtproxScanner:
    def __init__(self):
        self.timer = e32.Ao_timer()
        self.resolver = AoResolver()
        self.resolver.open()
        self.active = False

    def scan(self, cb):
        if self.active:
            self.cancel()
        self.cb = cb
        self.list = []
        self.resolver.discover(self._cb, None)
        self.timer.after(25, self._timeout)
        self.active = True

    def _timeout(self):
        """
        We use a timer to restrict the scan duration to something
        reasonable.
        """
        self.active = False
        ut.report("btprox scan timeout")
        self.resolver.cancel()
        self.cb(self.list) # anything so far

    def _cb(self, error, mac, name, dummy):
        ut.report([error, mac, name, dummy])
        self.active = False
        if error == -25: # KErrEof (no more devices)
            self.timer.cancel()
            self.cb(self.list)
        elif error:
            self.timer.cancel()
            ut.report("BT scan error %d" % error)
            appuifw.note(u"Bluetooth scan failed", "error")
            self.cb(None)
        else:
            self.list.append({"mac": add_colons(mac), "name": name})
            self.resolver.next()
            self.active = True

    def cancel(self):
        self.resolver.cancel()
        self.timer.cancel()
        self.active = False

    def close(self):
        self.cancel()
        self.resolver.close()