Example #1
0
PowerManagementRecordGui::PowerManagementRecordGui(SerialPort* p, QWidget* parent)
                                                    : QDialog(parent)
{
    socket = p;
#else
PowerManagementRecordGui::PowerManagementRecordGui(QTcpSocket* tcpSocket, QWidget* parent)
                                                    : QDialog(parent)
{
    socket = tcpSocket;
#endif
    PowerManagementRecordUi.setupUi(this);
    requestRecordingStatus();
// Ask for the microcontroller SD card free space (process response later)
    getFreeSpace();
    model = new QStandardItemModel(0, 2, this);
    PowerManagementRecordUi.fileTableView->setModel(model);
    PowerManagementRecordUi.fileTableView->setGridStyle(Qt::NoPen);
    PowerManagementRecordUi.fileTableView->setShowGrid(false);
    QHeaderView *verticalHeader = PowerManagementRecordUi.fileTableView->verticalHeader();
    verticalHeader->setResizeMode(QHeaderView::Fixed);
    verticalHeader->setDefaultSectionSize(18);
    row = 0;
// Signal to process a click on a directory item
    connect(PowerManagementRecordUi.fileTableView,
                     SIGNAL(clicked(const QModelIndex)),
                     this,SLOT(onListItemClicked(const QModelIndex)));
// Send a command to refresh the directory
    refreshDirectory();
    writeFileHandle = 0xFF;
}

PowerManagementRecordGui::~PowerManagementRecordGui()
{
}

//-----------------------------------------------------------------------------
/** @brief Delete File.

If the delete checkbox is selected, delete the file (if it exists).
*/

void PowerManagementRecordGui::on_deleteButton_clicked()
{
    QString fileName = PowerManagementRecordUi.recordFileName->text();
    if ((fileName.length() > 0) &&
        (PowerManagementRecordUi.deleteCheckBox->isChecked()))
    {
        socket->write("fX");
        socket->write(fileName.toLocal8Bit().data());
        socket->write("\n\r");
        refreshDirectory();
        getFreeSpace();
    }
}
Example #2
0
bool Page::hasSpaceForRecord(const std::string& record_data) const {
  std::size_t record_size = record_data.length();
  if (header_.num_free_slots == 0) {
    record_size += sizeof(PageSlot);
  }
  return record_size <= getFreeSpace();
}
void DiskAnalizer::paintEvent(QPaintEvent *e)
{
 	QWidget::paintEvent(e);
 	QPainter painter;

 	double bytesFree = getFreeSpace(drive);
	ui.lblBytesFree->setText(QString::number(bytesFree,'f',0));
	double gbFree=(bytesFree/1048576)/1024;
	ui.lblGBFree->setText(QString::number(gbFree,'f',2));
 	double bytesUsed = getUsedSpace(drive);
	ui.lblBytesUsed->setText(QString::number(bytesUsed,'f',0));
	double gbUsed=(bytesUsed/1048576)/1024;
	ui.lblGBUsed->setText(QString::number(gbUsed,'f',2));
	double bytesTotal = getTotalSpace(drive);
 	
	float p =((bytesFree*100)/bytesTotal);

  	painter.begin(this);
  	Nightcharts PieChart;
  	PieChart.setType(Nightcharts::Pie);//{Histogramm,Pie,Dpie};
  	PieChart.setLegendType(Nightcharts::Vertical);//{Round,Vertical}
  	PieChart.setCords(ui.widget->geometry().x(),ui.widget->geometry().y(),ui.widget->width(),ui.widget->height());
  
  	PieChart.addPiece("Free Space",Qt::green,p);
  	PieChart.addPiece("Used Space",QColor(200,10,50),100);
  
  	PieChart.draw(&painter);
}
void SequentialFile::AppendRaw(void* data, size_t size) {
  record_frame_t* location = (record_frame_t*)getFreeSpace(size);
  location--;  // TODO: clean up
  memcpy(location, data, size);
  Record* new_record = static_cast<Record*>((void*)location);
  ASSERT_TRUE(new_record->isValid());
  next_write_offset = record2offset( (SequentialFile::Record*)new_record->getEndOfRecord() );
  ASSERT_TRUE(ISALIGNED((void*)next_write_offset, RECORD_FRAME_ALIGNMENT));
}
Example #5
0
RecordId Page::insertRecord(const std::string& record_data) {
  if (!hasSpaceForRecord(record_data)) {
    throw InsufficientSpaceException(
        page_number(), record_data.length(), getFreeSpace());
  }
  const SlotId slot_number = getAvailableSlot();
  insertRecordInSlot(slot_number, record_data);
  return {page_number(), slot_number};
}
Example #6
0
void Page::updateRecord(const RecordId& record_id,
                        const std::string& record_data) {
  validateRecordId(record_id);
  const PageSlot* slot = getSlot(record_id.slot_number);
  const std::size_t free_space_after_delete =
      getFreeSpace() + slot->item_length;
  if (record_data.length() > free_space_after_delete) {
    throw InsufficientSpaceException(
        page_number(), record_data.length(), free_space_after_delete);
  }
  // We have to disallow slot compaction here because we're going to place the
  // record data in the same slot, and compaction might delete the slot if we
  // permit it.
  deleteRecord(record_id, false /* allow_slot_compaction */);
  insertRecordInSlot(record_id.slot_number, record_data);
}
Example #7
0
void GameEscape::createFood()
{
    foods.push_back(Food(this, getFreeSpace(1), 1, FOOD_RANDMOVE));
}
Example #8
0
void DiskSensor::processExited(TDEProcess *)
{
    TQStringList stringList = TQStringList::split('\n',sensorResult);
    sensorResult = "";
    TQStringList::Iterator it = stringList.begin();
    //TQRegExp rx( "^(/dev/).*(/\\S*)$");
    TQRegExp rx( ".*\\s+(/\\S*)$");

    while( it != stringList.end())
    {
        rx.search( *it );
        if ( !rx.cap(0).isEmpty())
        {
            mntMap[rx.cap(1)] = *it;
        }
        it++;
    }
    stringList.clear();

    TQString format;
    TQString mntPt;
    SensorParams *sp;
    Meter *meter;

    TQObjectListIt lit( *objList );
    while (lit != 0)
    {
        sp = (SensorParams*)(*lit);
        meter = sp->getMeter();
        format = sp->getParam("FORMAT");
        mntPt = sp->getParam("MOUNTPOINT");
        if (mntPt.length() == 0)
            mntPt="/";

        if (format.length() == 0 )
        {
            format = "%u";
        }
        format.replace( TQRegExp("%fp", false),TQString::number(getPercentFree(mntPt)));
        format.replace( TQRegExp("%fg",false),
                        TQString::number(getFreeSpace(mntPt)/(1024*1024)));
        format.replace( TQRegExp("%fkb",false),
                        TQString::number(getFreeSpace(mntPt)*8) );
        format.replace( TQRegExp("%fk",false),
                        TQString::number(getFreeSpace(mntPt)) );
        format.replace( TQRegExp("%f", false),TQString::number(getFreeSpace(mntPt)/1024));
        
        format.replace( TQRegExp("%up", false),TQString::number(getPercentUsed(mntPt)));
        format.replace( TQRegExp("%ug",false),
                        TQString::number(getUsedSpace(mntPt)/(1024*1024)));
        format.replace( TQRegExp("%ukb",false),
                        TQString::number(getUsedSpace(mntPt)*8) );
        format.replace( TQRegExp("%uk",false),
                        TQString::number(getUsedSpace(mntPt)) );
        format.replace( TQRegExp("%u", false),TQString::number(getUsedSpace(mntPt)/1024));

        format.replace( TQRegExp("%tg",false),
                        TQString::number(getTotalSpace(mntPt)/(1024*1024)));
        format.replace( TQRegExp("%tkb",false),
                        TQString::number(getTotalSpace(mntPt)*8));
        format.replace( TQRegExp("%tk",false),
                        TQString::number(getTotalSpace(mntPt)));
        format.replace( TQRegExp("%t", false),TQString::number(getTotalSpace(mntPt)/1024));
        meter->setValue(format);
        ++lit;
    }
    if ( init == 1 )
    {
        emit initComplete();
        init = 0;
    }
}
void* SequentialFile::append(size_t size) {
  void* location = getFreeSpace(size);
  frameData(location, size);
  return location;
}
Example #10
0
int main() {
    //Do forks and stuff to run as a service
    daemonize();
    syslog(LOG_INFO, "%s version %d started.", PROGRAM_NAME, PROGRAM_VERSION);
    
    //Reading the configuration
    setDefault(&config);
    if (parseConfigFile(&config) == 0) {
        if (checkConfig(&config) == 0) {
            /*
            syslog(LOG_INFO, "%s %s", VIDEO_SAVE_DIRECTORY, config.VideoSaveDirectory);
            syslog(LOG_INFO, "%s %s", THUMBNAIL_SAVE_DIRECTORY, config.ThumbnailSaveDirectory);
            syslog(LOG_INFO, "%s %s", FFMPEG_PATH, config.ffmpegPath);
            syslog(LOG_INFO, "%s %lu", MINIMUM_FREE_DISK_SPACE, config.MinimumFreeDiskSpace);
            syslog(LOG_INFO, "%s %s", RASPIVID_ROTATION, config.RaspividRotation);
            syslog(LOG_INFO, "%s %s", RASPIVID_WIDTH, config.RaspividWidth);
            syslog(LOG_INFO, "%s %s", RASPIVID_HEIGHT, config.RaspividHeight);
            syslog(LOG_INFO, "%s %s", RASPIVID_CRF, config.RaspividCRF);
            syslog(LOG_INFO, "%s %s", RASPIVID_PREVIEW, config.RaspividPreview);
            syslog(LOG_INFO, "%s %s", RASPIVID_FRAMERATE, config.RaspividFramerate);
            syslog(LOG_INFO, "%s %s", RASPIVID_SEGMENT_DURATION, config.RaspividSegmentDuration);
            syslog(LOG_INFO, "%s %s", RASPIVID_INTRAFRAME_INTERVAL, config.RaspividIntraframeInterval);
            syslog(LOG_INFO, "%s %s", RASPIVID_EXPOSURE, config.RaspividExposure);
            syslog(LOG_INFO, "%s %s", RASPIVID_WHITEBLANCE, config.RaspividAWB);
            syslog(LOG_INFO, "%s %s", RASPIVID_METERING, config.RaspividMetering);
            syslog(LOG_INFO, "%s %s", RASPIVID_PROFILE, config.RaspividProfile);
            syslog(LOG_INFO, "%s %s", THUMBNAIL_WIDTH, config.ThumbnailWidth);
            syslog(LOG_INFO, "%s %s", THUMBNAIL_FORMAT, config.ThumbnailFormat);
            syslog(LOG_INFO, "%s %s", THUMBNAIL_OPTIONS, config.ThumbnailOptions);
            syslog(LOG_INFO, "%s %s", TEMPORARY_DIRECTORY, config.TemporaryDirectory);
            syslog(LOG_INFO, "%s %hho", NUMBER_TEMPORARY_RAW_FILES, config.NumberTemporaryRawFiles);
            */
            
            //Creating directories
            mkdir(config.TemporaryDirectory, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
            mkdir(config.VideoSaveDirectory, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
            mkdir(config.ThumbnailSaveDirectory, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);

            //Muxing and removing any h264 files in temp folder
            muxAll();
            
            //While there's not enough free space, delete old videos
            unsigned long long freeSpace = getFreeSpace(config.VideoSaveDirectory);
            while (freeSpace < config.MinimumFreeDiskSpace) {
                deleteOldestVideo();
                freeSpace = getFreeSpace(config.VideoSaveDirectory);
            }
            
            //Start the camera
            raspivid = startCamera(&config);
            if (raspivid > 0) {
                syslog(LOG_INFO, "Raspivid started with pid %d.", raspivid);

                //Waiting for a bit to get a little behind the camera
                sleep(1);

                //Main loop
                run = 1;
                while (run) {
                    //Wait some time before looking for raw files
                    sleep(20);

                    //While there's not enough free space, delete old videos
                    unsigned long long freeSpace = getFreeSpace(config.VideoSaveDirectory);
                    while (freeSpace < config.MinimumFreeDiskSpace) {
                        deleteOldestVideo();
                        freeSpace = getFreeSpace(config.VideoSaveDirectory);
                    }

                    //Mux and delete h264 files that aren't being recorded to
                    checkForReadyh264Files();
                }
            } else {
                syslog(LOG_ERR, "Error starting raspivid.", raspivid);
            }
        }
    }
    
    //Freeing up memory from config struct
    freeConfig(&config);
    
    syslog(LOG_NOTICE, "%s terminated.", PROGRAM_NAME);
    closelog();
    
    return (EXIT_SUCCESS);
}