Example #1
0
 def run_payload_noop(self):
     """
     Send a no-op command to the payload.
     """
     Send.send_payload_cmd(Hardware.PAYLOAD_BUS_ID,
                           PayloadCommandId.NO_OP,
                           None) # no data        
Example #2
0
 def abort_capture(self):
     """
     Send a command to the payload computer to abort any image capture operation.
     """
     Send.send_payload_cmd(Hardware.PAYLOAD_BUS_ID,
                           PayloadCommandId.ABORT_CAPTURE,
                           None) # no data
Example #3
0
    def run_capture_180(self, num_frames):
        """
        Send a command to the payload to run a 180-degree (four camera) capture
        for the specified number of frames.
        """

        Send.send_payload_cmd(Hardware.PAYLOAD_BUS_ID,
                              PayloadCommandId.CAPTURE_180,
                              bytearray([num_frames]) ) # no data
Example #4
0
def main():
    # My payload ID
    my_id = 4

    print("Sending no-op command to bus...")
    bc = BusCommands(my_id)
    bc.noop()

    print("Sending shell command to self...")
    Send.send_payload_cmd(my_id, 0x00, "ls")
Example #5
0
    def power_cameras(self, enable):
        """
        Power on/off the camera hardware.
        """

        if (enable):
            Send.send_payload_cmd(Hardware.PAYLOAD_BUS_ID,
                                  PayloadCommandId.CAMERA_POWER_ON,
                                  None )
        else:
            Send.send_payload_cmd(Hardware.PAYLOAD_BUS_ID,
                                  PayloadCommandId.CAMERA_POWER_OFF,                     
                                  None )
Example #6
0
def test_error_cases():

    # Exceptional: Invalid parameter type
    with pytest.raises(TypeError) as ex:
        Send.send(bytearray(266))

    # Exceptional: Invalid parameter type
    with pytest.raises(TypeError) as ex:
        Send.send_payload_cmd(4, 0x00, 0x00)

    # Exceptional: Invalid parameter type
    with pytest.raises(TypeError) as ex:
        Send.send_bus_cmd(0x00, 0x00)
Example #7
0
def test_send_payload_command():
    Send.send_payload_cmd(4, 0x00, None)
    Send.send_payload_cmd(4, 0x00, b"Command string")

    # Exceptional: Packet too long
    with pytest.raises(ValueError) as ex:
        Send.send_payload_cmd(4, 0x00, bytearray(1000))
    def run_shell(packet):
        """ The "shell" command runs a bash command.

        It can be split across multiple packets, in which case
        the string will be accumulated between the first and
        last packets, and it will be run when the last packet
        is received.
        """

        if (packet.seq_flags & Packet.SEQ_FLAG_FIRST):
            # On the first packet, clear whatever old command string
            PayloadCommandHandler.shell_cmd = ""

        PayloadCommandHandler.shell_cmd = PayloadCommandHandler.shell_cmd + packet.data.decode("utf-8")
        shell_cmd = PayloadCommandHandler.shell_cmd
        shell_rsl = ""

        if (packet.seq_flags & Packet.SEQ_FLAG_LAST):

            # On the last packet, we actually run the command
            print("Running in shell...\n $ %s \n" % (shell_cmd))

            # TODO: add some safeguards against timeout
            try:
                shell_rsl = subprocess.check_output(shell_cmd, shell=True, stderr=subprocess.STDOUT)
                # Or, if we don't want to use the shell interpreter:
                # shell_rsl = subprocess.check_output(shlex.split(shell_cmd), shell=False)
            except subprocess.CalledProcessError as e:
                shell_rsl = "ERROR exit=%d %s" % (e.returncode, e.output)

            if PayloadCommandHandler.DEBUG:
                print('================= BEGIN OUTPUT =================')
                print(shell_rsl)
                print('================== END OUTPUT ==================')

            # Send reponse packet
            # TODO: send back to packet source
            Send.send_payload_cmd(4, PayloadCommandHandler.SHELL_RESP, shell_rsl)
Example #9
0
def thread1_keyboard():
    # Send user input, one line at a time
    print("----- Remote terminal ----- \n")
    while(True):
        cmd = raw_input()
        Send.send_payload_cmd(DEST_ID, PayloadCommandHandler.SHELL_CMD, cmd)
    def run_echo(packet):
        """ The "echo" command simply sends back a packet with the same data.

        """
        # TODO: send back to packet source
        Send.send_payload_cmd(4, PayloadCommandHandler.ECHO_RESP, packet.data)