Exemplo n.º 1
0
    def SendCommand(self, cmd_code, pub_name):
        """Sends a command to the subscriber over the network. """

        # Get the transaction id and create the command structure.
        TxId = SMPCentralNodeRequestHandler.GetNextTransactionID()
        command = Command().CreateFromParams(cmd_code, TxId, self.SensorType,
                                             pub_name)

        #log the transaction, the Key is the client address in this case.
        SMPCentralNodeRequestHandler.StoreTransaction(TxId, command,
                                                      self.Socket, self.Key)

        print "Sending: " + command.GetCommandString() + " <" + str(
            command) + ">"

        # In a happy accident the subscribers key is actually the client address, so we just pass that into the send call.
        self.Socket.sendto(command.GetPacket(), self.Key)
Exemplo n.º 2
0
    def SendCommand(self, cmd_code):
        """ Sends a command to the publisher over the network. """

        # Get the id ahead of time since we need it to log the transaction.
        TxId = SMPCentralNodeRequestHandler.GetNextTransactionID()

        #Create the command the key is the payload, its the name of the publisher.
        command = Command().CreateFromParams(cmd_code, TxId, self.SensorType,
                                             self.Key)

        # We log the transaction with the central node since we may need to resend it if we don't get a success.
        SMPCentralNodeRequestHandler.StoreTransaction(TxId, command,
                                                      self.Socket,
                                                      self.ClientAddress)

        print "Sending: " + command.GetCommandString() + " <" + str(
            command) + ">"

        # Actually do the sending.
        self.Socket.sendto(command.GetPacket(), self.ClientAddress)