Exemple #1
0
void
badboy_fork ()
{
	int status, pid;

      status = fork ();
      badboy_pid = status;
      if (status == 0)	/* badboy */
	{
#ifdef DEBUG_LATE_BADBOY
	  sleep(ntries*MAX_TRY_TIME+10);
#else
	  badboy_loop ();
#endif
	  exit (0);	/* tough guy */
	}
      else if (status < 0)
	perror ("fork");
      else			/* parent watching over badboy */
	{
	  if (verbose_level > 3)
	  	printf ("badboy pid = %d\n", badboy_pid);

/* don't trust the child to return at night */
      my_signal (SIGALRM, monitor_fcn);
      alarm (ntries*MAX_TRY_TIME);

	  pid = waitpid (-1, &status, WUNTRACED);
	  if (pid <= 0)
	  {
		  perror ("wait");
	  } else {
	  	if (verbose_level > 3)
		  printf ("pid %d exited with status %d\n", pid, status);
		#if 0
		record_status(status);
		#endif
	   }
	}	/* parent */
	alarm(0);
}
Exemple #2
0
void badboy_fork()
{
	int status, pid;
	pid_t child;
	child = fork();
	badboy_pid = status;
	switch (child) {
	case -1:
		perror("fork");
	case 0:
#ifdef DEBUG_LATE_BADBOY
		sleep(ntries * MAX_TRY_TIME + 10);
#else
		badboy_loop();
#endif
		exit(0);
	default:
		if (verbose_level > 3)
			printf("badboy pid = %d\n", badboy_pid);

		/* don't trust the child to return at night */
		my_signal(SIGALRM, monitor_fcn);
		alarm(ntries * MAX_TRY_TIME);

		pid = waitpid(-1, &status, WUNTRACED);
		if (pid <= 0)
			perror("wait");
		else {
			if (verbose_level > 3)
				printf("pid %d exited with status %d\n",
				       pid, status);
#if 0
			record_status(status);
#endif
		}
	}
	alarm(0);
}
Exemple #3
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{

    FILE*       fp = NULL;
    int         fd;
    int         i;
    int         total_msg_cnt,cnt;
    int         log_flag;
    u_int16_t   buf_len;
    char buff[BUFSIZE];
    char *outputFileName;

    log_flag = 1;
    csi_status = (csi_struct*)malloc(sizeof(csi_struct));
    /* check usage */
    if (0 == nrhs){
        log_flag  = 0;
        mexPrintf("/*   log off   */\n");
    }
    if (1 == nrhs){
        mexPrintf("/*   log on    */\n");
        mxGetString(prhs[0], buff, BUFSIZE);
        sprintf(outputFileName, "%s", buff);
        fp = fopen(outputFileName,"a");
        if (!fp){
            mexPrintf("Fail to open <output_file>, are you root?\n");
            fclose(fp);
            set_err_return_value(plhs, nlhs, 1);
            return;
        }
    }
    if (nrhs > 1){
        mexPrintf(" Too many input arguments !\n");
        set_err_return_value(plhs, nlhs, 1);
        return;
    }

    fd = open_csi_device();
    if (fd < 0){
        perror("Failed to open the device...");
        set_err_return_value(plhs, nlhs, errno);
        return;
    }

    mexPrintf("#Receiving data! Press Ctrl+C to quit!\n");

    quit = 0;
    total_msg_cnt = 0;

    while(1){
        if (1 == quit)
            break;

        /* keep listening to the kernel and waiting for the csi report */
        cnt = read_csi_buf(buf_addr,fd,BUFSIZE);

        if (cnt){
            total_msg_cnt += 1;

            /* fill the status struct with information about the rx packet */
            record_status(buf_addr, cnt, csi_status);

            /*
             * fill the payload buffer with the payload
             * fill the CSI matrix with the extracted CSI value
             */
            record_csi_payload(buf_addr, csi_status, data_buf, csi_matrix);

            /* Till now, we store the packet status in the struct csi_status
             * store the packet payload in the data buffer
             * store the csi matrix in the csi buffer
             * with all those data, we can build our own processing function!
             */
            /*porcess_csi(data_buf, csi_status, csi_matrix);*/

            /*Return the csi_matrix combined with csi_status properly.*/
            int k, nc_idx, nr_idx;
            int nr = csi_status->nr;
            int nc = csi_status->nc;
            int num_tones = csi_status->num_tones;

            mxArray *csi = csiMatrix2mxArray(csi_matrix, nr, nc, num_tones);

            const char *fieldNames[] = {"channel", "chanBW", "rate",
                                        "nr", "nc", "num_tones",
                                        "rssi", "rssi_0", "rssi_1",
                                        "rssi_2", "payload_len", "csi"};
#define NUMBER_OF_FIELDS (sizeof(fieldNames)/sizeof(*fieldNames))
            plhs[0] = mxCreateStructMatrix(1, 1, NUMBER_OF_FIELDS, fieldNames);

            int fieldNumbers[NUMBER_OF_FIELDS];
            for (k = 0; k < NUMBER_OF_FIELDS; k++)
                fieldNumbers[k] = mxGetFieldNumber(plhs[0], fieldNames[k]);
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[0], mxCreateDoubleScalar((double)csi_status->channel));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[1], mxCreateDoubleScalar((double)csi_status->chanBW));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[2], mxCreateDoubleScalar((double)csi_status->rate));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[3], mxCreateDoubleScalar((double)csi_status->nr));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[4], mxCreateDoubleScalar((double)csi_status->nc));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[5], mxCreateDoubleScalar((double)csi_status->num_tones));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[6], mxCreateDoubleScalar((double)csi_status->rssi));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[7], mxCreateDoubleScalar((double)csi_status->rssi_0));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[8], mxCreateDoubleScalar((double)csi_status->rssi_1));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[9], mxCreateDoubleScalar((double)csi_status->rssi_2));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[10], mxCreateDoubleScalar((double)csi_status->payload_len));
            mxSetFieldByNumber(plhs[0], 0, fieldNumbers[11], csi);

            mexPrintf("Recv %dth msg with rate: 0x%02x | payload len: %d\n",total_msg_cnt,csi_status->rate,csi_status->payload_len);

            /* log the received data for off-line processing */
            if (log_flag){
                buf_len = csi_status->buf_len;
                fwrite(&buf_len,1,2,fp);
                fwrite(buf_addr,1,buf_len,fp);
            }
            else break;
        }
    }
    if (fp)
        fclose(fp);
    close_csi_device(fd);
    free(csi_status);
    return;
}