def SendAndSaveIQ(self):
        self.IQList=[]
        recvIQList = self.SweepRangeIQ
        for recvIQ in recvIQList:
            block = IQBlock(recvIQ.CurBlockNo, recvIQ.IQDataAmp)
            self.IQList.append(block)

        head = IQUploadHeader(0x00, recvIQ.LonLatAlti, recvIQ.Param)

        #####组合IQ文件################
        curTime = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
        Year = int(curTime[0:4])
        Month = int(curTime[4:6])
        Day = int(curTime[6:8])
        Hour = int(curTime[8:10])
        Minute = int(curTime[10:12])
        Second = int(curTime[12:14])
        ID = staticVar.getid()

        fileName = str(Year) + "-" + str(Month) + "-" + str(Day) + \
                   "-" + str(Hour) + "-" + str(Minute) + "-" + str(Second) + '-' + str(ID) + '.iq'

        fileNameLen = len(fileName)
        fileContentLen = sizeof(head) + sizeof(block) * len(self.IQList) + 1

        print fileName
        print fileNameLen
        print fileContentLen

        ###########SendToServer###################(H :2字节  Q:8 字节)
        if (not staticVar.getSockFile()==0):
            if(not self.mainframe.start_local_iq):   ##如果没有启动本地定频才是中心站发起的
                sockFile=staticVar.getSockFile()
                str1 = struct.pack("!2BHQ", 0x00, 0xFF, fileNameLen, fileContentLen)
                sockFile.send(str1 + fileName)
        
                sockFile.send(bytearray(head))
                for block in self.IQList:
                    sockFile.send(bytearray(block))
                sockFile.send(struct.pack("!B", 0x00))
            else:
                self.mainframe.start_local_iq=0


        ###########SaveToLocal####################
        fid=open(".\LocalData\\IQ\\"+ fileName,'wb+')
        # fid = open(self.dir_iq + fileName, 'wb+')
        fid.write(bytearray(head))
        for block in self.IQList:
            fid.write(bytearray(block))
        fid.write(struct.pack("!B", 0x00))
        fid.close()
        #########################################
        del self.IQList
Ejemplo n.º 2
0
    def SendAndSaveIQ(self):
        self.IQList = []
        recvIQList = self.SweepRangeIQ
        for recvIQ in recvIQList:
            block = IQBlock(recvIQ.CurBlockNo, recvIQ.IQDataAmp)
            self.IQList.append(block)

        head = IQUploadHeader(0x00, recvIQ.LonLatAlti, recvIQ.Param)

        #####组合IQ文件################
        curTime = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
        Year = int(curTime[0:4])
        Month = int(curTime[4:6])
        Day = int(curTime[6:8])
        Hour = int(curTime[8:10])
        Minute = int(curTime[10:12])
        Second = int(curTime[12:14])
        ID = staticVar.getid()

        fileName = str(Year) + "-" + str(Month) + "-" + str(Day) + \
                   "-" + str(Hour) + "-" + str(Minute) + "-" + str(Second) + '-' + str(ID) + '.iq'

        fileNameLen = len(fileName)
        fileContentLen = sizeof(head) + sizeof(block) * len(self.IQList) + 1

        print fileName
        print fileNameLen
        print fileContentLen

        ###########SendToServer###################(H :2字节  Q:8 字节)
        if (not staticVar.getSockFile() == 0):
            if (not self.mainframe.start_local_iq):  ##如果没有启动本地定频才是中心站发起的
                sockFile = staticVar.getSockFile()
                str1 = struct.pack("!2BHQ", 0x00, 0xFF, fileNameLen,
                                   fileContentLen)
                sockFile.send(str1 + fileName)

                sockFile.send(bytearray(head))
                for block in self.IQList:
                    sockFile.send(bytearray(block))
                sockFile.send(struct.pack("!B", 0x00))
            else:
                self.mainframe.start_local_iq = 0

        ###########SaveToLocal####################
        fid = open(".\LocalData\\IQ\\" + fileName, 'wb+')
        # fid = open(self.dir_iq + fileName, 'wb+')
        fid.write(bytearray(head))
        for block in self.IQList:
            fid.write(bytearray(block))
        fid.write(struct.pack("!B", 0x00))
        fid.close()
        #########################################
        del self.IQList
    def upload(self):
        #数到了最后

        if(self.indexOfNameList==len(self.nameListTdoa)):
            self.indexOfNameList=0
            self.nameListTdoa=[]


        else:
            # 传输文件

            fileName=self.nameListTdoa[self.indexOfNameList]
            self.indexOfNameList+=1
            if(os.path.isfile(self.FILE_PATH+fileName)):
                fid = open(".\LocalData\\Tdoa\\" + fileName, 'rb')
                d=pickle.load(fid)
                fid.close()

                head=d['head']
                block=d['block']

                fileNameLen = len(fileName)
                fileContentLen = sizeof(head) + sizeof(block) + 1




                ###########SendToServer###################(H :2字节  Q:8 字节)
                if(not staticVar.getSockFile()==0):
                    try:
                        sockFile = staticVar.getSockFile()
                        str1 = struct.pack("!2BHQ", 0x00, 0xFF, fileNameLen, fileContentLen)
                        sockFile.sendall(str1 + fileName)

                        sockFile.sendall(bytearray(head))

                        sockFile.sendall(bytearray(block))
                        sockFile.sendall(struct.pack("!B", 0x00))

                        print fileName
                        os.remove(self.FILE_PATH + fileName)
                        Log.getLogger().debug("send_tdoa_file_ok:%s"% fileName)
                    except socket.error, e:
                        Log.getLogger().debug(" socket_error_found_in_send_tdoa_file: %s" % e)
                        Log.getLogger().debug(" Cur socket sockFile=: %s" % staticVar.sockFile)

                        print 'socket error occur in send tdoa ', e
                        staticVar.sockFile = 0
Ejemplo n.º 4
0
    def upload(self):
        #数到了最后

        if (self.indexOfNameList == len(self.nameListTdoa)):
            self.indexOfNameList = 0
            self.nameListTdoa = []

        else:
            # 传输文件

            fileName = self.nameListTdoa[self.indexOfNameList]
            self.indexOfNameList += 1
            if (os.path.isfile(self.FILE_PATH + fileName)):
                fid = open(".\LocalData\\Tdoa\\" + fileName, 'rb')
                d = pickle.load(fid)
                fid.close()

                head = d['head']
                block = d['block']

                fileNameLen = len(fileName)
                fileContentLen = sizeof(head) + sizeof(block) + 1

                ###########SendToServer###################(H :2字节  Q:8 字节)
                if (not staticVar.getSockFile() == 0):
                    try:
                        sockFile = staticVar.getSockFile()
                        str1 = struct.pack("!2BHQ", 0x00, 0xFF, fileNameLen,
                                           fileContentLen)
                        sockFile.sendall(str1 + fileName)

                        sockFile.sendall(bytearray(head))

                        sockFile.sendall(bytearray(block))
                        sockFile.sendall(struct.pack("!B", 0x00))

                        print fileName
                        os.remove(self.FILE_PATH + fileName)
                        Log.getLogger().debug("send_tdoa_file_ok:%s" %
                                              fileName)
                    except socket.error, e:
                        Log.getLogger().debug(
                            " socket_error_found_in_send_tdoa_file: %s" % e)
                        Log.getLogger().debug(" Cur socket sockFile=: %s" %
                                              staticVar.sockFile)

                        print 'socket error occur in send tdoa ', e
                        staticVar.sockFile = 0
    def __init__(self,mainframe): 
        threading.Thread.__init__(self)
        
        self.dictFreqPlan=staticVar.getdictFreqPlan()
        self.event = threading.Event()
        self.event.set()
        self.sock=staticVar.getSock()
        self.sockFile=staticVar.getSockFile()
        self.outPoint=staticVar.outPoint
        self.specFrame=mainframe.SpecFrame
        self.specFrame.iq_sequence=0

        self.mainframe=mainframe

        self.thread_tdoa=0

        '''这里是四个发送文件的class'''
        self.send_file_class=class_upload.SendFileClass(self.specFrame,self.mainframe.queueFFTUpload,
                                                        self.mainframe.queueAbUpload)

        self.send_file_iq_class=class_upload_iq.SendIQFile(self.mainframe)

        self.send_file_poa_class=class_upload_poa.SendPoaFile()

        self.send_file_tdoa_class=class_upload_tdoa.SendTdoaFile()

        self.count_heart_beat=0
        self.thread_timer=0
        self.thread_timer=0
        '''0:spec   1:iq    2: POA  3: TDOA  文件上传'''
        self.switch_to_transfer=0

        self.rlist=[self.sock,self.sockFile]
        self.wlist=[self.sock,self.sockFile]
        self.xlist=[self.sock,self.sockFile]
Ejemplo n.º 6
0
    def __init__(self, SpecFrame, queueFFTUpload, queueAbUpload):
        threading.Thread.__init__(self)
        self.event = threading.Event()
        self.event.set()

        self.queueFFTUpload = queueFFTUpload
        self.queueAbUpload = queueAbUpload

        self.SpecFrame = SpecFrame

        self.sockFile = staticVar.getSockFile()

        self.SpecList = []

        self.Second = 0
        self.countFFT = 0

        self.count = 1  ##用来计数一秒钟发了多少个功率谱文件

        self.fileUploadMode = 2
        self.extractM = 1
        self.changeThres = 10

        self.extract_num = 0

        self.startTrans = 0
    def __init__(self,SpecFrame,
                 queueFFTUpload,queueAbUpload):
        threading.Thread.__init__(self)
        self.event = threading.Event()  
        self.event.set()
        
        self.queueFFTUpload=queueFFTUpload
        self.queueAbUpload=queueAbUpload

        self.SpecFrame=SpecFrame
        
        self.sockFile=staticVar.getSockFile()
        
        self.SpecList=[]

        
        self.Second=0
        self.countFFT=0

        self.count=1  ##用来计数一秒钟发了多少个功率谱文件
        
        self.fileUploadMode=2
        self.extractM=1
        self.changeThres=10

        self.extract_num=0
        
        self.startTrans=0
Ejemplo n.º 8
0
  def reConnect(self):
      '''stop all thread related to sock '''
      self.thread_upload.stop()
      self.thread_station.stop()
      
      
      staticVar.getSock().close()
      staticVar.getSockFile().close()
      
      self.thread_station.input1=[]
      staticVar.sock=0
      staticVar.sockFile=0
      
      serverCom=ServerCommunication() #实例化服务器连接对象
      while(1):
          try:
              serverCom.ConnectToServer(9000)
              staticVar.sock=serverCom.sock
              self.thread_station.sock=serverCom.sock 
              
              
          except Exception:
              wx.MessageBox('reConnect To Monitor Server Failure!', 
                         'Alert', wx.ICON_EXCLAMATION | wx.STAY_ON_TOP)
          
 
          try:
              serverCom.ConnectToServer(9988)
              staticVar.sockFile=serverCom.sockFile
              self.thread_station.sockFile=serverCom.sockFile
              self.thread_upload.sockFile=serverCom.sockFile 
              break 
          except Exception:
              wx.MessageBox('reConnect To File Server Failure!', 
                         'Alert', wx.ICON_INFORMATION | wx.STAY_ON_TOP)
          time.sleep(5)
      
      self.thread_station.input1.append(staticVar.sock)
      self.thread_station.input1.append(staticVar.sockFile)
      
      
      ''' start all the thread '''
      
      self.thread_station.event.set()
      self.thread_upload.event.set()
    def upload_iq(self):

        self.IQList=[]
        recvIQList = self.queueIQUpload.get()
        for recvIQ in recvIQList:
            block = IQBlock(recvIQ.CurBlockNo, recvIQ.IQDataAmp)
            self.IQList.append(block)

        head = IQUploadHeader(0x00, recvIQ.LonLatAlti, recvIQ.Param)

        #####组合IQ文件################

        Time=recvIQ.Time_
        # CommonHeader=recvIQ.CommonHeader
        # ID=(CommonHeader.HighDeviceID<<8)+CommonHeader.LowDeviceID
        Year=(Time.HighYear<<4)+Time.LowYear
        Month=Time.Month
        Day=Time.Day
        Hour=(Time.HighHour<<2)+Time.LowHour+8
        Minute=Time.Minute
        Second=Time.Second
        ID = staticVar.getid()

        if(not Year==2016):
            curTime = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
            Year = int(curTime[0:4])
            Month = int(curTime[4:6])
            Day = int(curTime[6:8])
            Hour = int(curTime[8:10])
            Minute = int(curTime[10:12])
            Second = int(curTime[12:14])
            

        fileName = str(Year) + "-" + str(Month) + "-" + str(Day) + \
                   "-" + str(Hour) + "-" + str(Minute) +  \
                   "-" + str(Second) + '-' + str(ID) +  '-'+\
                   str(self.mainframe.SpecFrame.iq_sequence)+ '.iq'

        fileNameLen = len(fileName)
        fileContentLen = sizeof(head) + sizeof(block) * len(self.IQList) + 1

        print fileName
        ###########SendToServer###################(H :2字节  Q:8 字节)

        sockFile=staticVar.getSockFile()
        str1 = struct.pack("!2BHQ", 0x00, 0xFF, fileNameLen, fileContentLen)
        sockFile.send(str1 + fileName)

        sockFile.send(bytearray(head))
        for block in self.IQList:
            sockFile.send(bytearray(block))
        sockFile.send(struct.pack("!B", 0x00))



        del self.IQList
    def upload_iq(self):

        self.IQList = []
        recvIQList = self.queueIQUpload.get()
        for recvIQ in recvIQList:
            block = IQBlock(recvIQ.CurBlockNo, recvIQ.IQDataAmp)
            self.IQList.append(block)

        head = IQUploadHeader(0x00, recvIQ.LonLatAlti, recvIQ.Param)

        #####组合IQ文件################

        Time = recvIQ.Time_
        # CommonHeader=recvIQ.CommonHeader
        # ID=(CommonHeader.HighDeviceID<<8)+CommonHeader.LowDeviceID
        Year = (Time.HighYear << 4) + Time.LowYear
        Month = Time.Month
        Day = Time.Day
        Hour = (Time.HighHour << 2) + Time.LowHour + 8
        Minute = Time.Minute
        Second = Time.Second
        ID = staticVar.getid()

        if (not Year == 2016):
            curTime = time.strftime('%Y%m%d%H%M%S',
                                    time.localtime(time.time()))
            Year = int(curTime[0:4])
            Month = int(curTime[4:6])
            Day = int(curTime[6:8])
            Hour = int(curTime[8:10])
            Minute = int(curTime[10:12])
            Second = int(curTime[12:14])


        fileName = str(Year) + "-" + str(Month) + "-" + str(Day) + \
                   "-" + str(Hour) + "-" + str(Minute) +  \
                   "-" + str(Second) + '-' + str(ID) +  '-'+\
                   str(self.mainframe.SpecFrame.iq_sequence)+ '.iq'

        fileNameLen = len(fileName)
        fileContentLen = sizeof(head) + sizeof(block) * len(self.IQList) + 1

        print fileName
        ###########SendToServer###################(H :2字节  Q:8 字节)

        sockFile = staticVar.getSockFile()
        str1 = struct.pack("!2BHQ", 0x00, 0xFF, fileNameLen, fileContentLen)
        sockFile.send(str1 + fileName)

        sockFile.send(bytearray(head))
        for block in self.IQList:
            sockFile.send(bytearray(block))
        sockFile.send(struct.pack("!B", 0x00))

        del self.IQList
Ejemplo n.º 11
0
    def upload(self):

        if (self.indexOfNameList == len(self.nameListIQ2)):

            self.indexOfNameList = 0
            self.nameListIQ2 = []

        else:
            #传输文件

            fileName = self.nameListIQ2[self.indexOfNameList]
            self.indexOfNameList += 1
            if (os.path.isfile(self.FILE_PATH + fileName)):

                #                 d = pickle.load(fid)
                #                 fid.close()
                #
                #                 LonLat= d['LonLat']
                #                 count_ab= d['count_ab']
                #                 list_for_ab=d['list_for_ab']
                #
                #
                fileNameLen = len(fileName)
                #                 fileContentLen=sizeof(LonLat)+5*count_ab+3

                sockFile = staticVar.getSockFile()
                if (not sockFile == 0):
                    try:
                        str1 = struct.pack("!2BHQ", 0x00, 0xFF, fileNameLen,
                                           6017)  ######服务器规定的格式
                        sockFile.sendall(str1 + fileName)
                        # sockFile.sendall(struct.pack("!B", 0x00))

                        print str1 + fileName
                        f = open(".\LocalData\\IQ2\\" + fileName, 'rb').read()
                        for i in f:
                            sockFile.sendall(i)

#                         sockFile.sendall(bytearray(LonLat))
#                         sockFile.sendall(struct.pack("!B",  count_ab))
#                         sockFile.sendall(bytearray(list_for_ab))
#                         sockFile.sendall(struct.pack("!B",0x00))

                        print fileName
                        os.remove(self.FILE_PATH + fileName)
                        Log.getLogger().debug("send_iq2_file_ok:%s" % fileName)

                    except socket.error, e:
                        print 'socket error occur in send iq2 ', e
                        Log.getLogger().debug(
                            " socket_error_found_in_send_iq2_file: %s" % e)
                        Log.getLogger().debug(" Cur socket sockFile=: %s" %
                                              staticVar.sockFile)

                        staticVar.sockFile = 0
Ejemplo n.º 12
0
    def reConnect(self):
        '''stop all thread related to sock '''
        self.thread_upload.stop()
        self.thread_station.stop()

        staticVar.getSock().close()
        staticVar.getSockFile().close()

        self.thread_station.input1 = []
        staticVar.sock = 0
        staticVar.sockFile = 0

        serverCom = ServerCommunication()  #实例化服务器连接对象
        while (1):
            try:
                serverCom.ConnectToServer(9000)
                staticVar.sock = serverCom.sock
                self.thread_station.sock = serverCom.sock

            except Exception:
                wx.MessageBox('reConnect To Monitor Server Failure!', 'Alert',
                              wx.ICON_EXCLAMATION | wx.STAY_ON_TOP)

            try:
                serverCom.ConnectToServer(9988)
                staticVar.sockFile = serverCom.sockFile
                self.thread_station.sockFile = serverCom.sockFile
                self.thread_upload.sockFile = serverCom.sockFile
                break
            except Exception:
                wx.MessageBox('reConnect To File Server Failure!', 'Alert',
                              wx.ICON_INFORMATION | wx.STAY_ON_TOP)
            time.sleep(5)

        self.thread_station.input1.append(staticVar.sock)
        self.thread_station.input1.append(staticVar.sockFile)
        ''' start all the thread '''

        self.thread_station.event.set()
        self.thread_upload.event.set()
    def __init__(self, mainframe):
        threading.Thread.__init__(self)

        self.dictFreqPlan = staticVar.getdictFreqPlan()
        self.event = threading.Event()
        self.event.set()
        self.sock = staticVar.getSock()
        self.sockFile = staticVar.getSockFile()
        self.outPoint = staticVar.outPoint
        self.specFrame = mainframe.SpecFrame
        self.specFrame.iq_sequence = 0

        self.mainframe = mainframe
        self.input1 = [self.sock, self.sockFile]  ##便于timer 控制
    def upload(self):

        if (self.indexOfNameList == len(self.nameListPoa)):

            self.indexOfNameList = 0
            self.nameListPoa = []

        else:
            # 传输文件

            fileName = self.nameListPoa[self.indexOfNameList]
            self.indexOfNameList += 1
            if (os.path.isfile(self.FILE_PATH + fileName)):

                fid = open(".\LocalData\\Poa\\" + fileName, 'rb')
                d = pickle.load(fid)
                fid.close()

                LonLat = d['LonLat']
                count_ab = d['count_ab']
                list_for_ab = d['list_for_ab']

                fileNameLen = len(fileName)
                fileContentLen = sizeof(LonLat) + 5 * count_ab + 3

                sockFile = staticVar.getSockFile()
                if (not sockFile == 0):
                    try:
                        str1 = struct.pack("!2BHQ", 0x00, 0xFF, fileNameLen,
                                           fileContentLen)
                        sockFile.sendall(str1 + fileName)
                        sockFile.sendall(struct.pack("!B", 0x00))
                        sockFile.sendall(bytearray(LonLat))
                        sockFile.sendall(struct.pack("!B", count_ab))
                        sockFile.sendall(bytearray(list_for_ab))
                        sockFile.sendall(struct.pack("!B", 0x00))

                        print fileName
                        os.remove(self.FILE_PATH + fileName)
                        Log.getLogger().debug("send_poa_file_ok:%s" % fileName)

                    except socket.error, e:
                        print 'socket error occur in send poa ', e
                        Log.getLogger().debug(
                            " socket_error_found_in_send_poa_file: %s" % e)
                        Log.getLogger().debug(" Cur socket sockFile=: %s" %
                                              staticVar.sockFile)

                        staticVar.sockFile = 0
Ejemplo n.º 15
0
    def FFTParse(self, ListSpec, ListAb):
        for i in range(len(ListSpec)):
            recvFFT = ListSpec[i]
            recvAbList = ListAb[i]

            TotalNum = recvFFT.SweepSectionTotalNum
            blockFFT = FFTBlock(recvFFT.CurSectionNo, recvFFT.AllFreq)
            blockAb = AbListBlock(recvAbList.CurSectionNo,
                                  recvAbList.AbFreqNum, recvAbList.AllAbFreq)
            self.SpecList.append(blockFFT)
            self.SpecList.append(blockAb)

        head=SpecUploadHeader(0x00,recvFFT.LonLatAlti,recvFFT.SweepRecvMode, \
        recvFFT.FileUploadMode,self.changeThres,self.extractM,TotalNum)

        ###组合功率谱文件####

        Time = recvFFT.Time_
        CommonHeader = recvFFT.CommonHeader
        ID = (CommonHeader.HighDeviceID << 8) + CommonHeader.LowDeviceID
        Year = (Time.HighYear << 4) + Time.LowYear
        Month = Time.Month
        Day = Time.Day
        Hour = (Time.HighHour << 2) + Time.LowHour + 8
        Minute = Time.Minute
        Second = Time.Second

        if (not Year == 2016):
            curTime = time.strftime('%Y%m%d%H%M%S',
                                    time.localtime(time.time()))
            Year = int(curTime[0:4])
            Month = int(curTime[4:6])
            Day = int(curTime[6:8])
            Hour = int(curTime[8:10])
            Minute = int(curTime[10:12])
            Second = int(curTime[12:14])

        ID = staticVar.getid()

        if (self.startTrans == 0):
            self.Second = Second
            self.startTrans = 1
        if ((self.startTrans == 1) and (self.Second != Second)):
            self.count = 1
            self.Second = Second
        fileName=str(Year)+"-"+str(Month)+"-"+str(Day)+  \
                 "-"+str(Hour)+"-"+str(Minute)+"-"+str(Second)+"-"+str(self.count)+'-'+str(ID)

        if (recvFFT.CommonHeader.FunctionPara == 0x51):
            fileName += '-fine.pwr'
        else:
            fileName += '-coarse.pwr'

        fileNameLen = len(fileName)
        fileContentLen = sizeof(head) + (sizeof(blockFFT) +
                                         sizeof(blockAb)) * TotalNum + 2

        # print fileNameLen
        # print fileContentLen

        ############SendToServer###################
        if (not staticVar.getSockFile() == 0):
            try:
                sockFile = staticVar.getSockFile()
                str1 = struct.pack("!2BHQ", 0x00, 0xFF, fileNameLen,
                                   fileContentLen)
                sockFile.sendall(str1 + fileName)
                sockFile.sendall(bytearray(head))
                for i in xrange(len(self.SpecList) / 2):
                    sockFile.sendall(bytearray(self.SpecList[2 * i]))
                sockFile.sendall(struct.pack("!B", 0xFF))
                for i in xrange(len(self.SpecList) / 2):
                    sockFile.sendall(bytearray(self.SpecList[2 * i + 1]))
                sockFile.sendall(struct.pack("!B", 0x00))
                ### 发送成功以后打个文件名 ###########

                print fileName
                self.count += 1
                self.countFFT += 1
                print 'self.countFFT', self.countFFT
                Log.getLogger().debug("send_spec_file_ok--name: %s--num:%s" %
                                      (fileName, self.countFFT))
            except socket.error, e:
                print 'socket_error_send_spec  ', e
                Log.getLogger().debug(
                    " socket_error_found_in_send_spec_file: %s" % e)
                Log.getLogger().debug(" Cur socket sockFile=: %s" %
                                      staticVar.sockFile)
                staticVar.sockFile = 0