/[rdesktop]/jpeg/rdesktop/trunk/serial.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /jpeg/rdesktop/trunk/serial.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 580 by astrand, Fri Jan 23 08:35:52 2004 UTC revision 602 by stargo, Sat Feb 7 17:32:21 2004 UTC
# Line 55  Line 55 
55    
56  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
57    
58  int serial_fd;  SERIAL_DEVICE *
59  struct termios termios;  get_serial_info(HANDLE handle)
   
 int dtr;  
 uint32 baud_rate;  
 uint32 queue_in_size, queue_out_size;  
 uint32 wait_mask;  
 uint8 stop_bits, parity, word_length;  
   
 SERIAL_DEVICE * get_serial_info(HANDLE handle)  
60  {  {
61          int index;          int index;
62    
# Line 198  get_termios(SERIAL_DEVICE * pser_inf, HA Line 190  get_termios(SERIAL_DEVICE * pser_inf, HA
190  }  }
191    
192  static void  static void
193  set_termios(void)  set_termios(SERIAL_DEVICE * pser_inf, HANDLE serial_fd)
194  {  {
195          speed_t speed;          speed_t speed;
196    
197          switch (baud_rate)          struct termios *ptermios;
198    
199            ptermios = pser_inf->ptermios;
200    
201    
202            switch (pser_inf->baud_rate)
203          {          {
204  #ifdef B75  #ifdef B75
205                  case 75:                  case 75:
# Line 286  set_termios(void) Line 283  set_termios(void)
283    
284          /* on systems with separate ispeed and ospeed, we can remember the speed          /* on systems with separate ispeed and ospeed, we can remember the speed
285             in ispeed while changing DTR with ospeed */             in ispeed while changing DTR with ospeed */
286          cfsetispeed(&termios, speed);          cfsetispeed(pser_inf->ptermios, speed);
287          cfsetospeed(&termios, dtr ? speed : 0);          cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0);
288    
289          termios.c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE);          ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE);
290          switch (stop_bits)          switch (pser_inf->stop_bits)
291          {          {
292                  case STOP_BITS_2:                  case STOP_BITS_2:
293                          termios.c_cflag |= CSTOPB;                          ptermios->c_cflag |= CSTOPB;
294                          break;                          break;
295          }          }
296          switch (parity)          switch (pser_inf->parity)
297          {          {
298                  case EVEN_PARITY:                  case EVEN_PARITY:
299                          termios.c_cflag |= PARENB;                          ptermios->c_cflag |= PARENB;
300                          break;                          break;
301                  case ODD_PARITY:                  case ODD_PARITY:
302                          termios.c_cflag |= PARENB | PARODD;                          ptermios->c_cflag |= PARENB | PARODD;
303                          break;                          break;
304          }          }
305          switch (word_length)          switch (pser_inf->word_length)
306          {          {
307                  case 5:                  case 5:
308                          termios.c_cflag |= CS5;                          ptermios->c_cflag |= CS5;
309                          break;                          break;
310                  case 6:                  case 6:
311                          termios.c_cflag |= CS6;                          ptermios->c_cflag |= CS6;
312                          break;                          break;
313                  case 7:                  case 7:
314                          termios.c_cflag |= CS7;                          ptermios->c_cflag |= CS7;
315                          break;                          break;
316                  default:                  default:
317                          termios.c_cflag |= CS8;                          ptermios->c_cflag |= CS8;
318                          break;                          break;
319          }          }
320    
321          tcsetattr(serial_fd, TCSANOW, &termios);          tcsetattr(serial_fd, TCSANOW, ptermios);
322  }  }
323    
324  /* Enumeration of devices from rdesktop.c        */  /* Enumeration of devices from rdesktop.c        */
# Line 330  set_termios(void) Line 327  set_termios(void)
327  /* when it arrives to this function.              */  /* when it arrives to this function.              */
328  /* :com1=/dev/ttyS0,com2=/dev/ttyS1 */  /* :com1=/dev/ttyS0,com2=/dev/ttyS1 */
329  int  int
330  serial_enum_devices(int *id, char *optarg)  serial_enum_devices(uint32 *id, char *optarg)
331  {  {
332          SERIAL_DEVICE *pser_inf;          SERIAL_DEVICE *pser_inf;
333    
# Line 380  serial_create(uint32 device_id, uint32 a Line 377  serial_create(uint32 device_id, uint32 a
377          serial_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR | O_NOCTTY);          serial_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR | O_NOCTTY);
378    
379          if (serial_fd == -1)          if (serial_fd == -1)
380            {
381                    perror("open");
382                  return STATUS_ACCESS_DENIED;                  return STATUS_ACCESS_DENIED;
383            }
384    
385          if (!get_termios(pser_inf, serial_fd))          if (!get_termios(pser_inf, serial_fd))
386                  return STATUS_ACCESS_DENIED;                  return STATUS_ACCESS_DENIED;
# Line 392  serial_create(uint32 device_id, uint32 a Line 392  serial_create(uint32 device_id, uint32 a
392          printf("INFO: SERIAL %s to %s\nINFO: speed %u baud, stop bits %u, parity %u, word length %u bits, dtr %u\n", g_rdpdr_device[device_id].name, g_rdpdr_device[device_id].local_path, pser_inf->baud_rate, pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length, pser_inf->dtr);          printf("INFO: SERIAL %s to %s\nINFO: speed %u baud, stop bits %u, parity %u, word length %u bits, dtr %u\n", g_rdpdr_device[device_id].name, g_rdpdr_device[device_id].local_path, pser_inf->baud_rate, pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length, pser_inf->dtr);
393          printf("INFO: use stty to change settings\n");          printf("INFO: use stty to change settings\n");
394    
395          //tcgetattr(serial_fd, pser_inf->ptermios);  /*      ptermios->c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;
396            ptermios->c_cflag |= CREAD;
397            ptermios->c_lflag |= ICANON;
398            ptermios->c_iflag = IGNPAR | ICRNL;
399    
400            tcsetattr(serial_fd, TCSANOW, ptermios);
401    */
402    
403          *handle = serial_fd;          *handle = serial_fd;
404    
405            /* all read and writes should be non blocking */
406            if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1)
407                    perror("fcntl");
408    
409          return STATUS_SUCCESS;          return STATUS_SUCCESS;
410  }  }
411    
412  static NTSTATUS  static NTSTATUS
413  serial_close(HANDLE handle)  serial_close(HANDLE handle)
414  {  {
415          close(serial_fd);          g_rdpdr_device[get_device_index(handle)].handle = 0;
416            close(handle);
417          return STATUS_SUCCESS;          return STATUS_SUCCESS;
418  }  }
419    
# Line 412  serial_read(HANDLE handle, uint8 * data, Line 424  serial_read(HANDLE handle, uint8 * data,
424          SERIAL_DEVICE *pser_inf;          SERIAL_DEVICE *pser_inf;
425          struct termios *ptermios;          struct termios *ptermios;
426    
427          timeout = 0;          timeout = 90;
428          pser_inf = get_serial_info(handle);          pser_inf = get_serial_info(handle);
429          ptermios = pser_inf->ptermios;          ptermios = pser_inf->ptermios;
430    
# Line 444  serial_read(HANDLE handle, uint8 * data, Line 456  serial_read(HANDLE handle, uint8 * data,
456          }          }
457          tcsetattr(handle, TCSANOW, ptermios);          tcsetattr(handle, TCSANOW, ptermios);
458    
459    
460          *result = read(handle, data, length);          *result = read(handle, data, length);
461    
462          return STATUS_SUCCESS;          return STATUS_SUCCESS;
463  }  }
464    
# Line 460  serial_device_control(HANDLE handle, uin Line 474  serial_device_control(HANDLE handle, uin
474  {  {
475          uint32 result;          uint32 result;
476          uint8 immediate;          uint8 immediate;
477            SERIAL_DEVICE *pser_inf;
478            struct termios *ptermios;
479    
480          if ((request >> 16) != FILE_DEVICE_SERIAL_PORT)          if ((request >> 16) != FILE_DEVICE_SERIAL_PORT)
481                  return STATUS_INVALID_PARAMETER;                  return STATUS_INVALID_PARAMETER;
482    
483            pser_inf = get_serial_info(handle);
484            ptermios = pser_inf->ptermios;
485    
486          /* extract operation */          /* extract operation */
487          request >>= 2;          request >>= 2;
488          request &= 0xfff;          request &= 0xfff;
# Line 473  serial_device_control(HANDLE handle, uin Line 492  serial_device_control(HANDLE handle, uin
492          switch (request)          switch (request)
493          {          {
494                  case SERIAL_SET_BAUD_RATE:                  case SERIAL_SET_BAUD_RATE:
495                          in_uint32_le(in, baud_rate);                          in_uint32_le(in, pser_inf->baud_rate);
496                          set_termios();                          set_termios(pser_inf, handle);
497                          break;                          break;
498                  case SERIAL_GET_BAUD_RATE:                  case SERIAL_GET_BAUD_RATE:
499                          out_uint32_le(out, baud_rate);                          out_uint32_le(out, pser_inf->baud_rate);
500                          break;                          break;
501                  case SERIAL_SET_QUEUE_SIZE:                  case SERIAL_SET_QUEUE_SIZE:
502                          in_uint32_le(in, queue_in_size);                          in_uint32_le(in, pser_inf->queue_in_size);
503                          in_uint32_le(in, queue_out_size);                          in_uint32_le(in, pser_inf->queue_out_size);
504                          break;                          break;
505                  case SERIAL_SET_LINE_CONTROL:                  case SERIAL_SET_LINE_CONTROL:
506                          in_uint8(in, stop_bits);                          in_uint8(in, pser_inf->stop_bits);
507                          in_uint8(in, parity);                          in_uint8(in, pser_inf->parity);
508                          in_uint8(in, word_length);                          in_uint8(in, pser_inf->word_length);
509                          set_termios();                          set_termios(pser_inf, handle);
510                          break;                          break;
511                  case SERIAL_GET_LINE_CONTROL:                  case SERIAL_GET_LINE_CONTROL:
512                          out_uint8(out, stop_bits);                          out_uint8(out, pser_inf->stop_bits);
513                          out_uint8(out, parity);                          out_uint8(out, pser_inf->parity);
514                          out_uint8(out, word_length);                          out_uint8(out, pser_inf->word_length);
515                          break;                          break;
516                  case SERIAL_IMMEDIATE_CHAR:                  case SERIAL_IMMEDIATE_CHAR:
517                          in_uint8(in, immediate);                          in_uint8(in, immediate);
# Line 523  serial_device_control(HANDLE handle, uin Line 542  serial_device_control(HANDLE handle, uin
542                          out_uint8s(out, 20);                          out_uint8s(out, 20);
543                          break;                          break;
544                  case SERIAL_GET_WAIT_MASK:                  case SERIAL_GET_WAIT_MASK:
545                          out_uint32(out, wait_mask);                          out_uint32(out, pser_inf->wait_mask);
546                          break;                          break;
547                  case SERIAL_SET_WAIT_MASK:                  case SERIAL_SET_WAIT_MASK:
548                          in_uint32(in, wait_mask);                          in_uint32(in, pser_inf->wait_mask);
549                          break;                          break;
550                  case SERIAL_SET_DTR:                  case SERIAL_SET_DTR:
551                          dtr = 1;                          pser_inf->dtr = 1;
552                          set_termios();                          set_termios(pser_inf, handle);
553                          break;                          break;
554                  case SERIAL_CLR_DTR:                  case SERIAL_CLR_DTR:
555                          dtr = 0;                          pser_inf->dtr = 0;
556                          set_termios();                          set_termios(pser_inf, handle);
557                          break;                          break;
558  #if 0  #if 0
559                  case SERIAL_WAIT_ON_MASK:                  case SERIAL_WAIT_ON_MASK:
# Line 579  serial_device_control(HANDLE handle, uin Line 598  serial_device_control(HANDLE handle, uin
598    
599  /* Read timeout for a given file descripter (device) when adding fd's to select() */  /* Read timeout for a given file descripter (device) when adding fd's to select() */
600  BOOL  BOOL
601  serial_get_timeout(uint32 handle, uint32 length, uint32 * timeout, uint32 * itv_timeout)  serial_get_timeout(HANDLE handle, uint32 length, uint32 * timeout, uint32 * itv_timeout)
602  {  {
603          int index;          int index;
604          SERIAL_DEVICE *pser_inf;          SERIAL_DEVICE *pser_inf;

Legend:
Removed from v.580  
changed lines
  Added in v.602

  ViewVC Help
Powered by ViewVC 1.1.26