home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_03 / 9n03054a < prev    next >
Text File  |  1990-12-10  |  2KB  |  62 lines

  1. Listing 4 (lidar_read.c) 
  2. /* ---
  3.    lidar_read task. This task initializes shared 
  4.    memory, waits for a  message, reads a frame 
  5.    buffer from the digitizer, and sends a message
  6.    to the write task when the frame buffer is full.  
  7. --- */
  8.  
  9. #include    "lidar.h"
  10.  
  11. main()
  12. {
  13.     int     ieee_488;
  14.     int     read_qid, write_qid;
  15.     int     alive_sem;
  16.     int     terminate = FALSE;
  17.     char    *fb_shm; 
  18.     message mptr;
  19.  
  20.     /* --- set process prioprity --- */
  21.     setpriority (PRIO_PROCESS, 0, LIDAR_READ);
  22.  
  23.     /* --- open message queues --- */
  24.     read_qid = msgget (READ_Q, 0666 | IPC_CREAT);
  25.     write_qid = msgget (WRITE_Q, 0666 | IPC_CREAT);
  26.  
  27.     /* --- get semaphore --- */
  28.     alive_sem = sem_get (ALIVE_KEY, 0);
  29.  
  30.     /* -- create shared memory frame buffers  -- */
  31.     fb_shm = shmat(shmget (FB_KEY, FRAME_SIZE*N_FRAMES, 
  32.                    0666|IPC_CREAT), 0, 0);
  33.  
  34.     /* --- open ieee file and set up digitizer --- */
  35.     ieee_488 = init_digitizer ();
  36.  
  37.     /* --- tell the world we're open for business --- */
  38.     sem_signal (alive_sem);
  39.  
  40.     /* --- while lidar data acquisition program running --- */
  41.     while (!terminate) {
  42.        /* --- wait for a message to start read --- */
  43.        msgrcv (read_qid, &mptr, MSG_SIZE, ANYTYPE, NOFLAGS);
  44.  
  45.        /* --- check for quit --- */
  46.        if (mptr.key == QUIT)
  47.           terminate = 1;
  48.        else 
  49.           read_digitizer (ieee_488, fb_shm + 
  50.                           mptr.key * FRAME_SIZE);
  51.        
  52.        /* --- send the message on to the write task --- */
  53.        msgsnd (write_qid, &mptr, MSG_SIZE, IPC_NOWAIT);
  54.        }
  55.  
  56.     /* --- close digitizer file --- */
  57.     close_digitizer (ieee_488);
  58.  
  59.     /* --- release memory --- */
  60.     shmdt (fb_shm);
  61. }
  62.