Exemplo n.º 1
0
    def cmd(self, command, parameters):
        """
        Send a command to the server
        
        Inputs
        ----------
        command : str
            Command name
            
        parameters : list of str
            list of parameters, they must all be strings
            
        """

        if isinstance(parameters, str):
            parameters = [parameters]

        # Check everything is a string
        assert all([
            isinstance(s, str) for s in parameters
        ]), "FileTransferClient/cmd: All parameters must be strings"

        # Make the command packet
        cmd_packet = pcl.makeTextPacket('command', [command] + parameters)

        # Send to server
        reply = self.send(cmd_packet)

        return reply
Exemplo n.º 2
0
    def addFile(self, filename):
        """
        Add a file to the storage repository in the the specified master folder.
        
        Inputs
        --------
        master_folder_name : str
            Name of master folder to store file in
            
        filename : str
            path/filename to local file that is to be uploaded to repository
            
        """

        # Check if file exists in master storage
        # if not then return
        pcl.makeTextPacket('command:')

        # Check last time the file was modified

        # Send file to master storage
        pass
 def test_text_string_packet(self):
     """
     Create and extract text packets using string format
     
     """
     
     # Input data
     data_label = "/Data/New_place"
     text = "Some text to send"
     
     # Packet
     text_packet = pcl.makeTextPacket(data_label,text)
     
     # Extracted packet
     (label,text_out) = pcl.extractPacket(text_packet)
     
     self.assertTrue(label==data_label and text_out==text)
    def test_text_list_packet(self):
        """
        Create and extract text packets using list format
        
        """
        
        # Input data
        data_label = "/Data/New_place"
        text_list = ["Sending","some","text","in","a","list"]
        
        # Packet
        text_list_packet = pcl.makeTextPacket(data_label,text_list)
        
        # Extracted data
        (list_label,text_list_out) = pcl.extractPacket(text_list_packet)

        self.assertTrue(list_label==data_label and text_list_out==text_list)
#%% Send packet to server

dataPacket = "Hi Raspberry Pi, are you tasty"
pcl.sendPacket(hostIP, dataPacket)

#%% Shutdown server
pcl.serverShutdown(hostIP)

#%% Test sending text packets
data_label = "/Data/New_place"

text = "Some text to send"
text_list = ["Sending", "some", "text", "in", "a", "list"]

text_packet = pcl.makeTextPacket(data_label, text)
text_list_packet = pcl.makeTextPacket(data_label, text_list)

pcl.sendPacket(hostIP, text_packet)
pcl.sendPacket(hostIP, text_list_packet)

#=================================================================
#%% Array Packet making/extracting test
#=================================================================
import sys, imp
sys.path.append(
    '/home/john/Documents/Python/Projects/packet_comms_checkouts/trunk')
import packetcommslib as pcl

# Make an array packet
# -----------------------