#include #include #include #include #include #include #include #include #include #include "period.h" static float *data; static struct my_msg_struct *msg; static void emergency_stop(int d) { msg->command = STOP_TASK; rtai_free (nam2num("data"), data); rtai_free (nam2num("msg"), msg); exit(1); } int main(int argc, char *argv[]) { int i, j, count; if((data = (float *)rtai_malloc(nam2num("data"), 0)) == NULL){ printf("rtai_malloc() failed (maybe /dev/rtai_shm is missing)!\n"); return -1; } if((msg = (struct my_msg_struct *)rtai_malloc(nam2num("msg"), 0)) == NULL){ printf("rtai_malloc() failed (maybe /dev/rtai_shm is missing)!\n"); return -1; } msg->command = STOP_TASK; signal(SIGINT, emergency_stop); data[BUF_LEN * (RECORDING_SAMPLES - 1)] = -1.; /* Now start the tasks */ fprintf(stderr, "Starting real time task ... "); msg->command = START_TASK; fprintf(stderr, "done.\n"); fprintf(stderr, "Waiting for record ... "); while (data[BUF_LEN * (RECORDING_SAMPLES - 1)] < 0.){ fprintf(stderr, "\r"); // ここを空行にすると、何故か終了判定が働かなくなる。 } /* 正常にデータが書きこまれれば,正になる */ fprintf(stderr, "done.\n"); count = 0; for(i = 0; i < RECORDING_SAMPLES; i++){ for(j = 0; j < BUF_LEN; j++){ fprintf(stdout, "%g ", data[count++]); } fprintf(stdout, "\n"); } rtai_free (nam2num("data"), data); rtai_free (nam2num("msg"), msg); return 0; }