Example #1
0
int readDevice(void *ptr_usb_data) {
	char cTmp[MAX_LINE];
	int countBytes = 0;
	if (usb_status < 0) {
		return usb_status;
	}
	struct usb_data *l_ptr_usb_data;
	l_ptr_usb_data = (struct usb_data *) ptr_usb_data;
	// read colomboard
	int result = 0;
	unsigned char buf[5];
	countBytes = cb_panel_read_non_blocking(buf);
	l_ptr_usb_data->usbCounter++;
	if (countBytes <= 0) {
		result = countBytes;
	} else if (countBytes != sizeof(buf)) {
		sprintf(cTmp, "error: interrupt read failed, %d, %d\n", countBytes, l_ptr_usb_data->usbCounter);
		writeConsole(13, 0, cTmp);
		result = -1;
	} else {
		l_ptr_usb_data->board0 = buf[0];
		l_ptr_usb_data->board1 = buf[1];
		l_ptr_usb_data->board2 = buf[2];
		l_ptr_usb_data->board3 = buf[3];
		l_ptr_usb_data->board4 = buf[4];
		result = countBytes;
	}
	return result;
}
Example #2
0
int writeDevice(void *ptr_usb_data) {
	char cTmp[MAX_LINE];
	if (usb_status < 0) {
		return usb_status;
	}
	struct usb_data *l_ptr_usb_data;
	l_ptr_usb_data = (struct usb_data *) ptr_usb_data;
	unsigned char tmp_buffer_out[12];
	// write colomboard
	tmp_buffer_out[0] = 0x00;
	tmp_buffer_out[1] = l_ptr_usb_data->selectedDevice; // Device id
	tmp_buffer_out[2] = l_ptr_usb_data->comFreq / 100;
	tmp_buffer_out[3] = (l_ptr_usb_data->comFreq / 10) % 10;
	tmp_buffer_out[4] = l_ptr_usb_data->comFreq % 10;
	tmp_buffer_out[5] = l_ptr_usb_data->comFreqFraction / 10;
	tmp_buffer_out[6] = l_ptr_usb_data->comFreqFraction % 10;
	tmp_buffer_out[7] = l_ptr_usb_data->comFreqStandby / 100;
	tmp_buffer_out[8] = (l_ptr_usb_data->comFreqStandby / 10) % 10;
	tmp_buffer_out[9] = l_ptr_usb_data->comFreqStandby % 10;
	tmp_buffer_out[10] = l_ptr_usb_data->comFreqStandbyFraction / 10;
	tmp_buffer_out[11] = l_ptr_usb_data->comFreqStandbyFraction % 10;
	if ((usb_status = cb_panel_write(tmp_buffer_out))
			< sizeof(tmp_buffer_out)) {
		sprintf(cTmp, "error: interrupt write failed, %d, %d\n", usb_status, l_ptr_usb_data->usbCounter);
		writeConsole(12, 0, cTmp);
	}
	l_ptr_usb_data->usbCounter++;
	return 0;
}
Example #3
0
void dbgShow(Cluster *head, LPCLUSIMG clusImg){
	int i, j, pixCnt;
	Cluster *thisClus, *lastClus, **thisPx;
	writeConsoleFmt("\n\nhead: %08x. clusImg: %08x\n",head,clusImg);
	lastClus = thisClus = head;
	pixCnt = clusImg->width*clusImg->height;
	while(thisClus != (Cluster*)NULL){
		writeConsoleFmt("%08x->",thisClus);
		thisClus->testClusImg(clusImg);
		if(thisClus == thisClus->getNext()){
			writeConsole("SELF REFERENCE!\n");
			waitKeyPress(true);
			exit(-1);
			return;
		}
				
		if(thisClus->getCount() == 0 || thisClus->getCount() > pixCnt){
    		writeConsoleFmt("DAMMIT! %08x: CORRUPTED CLUSTER! PIXCNT: %d\n",thisClus,thisClus->getCount());
			waitKeyPress(true);
			exit(-1);
			return;
		}
		
		thisClus = thisClus->getNext();
		if(thisClus != (Cluster*)NULL && thisClus->getBefore() != lastClus){
			writeConsole("LIST IS NOT RIGTH LINKED!\n");
			waitKeyPress(true);
			exit(-1);
			return;
		}
		lastClus = thisClus;
	}
    writeConsole("NULL\n\n");
    
    thisPx = (Cluster**)clusImg->pixClus;
    for(i = 0; i < clusImg->height; i++){
    	for(j = 0; j < clusImg->width; j++){
	    	if(*thisPx != NULL && ((*thisPx)->getCount() == 0 || (*thisPx)->getCount() > pixCnt)){
	    		writeConsoleFmt("DAMMIT! ORPHAN PIXEL %dx%d! CLUS->PIXCNT %d\n",j+1,i+1,(*thisPx)->getCount());
				waitKeyPress(true);
				exit(-1);
				return;
			}
		}
	}
}
Example #4
0
void Cluster::mergeCluster(Cluster* c2, Cluster* head){
	int i;
	Cluster *clusBefore, **thisPx;
	if(c2 == this){
		writeConsole("SELF-MERGE????\n");
		waitKeyPress(true);
		exit(-1);
		return;
	}
	
	float newR = (avgTone.red*pixelCount + c2->avgTone.red*c2->pixelCount);
	float newG = (avgTone.green*pixelCount + c2->avgTone.green*c2->pixelCount);
	float newB = (avgTone.blue*pixelCount + c2->avgTone.blue*c2->pixelCount);
	
	pixelCount += c2->pixelCount;
	newR /= pixelCount;
	newG /= pixelCount;
	newB /= pixelCount;
	avgTone.red = (unsigned char)round(newR);
	avgTone.green = (unsigned char)round(newG);
	avgTone.blue = (unsigned char)round(newB);
		
	if(left > c2->left)
        left = c2->left;
    if(top > c2->top)
        top = c2->top;
    if(right < c2->right)
        right = c2->right;
    if(bottom < c2->bottom)
        bottom = c2->bottom;
	
	thisPx = (Cluster**)clustImage->pixClus;
	for(i = 0; i < clustImage->width*clustImage->height; i++){
		if(*thisPx == c2)
			*thisPx = this;
		thisPx++;
	}
	
    c2->avgTone = (COLOR){0,0,0};
    c2->pixelCount = 0;
    c2->left = 0;
    c2->top = 0;
    c2->right = 0;
    c2->bottom = 0;
    
    clusBefore = c2->before;
    clusBefore->next = c2->next;
    if(clusBefore->next != (Cluster*)NULL)
    	clusBefore->next->before = clusBefore;
    //writeConsoleFmt("List: %08x->%08x. Delete: %08x. Merged with %08x.\n",clusBefore,c2->next,c2,this);
    delete c2;
}
Example #5
0
void Logger::log(string message, int pid) {
	message.append("\n");
	if(pid) {
		stringstream ss;
		ss << pid;
		message = "[PID " + ss.str() + "] " + message;
	}

	if(console)
		writeConsole(message);

	if(file)
		writeFile(message);
}
Example #6
0
int   main(int argc, char *argv[])
/*--------------------------------------------------------------
 **  Input:   argc    = number of command line arguments
 **           *argv[] = array of command line arguments
 **  Output:  none
 **  Purpose: main program segment
 **
 **  Command line for stand-alone operation is:
 **    progname f1  f2  f3
 **  where progname = name of executable this code was compiled to,
 **  f1 = name of input file,
 **  f2 = name of report file (optional, stdout if left blank)
 **  f3 = name of binary output file (optional, nullfile if left blank).
 **--------------------------------------------------------------
 */
{
    char *f1,*f2,*f3;
    char blank[] = "";
    char errmsg[MAXMSG+1]="";
    int  errcode;
    int  version;
    char s[25];
    int major;
    int minor;
    int patch;

    /* get version from DLL and trasform in Major.Minor.Patch format
    instead of hardcoded version */
    ENgetversion(&version);
    major=  version/10000;
    minor=  (version%10000)/100;
    patch=  version%100;
    sprintf(s,FMT01, major , minor, patch);
    writeConsole(s);


    /* Check for proper number of command line arguments */
    if (argc < 2) {
        writeConsole(FMT03);
        return(1);
    }

    /* set inputfile name */
    f1 = argv[1];
    if (argc > 2) {
        /* set rptfile name */
        f2 = argv[2];
    }
    else {
        /* use stdout for rptfile */
        f2 = blank;
    }
    if (argc > 3) {
        /* set binary output file name */
        f3 = argv[3];
    }
    else {
        /* NO binary output*/
        f3 = blank;
    }

    /* Call the main control function */
    if (strlen(f2)> 0) {
        /* use stdout for progress messages */
        errcode = ENepanet(f1,f2,f3,writeConsole);
    }
    else {
        /* use stdout for reporting, no progress messages */
        errcode = ENepanet(f1,f2,f3,NULL);
    }

    /* Error/Warning check   */
    if (errcode == 0) {
        /* no errors */
        writeConsole(FMT09);
        return(0);
    }
    else {
        ENgeterror(errcode, errmsg, MAXMSG);
        writeConsole(errmsg);
        if (errcode > MAXWARNCODE) {
            /* error */
            writeConsole(FMT11);
            return(errcode);
        }
        else {
            /* warning */
            writeConsole(FMT10);
            return(0);
        }
    }


}                                       /* End of main */
Example #7
0
void DKHFastScanning(LPIMGDATA imgData){
	int i, j, clusterCount, maxSize;
	CLUSIMG clusImg;
	//ALLOCDATA delLists;
	float threshold, dist;
	Cluster *clusterList, *Ci, *lastClus;
	char strThreshold[16];
	
	clusterCount = 1;
	threshold = 45.0f;
	clusImg.width = imgData->width;
	clusImg.height = imgData->height;
	clusImg.pixClus = (void**)HeapAlloc(GetProcessHeap(),0,clusImg.width*clusImg.height*sizeof(void*));
	writeConsole("\nThreshold distance: ");
	readConsoleString(strThreshold);
	threshold = atof(strThreshold);
	if(threshold < 1.0f)
		threshold = 50.0f;
	writeConsoleFmt("We'll be using threshold %.2f\n",threshold);
	
	LPCOLOR thisPx = (LPCOLOR)imgData->bitmap;
	Ci = new Cluster(0,0,*thisPx,&clusImg);
	lastClus = clusterList = Ci;
	thisPx++;
	for(j = 1; j < clusImg.width; j++){
		Ci = getPixelCluster(clusterList,&clusImg,j-1,0);
		dist = getColorDistance(Ci->getTone(),*thisPx);
		if(dist < threshold)
			Ci->mergePoint(j,0,*thisPx);
		else{
			Ci = new Cluster(j,0,*thisPx,&clusImg);
			lastClus->setNext(Ci);
			Ci->setBefore(lastClus);
			lastClus = Ci;
			clusterCount++;
		}
		thisPx++;
	}
	
	for(i = 1; i < clusImg.height; i++){
		Ci = getPixelCluster(clusterList,&clusImg,0,i-1);
		
		dist = getColorDistance(Ci->getTone(),*thisPx);
		if(dist < threshold)
			Ci->mergePoint(0,i,*thisPx);
		else{
			Ci = new Cluster(0,i,*thisPx,&clusImg);
			lastClus->setNext(Ci);
			Ci->setBefore(lastClus);
			lastClus = Ci;
			clusterCount++;
		}
		thisPx++;
		
		for(j = 1; j < clusImg.width; j++){
			Cluster* Cu = getPixelCluster(clusterList,&clusImg,j,i-1);
			Cluster* Cl = getPixelCluster(clusterList,&clusImg,j-1,i);
			dist = getColorDistance(Cu->getTone(),*thisPx);
			if(dist < threshold){
				Cu->mergePoint(j,i,*thisPx);
				dist = getColorDistance(Cl->getTone(),*thisPx);
				if(dist < threshold){
					if(Cu != Cl){
						clusterCount--;
						if(Cl != clusterList){
							if(Cl == lastClus)
								lastClus = lastClus->getBefore();
							Cu->mergeCluster(Cl,clusterList);
						}else{
							if(Cu == lastClus)
								lastClus = lastClus->getBefore();
							Cl->mergeCluster(Cu,clusterList);
						}
				    }
				}
			}else{
				dist = getColorDistance(Cl->getTone(),*thisPx);
				if(dist < threshold)
					Cl->mergePoint(j,i,*thisPx);
				else{
					Ci = new Cluster(j,i,*thisPx,&clusImg);
					lastClus->setNext(Ci);
					Ci->setBefore(lastClus);
					lastClus = Ci;
					clusterCount++;
				}
			}
			thisPx++;
		}
		writeConsoleFmt("Line %d done. Cluster count %d.\n",i,clusterCount);
		//dbgShow(clusterList,&clusImg);
	}
	
	j = 0;
	//Remove small clusters (less than 1%)
	writeConsoleFmt("Wich it's the minimum cluster size(size threshold in percent)?");
	readConsoleString(strThreshold);
	threshold = atof(strThreshold)/100.0f;
	if(threshold > 0.1f){
		writeConsole("Too big. You should had inserted values lower than 10.0\n");
		threshold = 0.01f;
	}else if(threshold < 0.0001f){
		writeConsole("Too small. You should had inserted values greater than 0.01\n");
		threshold = 0.01f;
	}
	writeConsoleFmt("Minimal cluster size to image ratio: %.4f%%\n",threshold*100.0f);
	maxSize = (int)((clusImg.width*clusImg.height)*threshold);
	maxSize = (clusImg.width*clusImg.height)/400; //Get how much is 1%
	Ci = clusterList->getNext();
	i = 0;
	while(Ci != (Cluster*)NULL){
		if(Ci->getCount() < maxSize){
			Cluster* delClus = Ci;
			j++;
			writeConsoleFmt("Merging cluster %08x because of low pixel count: %d. Clusters deleted: %d\n",Ci,Ci->getCount(),j);
			Ci = Ci->getNext();
			clusterCount--;
			delClus->mergeClosest(clusterList);
			continue;
		}else if(Ci->getCount() > i){
			i = Ci->getCount();
		}
		Ci = Ci->getNext();
	}
	//HeapDestroy(delLists.hHeap);
	convertClustersBitmap(clusterList, &clusImg, imgData);
	
	writeConsoleFmt("%d clusters found.\n",clusterCount);
	
	//seekDiamonds(&clusImg,clusterList);
	
	lastClus = clusterList;
	//writeConsole("   ID         RGB        Count   Position,Box\n");
	while(clusterList != (Cluster*)NULL){
		clusterList = clusterList->getNext();
		//writeConsoleFmt("%08x (%3d,%3d,%3d) %9d %dx%d,%dx%d",lastClus,lastClus->getTone().red,lastClus->getTone().green,lastClus->getTone().blue,
		//lastClus->getCount(),lastClus->getLeft(),lastClus->getTop(),lastClus->getRight()-lastClus->getLeft(),lastClus->getBottom()-lastClus->getTop());
		lastClus->detectShape();
		delete lastClus;
		lastClus = clusterList;
	}
	
}
Example #8
0
int
ringBell (void) {
  static unsigned char bellSequence[] = {0X07};
  return writeConsole(bellSequence, sizeof(bellSequence));
}