Exemple #1
0
int main(int argc, char* argv[])
{
	//==================================================//
    // Check to make sure enough arguments are input:   //
    //==================================================//    
    if (argumentCheck(argc, argv) != 0) {
        return -1;
    }

	//==================================================//
    // Open USB HID:		                            //
    //==================================================//
    if (hidOpen() != 0) {
        return -1;
    }

	//==================================================//
    // Create Log File:                                 //
    //==================================================//
    if (logSetup(argv) != 0) {
        return -1;
    }

	//==================================================//
    // System ready...                                  //
    //==================================================//
    printf("\nREADY! Now logging...\n\n");

    //==================================================//
    // Run until error or user-terminated:              //
    //==================================================//
    int run = 1;
	while (run) {
		readTask();
		run = KB.kbhit() ? 0 : 1;
	}

	//==================================================//
    // Closing house-keeping tasks:                     //
    //==================================================//
	hid_close(hHID);
	fclose(fOutput);
	hid_exit();

	return EXIT_SUCCESS;
}
//main function
int main(int argc,char* argv[]){

	int iMatrixSize,numOfMatrices;
	int i_x,i_y,iCtr;
	double dMatrix[MAX_SIZE_MATRIX][MAX_SIZE_MATRIX];
	char c='.';
	srand(time(NULL));


	if (signal(SIGINT, signalHandler) == SIG_ERR ) {
		fputs("An error occurred while setting a signal handler.\n", stderr);
		finalize();
	}

	//Argument check
	if(argc!=3){
		//usage();
		exit(1);
	}

	if(!argumentCheck(argv[1],argv[2])){
		fprintf(stderr,"Arguments are not valid\n");
		exit(1);
	}
	
	iMatrixSize=atoi(argv[1]);
	numOfMatrices = atoi(argv[2]);
	//open message queue
    if ((key = ftok("matrixGenerator.c", 'B')) == -1) {
        perror("ftok");
        exit(1);
    }

    if ((msqid = msgget(key, 0644 | IPC_CREAT)) == -1) {
        perror("msgget");
        exit(1);
    }
    
    buf.mtype=1;   
    
    //generating matrices and sending them to lu module loop
    for(iCtr=0;iCtr<numOfMatrices;++iCtr){
		//matrix generation
		matrixGenerateRandVal(dMatrix,iMatrixSize);
		//assign the message queue struct
		for(i_x=0;i_x<iMatrixSize;i_x++){
			for(i_y=0;i_y<iMatrixSize;i_y++){
				buf.myArray[i_x][i_y]=dMatrix[i_x][i_y];
			}
		}
		buf.numberOfMatrices=numOfMatrices;
		printMatrix(dMatrix,iMatrixSize);
		//message sending
		if (msgsnd(msqid, &buf, sizeof(buf.myArray)+
								sizeof(buf.numberOfMatrices), 0) == -1)
            perror("msgsnd");
		
	}
	//waiting for user
	do {
		c=getchar();
	}while (c == '.');
	//close message queue
	if (msgctl(msqid, IPC_RMID, NULL) == -1) {
        perror("msgctl");
        exit(1);
    }
    
	return 0;
}