def _action_TXCON(self): # log log.debug('_action_TXCON()') # flag error if max number of CON transmits reached if self.numTxCON > self.maxRetransmit + 1: # this is an error case self.coapError = e.coapTimeout( 'No ACK received after {0} tries (max {1})'.format( self.numTxCON, self.maxRetransmit + 1, )) return # build message message = m.buildMessage( msgtype=d.TYPE_CON, token=self.token, code=self.code, messageId=self.messageId, options=self.options, payload=self.payload, securityContext=self.securityContext, partialIV=self.requestSeq, ) # send self.sendFunc( destIp=self.destIp, destPort=self.destPort, msg=message, ) # increment number of transmitted messages self.numTxCON += 1 # update FSM state self._setState(self.STATE_WAITFORACK) # kick FSM self._kickFsm()
def _action_WAITFORRESP(self): # log log.debug('_action_WAITFORRESP()') startTime = time.time() while True: waitTimeLeft = startTime+self.respTimeout-time.time() if self.rxMsgEvent.wait(timeout=waitTimeLeft): # I got message with self.dataLock: (timestamp,srcIp,srcPort,message) = self.LastRxPacket if isinstance(message,e.coapRc): with self.dataLock: self.coapError = message return elif ( ( message['type']==d.TYPE_CON or message['type']==d.TYPE_NON ) and message['token']==self.token ): # store response with self.dataLock: self.receivedResp = (timestamp,srcIp,srcPort,message) # update FSM state self._setState(self.STATE_RESPRX) # kick FSM self._kickFsm() return else: # this is an error case self.coapError = e.coapTimeout('No Response received after {0}s'.format( self.respTimeout, ) ) return
def _action_TXCON(self): # log log.debug('_action_TXCON()') # flag error if max number of CON transmits reached if self.numTxCON>self.maxRetransmit+1: # this is an error case self.coapError = e.coapTimeout('No ACK received after {0} tries (max {1})'.format( self.numTxCON, self.maxRetransmit+1, ) ) return # build message message = m.buildMessage( type = d.TYPE_CON, token = self.token, code = self.code, messageId = self.messageId, options = self.options, payload = self.payload, ) # send self.sendFunc( destIp = self.destIp, destPort = self.destPort, msg = message, ) # increment number of transmitted messages self.numTxCON += 1 # update FSM state self._setState(self.STATE_WAITFORACK) # kick FSM self._kickFsm()
def _action_WAITFORRESP(self): # log log.debug('_action_WAITFORRESP()') startTime = time.time() while True: waitTimeLeft = startTime + self.respTimeout - time.time() if self.rxMsgEvent.wait(timeout=waitTimeLeft): # I got message with self.dataLock: (timestamp, srcIp, srcPort, message) = self.LastRxPacket if isinstance(message, e.coapRc): with self.dataLock: self.coapError = message return elif ((message['type'] == d.TYPE_CON or message['type'] == d.TYPE_NON) and message['token'] == self.token): # store response with self.dataLock: self.receivedResp = (timestamp, srcIp, srcPort, message) # update FSM state self._setState(self.STATE_RESPRX) # kick FSM self._kickFsm() return else: # this is an error case self.coapError = e.coapTimeout( 'No Response received after {0}s'.format( self.respTimeout, )) return