bool SerialPort::get(uint8_t* byte)
{
	if (m_rxfifo.IsEmpty())
		return false;
	*byte = m_rxfifo.Get() & 0xFF;
	return true;
}
int main()
{
	FIFO stack;
	DataItem* arr[20] = {0};
	
	for(int i = 0; i < 20; i++)
		stack.push(arr[i] = new DataItem(i));

	for(int i = 0; i < 25; i++)
		cout << stack.pop() << endl;

	for(int i = 0; i < 20; i++)
		delete arr[i];

	return 0;
}
	bool push(const void* const buf, const size_t len) {
		chMtxLock(&mutex_write);
		const auto result = fifo.in_r(buf, len);
		chMtxUnlock();

		const bool success = (result == len);
		if( success ) {
			signal();
		}
		return success;
	}
int _tmain(int argc, _TCHAR* argv[])
{
	cout << "Planificadores de procesos" << endl;

	int cantidad = 0;

	cout << "Ingrese la cantidad de procesos: " << endl;

	cin >> cantidad;

	queue<Proceso *> trabajos = AEsquema<AProceso>::tareas(cantidad);

	cout << "Procesos: " << endl;
	for (int i = 0; i < cantidad; i++)
	{
		Proceso *parte = trabajos.front();
		cout << "Id: " << parte->getId() << ", Llegada: " << parte->getLlegada() << ", Rafaga: " << parte->getRafaga() << endl;
		trabajos.pop();
		trabajos.push(parte);
	}

	//Copiar con su respectivo planificador
	cout << "FIFO" << endl;
	FIFO *esquema = new FIFO(trabajos, cantidad);
	esquema->iniciar();
	cout << "" << endl;
	esquema->desplegarLista();
	cout << "" << endl;

	// Aplica el SJF
	cout << "SJF" << endl;
	SJF *esquemaSJF = new SJF(trabajos, cantidad);
	esquemaSJF->iniciar();
	cout << "" << endl;
	esquemaSJF->desplegarLista();
	cout << "" << endl;

	system("pause");

	return 0;
}
Exemple #5
0
		std::string get_line_()
		{
			std::string line;
			if(fifo_.empty()) {
				return line;
			}

			while(!fifo_.empty()) {
				auto ch = fifo_.front();
				fifo_.pop();
				if(ch == '\n') {
					line = line_;
					line_.clear();
					break;
				} else if(ch == '\r') {
				} else {
					line_ += ch;
				}
			}
			return line;
		}
Exemple #6
0
raft::kstatus
Schedule::quitHandler( FIFO              &fifo, 
                       raft::kernel      *kernel,
                       const raft::signal signal,
                       void              *data )
{
   /**
    * NOTE: This should be the only action needed
    * currently, however that may change in the futre
    * with more features and systems added.
    */
   fifo.invalidate();  
   return( raft::stop );
}
Exemple #7
0
//------------------------------------------------------------------------------
BigNumber operator+ (BigNumber x1, BigNumber x2) {
        int carry=0;
        int result;
        BigNumber temp;
        FIFO fifo;
        if (x1.Count()<x2.Count()) {
                temp=x1;
                x1=x2;
                x2=temp;
        }
        //temp.DeleteList(); //????????????????????????????????
        TNode *temp_x1=x1.last;
        TNode *temp_x2=x2.last;
        TNode *temp_result=temp.last;//???????????????????????
        for (int i=0;i<x2.Count();i++) { //Ѕлок протестирован
                result=temp_x1->data+temp_x2->data+carry;
                carry=(int)(result/1000);
                fifo.Push(result%1000);
                temp_x1=temp_x1->prev;
                temp_x2=temp_x2->prev;
        }
        if ( (x2.Count()==x1.Count() ) && (carry!=0) )
                fifo.Push(carry);
        else {
                for (int i=x2.Count();i<x1.Count();i++) {
                        result=temp_x1->data+carry;
                        carry=(int)(result/1000);
                        fifo.Push(result%1000);
                        temp_x1=temp_x1->prev;
                }
                if (carry!=0)
                        fifo.Push(carry);
        }

        int count=fifo.Count();
        for (int i=0;i<count;i++) {
                if (!fifo.Pop(result)) {
                        cout <<"Error\n";
                        exit(-1);
                }
                temp.AddBefore(temp.root,result);
        }
        return temp;

}
Exemple #8
0
int main() {

	FIFO f;
	struct kunde k;

	k.name = "name";
	k.art = "art";
	f.einfuegen(k);

	k.name = "name2";
	k.art = "art2";
	f.einfuegen(k);

	f.verarbeiten();

	k.name = "name3";
 	k.art = "art3";
	f.einfuegen(k);

	f.verarbeiten();


}
void SerialPort::threadLoop()
{
	const int fd = m_fd;
	const int max_fd = fd+1;

	m_running = true;
	m_rxErrors[1] = 0;

	while (true) {
		fd_set rfds;

		FD_ZERO(   &rfds);
		FD_SET(fd, &rfds);

		struct timeval timeout;
		timeout.tv_sec = kReadTimeoutMs/1000;
		timeout.tv_usec = (kReadTimeoutMs%1000)*1000;

		int n = select(max_fd, &rfds, 0, 0, &timeout);
		// 	int fdset = FD_ISSET(fd, &rfds);
		// 	printf( "fdset %i, n %i, errno %i\n", fdset, n, errno );
		if ( m_open ){
			if ((n > 0) && FD_ISSET(fd, &rfds)) {
				// printf("poll input\n");
				int nr = 0;
				// while (true) {
				if ( m_open ){
					int n2 = read(fd, m_rxbuffer, kBufferSize);
					//  printf("read %d, errno %i, errbadf %i, %i, %i\n", n2, errno, EBADF, EAGAIN, EIO);
					if (n2 > 0) {
						// write data to ringbuffer
						for (int i=0; i < n2; ++i) {
							if (!m_rxfifo.Put(m_rxbuffer[i])) {
								m_rxErrors[1]++;
								break;
							}
						}
						nr += n2;
					} else if ((n2 == 0) && (n == 1) ) { // added by nescivi, to check for disconnected device. In this case the read is 0 all the time and otherwise eats up the CPU
						//	printf( "done\n" );
						goto done;
					} else if ((n2 == 0) || ((n2 == -1) && (errno == EAGAIN))) {
						//	printf( "break\n");
						break;
					} else {
#ifndef NDEBUG
						printf("SerialPort HUP\n");
#endif
						goto done;
					}
				}
				//}
				if (!m_running) {
					// close and cleanup
					goto done;
				}
				if (nr > 0) {
					dataAvailable();
				}
			} else if (n == -1) {
				goto done;
			}
		}
		if (!m_running) {
			// close and cleanup
			goto done;
		}
	}

done:
	// doneAction();
	if ( m_open ){
		tcflush(fd, TCIOFLUSH);
		tcsetattr(fd, TCSANOW, &m_oldtermio);
		close(fd);
	};
	m_open = false;
	m_running = false;
	if ( m_dodone )
		doneAction();
#ifndef NDEBUG
	printf("SerialPort closed\n");
#endif
}
	size_t len() const {
		return fifo.len();
	}
	Message* pop(std::array<uint8_t, Message::MAX_SIZE>& buf) {
		Message* const p = reinterpret_cast<Message*>(buf.data());
		return fifo.out_r(buf.data(), buf.size()) ? p : nullptr;
	}
	bool skip() {
		return fifo.skip();
	}
void threadProcess(
	std::string iFileDir, 
	std::string oFileDir, 
	FIFO<int>& module_list, 
	int threadID)
{
	while(1)
	{
		// get next module for process or exit if done.
		int module_number;
		try {
			module_number = module_list.pop();
			std:: stringstream report;
			report << "Stating module " << module_number;
			thread_report(report.str(),threadID);
		}catch(std::string i) {
			thread_report("Terminating",threadID);
			return;
		}

		std::array<FIFO<std::string>,12> asicData; //stores the data from the asic asicData[asicID][SPP]
		FIFO<std::string> side1, side2;

		for(int i(0); i < 12; i++)
		{
			std::stringstream filename;
			filename << iFileDir << "/timesync" << module_number*12 + i << ".txt";
			std::ifstream iFile(filename.str());
			std::string tempIn;

			while(iFile >> tempIn)
			{
				if (atoi(tempIn.c_str()) == 0) continue;
				asicData[i].store(tempIn);
			}
		}

		bool complete = false;
		bool next_bcid = true;
		int bcid = 0;
		while(!complete)
		{
			for (int i(0); i < 12; i++)
				if(!asicData[i].is_empty()){
					if(get_bcid(asicData[i].peek()) == bcid){
						if (i < 3 || i >= 9)
							side1.store(asicData[i].pop());
						else
							side2.store(asicData[i].pop());
						next_bcid = false;
					}
				}

			complete = true;
			for (auto& asic : asicData) if (!asic.is_empty()) complete = false;
			if (next_bcid) if (++bcid >= 512) bcid = 0;
			next_bcid = true;
		}

		std::stringstream outFileName1;
		outFileName1 << oFileDir << "/module_" << module_number << "_";
		std::stringstream outFileName2;
		outFileName2 << outFileName1.str(); //shits and giggles
		outFileName1 << 1 << ".txt";
		outFileName2 << 2 << ".txt";

		std::ofstream oFile1(outFileName1.str());
		std::ofstream oFile2(outFileName2.str());

		thread_report("Writing to file",threadID);
		while(!side1.is_empty())
			oFile1 << side1.pop() << '\n';

		while(!side2.is_empty())
			oFile2 << side2.pop() << '\n';
	}
}
Exemple #14
0
int main() {

	ifstream printdata("printdata.txt"); //make a stream
	List<job> printQueue;//this queue is going to be used for FIFO processing

	//create a whole bunch of dummy variables to put in the list
	int eyeD, tstamp, numP;
	char auth;
	job temp;




	while (printdata >> eyeD) {
		//read in data
		temp.id = eyeD;
		printdata >> tstamp;
		temp.timestamp = tstamp;
		printdata >> auth;
		temp.user = auth;
		printdata >> numP;
		temp.pages = numP;
		printQueue.push_back(temp); // callthe lists pushback method to add it to the back of the FIFO queue.
	}

	//create a dummy front job
	job frontJob;
	frontJob = printQueue.pop_front(); //get the first element in the fifo queue.
	int clock = frontJob.timestamp;
	//begin FIFO processing
	FIFO<job> feefo; //create a fifo list type
	feefo.push(frontJob); //place it at the beginning of the queue
	int stoptime = 0;
	zachresults << "Processing and calculating FIFO queue." << endl;
	job printing; //printing will hold the current job that is printing
	//initialize all of our stats
	int minwait = 0, maxwait = 0, totalwait = 0, jobsprocessed = 0;
	double avgwait;

	bool busyPrinter = false; // the printer isn't busy, so tell the truth, you goon
	do {
		if (!busyPrinter) { //if the printer isn't busy, begin printing the next job in the fifo queue
			printing = feefo.pop(clock);
			zachresults << "Starting print id " << printing.id << " at " << clock << endl;
			stoptime = clock + printing.length();
			zachresults << "This job will end at " << stoptime << endl;
			zachresults << "This job waited " << printing.waittime << " seconds." << endl;
			if (printing.id != 165896) { //don't collect wait time stats on the first print job. it doesn't wait.
				if(minwait == 0)	{
					minwait = printing.waittime;
					maxwait = printing.waittime;
					jobsprocessed++;
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				else {
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				if (printing.waittime < minwait) {
					minwait = printing.waittime;
				}
				if (printing.waittime > maxwait) {
					maxwait = printing.waittime;
				}
				
			}
			busyPrinter = true; //the printer is now busy
		}
		if (!printQueue.is_empty()) { //as long as we're still pulling jobs off the queue as they arrive, run this block of code
			frontJob = printQueue.pop_front(); //get the next job and put it in our frontjob variable
			while (busyPrinter && clock < frontJob.timestamp) { //while the printr is busy and the next job hasn't arrived yet, increment the clock
				clock++;
				if (clock == frontJob.timestamp) { //add a job to the queue once our clock hits its timestamp
					feefo.push(frontJob);
					zachresults << "Job " << frontJob.id << " arrived at " << clock << endl;
				}
				if (stoptime == clock) { //the print job is done once this stoptime is satisfied
					busyPrinter = false;
				}
			}
		}
		else {
			while (busyPrinter) {//run this once all of the jobs from printdata.txt are in our queue
				clock++;
				if (stoptime == clock) {
					busyPrinter = false;
				}
			}
		}
	} while (!feefo.isempty()); //bail once all of our jobs are done

	zachresults << "The minimum wait time was " << minwait << " seconds." << endl;
	zachresults << "The maximum wait time was " << maxwait << " seconds." << endl;
	zachresults << "The average wait time was " << avgwait << " seconds" << endl;
	zachresults << "The total wait time was " << totalwait << " seconds." << endl;
	//tidy everything up before we move on to SJF
	printdata.close();
	feefo.clear();
	printQueue.clear();
	minwait = maxwait = totalwait = clock = stoptime = 0;
	avgwait = 0.0;
	busyPrinter = false;
	//end FIFO processing


	//begin SJF processing
	List<job> SJFqueue;
	SJF<job> essjayeff;
	//we're replicating a lot of what we accomplished with feefo up there. I'll let you know when things are different
	printdata.open("printdata.txt");

	while (printdata >> eyeD) {
		//read in data
		temp.id = eyeD;
		printdata >> tstamp;
		temp.timestamp = tstamp;
		printdata >> auth;
		temp.user = auth;
		printdata >> numP;
		temp.pages = numP;
		SJFqueue.push_back(temp);
	}

	frontJob = SJFqueue.pop_front();
	essjayeff.push_back(frontJob);
	clock = frontJob.timestamp;

	zachresults << endl << "Processing and calculating SJF queue." << endl;
	do {
		if (!busyPrinter) {
			printing = essjayeff.pop(clock);
			zachresults << "Starting print id " << printing.id << " at " << clock << endl;
			stoptime = clock + printing.length();
			zachresults << "This job will end at " << stoptime << endl;
			zachresults << "This job waited " << printing.waittime << " seconds." << endl;
			if (printing.id != 165896) {
				if (minwait == 0) {
					minwait = printing.waittime;
					maxwait = printing.waittime;
					jobsprocessed++;
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				else {
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				if (printing.waittime < minwait) {
					minwait = printing.waittime;
				}
				if (printing.waittime > maxwait) {
					maxwait = printing.waittime;
				}

			}
			busyPrinter = true;
		}
		if (!SJFqueue.is_empty()) {
			frontJob = SJFqueue.pop_front();
			while (busyPrinter && clock < frontJob.timestamp) {
				clock++;
				if (clock == frontJob.timestamp) {
					essjayeff.push(frontJob); //hi, this is where things get different. in SJF.h, we deal with push_ordered appropriately.
					zachresults << "Job " << frontJob.id << " arrived at " << clock << endl;
				}
				if (stoptime == clock) {
					busyPrinter = false;
				}
			}
		}
		else {
			while (busyPrinter) {
				clock++;
				if (stoptime == clock) {
					busyPrinter = false;
				}
			}
		}
		//if the printer is starved. i had an issue with the print jobs being starved
		if (essjayeff.isempty() && !SJFqueue.is_empty()) {
			frontJob = SJFqueue.pop_front();
			while (clock != frontJob.timestamp) {
				zachresults << "The time is " << clock << ", and the printer is starved." << endl;
				clock++;
			}
			essjayeff.push(frontJob);
		}

	} while (!essjayeff.isempty());

	zachresults << "The minimum wait time was " << minwait << " seconds." << endl;
	zachresults << "The maximum wait time was " << maxwait << " seconds." << endl;
	zachresults << "The average wait time was " << avgwait << " seconds" << endl;
	zachresults << "The total wait time was " << totalwait << " seconds." << endl;

	printdata.close();
	essjayeff.clear();
	SJFqueue.clear();
	minwait = maxwait = totalwait = clock = stoptime = 0;
	avgwait = 0.0;
	busyPrinter = false;
	//end SJF processing



	//begin MPQ processing!
	List<job> MPQqueue;
	MPQ<job> empeeq;

	printdata.open("printdata.txt");

	while (printdata >> eyeD) {
		//read in data
		temp.id = eyeD;
		printdata >> tstamp;
		temp.timestamp = tstamp;
		printdata >> auth;
		temp.user = auth;
		printdata >> numP;
		temp.pages = numP;
		MPQqueue.push_back(temp);
	}

	frontJob = MPQqueue.pop_front();
	empeeq.push(frontJob);
	clock = frontJob.timestamp;

	zachresults << endl << "Processing and calculating MPQ queue." << endl;
	do {
		if (!busyPrinter) {
			printing = empeeq.pop(clock);
			zachresults << "Starting print id " << printing.id << " at " << clock << endl;
			stoptime = clock + printing.length();
			zachresults << "This job will end at " << stoptime << endl;
			zachresults << "This job waited " << printing.waittime << " seconds." << endl;
			if (printing.id != 165896) {
				if (minwait == 0) {
					minwait = printing.waittime;
					maxwait = printing.waittime;
					jobsprocessed++;
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				else {
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				if (printing.waittime < minwait) {
					minwait = printing.waittime;
				}
				if (printing.waittime > maxwait) {
					maxwait = printing.waittime;
				}
			}
			busyPrinter = true;
		}
		if (!MPQqueue.is_empty()) {
			frontJob = MPQqueue.pop_front();
			while (busyPrinter && clock < frontJob.timestamp) {
				clock++;
				if (clock == frontJob.timestamp) {
					zachresults << "Job " << frontJob.id << " arrived at " << clock << endl;
					empeeq.push(frontJob);
				}
				if (stoptime == clock) {
					busyPrinter = false;
				}
			}
		}
		else {
			while (busyPrinter) {
				clock++;
				if (stoptime == clock) {
					busyPrinter = false;
				}
			}
		}
	} while (!empeeq.isempty());

	zachresults << "The minimum wait time was " << minwait << " seconds." << endl;
	zachresults << "The maximum wait time was " << maxwait << " seconds." << endl;
	zachresults << "The average wait time was " << avgwait << " seconds" << endl;
	zachresults << "The total wait time was " << totalwait << " seconds." << endl;

	printdata.close();
	empeeq.clear();
	MPQqueue.clear();

	system("pause");
	return 0;
}
int main(int argc, char** argv) {
    //ҳ������˳���
    int arr[__LENGTH__];
    srand((unsigned int)time(NULL));
    for(auto& i : arr) {
        //���ҳ��
        i = rand() % 100;
    }
    //ҳ���
    int frame_id;
    //�������ʹ���û��㷨
    LRU LRUManager;
    //ȱҳ�жϼ���
    unsigned int missing_page_lru = 0;
    //ҳ���û�����
    unsigned int page_algorithm_lru = 0;
    //ģ������
    cout << "******************** LRU ********************" << endl;
    for(auto i : arr) {
        cout << "����ҳ�ţ�" << i << "\t";
        switch(LRUManager.requireFrame(i, frame_id)) {
        case No:
            cout << "ҳ�����У�ҳ��ţ�";
            break;
        case MissingPage:
            missing_page_lru++;
            cout << "ҳ��δ���У�����ҳ����ҳ��ţ�";
            break;
        case MissingPageAndReplace:
            missing_page_lru++;
            page_algorithm_lru++;
            cout << "ҳ��δ���У�ҳ������������ҳ�沢�滻ҳ��ţ�";
            break;
        }
        cout << frame_id << endl;
    }
    cout << "#################### LRU ####################" << endl;
    //�Ƚ��ȳ��û��㷨
    FIFO FIFOManager;
    //ȱҳ�жϼ���
    unsigned int missing_page_fifo = 0;
    //ҳ���û�����
    unsigned int page_algorithm_fifo = 0;
    //ģ������
    cout << "******************** FIFO ********************" << endl;
    for(auto i : arr) {
        cout << "����ҳ�ţ�" << i << "\t";
        switch(FIFOManager.requireFrame(i, frame_id)) {
        case No:
            cout << "ҳ�����У�ҳ��ţ�";
            break;
        case MissingPage:
            missing_page_fifo++;
            cout << "ҳ��δ���У�����ҳ����ҳ��ţ�";
            break;
        case MissingPageAndReplace:
            missing_page_fifo++;
            page_algorithm_fifo++;
            cout << "ҳ��δ���У�ҳ������������ҳ�沢�滻ҳ��ţ�";
            break;
        }
        cout << frame_id << endl;
    }
    cout << "#################### FIFO ####################" << endl;
    //������û��㷨
    LFU LFUManager;
    //ȱҳ�жϼ���
    unsigned int missing_page_lfu = 0;
    //ҳ���û�����
    unsigned int page_algorithm_lfu = 0;
    //ģ������
    cout << "******************** LFU ********************" << endl;
    for(auto i : arr) {
        cout << "����ҳ�ţ�" << i << "\t";
        switch(LFUManager.requireFrame(i, frame_id)) {
        case No:
            cout << "ҳ�����У�ҳ��ţ�";
            break;
        case MissingPage:
            missing_page_lfu++;
            cout << "ҳ��δ���У�����ҳ����ҳ��ţ�";
            break;
        case MissingPageAndReplace:
            missing_page_lfu++;
            page_algorithm_lfu++;
            cout << "ҳ��δ���У�ҳ������������ҳ�沢�滻ҳ��ţ�";
            break;
        }
        cout << frame_id << endl;
    }
    cout << "#################### LFU ####################" << endl;
    //ʱ���û��㷨
    CLOCK CLOCKManager;
    //ȱҳ�жϼ���
    unsigned int missing_page_clock = 0;
    //ҳ���û�����
    unsigned int page_algorithm_clock = 0;
    //ģ������
    cout << "******************** CLOCK ********************" << endl;
    for(auto i : arr) {
        cout << "����ҳ�ţ�" << i << "\t";
        switch(CLOCKManager.requireFrame(i, frame_id)) {
        case No:
            cout << "ҳ�����У�ҳ��ţ�";
            break;
        case MissingPage:
            missing_page_clock++;
            cout << "ҳ��δ���У�����ҳ����ҳ��ţ�";
            break;
        case MissingPageAndReplace:
            missing_page_clock++;
            page_algorithm_clock++;
            cout << "ҳ��δ���У�ҳ������������ҳ�沢�滻ҳ��ţ�";
            break;
        }
        cout << frame_id << endl;
    }
    cout << "#################### CLOCK ####################" << endl;
    //�Ľ�ʱ���û��㷨
    CLOCK2 CLOCK2Manager;
    //ȱҳ�жϼ���
    unsigned int missing_page_clock2 = 0;
    //ҳ���û�����
    unsigned int page_algorithm_clock2 = 0;
    //ģ������
    cout << "******************** CLOCK2 ********************" << endl;
    for(auto i : arr) {
        cout << "����ҳ�ţ�" << i << "\t";
        switch(CLOCK2Manager.requireFrame(i, frame_id, rand() % 2 == 0 ? false : true)) {
        case No:
            cout << "ҳ�����У�ҳ��ţ�";
            break;
        case MissingPage:
            missing_page_clock2++;
            cout << "ҳ��δ���У�����ҳ����ҳ��ţ�";
            break;
        case MissingPageAndReplace:
            missing_page_clock2++;
            page_algorithm_clock2++;
            cout << "ҳ��δ���У�ҳ������������ҳ�沢�滻ҳ��ţ�";
            break;
        }
        cout << frame_id << endl;
    }
    cout << "#################### CLOCK2 ####################" << endl;
    //������
    cout << "�������ʹ���û��㷨LRU�㷨�����Ʋ���ҳ��ʧЧ"
        << missing_page_lru
        << "�Σ����з���ҳ���û�"
        << page_algorithm_lru
        << "�Ρ�"
        << endl;
    cout << "�Ƚ��ȳ��û��㷨FIFO�㷨�����Ʋ���ҳ��ʧЧ"
        << missing_page_fifo
        << "�Σ����з���ҳ���û�"
        << page_algorithm_fifo
        << "�Ρ�"
        << endl;
    cout << "������û��㷨LFU�㷨�����Ʋ���ҳ��ʧЧ"
        << missing_page_lfu
        << "�Σ����з���ҳ���û�"
        << page_algorithm_lfu
        << "�Ρ�"
        << endl;
    cout << "ʱ���û��㷨CLOCK�㷨�����Ʋ���ҳ��ʧЧ"
        << missing_page_clock
        << "�Σ����з���ҳ���û�"
        << page_algorithm_clock
        << "�Ρ�"
        << endl;
    cout << "�Ľ�ʱ���û��㷨CLOCK2�㷨�����Ʋ���ҳ��ʧЧ"
        << missing_page_clock2
        << "�Σ����з���ҳ���û�"
        << page_algorithm_clock2
        << "�Ρ�"
        << endl;
    system("pause");
    return 0;
}
Exemple #16
0
		//-----------------------------------------------------------------//
		void update()
		{
			gui::widget_director& wd = director_.at().widget_director_;

			// シリアルポートの更新
			if(serial_list_.empty() || !serial_.compare(serial_list_)) {
				serial_.create_list();
				serial_list_ = serial_.get_list();
				utils::strings list;
				for(const auto& t : serial_list_) {
					list.push_back(t.port);
					terminal_core_->output(t.port + " (" + t.info + ")\n");
				}
				ports_->get_menu()->build(list);
				ports_->select(0);
			}

			// RAWデータの取得と変換
			if(serial_.probe()) {
				char tmp[256];
				auto len = serial_.read(tmp, sizeof(tmp));
				for(uint32_t i = 0; i < len; ++i) {
					fifo_.push(tmp[i]);
				}
			}

			while(1)  {
				auto line = get_line_();
				if(line.empty()) {
					break;
				}
				int x, y, z;
				if((utils::input("%d,%d,%d", line.c_str()) % x % y % z).num() == 3) {
					raw_.x = x;
					raw_.y = y;
					raw_.z = z;
//					char tmp[256];
//					utils::sformat("%d, %d, %d\n", tmp, sizeof(tmp)) % x % y % z;
//					terminal_core_->output(tmp);
					if(ref_count_ > 0) {  // キャリブレーション
						if(ref_min_.x > raw_.x) ref_min_.x = raw_.x;
						if(ref_max_.x < raw_.x) ref_max_.x = raw_.x;
						if(ref_min_.y > raw_.y) ref_min_.y = raw_.y;
						if(ref_max_.y < raw_.y) ref_max_.y = raw_.y;
						if(ref_min_.z > raw_.z) ref_min_.z = raw_.z;
						if(ref_max_.z < raw_.z) ref_max_.z = raw_.z;
						--ref_count_;
						if(ref_count_ == 0) {
							gv_.set(0.0f);
						}
					} else {
						vtx::ivtx d(0);
						if(ref_min_.x > raw_.x || ref_max_.x < raw_.x) d.x = raw_.x;
						if(ref_min_.y > raw_.y || ref_max_.y < raw_.y) d.y = raw_.y;
						if(ref_min_.z > raw_.z || ref_max_.z < raw_.z) d.z = raw_.z;
						float g = 0.07f;
						gv_.x += static_cast<float>(d.x) * g;
						gv_.y += static_cast<float>(d.y) * g;
						gv_.z += static_cast<float>(d.z) * g;
					}
				} else {
					std::string s = "NG: ";
					s += line;
					terminal_core_->output(s);
				}
			}

			if(serial_.probe()) {
				++count_;
				if(count_ >= 30) {
					count_ = 0;
					char tmp[256];
					utils::sformat("%3.2f, %3.2f, %3.2f\n", tmp, sizeof(tmp))
						% gv_.x % gv_.y % gv_.z;
					terminal_core_->output(tmp);				
				}
			}

			if(!wd.update()) {
				camera_.update();
			}
		}