示例#1
0
    def waitForFileTransfer(self) -> None:
        """
        Spawns threads that will wait for both phones to send a signal saying that the file transfer
        of the videos is complete.

        :return: None
        """
        # Make sure the phones are connected and synced first
        if not self.connected:
            raise PhonesNotSyncedException("ERROR: Phones not synced up yet!")

        threads = list()

        if not self.transferring:
            raise TransferNotStartedException("ERROR! Transfer has not been started! Can't wait for it!")

        try:
            for conn in self.connections:
                # Start a new thread and return its identifier
                x = threading.Thread(target=self.threadWaitForFileTransfer, args=(conn,))
                threads.append(x)
                x.start()

            for index, thread in enumerate(threads):
                thread.join()

            print("Start FTP Threads Joined!\n")
            self.transferring = False  # Set flag that we are currently transferring the file over

        except Exception as e:
            self.closeConn()
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
示例#2
0
    def startFileTransfer(self, filepath: str) -> None:
        """
        Will send a signal to the phone that tells it to transfer the video files it recorded over to the laptop
        by opening an FTP connection.

        :param filepath: The file path on our laptop that the phones will need to send their videos to over FTP.
        :return: None
        """
        # Make sure the phones are connected and synced first
        if not self.connected:
            raise PhonesNotSyncedException("ERROR: Phones not synced up yet!")

        threads = list()

        try:
            for conn in self.connections:
                # Start a new thread and return its identifier
                x = threading.Thread(target=self.threadSendSignal, args=(conn, "START_FTP", filepath, "START_FTP_ACKNOWLEDGE"))
                threads.append(x)
                x.start()

            for index, thread in enumerate(threads):
                thread.join()

            print("Start FTP Threads Joined!\n")
            self.transferring = True # Set flag that we are currently transferring the file over

        except Exception as e:
            self.closeConn()
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
示例#3
0
    def startRecording(self) -> None:
        """
        Call this in order to send a signal to the phones that they need to start recording.

        :return: None
        """
        threads = list()

        # Make sure the phones are connected and synced first
        if not self.connected:
            raise PhonesNotSyncedException("ERROR: Phones not synced up yet!")

        num = 1
        try:
            for conn in self.connections:
                # Start a new thread and return its identifier
                phoneID = "phone-" + str(num)
                x = threading.Thread(target=self.threadSendSignal, args=(conn, "START", phoneID, "START_ACKNOWLEDGE"))
                num += 1
                threads.append(x)
                x.start()

            for index, thread in enumerate(threads):
                thread.join()
            self.recording = True
            print("Start Threads Joined!\n")

        except Exception as e:
            self.closeConn()
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
示例#4
0
    def closeConn(self):
        """
        Closes all of the connections and the socket.
        :return: None
        """
        # Make sure the phones are connected and synced first
        if not self.connected:
            raise PhonesNotSyncedException("ERROR: Phones not synced up yet!")

        for conn in self.connections:
            conn.close()

        self.socket.close()
        self.connected = False
示例#5
0
    def stopRecording(self):
        """
        Call this in order to send a signal to the phones that they need to stop tracking. Sends both
        phones a stop signal and the name of the file path that they will need to send their
        videos to over FTP.
        :return: None
        """
        # Make sure the phones are connected and synced first
        if not self.connected:
            raise PhonesNotSyncedException("ERROR: Phones not synced up yet!")

        # make sure that we are recording first
        if not self.recording:
            raise RecordingNotStartedException(
                "ERROR! Recording must be started to be stopped")

        threads = list()

        try:
            for conn in self.connections:
                # Start a new thread and return its identifier
                timestamp = datetime.datetime.now()
                x = threading.Thread(target=self.threadSendSignal,
                                     args=(conn, "STOP", str(timestamp),
                                           "STOP_ACKNOWLEDGE"))
                threads.append(x)
                x.start()

            for index, thread in enumerate(threads):
                thread.join()

            self.recording = False
            print("Stop Threads Joined!\n")

        except Exception as e:
            self.closeConn()
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)