コード例 #1
0
ファイル: ntp-client.cpp プロジェクト: villoiseaux/arduino
unsigned long ntp::getInternetTime(){
  unsigned long epoch;
  int i=0;
  int t=0;
  sendNTPpacket();
  delay(500);
  epoch=receiveTime();
  t=0; // count sent tries
  while ((epoch == 0xFFFFFFFF) && (t<4)){  
    i=0; // count receve tries
    while ((epoch == 0xFFFFFFFF) && (i<4)){
      delay(500);
      epoch=receiveTime();
      i++;
    } 
    if (epoch == 0xFFFFFFFF) {    
      sendNTPpacket();
      t++;
    }
  }

   internetEpoch=epoch;
   arduinoShift=millis()/1000;

  return (epoch);
}
コード例 #2
0
ファイル: myrimatchMPI.cpp プロジェクト: lgatto/proteowizard
    int ReceiveUnpreparedSpectraBatchFromRootProcess()
    {
        int batchSize;

        MPI_Ssend( &g_pid,        1,    MPI_INT,        0,    0xFF, MPI_COMM_WORLD );
        string pack;
        int len;

        #ifdef MPI_DEBUG
            cout << g_hostString << " is receiving a batch of unsequenced spectra." << endl;
            Timer receiveTime(true);
        #endif
        MPI_Recv( &len,                    1,            MPI_INT,    0,    0x00, MPI_COMM_WORLD, &st );
        pack.resize( len );
        MPI_Recv( (void*) pack.data(),    len,        MPI_CHAR,    0,    0x01, MPI_COMM_WORLD, &st );

        stringstream compressedStream( pack );
        stringstream packStream;
        boost::iostreams::filtering_ostream decompressorStream;
        decompressorStream.push( boost::iostreams::zlib_decompressor() );
        decompressorStream.push( packStream );
        boost::iostreams::copy( compressedStream, decompressorStream );
        decompressorStream.reset();

        binary_iarchive packArchive( packStream );

        try
        {
            packArchive & batchSize;

            if( !batchSize )
            {
                #ifdef MPI_DEBUG
                    cout << g_hostString << " is informed that all spectra have been sequence tagged." << endl;
                #endif

                return 0; // do not expect another batch
            }

            #ifdef MPI_DEBUG
                cout << g_hostString << " finished receiving a batch of " << batchSize << " unsequenced spectra; " <<
                        receiveTime.End() << " seconds elapsed." << endl;
            #endif

            for( int j=0; j < batchSize; ++j )
            {
                Spectrum* s = new Spectrum;
                packArchive & *s;
                spectra.push_back( s );

            }
        } catch( exception& e )
        {
            cerr << g_hostString << " had an error: " << e.what() << endl;
            exit(1);
        }

        return 1; // expect another batch
    }
コード例 #3
0
ファイル: myrimatchMPI.cpp プロジェクト: lgatto/proteowizard
    int ReceiveProteinBatchFromRootProcess()
    {
        int batchSize;

        MPI_Ssend( &g_pid,            1,                MPI_INT,    0,    0xFF, MPI_COMM_WORLD );
        MPI_Ssend( &g_numWorkers,    1,                MPI_INT,    0,    0xFF, MPI_COMM_WORLD );

        MPI_Recv( &batchSize,        1,                MPI_INT,    0,    0x99, MPI_COMM_WORLD, &st );

        if( !batchSize )
        {
            #ifdef MPI_DEBUG
                cout << g_hostString << " is informed that all proteins have been searched." << endl;
            #endif

            return 0; // expect another batch
        }

        #ifdef MPI_DEBUG
            cout << g_hostString << " is receiving " << batchSize << " proteins." << endl;
            Timer receiveTime(true);
        #endif

        string pack;
        int len;

        MPI_Recv( &len,                    1,            MPI_INT,    0,    0x00, MPI_COMM_WORLD, &st );
        pack.resize( len );
        MPI_Recv( (void*) pack.data(),    len,        MPI_CHAR,    0,    0x01, MPI_COMM_WORLD, &st );

        #ifdef MPI_DEBUG
            cout << g_hostString << " finished receiving " << batchSize << " proteins; " <<
                    receiveTime.End() << " seconds elapsed." << endl;
        #endif
        
        stringstream packStream( pack );
        binary_iarchive packArchive( packStream );

        try
        {
            packArchive & g_rtConfig->ProteinIndexOffset;

            string proteinString;
            packArchive & proteinString;
            shared_ptr<std::istream> proteinStream(new std::istringstream(proteinString));

            Serializer_FASTA unpacker;
            shared_ptr<ProteomeData> subsetProteinsPtr(new ProteomeData);
            unpacker.read(proteinStream, *subsetProteinsPtr);
            proteins = proteinStore(subsetProteinsPtr, g_rtConfig->DecoyPrefix, false);
        } catch( exception& e )
        {
            cerr << g_hostString << " had an error: " << typeid(e).name() << " (" << e.what() << ")" << endl;
            exit(1);
        }

        return 1; // don't expect another batch
    }
コード例 #4
0
ファイル: MySensorCore.cpp プロジェクト: skatun/Openhab
// Message delivered through _msg
void _processInternalMessages() {
	bool isMetric;
	uint8_t type = _msg.type;

	#if !defined(MY_DISABLE_REMOTE_RESET)
		if (type == I_REBOOT) {
			// Requires MySensors or other bootloader with watchdogs enabled
			hwReboot();
		} else
	#endif
		if (type == I_CONFIG) {
		// Pick up configuration from controller (currently only metric/imperial)
		// and store it in eeprom if changed
	 	if (_msg.getString() == NULL) {
			isMetric = true;
		} else {
			isMetric = _msg.getString()[0] == 'M';
		}
		_cc.isMetric = isMetric;
		hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
	} else if (type == I_PRESENTATION) {
		if (!mGetAck(_msg)) {
			// Re-send node presentation to controller
			#if defined(MY_RADIO_FEATURE)
				transportPresentNode();
			#endif
			if (presentation)
				presentation();
		}
	} else if (type == I_HEARTBEAT) {
		sendHeartbeat();
	} else if (type == I_TIME) {
		// Deliver time to callback
		if (receiveTime)
			receiveTime(_msg.getULong());
	}
	#if defined(MY_REPEATER_FEATURE)
		if (type == I_CHILDREN) {
			if (_msg.getString()[0] == 'C') {
				// Clears child relay data for this node
				debug(PSTR("clear routing table\n"));
				uint8_t i = 255;
				do {
					hwWriteConfig(EEPROM_ROUTES_ADDRESS+i, BROADCAST_ADDRESS);
				} while (i--);
				// Clear parent node id & distance to gw
				hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, AUTO);
				hwWriteConfig(EEPROM_DISTANCE_ADDRESS, DISTANCE_INVALID);
				// Find parent node
				transportFindParentNode();
				_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set(""));
			}
		}
	#endif
}
コード例 #5
0
ファイル: myrimatchMPI.cpp プロジェクト: lgatto/proteowizard
    int ReceiveSpectraFromRootProcess()
    {
        int numSpectra;
        int done;

        #ifdef MPI_DEBUG
            cout << g_hostString << " is receiving " << numSpectra << " unprepared spectra." << endl;
            Timer receiveTime(true);
        #endif

        string pack;
        int len;

        MPI_Recv( &len,                    1,            MPI_INT,    0,    0x00, MPI_COMM_WORLD, &st );
        pack.resize( len );
        MPI_Recv( (void*) pack.data(),    len,        MPI_CHAR,    0,    0x01, MPI_COMM_WORLD, &st );

        stringstream compressedStream( pack );
        stringstream packStream;
        boost::iostreams::filtering_ostream decompressorStream;
        decompressorStream.push( boost::iostreams::zlib_decompressor() );
        decompressorStream.push( packStream );
        boost::iostreams::copy( compressedStream, decompressorStream );
        decompressorStream.reset();

        binary_iarchive packArchive( packStream );

        try
        {
            //cout << g_hostString << " is unpacking spectra." << endl;
            packArchive & numSpectra;
            //cout << g_hostString << " has " << numSpectra << " spectra." << endl;
            packArchive & done;

            for( int j=0; j < numSpectra; ++j )
            {
                Spectrum* s = new Spectrum;
                packArchive & *s;
                spectra.push_back( s );

            }
            //cout << g_hostString << " is finished unpacking spectra." << endl;
        } catch( exception& e )
        {
            cerr << g_hostString << " had an error: " << e.what() << endl;
            exit(1);
        }

        #ifdef MPI_DEBUG
            cout << g_hostString << " finished receiving " << numSpectra << " unprepared spectra; " <<
                    receiveTime.End() << " seconds elapsed." << endl;
        #endif

        return done;
    }
コード例 #6
0
ファイル: network-w5100.cpp プロジェクト: housecream/restmcu
void networkManage() {
	uint16_t size;

	if (sendClient.available()) {
//		int size = sendClient.read((uint8_t *) buf2, BUFFER_SIZE);
		size = readHttpFrame(sendClient);
#ifdef HMAC
		if (!isTimeReady()) {
			uint16_t endPos = strstrpos_P((char *) buf, DOUBLE_ENDL);
			receiveTime((char *) &buf[endPos + 4]);
		}
#endif
	}

#ifdef HMAC
	if (!isTimeReady() && sendClient.status() == SnSR::CLOSED && (lastFailTime == 0 || millis() - lastFailTime > dateFailRetryWait)) {
		if (sendClient.connect(NotifyDstIp, notifyDstPort)) {
			int len = clientBuildTimeQuery((char *) buf);
			sendClient.write(buf, len);
		} else {
			lastFailTime = millis();
			sendClient.stop();
		}
	}
#endif

	if (!sendClient.connected()) {
		sendClient.stop();
	}

	if (notification != 0 && sendClient.status() == SnSR::CLOSED) {
		// there is a notif and we are not handling another one
		if (lastFailTime == 0 || millis() - lastFailTime > notifFailRetryWait) {
			if (sendClient.connect(NotifyDstIp, notifyDstPort)) {
				int len = clientBuildNextQuery((char *) buf);
				sendClient.write(buf, len);
			} else {
				lastFailTime = millis();
				sendClient.stop();
			}
		}
	}

	EthernetClient client = server.available();
    if (client) {
        while (client.connected()) {
            if (client.available()) {
                size = readHttpFrame(client);

                if (size > 0) {
                    buf[size] = 0;
                    size = handleWebRequest((char *) buf, 0, size);
                    buf[size] = 0;
                    client.println((const char *) buf);
                }

                delay(1);
                client.stop();
            }
        }
    }
	if (needReboot) {
		resetFunc();
	}
}
コード例 #7
0
ファイル: myrimatchMPI.cpp プロジェクト: lgatto/proteowizard
    int ReceiveResultsFromChildProcesses(bool firstBatch = false)
    {
        int numSpectra;
        int sourceProcess;

        Timer ResultsTime( true );
        float totalResultsTime = 0.01f;
        float lastUpdate = 0.0f;

        for( int p=0; p < g_numChildren; ++p )
        {
            MPI_Recv( &sourceProcess,        1,        MPI_INT,    MPI_ANY_SOURCE,    0xEE, MPI_COMM_WORLD, &st );

            #ifdef MPI_DEBUG
                cout << g_hostString << " is receiving search results." << endl;
                Timer receiveTime(true);
            #endif

            string pack;
            int len;

            MPI_Recv( &len,                    1,        MPI_INT,    sourceProcess,    0x00, MPI_COMM_WORLD, &st );
            pack.resize( len );
            MPI_Recv( (void*) pack.data(),    len,    MPI_CHAR,    sourceProcess,    0x01, MPI_COMM_WORLD, &st );

            stringstream compressedStream( pack );
            stringstream packStream;
            boost::iostreams::filtering_ostream decompressorStream;
            decompressorStream.push( boost::iostreams::zlib_decompressor() );
            decompressorStream.push( packStream );
            boost::iostreams::copy( compressedStream, decompressorStream );
            decompressorStream.reset();

            binary_iarchive packArchive( packStream );

            try
            {
                SearchStatistics childSearchStats;
                packArchive & numSpectra;
                packArchive & childSearchStats;
                if(firstBatch)
                {
                    searchStatistics = searchStatistics + childSearchStats;
                }
                else 
                {
                    searchStatistics.numPeptidesGenerated += childSearchStats.numPeptidesGenerated;
                    searchStatistics.numVariantsGenerated += childSearchStats.numVariantsGenerated;
                    searchStatistics.numComparisonsDone += childSearchStats.numComparisonsDone;
                    searchStatistics.numPeptidesSkipped += childSearchStats.numPeptidesSkipped;
                }

                //cout << g_hostString << " is unpacking results for " << numSpectra << " spectra." << endl;
                for( SpectraList::iterator sItr = spectra.begin(); sItr != spectra.end(); ++sItr )
                {
                    Spectrum* childSpectrum = new Spectrum;
                    Spectrum* rootSpectrum = *sItr;
                    packArchive & *childSpectrum;
                    rootSpectrum->numTargetComparisons += childSpectrum->numTargetComparisons;
                    rootSpectrum->numDecoyComparisons += childSpectrum->numDecoyComparisons;
                    rootSpectrum->processingTime += childSpectrum->processingTime;

                    rootSpectrum->resultsByCharge.resize(childSpectrum->resultsByCharge.size());
                    for (size_t z=0; z < childSpectrum->resultsByCharge.size(); ++z)
                    {
                        Spectrum::SearchResultSetType& rootResults = rootSpectrum->resultsByCharge[z];
                        Spectrum::SearchResultSetType& childResults = childSpectrum->resultsByCharge[z];

                        BOOST_FOREACH(const Spectrum::SearchResultPtr& result, childResults)
                            rootResults.add( result );

                        if (childResults.bestFullySpecificTarget().get()) rootResults.add(childResults.bestFullySpecificTarget());
                        if (childResults.bestFullySpecificDecoy().get()) rootResults.add(childResults.bestFullySpecificDecoy());
                        if (childResults.bestSemiSpecificTarget().get()) rootResults.add(childResults.bestSemiSpecificTarget());
                        if (childResults.bestSemiSpecificDecoy().get()) rootResults.add(childResults.bestSemiSpecificDecoy());
                        if (childResults.bestNonSpecificTarget().get()) rootResults.add(childResults.bestNonSpecificTarget());
                        if (childResults.bestNonSpecificDecoy().get()) rootResults.add(childResults.bestNonSpecificDecoy());
                    }

                    for(flat_map<int,int>::iterator itr = childSpectrum->mvhScoreDistribution.begin(); itr != childSpectrum->mvhScoreDistribution.end(); ++itr)
                        rootSpectrum->mvhScoreDistribution[(*itr).first] += (*itr).second;
                    for(flat_map<int,int>::iterator itr = childSpectrum->mzFidelityDistribution.begin(); itr != childSpectrum->mzFidelityDistribution.end(); ++itr)
                        rootSpectrum->mzFidelityDistribution[(*itr).first] += (*itr).second;
                    rootSpectrum->scoreHistogram += childSpectrum->scoreHistogram;
                    delete childSpectrum;
                }
                //cout << g_hostString << " is finished unpacking results." << endl;
            } catch( exception& e )
            {
                cerr << g_hostString << " had an error: " << e.what() << endl;
                exit(1);
            }

            #ifdef MPI_DEBUG
                cout << g_hostString << " finished receiving " << numSpectra << " search results; " <<
                        receiveTime.End() << " seconds elapsed.";
            #endif

            totalResultsTime = ResultsTime.TimeElapsed();
            if( ( totalResultsTime - lastUpdate > g_rtConfig->StatusUpdateFrequency ) || p+1 == g_numChildren )
            {
                float nodesPerSec = float(p+1) / totalResultsTime;
                float estimatedTimeRemaining = float(g_numChildren-p-1) / nodesPerSec;
                cout << "Received results from " << p+1 << " of " << g_numChildren << " worker nodes; " << nodesPerSec <<
                        " per second, " << estimatedTimeRemaining << " seconds remaining." << endl;
                lastUpdate = totalResultsTime;
            }

        }

        return 0;
    }