示例#1
0
文件: serial.c 项目: Jeija/gtkterm
int Send_chars(char *string, int length)
{
	int bytes_written = 0;

	if(serial_port_fd == -1)
		return 0;

	/* Normally it never happens, but it is better not to segfault ;) */
	if(length == 0)
		return 0;

	/* RS485 half-duplex mode ? */
	if( config.flux==3 )
	{
		/* set RTS (start to send) */
		Set_signals( 1 );
		if( config.rs485_rts_time_before_transmit>0 )
			usleep(config.rs485_rts_time_before_transmit*1000);
	}

	bytes_written = write(serial_port_fd, string, length);

	/* RS485 half-duplex mode ? */
	if( config.flux==3 )
	{
		/* wait all chars are send */
		tcdrain( serial_port_fd );
		if( config.rs485_rts_time_after_transmit>0 )
			usleep(config.rs485_rts_time_after_transmit*1000);
		/* reset RTS (end of send, now receiving back) */
		Set_signals( 1 );
	}

	return bytes_written;
}
示例#2
0
文件: serial.c 项目: Jeija/gtkterm
int lis_sig(void)
{
	static int stat = 0;
	int stat_read;

	if ( config.flux==3 )
	{
		//reset RTS (default = receive)
		Set_signals( 1 );
	}

	if(serial_port_fd != -1)
	{
		if(ioctl(serial_port_fd, TIOCMGET, &stat_read) == -1)
		{
			/* Ignore EINVAL, as some serial ports
			genuinely lack these lines */
			/* Thanks to Elie De Brauwer on ubuntu launchpad */
			if (errno != EINVAL)
			{
				i18n_perror(_("Control signals read"));
				Close_port();
			}

			return -2;
		}

		if(stat_read == stat)
			return -1;

		stat = stat_read;

		return stat;
	}
	return -1;
}
示例#3
0
int main( int argc, char *argv[] )
{
  char *buf = NULL;
  time_t initial_read_time = 0;

  /* Parse command line. */

  Parse_command_line( argc, argv );

  /* Set up signal handlers */

  Set_signals();

  /* Set input stream (stdin) to be unbuffered. */

  setvbuf( stdin, buf, _IONBF, sizeof( _IONBF ) );

  /* Loop/read data. The format of a level-II file is as follows:
     24 byte volume header -
           bytes 00-08 - file name (AR2V00xx. where xx is LDM version)
           bytes 09-11 - volume number sequence (001-999)
           bytes 12-15 - volume start date
           bytes 16-19 - volume start time (milliseconds after midnight)
           bytes 20-23 - ICAO
      4 byte flag indicating length compressed meta data record
      compressed meta data record
      4 byte flag indicating length of compressed radials record
      compressed radials record
      4 byte flag indicating length of compressed radials record
      compressed radials record
      .
      .
      .
  */

  /* Note initial start time. */

  initial_read_time = time( NULL );

  /* Read the initial control word. */

  Read_control_word();
  P_debug( "control word 1: %d", Control_word );

  /* Ensure this is the start of a new volume file. If not, bail. */

  Check_for_start_of_volume();

  /* Read meta data (first record of new volume file). */

  Read_meta_data();

  /* Loop and read rest of volume file. */

  while( End_of_volume_flag == NO )
  {
    /* Sanity check. If it takes too long, assume something
       bad has happened and bail. */
    if( time( NULL ) - initial_read_time > DATA_READ_TIMEOUT )
    {
      P_err( "Read timeout (>%d). Exiting.", DATA_READ_TIMEOUT );
      Print_stats( READ_STDIN_TIMEOUT );
    }

    /* Read control word that tells us what to do. */
    Read_control_word();
    P_debug( "control word 2: %d", Control_word );

    Read_radial_data();
  }

  Print_stats( EXIT_SUCCESS );

  return 0;
}