home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s038 / 11.ddi / SSCOPE.LIF / CMAIN.C next >
Encoding:
C/C++ Source or Header  |  1992-07-02  |  5.2 KB  |  188 lines

  1. /*********************************************************/
  2. /*                                                       */
  3. /*                   CSAMP Sample Program                */
  4. /*                                                       */
  5. /*********************************************************/ 
  6.                  
  7. #include <stdarg.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <rmxc.h>
  13. #include "cutils.h"
  14.  
  15. #define UINT_8        unsigned char
  16. #define UINT_16        unsigned short
  17. #define UINT_32        unsigned long
  18. #define FALSE        0
  19. #define TRUE        1
  20.  
  21. #define    COUNT_PRIORITY        (BYTE) 200        /* Priority of count task        */
  22. #define    PROCESS_PRIORITY    (BYTE) 200        /* Priority of process task      */
  23. #define    BUFF_LEN            125                /* Length of buffer in MSG_STRUC */
  24. #define    DATA_MBOX            (WORD) 0x20        /* Code for creation of data mbx.*/
  25. #define    MAX_COUNT            (WORD) 0xffff    /* UI16_MAX                      */
  26. #define    NULL_TOKEN            (TOKEN) NULL
  27.  
  28. UINT_32        module_data;          /* Used in the create task system call */
  29.                                   /* Identifies the data segment         */
  30.  
  31. typedef struct {
  32.     short            count;
  33.     unsigned char    fillchar;
  34.     unsigned char    buffer[BUFF_LEN];
  35. } MSG_STRUC;
  36.  
  37. TOKEN             count_token;        /* Token for count task              */
  38. TOKEN            process_token;        /* Token for process task            */
  39. int                counter;            /* count_task's counter              */
  40.  
  41. void far main()
  42. {
  43.     UINT_16            exception;    /* Status code returned from system calls    */
  44.             
  45.     TOKEN            main_mbox;          /* Token for main task's mailbox     */
  46.     TOKEN            proc_mbox;          /* Token for process task's mailbox  */
  47.     UINT_16            msg_length;            /* Actual length of received message.*/
  48.     MSG_STRUC        msg;                 /* Message to be sent/received       */
  49.     UINT_16            msg_count;
  50.     UINT_16            i;
  51.  
  52.     extern void far count_task ();
  53.     extern void far process_task ();
  54.     
  55.     printf("Soft-Scope III 'C' Sample Session\r\n");
  56.  
  57.     /*
  58.      *  Create the mailbox for main task
  59.      */
  60.     main_mbox = rqcreatemailbox (DATA_MBOX, &exception);
  61.     /*
  62.      *  Catalog the mailbox token in the object directory
  63.      */
  64.     rqcatalogobject (NULL_TOKEN, main_mbox, (STRING*)"\010Main Box", &exception);
  65.  
  66.     /*
  67.      *  Create the process mailbox 
  68.      */
  69.     proc_mbox = rqcreatemailbox (DATA_MBOX, &exception);
  70.     /*
  71.      *  Catalog the mailbox token in the object directory
  72.      */
  73.     rqcatalogobject (0, proc_mbox, (STRING*)"\013Process Box", &exception);
  74.  
  75.     /*
  76.      *  Create tasks...
  77.      */
  78.     count_token = rqcreatetask (
  79.                 COUNT_PRIORITY,                        /* priority.         */
  80.                 (void (far *)(void))&count_task,    /* start address.    */
  81.                 (selector)&module_data,                /* data segment.     */
  82.                 0,                                    /* stack pointer.    */
  83.                 4096,                                /* stack size.       */
  84.                 0,                                    /* flags (no NPX).   */
  85.                 &exception);                        /* exception ptr.    */
  86.  
  87.     process_token = rqcreatetask (
  88.                 PROCESS_PRIORITY,                    /* priority.         */
  89.                 (void (far *)(void))&process_task,    /* start address.    */
  90.                 (selector)&module_data,                /* data segment.     */
  91.                 0,                                    /* stack pointer.    */
  92.                 4096,                                /* stack size.       */
  93.                 0,                                    /* flags (no NPX).   */
  94.                 &exception);                        /* exception ptr.    */
  95.  
  96.     msg_count = 0;
  97.     while(1)  {
  98.         msg.fillchar = '*';
  99.         if (msg_count >= MAX_COUNT)
  100.             msg_count = 0;
  101.         else
  102.             msg.count = msg_count++;
  103.         memset (msg.buffer, 0, sizeof (msg.buffer));
  104.         /*
  105.          *  Send data to process task to fill msg.buffer with fillchar
  106.          */
  107.         rqsenddata (main_mbox, 
  108.                     (STRING *)&msg, 
  109.                     sizeof (msg), 
  110.                     &exception);    
  111.         /*
  112.          *  Receive data back from process task 
  113.          */
  114.         msg_length = rqreceivedata (proc_mbox,
  115.                                      (STRING *)&msg,
  116.                                      0xffff,
  117.                                      &exception);
  118.     }
  119. }
  120.  
  121.  
  122.  
  123. void far process_task ()
  124. {
  125.     WORD            exception;    /* Status code returned from system calls    */
  126.     TOKEN            main_mbox;    /* Token for the read meter task's mailbox.  */
  127.     TOKEN            proc_mbox;    /* Token for update database task's mailbox. */
  128.     UINT_16            msg_length;    /* Actual length of received message.        */
  129.     MSG_STRUC        msg;        /* Message to be processed.                  */
  130.     unsigned char    pattern;
  131.     UINT_8            i;
  132.     
  133.     /*
  134.      *  Lookup the process task mailbox token from the object
  135.      *  directory.
  136.      */
  137.     proc_mbox = rqlookupobject (0, (STRING*) "\013Process Box", 0xffff, &exception);
  138.  
  139.     /*
  140.      *  Lookup the main task mailbox token from the object
  141.      *  directory.
  142.      */
  143.     main_mbox = rqlookupobject (0, (STRING*) "\010Main Box", 0xffff, &exception);
  144.  
  145.     /*
  146.      *  Loop forever responding to requests.
  147.      */    
  148.     while (1)  {    
  149.         
  150.         /*
  151.          *  Receive the next request 
  152.          */
  153.         msg_length = rqreceivedata (main_mbox,
  154.                                      (STRING *)&msg,
  155.                                      0xffff,
  156.                                      &exception);
  157.  
  158.         /*
  159.          *  Take action on the received message (fill msg.buffer)
  160.          */
  161.         for (i = 0; i < BUFF_LEN; i++)  {
  162.             msg.buffer[i] = msg.fillchar;
  163.         }
  164.  
  165.         delay (1000);        /*  Sleep for about 1 sec. so others can run.    */
  166.         /*
  167.          *  Send response
  168.          */
  169.         rqsenddata (proc_mbox, 
  170.                     (STRING *)&msg, 
  171.                     sizeof (msg), 
  172.                     &exception);    
  173.     }
  174. }
  175.  
  176. void far count_task ()
  177. {
  178.     WORD            exception;    /* Status code returned from system calls    */
  179.  
  180.     counter = 0;
  181.  
  182.     while (1)  {
  183.         counter++;
  184.         delay (1000);
  185.         c_data ();
  186.     }
  187. }
  188.