Пример #1
0
static bool GetEPUBBookProperties(const char *name, LVStreamRef stream, BookProperties * pBookProps)
{
    LVContainerRef m_arc = LVOpenArchieve( stream );
    if ( m_arc.isNull() )
        return false; // not a ZIP archive

    // check root media type
    lString16 rootfilePath = EpubGetRootFilePath(m_arc);
    if ( rootfilePath.empty() )
    	return false;

    lString16 codeBase;
    codeBase=LVExtractPath(rootfilePath, false);

    LVStreamRef content_stream = m_arc->OpenStream(rootfilePath.c_str(), LVOM_READ);
    if ( content_stream.isNull() )
        return false;

    ldomDocument * doc = LVParseXMLStream( content_stream );
    if ( !doc )
        return false;

    time_t t = (time_t)time(0);
    struct stat fs;
    if ( !stat( name, &fs ) ) {
        t = fs.st_mtime;
    }

    lString16 author = doc->textFromXPath( lString16("package/metadata/creator")).trim();
    lString16 title = doc->textFromXPath( lString16("package/metadata/title")).trim();
    lString16 language = doc->textFromXPath( lString16("package/metadata/language")).trim();

    pBookProps->author = author;
    pBookProps->title = title;
    pBookProps->language = language;

    for ( int i=1; i<20; i++ ) {
        ldomNode * item = doc->nodeFromXPath( lString16("package/metadata/meta[") << fmt::decimal(i) << "]" );
        if ( !item )
            break;
        lString16 name = item->getAttributeValue("name");
        lString16 content = item->getAttributeValue("content");
        if (name == "calibre:series")
        	pBookProps->series = content.trim();
        else if (name == "calibre:series_index")
        	pBookProps->seriesNumber = content.trim().atoi();
    }

    pBookProps->filesize = (long)stream->GetSize();
    pBookProps->filename = lString16(name);
    pBookProps->filedate = getDateTimeString( t );

    delete doc;

    return true;
}
Пример #2
0
	/// <summary>
	/// <para name='Name'>SLog::openLog</para>
	/// <para name='Purpose'>Open a log for output</para>
	/// </summary>
	/// <param name='szFullPathToLog'>the full path to the log file to open</param>
	/// <param name='makeUnique'>Whether to append a date/time stamp to the file name</param>
	/// <returns>S_OK if successful, failure if it failed</returns>
	/// <remarks>
	/// <para name='Notes'></para>
	/// <para name='Author'>Kenn Guilstorf</para>
	/// <para name='LastModified'>2015-10-26</para>
	/// </remarks>
	HRESULT SLog::openLog(TSTRING szFullPathToLog, bool makeUnique)
	{
		HRESULT hrRetVal = S_OK;
		TSTRING szFullLogPath = TSTRING();

		// If we're trying to open when a log is already open...
		// Let's flush and close the main OSTREAM first...
		if (NULL != m_pO)
		{
			m_pO->flush();
			delete m_pO;
			m_pO = NULL;
		}

		// Now, close the file stream...
		if (NULL != m_log)
		{
			if (m_log->is_open())
			{
				m_log->flush();
				m_log->close();
				delete m_log;
				m_log = NULL;
			}
		}

		// Split the path into path, name and ext
		hrRetVal = splitFullPath(szFullPathToLog);
		if (hrRetVal == ERROR_BAD_ARGUMENTS)
			goto EXIT;

		// Do we want to add date/time to the file?
		if (makeUnique)
			m_szLogFileName->append(getDateTimeString(false));

		szFullLogPath.append(m_szLogFilePath->c_str());
		szFullLogPath.append(m_szLogFileName->c_str());
		szFullLogPath.append(m_szLogFileExt->c_str());

		// Enter our critical section
		EnterCriticalSection(&m_CriticalSection);

		// Open our file stream
		m_log = new TOFSTREAM(szFullLogPath.c_str(),
			TOFSTREAM::app | TOFSTREAM::out);
		
		// Open a new output stream
		m_pO = new TOSTREAM(m_log->rdbuf());

		// Leave our critical section
		LeaveCriticalSection(&m_CriticalSection);

	EXIT:
		return hrRetVal;
	}
 ModNeatExperiment7::ModNeatExperiment7(string _experimentName, int _thread_id) : 
 Experiment(_experimentName, _thread_id), numNodesX(9), numNodesY(9) {
 	screen << "Creating ModNeatExperiment7(" << _experimentName << ")" << endl;
 	// generateSubstrate();
   // create experiment CPPN folder
   string experimentFolder = "/" + getDateTimeString();
   // construct path to experiment
   pathToExperiment = boost::filesystem::current_path().string() + "/../../../../" + pathToExperiment;
   screen << "relative path to experiment : " << pathToExperiment << endl;
   // construct path to worldfile
   pathToWorldFile = pathToExperiment + pathToWorldFile;
   pathToCurrentCppnFolder = createSubFolder(pathToExperiment, pathToArchive, experimentFolder);
 }
bool QDeclarativeVideoEditor::render()
{
    //sanity check
    if (m_size < 1) {
        emit error(NO_MEDIA, "No media added to the timeline");
        return false;
    }

    qDebug() << "Render preparations started";

    QString output_uri = "file:///home/user/MyDocs/Movies/" + getDateTimeString() + ".mp4";

    GstEncodingProfile *profile = createEncodingProfile();
    if (!ges_timeline_pipeline_set_render_settings (m_pipeline, output_uri.toUtf8().data(), profile)) {
        emit error(RENDERING_FAILED, "Failed setting rendering options");
        gst_encoding_profile_unref(profile);
        return false;
    }
    gst_encoding_profile_unref (profile);

    if (!ges_timeline_pipeline_set_mode (m_pipeline, TIMELINE_MODE_RENDER)) {
        emit error(RENDERING_FAILED, "Failed to set rendering mode");
        gst_encoding_profile_unref(profile);
        return false;
    }

    qDebug() << "Rendering to " << output_uri;

    // reset duration and progress
    setDuration(GST_CLOCK_TIME_NONE);
    setProgress(0.0);
    qDebug() << "Starting progress polling";

    m_positionTimer.start(500);
    //g_timeout_add (500, updateProgress, this);

    m_rendering = true;
    if(!gst_element_set_state (GST_ELEMENT (m_pipeline), GST_STATE_PLAYING)) {
        gst_element_set_state (GST_ELEMENT (m_pipeline), GST_STATE_NULL);

        m_rendering = false;
        emit error(RENDERING_FAILED, "Failed to set pipeline to playing state");
        return false;
    }
    return true;
}
Пример #5
0
static bool GetBookProperties(const char *name,  BookProperties * pBookProps)
{
    CRLog::trace("GetBookProperties( %s )", name);

    // check archieve
    lString16 arcPathName;
    lString16 arcItemPathName;
    bool isArchiveFile = LVSplitArcName( lString16(name), arcPathName, arcItemPathName );

    // open stream
    LVStreamRef stream = LVOpenFileStream( (isArchiveFile ? arcPathName : Utf8ToUnicode(lString8(name))).c_str() , LVOM_READ);
    if (!stream) {
        CRLog::error("cannot open file %s", name);
        return false;
    }


    if ( DetectEpubFormat( stream ) ) {
        CRLog::trace("GetBookProperties() : epub format detected");
    	return GetEPUBBookProperties( name, stream, pBookProps );
    }

    time_t t = (time_t)time(0);

    if ( isArchiveFile ) {
        int arcsize = (int)stream->GetSize();
        LVContainerRef container = LVOpenArchieve(stream);
        if ( container.isNull() ) {
            CRLog::error( "Cannot read archive contents from %s", LCSTR(arcPathName) );
            return false;
        }
        stream = container->OpenStream(arcItemPathName.c_str(), LVOM_READ);
        if ( stream.isNull() ) {
            CRLog::error( "Cannot open archive file item stream %s", LCSTR(lString16(name)) );
            return false;
        }
    }
    struct stat fs;
    if ( !stat( name, &fs ) ) {
        t = fs.st_mtime;
    }

    // read document
#if COMPACT_DOM==1
    ldomDocument doc(stream, 0);
#else
    ldomDocument doc;
#endif
    ldomDocumentWriter writer(&doc, true);
    doc.setNodeTypes( fb2_elem_table );
    doc.setAttributeTypes( fb2_attr_table );
    doc.setNameSpaceTypes( fb2_ns_table );
    LVXMLParser parser( stream, &writer );
    CRLog::trace( "checking format..." );
    if ( !parser.CheckFormat() ) {
        return false;
    }
    CRLog::trace( "parsing..." );
    if ( !parser.Parse() ) {
        return false;
    }
    CRLog::trace( "parsed" );
    #if 0
        char ofname[512];
        sprintf(ofname, "%s.xml", name);
        CRLog::trace("    writing to file %s", ofname);
        LVStreamRef out = LVOpenFileStream(ofname, LVOM_WRITE);
        doc.saveToStream(out, "utf16");
    #endif
    lString16 authors = extractDocAuthors( &doc, lString16("|"), false );
    lString16 title = extractDocTitle( &doc );
    lString16 language = extractDocLanguage( &doc ).lowercase();
    lString16 series = extractDocSeries( &doc, &pBookProps->seriesNumber );
#if SERIES_IN_AUTHORS==1
    if ( !series.empty() )
        authors << "    " << series;
#endif
    pBookProps->title = title;
    pBookProps->author = authors;
    pBookProps->series = series;
    pBookProps->filesize = (long)stream->GetSize();
    pBookProps->filename = lString16(name);
    pBookProps->filedate = getDateTimeString( t );
    pBookProps->language = language;
    return true;
}
Пример #6
0
		if (dbl==2){
			int max1 = getMaxValue(layer,1);
			if (max1>max0)
				max = max1;
		}
		return max;
	}
	String^ ImageData::getDateTimeString(){
		DateTime dt = dateTime;
		return String::Format("{0:d4}-{1:d2}-{2:d2}-{3:d2};{4:d2};{5:d2}",dt.Year,dt.Month,dt.Day,dt.Hour,dt.Minute,dt.Second);
	}
	void ImageData::saveFile(String^ filePath)
	{	//saves a 16-bit AIA file in little endian
		
		String^ extension =".aia";
		String^ basename = String::Format("{0}\\{1}",filePath,getDateTimeString());
		String^ filename = String::Copy(basename);
		
		//prevent overwrite by renaming
		for (int i=0; (i<1000) && File::Exists(String::Concat(filename,extension));i++){
			filename =String::Format("{0} Copy {1}",basename,i);
		}
		filename = String::Concat(filename,extension);
		//if (File::Exists(filename)) return;

		FileStream^ fs = File::Open(filename,FileMode::Create);
		BinaryWriter^ bw = gcnew BinaryWriter(fs);
		try{
			Byte b0 = 0x41;
			Byte b1 = 0x49;
			Byte b2 = 0x41;
Пример #7
0
int GetBookProperties(char *name,  struct BookProperties* pBookProps, int localLanguage)
{
    CRLog::trace("GetBookProperties( %s )", name);
    memset(pBookProps, 0, sizeof(BookProperties) );

    // open stream
    LVStreamRef stream = LVOpenFileStream(name, LVOM_READ);
    if (!stream) {
        CRLog::error("cannot open file %s", name);
        return 0;
    }
    // check archieve
#ifdef USE_ZLIB
    LVContainerRef arc;
    //printf("start opening arc\n");
    //for ( int i=0; i<1000; i++ )
    //for ( int kk=0; kk<1000; kk++) 
    {
        arc = LVOpenArchieve( stream );
    //printf("end opening arc\n");
    if (!arc.isNull())
    {
        CRLog::trace("%s is archive with %d items", name, arc->GetObjectCount());
        // archieve
        const LVContainerItemInfo * bestitem = NULL;
        const LVContainerItemInfo * fb2item = NULL;
        const LVContainerItemInfo * fbditem = NULL;
        for (int i=0; i<arc->GetObjectCount(); i++)
        {
            const LVContainerItemInfo * item = arc->GetObjectInfo(i);
            if (item)
            {
                if ( !item->IsContainer() )
                {
                    lString16 name( item->GetName() );
                    if ( name.length() > 5 )
                    {
                        name.lowercase();
                        const lChar16 * pext = name.c_str() + name.length() - 4;
                        if ( pext[0]=='.' && pext[1]=='f' && pext[2]=='b' && pext[3]=='2') {
                            fb2item = item;
                        } else if ( pext[0]=='.' && pext[1]=='f' && pext[2]=='b' && pext[3]=='d') {
                            fbditem = item;
                        }
                    }
                }
            }
        }
        bestitem = fb2item;
        if ( fbditem )
            bestitem = fbditem;
        if ( !bestitem )
            return 0;
        CRLog::trace( "opening item %s from archive", UnicodeToUtf8(bestitem->GetName()).c_str() );
        //printf("start opening stream\n");
        //for ( int k=0; k<1000; k++ ) {
            stream = arc->OpenStream( bestitem->GetName(), LVOM_READ );
            char buf[8192];
            stream->Read(buf, 8192, NULL );
        //}
        //printf("end opening stream\n");
        if ( stream.isNull() )
            return 0;
        CRLog::trace( "stream created" );
        // opened archieve stream
    }
    }

#endif //USE_ZLIB

    // read document
#if COMPACT_DOM==1
    ldomDocument doc(stream, 0);
#else
    ldomDocument doc;
#endif
    ldomDocumentWriter writer(&doc, true);
    doc.setNodeTypes( fb2_elem_table );
    doc.setAttributeTypes( fb2_attr_table );
    doc.setNameSpaceTypes( fb2_ns_table );
    LVXMLParser parser( stream, &writer );
    CRLog::trace( "checking format..." );
    if ( !parser.CheckFormat() ) {
        return 0;
    }
    CRLog::trace( "parsing..." );
    if ( !parser.Parse() ) {
        return 0;
    }
    CRLog::trace( "parsed" );
    #if 0
        char ofname[512];
        sprintf(ofname, "%s.xml", name);
        CRLog::trace("    writing to file %s", ofname);
        LVStreamRef out = LVOpenFileStream(ofname, LVOM_WRITE);
        doc.saveToStream(out, "utf16");
    #endif
    lString16 authors = extractDocAuthors( &doc );
    lString16 title = extractDocTitle( &doc );
    lString16 series = extractDocSeriesReverse( &doc );
#if SERIES_IN_AUTHORS==1
    if ( !series.empty() )
    	authors << L"    " << series;
#endif
    SetFieldValue( pBookProps->name, title );
    if ( !authors.empty() )
        SetFieldValue( pBookProps->author, authors );
    if ( !series.empty() )
        SetFieldValue( pBookProps->series, series );
    pBookProps->filesize = (long)stream->GetSize();
    strncpy( pBookProps->filename, name, MAX_PROPERTY_LEN-1 );
    struct stat fs;
    time_t t;
    if ( stat( name, &fs ) ) {
        t = (time_t)time(0);
    } else {
        t = fs.st_mtime;
    }
    SetFieldValue( pBookProps->filedate, getDateTimeString( t, localLanguage ) );
    return 1;
}
Пример #8
0
//--------------------------------------------------------------
void ofApp::draw(){
	ofSleepMillis(100);
	
	int newVal = lidar_read(fd);
	unsigned char  st = lidar_status(fd);
	//ver = lidar_version(fd);
	//printf("%3.0d cm \n", res);
	lidar_status_print(st);

	if (newVal < 2) {
		// Handle strange case where lidar reports 1cm when should be infinity
		newVal = 10000;
	}
	
	// increment up to max smoothing (deals with initial state)
	if (nSamplesToSmooth < maxSamplesToSmooth ) nSamplesToSmooth++; 
	// Calculate the weight of new value
	float newWeight = ((float)1)/((float)nSamplesToSmooth); 
	// Calculate the smoothed PWM value
	smoothPwm = ((float) newVal)*newWeight + smoothPwm*(1-newWeight);
	
	counter++;
	
	if (pitchBend) { // Pitch bend mode
		//cout << ofGetSystemTimeMicros() << "," << blinkTimer << endl;
		if (ofGetSystemTimeMicros() - blinkTimer >= 200000) {
			
			// Blink the LED
			if (gpio15outState) {
				gpio15->setval_gpio("0");
				gpio15outState = false;
			} else {
				gpio15->setval_gpio("1");
				gpio15outState = true;
			}
			
			if (gpio21outState) {
				gpio21->setval_gpio("0");
				gpio21outState = false;
			} else {
				gpio21->setval_gpio("1");
				gpio21outState = true;
			}
			
			// Play sound
			pitchSound.play();
			float soundSpeed = 1.5f - ofMap(smoothPwm, minDist, maxDist, 0.f, 1.f, true);
			pitchSound.setSpeed( soundSpeed );
			//ofSoundSetVolume(ofClamp(0.5f + smoothPwm, 0, 1));
			cout << getDateTimeString() << ", " << counter << " loops, " << ofGetFrameRate() 
				<< "Hz , " << smoothPwm << " cm" << " , " << soundSpeed <<", " << (int) st;
			if (gpio15outState){
				cout << ",LED=ON";
			} else {
				cout << ",LED=OFF";
			}
			cout << endl;
			
			blinkTimer = ofGetSystemTimeMicros();
			counter = 0;
		}
	} else if (volBend) { // Volume bend mode
		float soundVolume = 1.f - ofMap(smoothPwm, minDist, maxDist, 0.f, 1.f, true);
		
		if (ofGetSystemTimeMicros() - blinkTimer >= 1000000) {
			volSound.play();
			
			// Blink the LED
			if (gpio15outState) {
				gpio15->setval_gpio("0");
				gpio15outState = false;
			} else {
				gpio15->setval_gpio("1");
				gpio15outState = true;
			}
			
			if (gpio21outState) {
				gpio21->setval_gpio("0");
				gpio21outState = false;
			} else {
				gpio21->setval_gpio("1");
				gpio21outState = true;
			}
			
			cout << getDateTimeString() << ", " << counter << " loops, " << ofGetFrameRate() 
				<< "Hz , " << smoothPwm << " cm" << " , " << soundVolume <<", " << (int) st;
			if (gpio15outState){
				cout << ",LED=ON";
			} else {
				cout << ",LED=OFF";
			}
			cout << endl;
				
			blinkTimer = ofGetSystemTimeMicros();
			counter = 0;
		}
		volSound.setVolume(soundVolume);
		ofSoundSetVolume(soundVolume);
	}
	
	// Log data to file
	if (ofGetElapsedTimeMillis() - logTimer >= 60000) {

		
		// Get the temperature
		FILE *temperatureFile;
		double T;
		temperatureFile = fopen ("/sys/class/thermal/thermal_zone0/temp", "r");
		if (temperatureFile == NULL) {
			cout << "Failed to read temp file\n";
		} else {
			fscanf (temperatureFile, "%lf", &T);
			T /= 1000;
			//printf ("The temperature is %6.3f C.\n", T);
			fclose (temperatureFile);
		}
		
		// Log the data
		logTimer = ofGetElapsedTimeMillis();
		//string logFileName = "/logs/livestream/livestream01.log";
		string logFileName = "/logs/livestream/livestream_" + hostname + ".log";
		ofstream mFile;
		mFile.open(logFileName.c_str(), ios::out | ios::app);
		mFile << getDateTimeString() << ",TC," << T;
		for (int j=0; j<nSensors; j++) {
			float tempData = tempSensor.read(j);
			mFile << ",T" << j << "," << tempData;
		}
		mFile << ",DL," << smoothPwm << " cm" << ",LR," << ofGetFrameRate() << "Hz,";
		mFile << endl;
		mFile.close();
	}
}
Пример #9
0
//--------------------------------------------------------------
void ofApp::setup(){
	ofSetVerticalSync(false);
	//ofSetFrameRate(10000)
	
	counter = 0;
	blinkTimer = ofGetSystemTimeMicros();
	logTimer = ofGetElapsedTimeMillis();
	
	// Setup GPIOs
	gpio15  = new GPIO("15");
	gpio15->export_gpio();
	gpio15->setdir_gpio("out");
	gpio15->setval_gpio("0");
	gpio15outState = false;
	
	gpio21  = new GPIO("21");
	gpio21->export_gpio();
	gpio21->setdir_gpio("out");
	gpio21->setval_gpio("0");
	gpio21outState = false;

	// PWM smoothing parameters
	nSamplesToSmooth = 0;
	maxSamplesToSmooth = 1; // determines smoothing
	smoothPwm = 0; // smoothed PWM value
	minDist = 30; //cm
	maxDist = 30*20; //cm
	
	// Sound output
	pitchSound.loadSound("sounds/INT18PIPES1.mp3");
	pitchSound.setVolume(0.3f);
	pitchSound.setMultiPlay(false);
	
	volSound.loadSound("sounds/Tp10.wav");
	volSound.setVolume(0.3f);
	volSound.setMultiPlay(true);
	
	ofSoundSetVolume(1.0f);

	volBend = true;
	pitchBend = false;
	
	// Init I2C
	fd = lidar_init(false);
	if (fd == -1) 
	{
		printf("initialization error\n");
		ofApp::exit();
	}
	
	// Get the host name
	int z;  
	char buf[32];  
	z = gethostname(buf,sizeof buf);
	if ( z != -1 ) {
		hostname = string(buf);
		//printf("host name = '%s'\n",buf); 
		cout << "host name = " 	<< hostname << endl;
	} else {
		cout << "host name unknown" << endl;
		hostname = "unknown";
	}
	
	// Write initialization to the log
	string logFileName = "/logs/livestream/livestream_" + hostname + ".log";
	ofstream mFile;
	mFile.open(logFileName.c_str(), ios::out | ios::app);
	mFile << getDateTimeString() << ",INITILIZATION" << endl;
	mFile.close();
	
	nSensors = tempSensor.listDevices();
}