# -*- coding: cp1252 -*- ''' Created on 20.10.2011 @author: sth2mt ''' import FertigungsTest.Hardware.M24LR64R as EEProm import subprocess import os # GetMAC # exit class Treiber(object): ''' classdocs ''' # Achtung dies ist Pseudo Singleton -> variablen werden statisch verwendet. Aufgeraumt wird erst wenn alle instanzen weg sindwird nur einmal instaniiert !!!! ObjCount = 0 _Thread_name = "WLAN" stout = False s_FileName_nvs_map = "nvs_map.bin" L_MACAdress = None O_EEProm = None def __init__(self): ''' Constructor ''' Treiber.ObjCount += 1 self.printf("%i.Construktor %s Anzahl" % (Treiber.ObjCount,Treiber._Thread_name)) if Treiber.O_EEProm == None: Treiber.O_EEProm = EEProm.Treiber() if Treiber.L_MACAdress == None: Treiber.L_MACAdress=self.f_GetMACAdress() def __del__(self): #print "~WLAN_CL\n" ''' Destructor ''' self.printf("%i Destruktor %s" % (Treiber.ObjCount,Treiber._Thread_name)) if Treiber.ObjCount == 1: self.printf("Reste aufraumen") del(Treiber.O_EEProm) Treiber.O_EEProm = None if Treiber.ObjCount > 0: Treiber.ObjCount -= 1 pass def f_GetMACAdress(self): try: #nvs map auslesen s_DateiInhalt = Treiber.O_EEProm.read(4096, 468) self.printf ("WLAN.GetMACAdress()->open(%s) Treiber.O_EEProm.read successfully" %Treiber.s_FileName_nvs_map) return ([ord(s_DateiInhalt[11]),ord(s_DateiInhalt[10]),ord(s_DateiInhalt[6]),ord(s_DateiInhalt[5]),ord(s_DateiInhalt[4]),ord(s_DateiInhalt[3])]) except Exception,e: print "WLAN.GetMACAdress()", e return ([255,255,255,255,255,255]) pass def f_CopyNvsMap(self,sTargetPath): try: #nvs map auslesen s_DateiInhalt = Treiber.O_EEProm.read(4096, 468) self.printf ("WLAN.f_CopyNvsMap()->open(%s) Treiber.O_EEProm.read successfully" %Treiber.s_FileName_nvs_map) if (sTargetPath==None): sTargetPath="/opt/ti-wireless/WL6.1.6.0.3/" sFilePathName = sTargetPath + "nvs_map.bin" fwriteNvsMap = open(sFilePathName,"w+b") fwriteNvsMap.write(s_DateiInhalt) fwriteNvsMap.close() return True except IOError,e: print "WLAN.f_CopyNvsMap()", e return False pass def f_GetMACString(self,Trennzeichen='-'): try: s_MacAdress="" for i in Treiber.L_MACAdress: s_MacAdress+="%02x%s"%(i,Trennzeichen) return s_MacAdress.rstrip("-") except IOError,e: print "WLAN.GetMACAdress()", e return -1 pass def f_GetMACLong(self): try: l_MacAdress=0l for i in range (0,len(Treiber.L_MACAdress),1): #print i , " ", l_MacAdress+= (pow(256,len(Treiber.L_MACAdress)-i-1) * Treiber.L_MACAdress[i]) #print l_MacAdress return l_MacAdress except IOError,e: print "WLAN.GetMACAdress()", e return -1 pass def f_GetNFSAdress(self): try: output = open ("/tmp/MountInfo.log","w+") string = None self.printf("f_GetNFSAdress() START") if subprocess.call(["mount"],stderr=output,stdout=output,shell=True)!=0: output.close() print "WLAN.f_GetNFSAdress() subprocess.call([mount] ERROR" return -1 output.flush() output.seek(0) for line in output: if line.find("nfs")>0: string = (line.rsplit("addr="))[1] #string = alles nach "addr=" -> "xx.xx.xx.xx)" ip-adress of nfs server string = string.rsplit(")")[0] # alles vor ")" also xx.xx.xx.xx #self.printf(string) output.close() self.printf("f_GetNFSAdress()=%s ENDE"%string) return string except IOError,e: print "WLAN.f_GetNFSAdress()", e return -1 pass def f_GetIPAdress(self): try: output = open ("/tmp/ifconfigInfo.log","w+") string = None self.printf("f_GetIPAdress() START") if subprocess.call(["ifconfig"],stderr=output,stdout=output,shell=True)!=0: output.close() print "WLAN.f_GetIPAdress() subprocess.call([ifconfig] ERROR" return -1 output.flush() output.seek(0) for line in output: if line.find("inet addr:")>0: string = (line.rsplit("inet addr:"))[1] #string = alles nach "addr=" -> "xx.xx.xx.xx)" ip-adress of nfs server string = string.rsplit(" ")[0] # alles vor ")" also xx.xx.xx.xx #self.printf(string) break output.close() self.printf("f_GetIPAdress()=%s ENDE"%string) return string except IOError,e: print "WLAN.f_GetIPAdress()", e return -1 pass def printf(self,string): if Treiber.stout: print string pass