Exemplo n.º 1
0
/* loop on stdin, just for testing, it is fleece cores' job :) */
int main(void)
{
    char *errorcond;
    char buffer[LINE_MAXSZ];
    json_t *jsonevent;
    char ncsaline[LINE_MAXSZ];

    while (1) {
        if (inQueue(fileno(stdin))) {
            errorcond = fgets(buffer, LINE_MAXSZ, stdin);
            if (errorcond != NULL) {
                jsonevent = readjson(buffer);
                if (jsonevent == NULL) {
                    fprintf(stdout, BAD_JSON, buffer);
                    continue;
                }
                jsonncsa(jsonevent, ncsaline, LINE_MAXSZ);
                fprintf(stdout, "%s\n", ncsaline);
                json_decref(jsonevent);
            } else {
                perror("fgets got:");
                break;
            }
        }
    }

    return 0;
}
Exemplo n.º 2
0
bool SearchListItem::operator<(const QTreeWidgetItem & other_) const {
    const SearchListItem * other = dynamic_cast<const SearchListItem*>(&other_);
    if (!other)
        return false;

	int col = 0;
	if(treeWidget())
	col = treeWidget()->sortColumn();

	switch(col) {
	case 0:
		return n() < other->n();
	case 1:
		return user() < other->user();
	case 2:
		return text(2) < other->text(2);
	case 3:
		return size() < other->size();
	case 4:
		return speed() < other->speed();
	case 5:
		return inQueue() < other->inQueue();
	case 6:
		return freeSlot();
	case 7:
		return length() < other->length();
	case 8:
		return bitrate() < other->bitrate();
	case 9:
		return dir() < other->dir() ;
	}

  return false;
}
Exemplo n.º 3
0
void Cache::insertInQueue(TreeDescriptor treeIdx, int nid, char mode, int idx)
{
	queueLock.lock();
	if(mode == FLUSH_BEGIN_SEGMENT || !inQueue(treeIdx, nid, idx, FLUSH_PUT_RECORD))
	{
		NidChain *newNid = new NidChain;
		newNid->nid = nid;
		newNid->treeIdx = treeIdx;
      NidChain *chainTail;    
      for(chainTail = chainHead; chainTail && chainTail->nxt; chainTail = chainTail->nxt);
		if(chainTail)
			chainTail->nxt = newNid;
		newNid->nxt = 0;
		newNid->idx = idx;
		newNid->mode = mode;
		if(!chainHead)
			chainHead = newNid;
	}
	queueLock.unlock();
}
Exemplo n.º 4
0
 int findLongestPath() {
     vector<int> distance(n * m + 2, 0);
     vector<bool> inQueue(n * m + 2, false);
     queue<int> q;
     q.push(source);
     inQueue[source] = true;
     while (!q.empty()) {
         int u = q.front();
         inQueue[u] = false;
         q.pop();
         for (int p = head[u]; p != NIL; p = edge[p].nxt) {
             int v = edge[p].v, w = edge[p].w;
             if (distance[v] < distance[u] + w) {
                 distance[v] = distance[u] + w;
                 if (!inQueue[v]) {
                     inQueue[v] = true;
                     q.push(v);
                 }
             }
         }
     }
     return distance[sink] - 1;
 }
Exemplo n.º 5
0
LPOVERLAPPED TOCAnalyzer::readACK()
{
	 if(serialPortConfiguration==NULL)
		 return NULL;
	 writing = true;



 






	DWORD clearText = EV_TXEMPTY;
    DWORD dwCommEvent;
    DWORD dwRead;
	DWORD dwRes;
	DWORD bite;
    char  chRead;
    int index = 0;
	DCB commstate;
	DWORD wordstatus;
	OVERLAPPED *osReader = new OVERLAPPED;
	boolean fWaitingOnRead = false;
	WORD value;
	WORD arrayIn[40];

	 if( !_CrtCheckMemory())cout<<"bad memory";
osReader->hEvent = CreateEvent(NULL, TRUE, TRUE, L"osreader");
int size = 6;

if (osReader->hEvent == NULL);
   // Error creating overlapped event; abort.
while(index<size)
{
	bool ackBool = false;

	do
	{
		//cout<<"entered Read operation";

   // Issue read operation.
	if (!ReadFile(serialPortConfiguration, &arrayIn[index], 1, &dwRead, osReader)) {
	   if (GetLastError() != ERROR_IO_PENDING)  {}   // read not delayed?
         // Error in communications; report it.
      else
         reading = TRUE;
   }
   else {    
     // if(inQueue(doorHandle))
	  //{
		 // readBuffer.write[index] = value;

	      if(index!=0 || arrayIn[0]== 0xa5)
		  {
			 // if(ackBool == false)



			  index++;
		//  cout<<index<<"index value"<<size<<"size"<<endl;
		  }


	  }
    

   





if (reading) {
   dwRes = WaitForSingleObject(osReader->hEvent, 50000);
   switch(dwRes)
   {
      // Read completed.
      case WAIT_OBJECT_0:
		  {
		  if (!GetOverlappedResult(serialPortConfiguration, osReader, &dwRead, FALSE)){}
          else
		  {
         if(index!=0 || arrayIn[0]== 0xa5)
		  {


		  index++;

		  }

		 }

          //  Reset flag so that another opertion can be issued.
          reading = FALSE;
          break;
		  }

      case WAIT_TIMEOUT:
          // Operation isn't complete yet. fWaitingOnRead flag isn't
          // changed since I'll loop back around, and I don't want
          // to issue another read until the first one finishes.
          //
          // This is a good time to do some background work.
          break;                       

      default:
          // Error in the WaitForSingleObject; abort.
          // This indicates a problem with the OVERLAPPED structure's
          // event handle.
          break;
   }

   
}

   // size = 21;
//Sleep(5);

}while(inQueue(serialPortConfiguration,1));
}

 
   writing = false;
  
   return osReader;
}
Exemplo n.º 6
0
bool TOCAnalyzer::performTOCLab()
{

    LPOVERLAPPED readOverlapped;
    LPOVERLAPPED writeOverlapped;
    struct TOCData allocation;
    struct TOCData vialInformation;
    struct TOCData sampleInformation;
    struct TOCData sampleInformation2;


    for(int index=0; index<3; index++)
        vialInformation.write[index] = ACKStruct.write[index];

    vialInformation.write[4] = 0X05ab;
    vialInformation.write[5] = 0x07f4;
    vialInformation.write[6] = 0x2804;
    vialInformation.write[7] = 0;
    vialInformation.write[8] = 0;
    vialInformation.write[9] = 0;
    vialInformation.write[10] = 0;
    vialInformation.write[11] = 0x3200;
    vialInformation.size = 12;

    initLab(sampleInformation,sampleData.getSampleInformation().getVialPosition());


    for(int shift=0; shift<59; shift++)
        sampleInformation2.write[shift] = sampleInformation.write[shift+3];
    sampleInformation2.write[1] +=(1<<8);
    sampleInformation2.write[38]+=(1<<8);
    sampleInformation2.write[58] +=(2<<8);
    sampleInformation2.size = 59;
    Sleep(10);
    memset(&vialInformation,0,sizeof(struct TOCData));
	memset(&secWriteBuffer,0,sizeof(struct TOCData));
	memset(&secReadBuffer,0,sizeof(struct TOCData));
	memset(&writeBuffer,0,sizeof(struct TOCData));
	memset(&readBuffer,0,sizeof(struct TOCData));
    initLab(vialInformation,sampleData.getSampleInformation().getVialPosition());
   
    phase(secWriteBuffer);
    phase2(writeBuffer);
    Sleep(300);
    writeOverlapped = sendToTOC(serialPortConfiguration,secWriteBuffer);
    Sleep(250);
    readOverlapped =  readFromTOC(serialPortConfiguration,10,secReadBuffer.write);
    Sleep(400);
    while((!HasOverlappedIoCompleted(writeOverlapped) || !HasOverlappedIoCompleted(readOverlapped))||writing);
    delete writeOverlapped;
    delete readOverlapped;
    Sleep(400);


    writeOverlapped=sendToTOC(serialPortConfiguration,writeBuffer);
    Sleep(650);
    readOverlapped=readACK();
    while((!HasOverlappedIoCompleted(writeOverlapped) || !HasOverlappedIoCompleted(readOverlapped))||writing);
    delete writeOverlapped;
    delete readOverlapped;
    Sleep(4000);
    int index=0;
	cout<<"phase 1 done"<<endl;
    while(1) {

       
        //allocation= new TOCData;
        memset(&allocation,0,sizeof(struct TOCData));

        writeOverlapped=sendToTOC(serialPortConfiguration,ACKStruct);
        Sleep(50);
        readOverlapped=readFromTOC(serialPortConfiguration,12,allocation.write);

        while((!HasOverlappedIoCompleted(writeOverlapped) || !HasOverlappedIoCompleted(readOverlapped))||writing);
        if(allocation.write[1]==19 && allocation.write[13] ==0)
            break;
        allocation.size = 6;

        delete writeOverlapped;
        delete readOverlapped;
        // delete allocation;
        Sleep(250);

    }
    while((!HasOverlappedIoCompleted(writeOverlapped) || !HasOverlappedIoCompleted(readOverlapped))||writing);
    delete writeOverlapped;
    delete readOverlapped;
	cout<<"phase 2 done"<<endl;

    writeOverlapped=sendToTOC(serialPortConfiguration,sampleInformation);
    Sleep(700);
    readOverlapped=readFromTOC(serialPortConfiguration,8,readBuffer.write);
    while((!HasOverlappedIoCompleted(writeOverlapped) || !HasOverlappedIoCompleted(readOverlapped))||writing);
    delete writeOverlapped;
    delete readOverlapped;
    while(true) {
        memset(&allocation.write,0,sizeof(WORD)*BUFFERSIZE);
        writeOverlapped=sendToTOC(serialPortConfiguration,ACKStruct);
        Sleep(900);

		while(!HasOverlappedIoCompleted(writeOverlapped) &&writing);
		delete writeOverlapped;

        do
		{
        readOverlapped=readFromTOC(serialPortConfiguration,19,allocation.write);
        allocation.size = 7;

		while(!HasOverlappedIoCompleted(readOverlapped)&&writing);
		delete readOverlapped;
		Sleep(200);
		}
		while(inQueue(serialPortConfiguration,1));
        if(allocation.write[1]==23 && allocation.write[13] ==0) {
            
            break;
        }
     

        Sleep(400);
    }

    //while((!HasOverlappedIoCompleted(writeOverlapped) || !HasOverlappedIoCompleted(readOverlapped))||writing);
    //delete writeOverlapped;
    //delete readOverlapped;

    writeOverlapped=sendToTOC(serialPortConfiguration,sampleInformation2);
    Sleep(500);
    readOverlapped=readFromTOC(serialPortConfiguration,8,readBuffer.write);
    while((!HasOverlappedIoCompleted(writeOverlapped) || !HasOverlappedIoCompleted(readOverlapped))||writing);
    delete writeOverlapped;
    delete readOverlapped;
    cout<<"phase 3 done"<<endl;
    int byteID = 0;
	struct TOCData escapeSequence;
	escapeSequence.write[0] = 0x0BA5;
    escapeSequence.write[1] = 0x0AF4;
	escapeSequence.write[2] = 0x2A04;
	escapeSequence.write[3] = 0x00;
    escapeSequence.write[4] = 0x00;
	escapeSequence.write[5] = 0x00;
	escapeSequence.write[6] = 0x3700;
	escapeSequence.write[7] = 0x03A5;
    escapeSequence.write[8] = 0x00FC;
	escapeSequence.write[9] = 0x01;
	escapeSequence.size = 19;
	bool escape = false;
    while(true) {
        memset(&allocation.write,0,sizeof(WORD)*40);
		if(escape)
		{
            writeOverlapped=sendToTOC(serialPortConfiguration,escapeSequence);
			escape = false;

		}
		else
		{
			writeOverlapped=sendToTOC(serialPortConfiguration,ACKStruct);
		}
        Sleep(900);
	
        readOverlapped=readFromTOC(serialPortConfiguration,19,allocation.write);
        allocation.size = 19;
		while(!HasOverlappedIoCompleted(readOverlapped) &&reading);
		delete readOverlapped;
		if(allocation.write[1]==79)
		{
			
			
			sampleData.getSampleResults().addToPeak(allocation.write[14],allocation.write[15]);
		}
        if(allocation.write[1]==23) {
            
            escape = true;
        } 

		if(allocation.write[1]==43)
		{
			break;
		}
		cout<<"concentration so far"<<sampleData.getSampleResults().getAverageConcentration()<<endl;
		Sleep(250);
		
        Sleep(400);
    }

	 while(true) {
        memset(&allocation.write,0,sizeof(WORD)*40);
		if(escape)
		{
            writeOverlapped=sendToTOC(serialPortConfiguration,escapeSequence);
			break;

		}
		else
		{
			writeOverlapped=sendToTOC(serialPortConfiguration,ACKStruct);
		}
        Sleep(900);
	
        readOverlapped=readFromTOC(serialPortConfiguration,19,allocation.write);
        allocation.size = 19;
		while(!HasOverlappedIoCompleted(readOverlapped) &&reading);
		delete readOverlapped;
		if(allocation.write[1]==79)
		{
			
			
			sampleData.getSampleResults().addToPeak(allocation.write[14],allocation.write[15]);
		}
        if(allocation.write[2]==232 && allocation.write[1]==23) {
            
            escape = true;
        } 

		
		Sleep(250);
		
        Sleep(400);
    }


        Sleep(900);
        readOverlapped=readFromTOC(serialPortConfiguration,19,allocation.write);
        cout<<"Area Calculated" <<sampleData.getSampleResults().currentArea()<<endl;
		cout<<"Concentration Calculated"<<sampleData.getSampleResults().currentConcentration()<<endl;
}