Advertisement
bicepjai

host_linux_sending_io_com

Sep 22nd, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. /*
  2.  * T X _ D A T A -- Writes n bytes of data to communication device.  
  3.  */
  4. /*
  5.  * Call with: k = pointer to Kermit struct. p = pointer to data to
  6.  * transmit. n = length. Returns: X_OK on success. X_ERROR on failure to
  7.  * write - i/o error.
  8.  */
  9. int
  10. tx_data (struct k_data *k, UCHAR * p, int n)
  11. {
  12.    int x;
  13.    int i;
  14.    int max = 10;                /* Loop breaker */
  15.    long usecs;
  16.     UCHAR * p1;
  17.  
  18.    debug (DB_LOG, "TX_DATA write n=", 0, n);
  19.  
  20.    usleep (k->send_pause_us);
  21.  
  22. #if SIMULATED_RTT > 0
  23.    sleep (SIMULATED_RTT);
  24. #endif
  25.    printf("TX_DATA write n=%d\n",n);
  26.     for(i=0;i<n;i++){
  27.     printf("_(%c)_",*(p+i));
  28.     }
  29.    while (n > 0)
  30.    {                            /* Keep trying till done */
  31.  
  32.       printf("\nretrying tx_data x=%d n=%d\n", x, n);
  33.       for(i=0;i<n;i++){
  34.     x = write (ttyfd, (p+i), 1);
  35.     printf("%d]_%2.0x(%c)_\n",i,*(p),*(p));
  36.     usleep (1000000);
  37.     n -= x;
  38.     p += x;
  39.       }
  40.     printf("end\n");
  41.  
  42.       //x = write (ttyfd, p, n);
  43.       max--;
  44.       debug (DB_LOG, "TX_DATA write x=", 0, x);
  45.       if (x == -1 && max > 0)
  46.       {
  47.          usecs = k->s_maxlen * (10000000L / k->baud);
  48.          debug (DB_LOG, "TX_DATA sleeping usecs", 0, usecs);
  49.          usleep (usecs);
  50.          continue;
  51.       }
  52.       if (x < 0 || max < 1)     /* Errors are fatal */
  53.       {
  54.          debug (DB_LOG, "TX_DATA X_ERROR, max", 0, max);
  55.          return (X_ERROR);
  56.       }
  57.       //n -= x;
  58.       //p += x;
  59.    }
  60.    return (X_OK);               /* Success */
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement