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

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /*            CSAMP Sample Program, Support Procedures                */
  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.  
  14. /*    Forward declarations */
  15. extern void delay_fine();
  16. extern void delay();
  17.  
  18. /**********************************************************************/
  19. /*  C_DATA                                                            */
  20. /**********************************************************************/
  21. void c_data()
  22. {
  23.     char            array1[12];
  24.     int             i;
  25.  
  26.     struct struc1_type {
  27.         char            xchar;
  28.         short int       xshort;
  29.         int             xint;
  30.         unsigned int    xunint;
  31.     } struc1;
  32.  
  33.     struct customertype {
  34.         char                    name[8];
  35.         char                    phone[7];    
  36.         struct     customertype    *linkfor;
  37.     } customerlist[3];
  38.     
  39.     struct customertype    *customer,*oldcust;
  40.  
  41.     static char    *name_init[3] = {
  42.                  "Beth    ",
  43.                  "Steve   ",
  44.                  "Becky   "
  45.     };
  46.  
  47.     static char    *phone_init[3] = {
  48.                 "5551234",
  49.                 "5555678",
  50.                 "5554321"
  51.     };
  52.     /*  Format for a simple (unreal) Ethernet packet
  53.  
  54.     +----------------------------------------------------+
  55.     | P | Dest  | Source | Type |  Data            | CRC |
  56.     +----------------------------------------------------+
  57.     31  28      24       20     17                 1     0
  58.     */
  59.  
  60.     struct enet_pkt_type {
  61.         unsigned int    crc:2;
  62.         unsigned int    data:16;
  63.         unsigned int    pkt_type:3;
  64.         unsigned int    source_addr:4;
  65.         unsigned int     dest_addr:4;
  66.         unsigned int    preamble:3;
  67.     } enet_pkt;
  68.  
  69.     for( i = 0 ; i <= 11 ; i++ )
  70.         array1[i]= (char)i + ' ';
  71.     
  72.     struc1.xchar     = '!';
  73.     struc1.xshort    = -10;
  74.     struc1.xint      = 1;
  75.     struc1.xunint    = 6;
  76.     
  77.     enet_pkt.data = 4096;
  78.     enet_pkt.crc = 1;
  79.     enet_pkt.pkt_type = 3;
  80.     enet_pkt.source_addr = 10;
  81.     enet_pkt.dest_addr = 12;
  82.     enet_pkt.preamble = 7;
  83.     
  84.     customer = NULL;
  85.     for(i=0;i<=2;i++){
  86.         oldcust = customer;
  87.         customer = &customerlist[i];
  88.         strcpy(customerlist[i].name,name_init[i]);
  89.         strcpy(customerlist[i].phone,phone_init[i]);
  90.         customer->linkfor = NULL;
  91.         if (oldcust != NULL)
  92.             oldcust->linkfor = customer;
  93.     }
  94. }
  95.  
  96.  
  97. void delay (msecs)
  98. int msecs;
  99. {
  100.     int         sleep100;            /*  Each unit of "sleep100" is 100 msecs.    */
  101.  
  102.     sleep100 = msecs / 100;
  103.  
  104.     for (; sleep100 >= 0; sleep100--)
  105.         delay_fine (10);        /*  delay_fine(10) delays for 100 msecs.     */
  106. }
  107.  
  108.  
  109. static void delay_fine (count)
  110. int count;
  111. {
  112.     WORD        exception;
  113.  
  114.     if (count != 0) {
  115.         rqsleep (1, &exception);    /*  One rqsleep unit is 10 msecs. */
  116.         delay_fine (--count );        /*  Call self recursively.          */
  117.     }
  118. }
  119.