original_docstring:  Add a command to the send List 
              The List is needed to prevent sending messages too quickly normally it requires 500msec between messages 
docstring: Add a command to the send List
  The List is needed to prevent sending messages too quickly normally it requires 500msec between messages
docstring_tokens: Add a command to the send List The List is needed to prevent sending messages too quickly normally it requires 500msec between messages
code: def SendCommand(self, message_type, **kwargs):
          """ Add a command to the send List 
              The List is needed to prevent sending messages too quickly normally it requires 500msec between messages """
          interval = self.getTimeFunction() - self.pmLastTransactionTime
          timeout = (interval > RESEND_MESSAGE_TIMEOUT)
  
          # command may be set to None on entry
          # Always add the command to the list
          if message_type is not None:
              message = pmSendMsg[message_type]
              assert(message is not None)
              options = kwargs.get('options', None)
              e = VisonicListEntry(command = message, options = options)
              self.SendList.append(e)
              log.info("[QueueMessage] %s" % message.msg)
  
          # self.pmExpectedResponse will prevent us sending another message to the panel
          #   If the panel is lazy or we've got the timing wrong........
          #   If there's a timeout then resend the previous message. If that doesn't work then do a reset using triggerRestoreStatus function
          #  Do not resend during startup or download as the timing is critical anyway
          if not self.coordinating_powerlink and not self.DownloadMode and self.pmLastSentMessage != None and timeout and len(self.pmExpectedResponse) > 0:
              if not self.pmLastSentMessage.triedResendingMessage:
                  # resend the last message
                  log.info("[SendCommand] Re-Sending last message  {0}".format(self.pmLastSentMessage.command.msg))
                  self.pmSendPdu(self.pmLastSentMessage)
                  self.pmLastTransactionTime = self.getTimeFunction()
                  self.pmLastSentMessage.triedResendingMessage = True
              else:
                  # tried resending once, no point in trying again so reset settings, start from scratch
                  log.info("[SendCommand] Tried Re-Sending last message but didn't work. Assume a powerlink timeout state and reset")
                  self.triggerRestoreStatus() # this will call this function recursivelly to send the MSG_RESTORE.
                  return
          elif len(self.SendList) > 0:    # This will send commands from the list, oldest first
              if interval is not None and len(self.pmExpectedResponse) == 0: # we are ready to send
                  # check if the last command was sent at least 500 ms ago
                  td = timedelta(milliseconds=800)
                  ok_to_send = (interval > td) # pmMsgTiming_t[pmTiming].wait)
                  #log.debug("[SendCommand]        ok_to_send {0}    {1}  {2}".format(ok_to_send, interval, td))
                  if ok_to_send:
                      # pop the oldest item from the list, this could be the only item.
                      instruction = self.SendList.pop(0)
                      # Do we have to receive an acknowledge from the panel before we sent more messages
                      #self.pmWaitingForAckFromPanel = instruction.command.waitforack
                      self.reset_keep_alive_messages()   # no need to send i'm alive message for a while as we're about to send a command anyway
                      self.pmLastTransactionTime = self.getTimeFunction()
                      self.pmLastSentMessage = instruction
                      self.pmExpectedResponse.extend(instruction.response) # if an ack is needed it will already be in this list
                      self.pmSendPdu(instruction)
code_tokens: def SendCommand ( self , message_type , ** kwargs ) : interval = self . getTimeFunction ( ) - self . pmLastTransactionTime timeout = ( interval > RESEND_MESSAGE_TIMEOUT ) if message_type is not None : message = pmSendMsg [ message_type ] assert ( message is not None ) options = kwargs . get ( 'options' , None ) e = VisonicListEntry ( command = message , options = options ) self . SendList . append ( e ) log . info ( "[QueueMessage] %s" % message . msg ) if not self . coordinating_powerlink and not self . DownloadMode and self . pmLastSentMessage != None and timeout and len ( self . pmExpectedResponse ) > 0 : if not self . pmLastSentMessage . triedResendingMessage : log . info ( "[SendCommand] Re-Sending last message  {0}" . format ( self . pmLastSentMessage . command . msg ) ) self . pmSendPdu ( self . pmLastSentMessage ) self . pmLastTransactionTime = self . getTimeFunction ( ) self . pmLastSentMessage . triedResendingMessage = True else : log . info ( "[SendCommand] Tried Re-Sending last message but didn't work. Assume a powerlink timeout state and reset" ) self . triggerRestoreStatus ( ) return elif len ( self . SendList ) > 0 : if interval is not None and len ( self . pmExpectedResponse ) == 0 : td = timedelta ( milliseconds = 800 ) ok_to_send = ( interval > td ) if ok_to_send : instruction = self . SendList . pop ( 0 ) self . reset_keep_alive_messages ( ) self . pmLastTransactionTime = self . getTimeFunction ( ) self . pmLastSentMessage = instruction self . pmExpectedResponse . extend ( instruction . response ) self . pmSendPdu ( instruction )
short_docstring: Add a command to the send List
  The List is needed to prevent sending messages too quickly normally it requires 500msec between messages
short_docstring_tokens: Add a command to the send List The List is needed to prevent sending messages too quickly normally it requires 500msec between messages
comment: """ Add a command to the send List 
              The List is needed to prevent sending messages too quickly normally it requires 500msec between messages """$SEP$# command may be set to None on entry$SEP$# Always add the command to the list$SEP$# self.pmExpectedResponse will prevent us sending another message to the panel$SEP$#   If the panel is lazy or we've got the timing wrong........$SEP$#   If there's a timeout then resend the previous message. If that doesn't work then do a reset using triggerRestoreStatus function$SEP$#  Do not resend during startup or download as the timing is critical anyway$SEP$# resend the last message$SEP$# tried resending once, no point in trying again so reset settings, start from scratch$SEP$# this will call this function recursivelly to send the MSG_RESTORE.$SEP$# This will send commands from the list, oldest first$SEP$# we are ready to send$SEP$# check if the last command was sent at least 500 ms ago$SEP$# pmMsgTiming_t[pmTiming].wait)$SEP$#log.debug("[SendCommand]        ok_to_send {0}    {1}  {2}".format(ok_to_send, interval, td))$SEP$# pop the oldest item from the list, this could be the only item.$SEP$# Do we have to receive an acknowledge from the panel before we sent more messages$SEP$#self.pmWaitingForAckFromPanel = instruction.command.waitforack$SEP$# no need to send i'm alive message for a while as we're about to send a command anyway$SEP$# if an ack is needed it will already be in this list