Ejemplo n.º 1
0
 def _onRequestRecv(self, xAsyncTCPClient, data, arg) :
     uid = arg[0]
     if len(arg) == 2 :
         trackingNbr, dataFormat, formatOpt, dataLen = arg[1]
         data = data.tobytes()
     else :
         hdr = IoTSocketStruct.DecodeRequestHdr(data.tobytes())
         trackingNbr, dataFormat, formatOpt, dataLen = hdr
         if dataLen > 0 :
             self._recv(dataLen, self._onRequestRecv, (uid, hdr))
             return
         data = b''
     print('ON REQUEST [%s] RECV' % trackingNbr)
     self._send(IoTSocketStruct.MakeResponseTRHdr(uid, trackingNbr, 0, dataFormat, 0, dataLen) + data)
     self._waitDataTransmission()
 def _onRequestRecv(self, xAsyncTCPClient, data, arg):
     uid = arg[0]
     if len(arg) == 2:
         trackingNbr, dataFormat, formatOpt, dataLen = arg[1]
         data = data.tobytes()
     else:
         hdr = IoTSocketStruct.DecodeRequestHdr(data.tobytes())
         trackingNbr, dataFormat, formatOpt, dataLen = hdr
         if dataLen > 0:
             self._recv(dataLen, self._onRequestRecv, (uid, hdr))
             return
         data = b''
     if uid:
         strUID = ('{%s}' % IoTSocketStruct.UIDFromBin128(uid))
     else:
         strUID = 'CENTRAL'
     errCode = None
     with self._requestsLock:
         self._router.Log('SESSION %s > REQUEST TO %s RECEIVED (#%s)' %
                          (self._getSessionName(), strUID, trackingNbr))
         if not trackingNbr in self._requests:
             if self._router.RouteRequest(
                     fromUID=None if self._isCentral else self._uid,
                     toUID=uid,
                     trackingNbr=trackingNbr,
                     dataFormat=dataFormat,
                     formatOpt=formatOpt,
                     data=data):
                 exp = time() + self._reqTimeout
                 self._requests[trackingNbr] = (uid, exp)
             else:
                 errCode = IoTSocketStruct.RESP_CODE_ERR_NO_DEST
         else:
             self._router.Log(
                 'SESSION %s > TRACKING NUMBER #%s ALREADY EXISTS' %
                 (self._getSessionName(), trackingNbr))
             errCode = IoTSocketStruct.RESP_CODE_ERR_SAME_TRK_NBR
     if errCode:
         self.Send(
             IoTSocketStruct.MakeResponseErrTR(uid, trackingNbr, errCode))
     self._waitDataTransmission()