Пример #1
0
    def addJob(self, szData):

        # syncronized
        evAutoThreadLock(self.m_oLock)
        plog("JobManager:addJob : ", szData)

        oJob = JsonJob()

        try:
            oJob.setJsonData(szData)
            self.m_aJobList.append(oJob)
        except:
            perr("JobManager.addJob  exception!!.", szData)
Пример #2
0
 def procServerSyncSample(self, oJob) :
     plog ("processing server svr sample job..")
     
     plog ("job data : ", oJob.m_val)
     
     if (1) :
         # 처리 결과 저장
         oJob.resServerSync(2) # 동기식일 때 결과를 알린다. 비동기여도 결과를 체크하는 경우 결과를 알리는데 사용할 수 있다.
         return
     elif (0) :
         # 처리 결과 저장
         oJob.resError() # 동기식일 때 결과를 알린다. 비동기여도 결과를 체크하는 경우 결과를 알리는데 사용할 수 있다.
         return
     else :
         oJob.resOk()
         return
Пример #3
0
    def connectToServer(self):
        plog("SVRCOMM.trying to reconnect to server", self.m_szServerIP,
             self.m_nServerPort)

        try:
            self.m_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.m_socket.connect((self.m_szServerIP, self.m_nServerPort))
            self.m_tKeepAliveTime = UtilTime.getCurrentClock()
            plog("SVRCOMM.server connected..")
            self.m_connectionProblem = False
        except Exception, e:
            self.m_connectionProblem = True
            self.ip_change_process()
            plog("SVRCOMM.server connection fail.", str(e))
            return False
Пример #4
0
    def writeMessage(self, msg):

        with self.writer_lock:
            plog("cmpSEIRelayClient.writeMessage data : {}".format(msg))
            if msg is None:
                return False

            if self.m_connectionProblem is True:
                plog("[error] cmpMMARSClient.writeMessage to SEI-RELAY  fail.")
                if self.gateway_data_storage is not None:
                    self.gateway_data_storage.addMsg(msg)
                return False

            try:
                msg = msg + "\n"
                self.m_socket.send(msg)
            except Exception, e:
                plog("cmpMMARSClient.writeMessage to SEI-RELAY  fail.", str(e))
                self.closeSocket()
                self.m_connectionProblem = True
                return False
Пример #5
0
 def printJob(self):
     plog(self.m_oJson)
Пример #6
0
    def run(self):
        plog("cmpServerComm.thread started...")
        while (not self.m_bEnd):

            if (not self.connectToServer()):
                plog("cmpServerComm.connectToServer error.")
                time.sleep(10)
                continue

            self.writeMessage(ThingConfig.gw_id)

            while (not self.m_bEnd and not self.m_connectionProblem):
                # self.checkKeepAlive()

                try:
                    # self.m_socket.settimeout(2)
                    for data in self.buffered_readlines():
                        if (data == None):
                            plog("cmpSEIRelayClient.data is none.")
                            self.closeSocket()
                            self.m_connectionProblem = True
                            break

                        if (data == ""):
                            plog("cmpSEIRelayClient.data is empty.")
                            self.closeSocket()
                            self.m_connectionProblem = True
                            break

                        plog("cmpSEIRelayClient.received data : {}".format(
                            data))

                        self.executeData(data)

                except socket.timeout:
                    plog("SVRCOMM.recv time out.")
                    continue
                except socket.error:
                    self.closeSocket()
                    self.m_connectionProblem = True
                    plog("cmpMMARSClient socket error.")
                    break

        plog("cmpServerComm.thread terminated...")
Пример #7
0
 def procPowerToServer(self, oJob) :
     plog ("procPowerToServer called.", oJob.m_val)
     json_packet = self.makePowerMessage(oJob.m_val[0], oJob.m_val[1], oJob.m_val[2], oJob.m_val[3], oJob.m_val[4])   
     self.oSeiRelay.writeMessage(json_packet)
     
     oJob.resOk()     
Пример #8
0
 def procGateServerThread(oMdGate) :
     plog ("MdGateSvrThread start..")
     oMdGate.procGateServer()
     plog ("MdGateSvrThread terminated..")