Changeset 3091

Show
Ignore:
Timestamp:
07/06/08 15:27:00 (5 years ago)
Author:
devtar
Message:

Updates:
1. Info of devices displayed when icon clicked
2. SDP scanning works
3. SDP info displayed based on icon clicked
4. Restructuring process

-main.py
-threading

5. SDP bug fixed. (btsdp out of bounds error when sdp mode disabled)

Location:
branch/BluetoothScanner/umitBluetooth
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • branch/BluetoothScanner/umitBluetooth/__init__.py

    r2956 r3091  
    1919# along with this program; if not, write to the Free Software 
    2020# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
     21 
     22 
     23__author__ = "Devtar Singh <devtar@gmail.com>" 
     24__date__ = "7 July 2008" 
     25__version__ = "100" # build version 
  • branch/BluetoothScanner/umitBluetooth/btcore.py

    r3056 r3091  
    2626import interface 
    2727 
     28btname = [""] 
     29btmac = [""] 
     30btmanu = [""] 
     31btsdp = [""] 
     32sdpstatus = "" 
     33 
    2834class btcore: 
    2935 
    3036   def __init__(self): 
    31         self.btname = [""] 
    32         self.btmac = [""] 
    33         self.btmanu = [""] 
    34         self.btsdp = [""] 
     37        global btname 
     38        global btmac 
     39        global btmanu 
     40        global btsdp 
     41        global sdpstatus 
    3542        #entry_text = entry.get_active_text() 
    3643        #print "BT Address Entered: %s" % entry_text 
     
    3845   def scan(self, interface): 
    3946        print "Refresh Interface" 
    40         interface.progb.set_text("")                 
    41         interface.progb.set_fraction(0) 
    42         #interface.mapmodel.clear() 
    43         self.btname = [""] 
    44         self.btmac = [""] 
    45         self.btmanu = [""] 
    46         self.btsdp = [""] 
     47        self.clear_int(interface) 
     48        global btname 
     49        global btmac 
     50        global btsdp 
     51        global sdpstatus 
     52        count = 1 
    4753        btdevices = bluetooth.discover_devices(lookup_names = True) 
    4854        for addr, name in btdevices:                  
    4955                if (name == ""): 
    5056                   name = "N/A" 
    51                 self.btname.append(name) 
    52                 self.btmac.append(addr)          
     57                btname.append(name) 
     58                btmac.append(addr) 
     59                print sdpstatus 
     60                if (sdpstatus == "Enabled"): 
     61                 # first entry of btdevice is at index 1 hence +1 on initial 
     62                 self.sdp_scan(count) 
     63                count+=1 
    5364                print "\n" + name + "\n" + addr + "\n" 
    5465         # BTMAC input test 
    5566        interface.progb.set_text("40%") 
    5667        interface.progb.set_fraction(.4) 
    57         self.manufac(self.btmac) 
     68        self.manufac() 
    5869        interface.progb.set_text("75%") 
    5970        interface.progb.set_fraction(.75) 
    60         self.map(self.btname, self.btmanu, interface) 
     71        self.map(interface) 
    6172        interface.progb.set_text("100%") 
    6273        interface.progb.set_fraction(1) 
    6374        message_id = interface.status_bar.push(interface.context_id, "Scanning Completed") 
    6475 
    65    #def get_scan 
     76   def sdp_scan(self, btid): 
     77        global sdpstatus 
     78        global btmac 
     79        global btsdp 
     80        print "BTID: " + str(btid) 
     81        sdpservices=bluetooth.find_service(address=btmac[btid]) 
     82        if len(sdpservices) > 0: 
     83                 for svc in sdpservices: 
     84                         sdpbrowseinfo = "\nService Name: " + str(svc["name"]) + "\n Description: " + str(svc["description"]) + "\n Provided By: " + str(svc["provider"]) + "\n Protocol: " + str(svc["protocol"]) + "\n channel/PSM: " + str(svc["port"]) + "\n svc classes: " + str(svc["service-classes"]) + "\n profiles:  " + str(svc["profiles"]) + "\n service id: " + str(svc["service-id"]) 
     85                         btsdp.append("\nFound " + str(len(sdpservices)) + " services\n\n" + sdpbrowseinfo) 
     86                         print sdpbrowseinfo 
     87        else: 
     88                 sdpbrowseinfo = "no services found" 
     89                 btsdp.append(sdpbrowseinfo) 
     90                 print sdpbrowseinfo 
     91    
    6692 
    67    def manufac(self, btmac): 
     93   def manufac(self): 
     94        global btname 
     95        global btmac 
     96        global btmanu 
    6897        print "manufacturer detection" 
    6998        #Running from source directory 
     
    73102        btmacsearch = [""] 
    74103        btnamesearch = [""] 
    75         while ((len(self.btname)-1) > count): 
     104        while ((len(btname)-1) > count): 
    76105                count+= 1 
    77106                count2 = 0 
     
    94123                                btmacsearch.append(btbuf1) 
    95124                                btnamesearch.append(btbuf2) 
    96                         if(self.btmac[count][:8] == btmacsearch[count2]): 
    97                                 self.btmanu.append(btnamesearch[count2]) 
    98                                 print "Manufacturer detected : " + self.btmac[count] + "\n" + self.btmanu[count] 
     125                        if(btmac[count][:8] == btmacsearch[count2]): 
     126                                btmanu.append(btnamesearch[count2]) 
     127                                print "Count: " + str(count) + "\nNAME: " + btname[count] + "\nMAC : " + btmac[count] + "\nManufacturer detected : " + btmanu[count] 
    99128                                endsearch = True 
    100129                endread = True 
    101130                print "Status : " + str(endsearch) 
    102131                if(endsearch == False): 
    103                         print "Null: " + __main__.btmac[count][:8] 
    104                         self.btmanu.append("null") 
     132                        print "Null: " + btmac[count][:8] 
     133                        btmanu.append("null") 
    105134        btdb.close() 
    106135 
    107    def map(self, btname, btmanu, interface): 
     136   def map(self, interface):     
     137        global btname 
     138        global btmac 
     139        global btmanu 
    108140        count = 0 
    109         while ((len(self.btname)-1) > count): 
     141        while ((len(btname)-1) > count): 
    110142         count+=1 
    111143         if(btmanu[count].find("Nokia") > -1 ): 
     
    122154          interface.mapmodel.append([btname[count], pixbuf]) 
    123155 
    124         def onclick(self, interface): 
    125          print "Selected: " + interface.btmap.get_selected_items() 
    126           
    127               
     156   def set_info(self, interface, btid): 
     157         global btname 
     158         global btmac 
     159         global btmanu 
     160         global sdpstatus 
     161         btid+=1 
     162         print "Selected: " + str(interface.btmap.get_selected_items()) + "\n" + str(btid)        
     163         interface.label.set_text("Device Details\t\t\t\t\n\nName: " + btname[btid] + "\nMAC: " + btmac[btid] + "\nManufacturer: " + btmanu[btid]) 
     164         if (sdpstatus == "Enabled"): 
     165          interface.sdpview.get_buffer().set_text(btsdp[btid]) 
    128166 
    129    def sdpscan(self): 
    130         print "sdpinfo" 
     167   def set_sdp(self, status): 
     168         # Status of Enabled or Disabled 
     169         global sdpstatus 
     170         sdpstatus = status 
     171 
     172   def clear_int(self, interface):     
     173        interface.progb.set_text("")                 
     174        interface.progb.set_fraction(0) 
     175        #interface.mapmodel.clear() 
    131176 
    132177 
    133  
  • branch/BluetoothScanner/umitBluetooth/interface.py

    r3057 r3091  
    2626import about 
    2727import btcore 
     28 
    2829 
    2930class interface: 
     
    128129 
    129130        # Labels   
    130         self.btname_label = "" 
    131         self.btmac_label = "" 
    132         self.btmanu_label = "" 
    133         self.label = gtk.Label("Device Details\t\t\t\t\n\nName: " + self.btname_label + "\nMAC: " + self.btmac_label + "\nManufacturer: " + self.btmanu_label) 
     131        self.label = gtk.Label("Device Details\t\t\t\t\n\nName: " + "\nMAC: " + "\nManufacturer: ") 
    134132        self.label.set_selectable(True) 
    135133        self.label.set_alignment(0.4,0) 
     
    155153        #Output test 
    156154        pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.abspath(os.path.join("pixmaps", "bt.png"))) 
    157         self.mapmodel.append(["Test1", pixbuf]) 
    158         self.mapmodel.append(["Test2", pixbuf]) 
     155        #self.mapmodel.append(["Test1", pixbuf]) 
     156        #self.mapmodel.append(["Test2", pixbuf]) 
    159157 
    160158        self.window.show_all() 
     
    170168 
    171169    def sdp_cb(self, action): 
    172         # action has not toggled yet  
    173         text = ('Enabled', 'Disabled')[action.get_active()==False] 
    174         message_id = self.status_bar.push(self.context_id, "SDP Browsing is %s"%text)         
    175         return 
     170        # action has not toggled yet          
     171                text = ('Enabled', 'Disabled')[action.get_active()==False]         
     172                message_id = self.status_bar.push(self.context_id, "SDP Browsing is %s"%text) 
     173                btcore.btcore().set_sdp(text)         
     174                return 
    176175 
    177176    def iconclick_cb(self, path, action):         
    178                 print "clicked" 
    179177                iter = self.btmap.get_cursor() 
     178                buffer = str(iter[0])[:2].replace("(","") 
     179                btid = int(buffer) 
     180                print "Clicked Icon: "+ str(buffer) 
     181                btcore.btcore().set_info(self, btid) 
    180182                #outputs the location of the icon numerically 
    181                 print "\n" + str(iter[0])[:2].replace("(","") 
    182183         
    183184    def on_about(self, action): 
     
    185186            self._about = about.about_dialog() 
    186187            self._about.get_about() 
    187  
    188 if __name__ == '__main__': 
    189     ubt = interface() 
    190     gtk.main()