def run(self): from Switch import Switch """ process each incoming message """ while (self.active): try: message = self.queue.get(timeout=self.timeout) print "Net Management got message**********" log = dumpBinary(message) print log self.statusWin.addIncomingMessage(log) (rcvObj, log) = self.package.unpack(self.fielddef, message) print log self.statusWin.addIncomingMessage(log) except: # will get empty exception when timeout continue transDesc = self.findTransDesc(rcvObj) if transDesc == None: print "received message with no trans map" continue transObj = self.formTransObj(transDesc, rcvObj) message = self.package.pack(transDesc, transObj) self.switch.addMessage(message, Switch.MANAGEMENT_TRXN) # response message log = dumpBinary(message) print "Net Management repoinse message************" print log self.statusWin.addOutgoingMessage(log) (dummy, log) = self.package.unpack(self.fielddef, message) print log self.statusWin.addOutgoingMessage(log) print "end of management thread", self
def send(self, message): header = self.comm.packMessageHead(message) self.sndSocket.send(header) self.comm.logOutgoingMessage(header + message) print "send message:==================\n" print dumpBinary(header) print dumpBinary(message) print "===============================\n" nbytes = len(message) while (self.active and (nbytes > 0)): byte_snds = self.sndSocket.send(message) if (byte_snds == 0): # socket has broken raise ValueError('socket has broken') print "=============>", message[:byte_snds] message = message[byte_snds:] nbytes -= byte_snds
def doTransaction(self): # should be only called from transaction thread transObj = self._scrollFrame.formTransObj() rquestMsg = self._package.pack(self._scrollFrame.transDesc, transObj) # for aic message header now = datetime.datetime.now #timestamp = ("%d%d%d%d%d%d%06d" % (now.year, now.month, now.day, now.hour, now.minute, now.second, now.microsecond)) #header = ("%12.12s" % Configure.config['org']) + ("%6.6s" % Configure.config['version']) + '0' + '0' + '0' + '999999' + ' ' + time.strftime("%Y%m%d") + time.strftime("%Y%m%d%H%M%S') + timestamp + (' ' * 42) + ("%12.12s" % Configure.config['branch']) + ("%12.12s" % Configure.config['operator']) + (' ' * 13) + (' ' * 4) + (' ' * 100) + (' ' * 16) + (' ' * 30) # log outgoing message log = dumpBinary(rquestMsg) wx.CallAfter(self._logFrame.addOutgoingMessage, log) (dummy, log) = self._package.unpack(self._currTrans._fielddef, rquestMsg) wx.CallAfter(self._logFrame.addOutgoingMessage, log) # sending the message out if (self._switch == None): self._button.Enable() print "must open connection first" return self._switch.addMessage(rquestMsg, Switch.NORMAL_TRXN) t_start = time.time() rcvObj = None while self.transThread.active: t = time.time() if (t - t_start > self.transTimeOut): break try: responseMsg = self.queue.get(timeout=self.queueTimeOut) log = dumpBinary(responseMsg) wx.CallAfter(self._logFrame.addIncomingMessage, log) (rcvObj, log) = self._package.unpack(self._currTrans._fielddef, responseMsg) wx.CallAfter(self._logFrame.addIncomingMessage, log) break # got message, break the loop except: # will get empty exception when timeout continue wx.CallAfter(self._list.InsertTrxn, self._scrollFrame.transDesc.name, transObj, rcvObj) wx.CallAfter(self._button.Enable)
def run(self): self.queueTimeOut = 5 while self.active: try: message = self.frame.queue.get(timeout=self.queueTimeOut) print "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" log = dumpBinary(message) self.frame._logFrame.addIncomingMessage(log) (rcvObj, log) = frame._package.unpack(IsoFieldDef.GlobalIsoFieldDef, message) self.frame._logFrame.addIncomingMessage(log) # could do some statistic here except Queue.Empty: # will get empty exception when timeout continue
def logOutgoingMessage(self, message): msg = dumpBinary(message) if (self.serverStatusWin != None): wx.CallAfter(self.serverStatusWin.addMsg, msg)
def logIncomingMessage(self, message): msg = dumpBinary(message) if (self.clientStatusWin != None): wx.CallAfter(self.clientStatusWin.addMsg, msg)
transObj[32] = {'host' : "03112900"} transObj[33] = {'host' : "03112900"} transObj[35] = {'host' : "4026740000001234=081010100000123000"} transObj[37] = {'host' : "123456"} transObj[41] = {'host' : "001"} transObj[42] = {'host' : "100001"} transObj[43] = {'host' : "BANK OF SHANGHAI"} transObj[48] = {'host' : "NK"+unhexlify("1234567890ABCDEF")} transObj[49] = {'host' : "156"} transObj[52] = {'host' : "123456"} transObj[53] = {'host' : "1000000000000000"} transObj[55] = {'host' : "12345"} transObj[70] = {'host' : "101"} transObj[90] = {'host' : "020007631309071927010000102100000001021000"} transObj[96] = {'host' : unhexlify("1234567890ABCDEF")} transObj[100] = {'host' : "03112900"} transObj[121] = {'host' : "51100001403112900 "} transObj[123] = {'host' : "12345678"} buf = transDesc.pack(transObj) print buf print "\n\n" print dumpBinary(buf) print "\n\n" transObj = {} (transObj, buf) = transDesc._fielddef.messageFormat.unpack(transDesc._fielddef, buf, transObj) print transObj print buf
indexes = transDesc._fields.keys() indexes.sort() for index in indexes: field = transDesc._fields[index] value = field.getValue(transObj) transObj[index] = {'host': value} return transObj def doTransaction(self, case, card): transDesc = self.caseMap[case.name] transObj = self.formTransObj(case, card) msg = transDesc.pack(transObj) # log outgoing message log = dumpBinary(msg) wx.CallAfter(self._logFrame.addOutgoingMessage, log) (dummy, log) = self._package.unpack(transDesc._fielddef, msg) wx.CallAfter(self._logFrame.addOutgoingMessage, log) # sending the message out # self._switch.addMessage(msg, Switch.NORMAL_TRXN) if (__name__ == "__main__"): import IsoFieldDef fielddef = IsoFieldDef.LoadIsoFieldDef("project/cup/CupFieldDef.xml") config = {} config['pinblock_mode'] = "08" config['zpk'] = "1C25E98F9B9249AB"