[Python] Script bloccato in python per S60

saverio smucci a cpiprogetti.it
Ven 25 Gen 2008 16:22:49 CET


De Santis Luca wrote:
> Buongiorno a tutti
>  
> Ho un problema con uno script python per S60 su un nokia 6630. Sto 
> facendo un applicazione che comunica con il pc tramite bluetooth per 
> telefonare e ricevere messaggi tramite il bluetooth del telefono. Ho 
> fatto questo script (postato di seguito e funziona tutto bene. Solo 
> che al primo invio di un messgiio dal telefono al pc questo funziona 
> bene, appena prova a fare il secondo invio rimane bloccato 
> l'interprete python e devo spegnrere il cellulare. Credo sia un 
> problema di comunicazione perché se all'interno dello script 
> sostituisce i comandi di invio al telefono con dei semplici print va 
> tutto a meraviglia.
Ciao ... mi è capitato di voler fare una cosa simile ed il mio n-gage 
impazziva.... i crash li ho risolti evitando di condividere il socket 
tra più thread, che anche se solo referenziato mi faceva crashare tutto 
ma ancora non ho avuto tempo di cercare il reale motivo di questa 
cosa... possibile pys60 simuli i thread?

ciao Saverio
>  
> Grazie
>  
> Luca
>  
> import socket
> import appuifw
> import thread
> import e32
> import inbox
> import location
> import sysinfo
> #Assegnazione variabili globali
> DebugMode=1
> conn= None
> i = 0
> LastBattery=0
> LastSignal=0
> LastOperator=""
> LastPhoneStatus=0
> lock = e32.Ao_lock()
> lockTHR = thread.allocate_lock()
> #Definzione Classe telefono
> class JesterPhone:
>     PhoneModel = ""
>     PhoneBrand = ""
>     #Marca
>     def GetBrand(self):
>  return "Nokia"
>     #Modello
>     def GetModel(self):
>  try:
>      PhoneResp=sysinfo.sw_version()
>      firmware = PhoneResp.split(' ')[3]
>      mapping = {
>      'RM-51': '3230',
>      'RM-38': '3250',
>      'NHM-10': '3600',
>      'NHM-10X': '3620',
>      'NHL-8': '3650',
>      'NHL-8X': '3660',
>      'RM-25': '6260',
>      'RM-29': '6260b',
>      'NHL-10': '6600',
>      'NHL-12': '6620',
>      'NHL-12X': '6620',
>      'RM-1': '6630',
>      'RH-67': '6670',
>      'RH-68': '6670b',
>      'RM-36': '6680',
>      'RM-57': '6681',
>      'RM-58': '6682',
>      'RH-51': '7610',
>      'RH-52': '7610b',
>      'NHL-2NA': '7650',
>      'RM-49': 'E60-1',
>      'RM-89': 'E61-1',
>      'RM-10': 'E70-1',
>      'RM-24': 'E70-?',
>      'NEM-4': 'N-Gage',
>      'RH-29': 'N-Gage QD (asia/europe)',
>      'RH-47': 'N-Gage QD (americas)',
>      'RM-84': 'N70-1',
>      'RM-99': 'N70-5',
>      'RM-67': 'N71-1',
>      'RM-112': 'N71-5',
>      'RM-91': 'N80-3',
>      'RM-92': 'N80-1',
>      'RM-42': 'N90-1',
>      'RM-43': 'N91-1',
>      'RM-158': 'N91-5' }
>      return "Nokia "+mapping[firmware]
>  except:
>      return "notfound"
>     #Inizializzazione classe telefono
>     def InitMe(self):
>  self.PhoneBrand=self.GetBrand()
>  self.PhoneModel=self.GetModel()
>
> #Avvio del server RFCOMM
> def StartServer():
>     global conn
>     server = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
>     channel = socket.bt_rfcomm_get_available_server_channel(server)
>     server.bind(("", channel))
>     server.listen(1)
>     socket.bt_advertise_service(u"JesterPlugIn", server, True, 
> socket.RFCOMM)
>     socket.set_security(server, socket.AUTH | socket.AUTHOR)
>     print "- Waiting for clients..."
>     conn, client_addr = server.accept()
>     print "- Jester connected with phone"
>    
> #Aggiorna ststo telefono
> def GetPhoneInfo():
>     RefFlag=0
>     RefState=0
>     RetOper=location.gsm_location()
>     SignalDisp=sysinfo.signal()
>     BatteryDisp=sysinfo.battery()
>     Operator=str(RetOper[0])+str(RetOper[1])
>     global LastBattery
>     global LastSignal
>     global LastOperator
>     if LastBattery != BatteryDisp:
>     LastBattery=BatteryDisp
>     RefFlag=1
>     if LastSignal != SignalDisp:
>     LastSignal=SignalDisp
>     RefFlag=1
>     if LastOperator != Operator:
>     LastOperator=Operator
>     RefFlag=1
>     if RefFlag==1:
>         print "  Signal   "+str(LastSignal)
>         print "  Battery  "+str(LastBattery)
>         print "  Operator "+str(LastOperator)
>        
>     return RefFlag
> def receive_msg(fd):
>     reply = fd.readline()
>     print "- FromJester: " + reply
> def send_msg(fd,msg):
>     print >> fd, msg
>     print "- ToJester  : " + msg
> def talk(msg):
>     try:
>     fd = conn.makefile("rw", 0)
>     send_msg(fd,msg)
>     except:
>     appuifw.note(u"Connection lost", "info")
>     if conn:
>         conn.close()
>            print "Bye!"
> def Listen(client):
>     try:
>  if client:
>      print "- Init listen port sevice"
>      fd = client.makefile("rw", 0)
>  while True:
>      receive_msg(fd)
>     except:
>  appuifw.note(u"Connection lost", "info")
>  if client: client.close()
>  print "Bye!"
> def message_received(msg_id):
>     box = inbox.Inbox()
>     talk("New message incoming")
> def Daemon():
>     global i
>     while(1):
>      lockTHR.acquire()
>      e32.ao_sleep(10)
>      TmpInfo=GetPhoneInfo()
>         if TmpInfo==1:
>             
> ToSend="StatChn:"+str(LastSignal)+";"+str(LastBattery)+";"+str(LastOperator)
>             talk(ToSend)
>      #CheckPhoneStatus()
>      i+=1
>      lockTHR.release()
> #Inizio programma
> MainPhone=JesterPhone()
> StartServer()
> print "- Init SMS Notification service"
> box = inbox.Inbox()
> box.bind(message_received)
> thread.start_new_thread(Daemon, ())
> print "- Init Timer Daemon Class"
> print "- Detect phone properties"
> MainPhone.InitMe()
> talk("conok:"+MainPhone.PhoneBrand+";"+MainPhone.PhoneModel)
> thread.start_new_thread(Listen(conn), ())
> print "- Waiting for events"
> lock.wait()
> print "- Jester GSM Monitor Stop"
>
>
> ------------------------------------------------------------------------
> Messenger Giochi Prenditi una pausa e sfida i tuoi amici a Ladybird su 
> Messenger! <http://messengergiochi.it.msn.com/ladybird.aspx>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Python mailing list
> Python a lists.python.it
> http://lists.python.it/mailman/listinfo/python
>   



More information about the Python mailing list