Esempio n. 1
0
    def End(self, camera):

        # set th flash processing
        self.led_flash.setPixelColor(0, Color(255, 255, 0))
        self.led_flash.show()

        # if the process count matches the trigger count, we succeeded
        if self.process['count'] == self.script_cfg['triggers'] or path.isfile(
                self.script_cfg['path'] + '/tmp/stop.proc'):

            i = 0
            while i < 3:
                # set the camera led off
                self.led_flash.setPixelColor(0, Color(0, 0, 0))
                self.led_flash.show()
                sleep(0.25)
                i += 1
                # set the camera led to warn
                self.led_flash.setPixelColor(0, Color(255, 255, 0))
                self.led_flash.show()
                sleep(0.25)

            # close the camera
            camera.close()

            # kill the imu process
            IMUDevice.StopIMU(IMUDevice, self.process['pid'], self.script_cfg)

            # if we have reached the end, report
            rows = DBLite.DisplayDB(DBLite, self.process['connection'],
                                    self.script_cfg)

            # get the name of our archive before we close the database
            archive = DBLite.GetArchiveName(DBLite, self.process['connection'],
                                            self.script_cfg)

            # if we are in ascii then process the imu information
            if self.imu_cfg['stream'] == 'ascii':
                IMUDevice.ProcessIMU(IMUDevice, self.process['connection'],
                                     self.script_cfg, rows)

                # get the updated rows
                rows = DBLite.DisplayDB(DBLite, self.process['connection'],
                                        self.script_cfg)

                # export a processed imu file
                FileStruct.ProcessedCSV(FileStruct, self.script_cfg, rows)

            # close our db connection
            DBLite.CloseDB(DBLite, self.process['connection'], self.script_cfg)

            # write a friendly csv file
            FileStruct.WriteCSV(FileStruct, self.script_cfg, rows)

            # move the database/imu data to a new store location
            FileStruct.Save(FileStruct, self.script_cfg, archive)

            # pretty print the final results
            # if we are in ascii print the telemetry
            if self.imu_cfg['stream'] == 'ascii':
                output = tabulate(rows,
                                  headers=[
                                      "Trigger", "Trigger Lapse",
                                      "Camera Lapse", "Byte", "Image", "Size",
                                      "Telemetry"
                                  ],
                                  floatfmt=".12f")

                print(output)

                with open(self.script_cfg['path'] + '/tmp/results.txt',
                          "w") as text_file:
                    print(output, file=text_file)

            else:
                output = tabulate(rows,
                                  headers=[
                                      "Trigger", "Trigger Lapse",
                                      "Camera Lapse", "Byte", "Image", "Size"
                                  ],
                                  floatfmt=".12f")

                print(output)

                with open(self.script_cfg['path'] + '/tmp/results.txt',
                          "w") as text_file:
                    print(output, file=text_file)

            print("| done, ", self.process['count'], "/",
                  self.script_cfg['triggers'], "success |")

            self.led_flash.setPixelColor(0, Color(0, 255, 0))
            self.led_flash.show()

            self.process['start'] = False
            exit()

        else:

            # close the camera
            camera.close()

            # kill the imu process
            IMUDevice.StopIMU(IMUDevice, self.process['pid'], self.script_cfg)
            # close our db connection
            DBLite.CloseDB(DBLite, self.process['connection'], self.script_cfg)

            print("| done, ", self.process['count'], "/",
                  self.script_cfg['triggers'], "failed |")

            self.led_flash.setPixelColor(0, Color(0, 0, 0))
            self.led_flash.show()

            self.process['start'] = False
            exit()
Esempio n. 2
0
    def End(self):

        # kill the imu process
        IMUDevice.StopIMU(IMUDevice, self.process['pid'], self.script_cfg)

        # set some thing we will need
        display = {}
        archive = None

        # if the process count matches the trigger count
        if self.process['count'] == self.script_cfg['triggers']:

            # if we have reached the end, should we report
            rows = DBLite.DisplayDB(DBLite, self.process['connection'],
                                    self.script_cfg)

            # switch the camera to USB Mode
            CameraDevice.USBMode(CameraDevice, self.process['camera'],
                                 self.script_cfg)

            # update the rows with their binary telemetry
            IMUDevice.ProcessIMU(IMUDevice, self.process['connection'],
                                 self.script_cfg, rows)

            # test the mount is ready
            Test = CameraDevice.TestMount(CameraDevice, self.camera_cfg, 0)

            # get the name of our archive before we close the database
            archive = DBLite.GetArchiveName(DBLite, self.process['connection'],
                                            self.script_cfg)

            # copy the images off the camera
            if Test:
                CameraDevice.CopyImages(CameraDevice, self.camera_cfg,
                                        self.script_cfg)
                images = CameraDevice.GetImages(CameraDevice, self.camera_cfg,
                                                self.script_cfg)
                DBLite.UpdateImages(DBLite, self.process['connection'],
                                    self.script_cfg, rows, images)

            CameraDevice.CameraMode(CameraDevice, self.process['camera'],
                                    self.script_cfg)

            print("| closing, ", self.process['count'], "/",
                  self.script_cfg['triggers'], "success |")

        else:

            print("| closing ", self.process['count'], "/",
                  self.script_cfg['triggers'], "failed |")

        # if we have reached the end, should we report
        display = DBLite.DisplayDB(DBLite, self.process['connection'],
                                   self.script_cfg)

        # write a friendly csv file
        FileStruct.WriteCSV(FileStruct, self.script_cfg, display)

        # close our connections
        DBLite.CloseDB(DBLite, self.process['connection'], self.script_cfg)

        # if we have result to display and save
        if self.process['count'] == self.script_cfg['triggers']:

            # pretty print the final results
            print(
                tabulate(display,
                         headers=[
                             "Trigger", "Start", "Byte", "Stop", "Byte",
                             "Runtime", "Segment (size)", "BLOB (size)",
                             "Image"
                         ],
                         floatfmt=".12f"))

            # move the database/imu data to a new store location
            FileStruct.Save(FileStruct, self.script_cfg, archive)

        if self.script_cfg['debug']:
            print(' process end ', self.process['loop'])

        self.process['start'] = False
        exit()