⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ltmodem.c

📁 话带数据中传真解调程序
💻 C
📖 第 1 页 / 共 2 页
字号:
		fprintf(stderr, "+ answered OK\n" );
	  else
		fprintf(stderr, "- no answer tone, bummer!\n" );
#endif

    } else if (!strncmp(buf, "duplex", 6)) {
      voice_transmit(3);

    } else if (!strncmp(buf, "quit", 4) || !strncmp(buf, "exit", 4)) {
      fprintf(stderr, "+ exiting\n" );
      exit(0);

    } else if (!strncmp(buf, "speaker on", 10)) {
	  // Turn speaker on, and set volume to max.
      setSpeaker(true, 3);
      fprintf(stderr, "+ OK\n" );

    } else if (!strncmp(buf, "speaker off", 11)) {
	  // Turn speaker of, and set volume to min.
      setSpeaker(false, 0);
      fprintf(stderr, "+ OK\n" );

    } else if ((!strncmp(buf, "reset", 5)) ||
			   (!strncmp(buf, "hangup", 6))) {
	  // Hang up and reset the modem.
      hangup();
      fprintf(stderr, "+ OK\n" );

    } else
      fprintf(stderr, "- unknown command %s\n", buf );
  }

  PRINTF( "# Exiting command mode\n" );
  exit(1);
}


void setup_irq(void)
{
  // Setup IRQ variable used by other stuff.
  if (isapnp_modem)
    modem_irq = get_isamodem_irq();
  else
    modem_irq = get_pcimodem_irq();
}

void show_modem(void)
{
  if (isapnp_modem)
    show_isamodem();
  else
    show_pcimodem();
}

// Modem monitoring functions.
void
monitor_modem(void)
{
  // Value input by user.
  char input = 'z';

  // Monitoring activity type:
  // registers = 1, I/O = 2.
  int monitor_type = 1;

  // Monitoring period in milliseconds, defaults to one second.
  int monitoring_interval = 1000;

  while (input != 'Q') {
	// Ignore the newline char.
	if (input != '\n') {
	  printf ("***************************************************\n");
      printf ("monitoring menu (Monitor monitorIo monitorRegs monitorBoth iNterval Quit): ");

	}
	// Get user input in uppercase.
	input = toupper (getchar());
    switch (input) {
	case 'M':
	  continous_monitoring(monitor_type, monitoring_interval);
	  break;
	case 'I':
      printf( "Will monitor I/O ports.\n" );
      monitor_type = 2;
      break;
    case 'R':
      printf( "Will monitor PCI registers.\n" );
      monitor_type = 1;
      break;
    case 'B':
      printf( "Will monitor I/O ports and PCI registers.\n" );
      monitor_type = 3;
      break;
    case 'N':
      monitoring_interval = set_monitoring_interval();
      break;
	case '\n':
      break;
	case 'Q':
	  break;
	default:
	  printf ("Illegal option: %c\n", input);
	}    
  }
}

int set_monitoring_interval(void){

  // Value input by user.
  int input = 0;
  char trash; 

  // Allow user to set interval.
  printf ("Set monitoring interval (in miliseconds): ");
  scanf ("%d%c", &input, &trash);

  if (input > 0) {
	// Return the user's value.
	printf ("Interval set to %d milliseconds.\n", input); 
	return input;
  }
  else {
	// Default to one second.
	printf ("Illegal interval, using 1 second default.\n"); 
	return 1000;
  }
}

/* Modem writing functions. */
void
set_modem(void)
{
  /* value input by user. */
  char input = ' ';

  /* start by just doing a hex dump. */
  if (isapnp_modem)
    show_isahex_dump();
  else
    show_pcihex_dump(modem_dev);

  /* Offer the user a choice of what to set. */
  while (input != 'Q') {

	// Ignore newline character.
	if (input != '\n') {
       printf ("modem write (Controlreg Io Quit): ");
	}
	input = toupper (getchar ());
    switch (input) {
	case 'C':
	  if (!isapnp_modem)
		printf ("Option not valid for ISA modems.");
	  else {
	    set_modem_cont_reg();

	    redisplay_modem_regs();

	  }
	  break;
	case 'I':
	  set_modem_io();
	  break;
	case '\n':
      break;
	case 'Q':
	  break;
	default:
	  printf ("Illegal option: %c\n", input);
	}   
  }
}
/* Main command menu. */

void
main_menu(void)
{
  /* char input by user. */
  char input = 'z';

  while (input != 'Q') {
	// Ignore the newline char.
	if (input != '\n') {
      printf ("main menu (Monitor Write Quit): ");
	}
	// Get user input in uppercase.
	input = toupper (getchar());
    switch (input) {
	case 'M':
	  monitor_modem();
	  break;
	case 'W':
	  set_modem();
	  break;
	case '\n':
      break;
	case 'Q':
	  break;
	default:
	  printf ("Illegal option: %c\n", input);
	}    

  }
  /* Bye bye... */
  printf ("User stopped ltmodem.\n");
}

// Lucent modem specific stuff.  

void go_onhook(void)
{
  dp_onhook_cmd();
}

void io_init(void)
{

   // Set up the port IO.
   port_io_init(io_address[1], io_address[2]);

   // Set up EEPROM ?
   //SetUpEEPROM();

   // Set up the modem variables etc.
   MimicInit();

}

// Dial the number held in the argument string.
void dial(char *s)
{
  sleep(2);	/* We do no dial tone detection, so we'll just wait */
  while (*s) {

	//printf( "Dialing: `%c'.\n", *s );

    switch (*s) {
    case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
	  // Delay before each one.
	  usleep(400000);
      if (pulseDial) {
		usleep(50000 * (*s));
		dp_pulse_dial_cmd(*s-'0');
	  }
	  else 
		dp_DTMF_dial_cmd(*s-'0');
	  break;
	case '-': case '.': case '\n':
	  // Allow punctuation.
      break;
    default:
      printf( "Unknown character in dial sequence `%c' ignored.\n", *s );
      break;
    }
    s++;
  }
}

// Mess around with speaker.
void setSpeaker (bool Enabled, unsigned char Volume)
{

  // Set speaker globals.
  S_speaker_enable = (unsigned char)Enabled;
  S_speaker_volume = Volume; 

  dp_56k_speaker_cmd ();

}

// Wait for dial tone, timing out after 3 seconds.
bool waitForDialTone (void)
{

  int timeout = 3000;
  short local_timer;

  local_timer = x_current_time();

  // Set up tone detection.
  dp_detect_tones_cmd();

  // Wait until dial tone detected or 3 seconds has expired.
  while (!dp_dial_tone_detected()) {
	if (x_elapsed_time(local_timer) > timeout)
	  return false;
	usleep(1000);
  }
  return true;
}

// Wait for answer tone, timing out after 10 seconds.
bool waitForAnswerTone (void)
{

  int timeout = 10000;
  unsigned short local_timer;

  dp_answer_state = 0;

  local_timer = x_current_time();

  // Set up tone detection.
  dp_detect_tones_cmd();

  // Wait until answer tone detected or 10 seconds has expired.
  while (!dp_answer_tone_detected()) {
	if (x_elapsed_time(local_timer) > timeout)
	  return false;
  }
  return true;
}

// Wait for busy tone, timing out after 4 seconds.
bool waitForBusyTone (void)
{
  unsigned short local_timer;

  dp_busy_state = 0;

  local_timer = x_current_time();

  // Set up tone detection.
  dp_detect_tones_cmd();

  // Busy tone detection will not work if this is set!
  S_data_calling_tone = false;

  // Wait until busy tone detected or 4 seconds has expired.
  while (!dp_busy_tone_detected()) {
	if (x_elapsed_time(local_timer) > 4000)
	  return false;
  }
  return true;
}


void hangup (void)
{
  // This is on a clause in dp_period_task and other stuff.
  S(0x74) = 0;
  dp_onhook_cmd();
  dp_state = 1;
  x_modem_state = 1;
  dp_timer = x_current_time();

  x_send_mail(0x18, 3, 0, 0);

  // This is what Pavel had put at the end of dp_onhook_cmd.
  printf( "This should really hangup: " );
  modem_reset(); 
  printf( "\n" );
}

void  waitForCall(void)
{
   // Set up ring in stuff and tone detection.
   bodge_init_dial();
   dp_detect_tones_cmd();
   
   printf("Waiting for incoming call...\n");

   // Wait for call to come in.
   while (1) {
	 if (call_detected() == true) {
	   printf("Incoming call detected!\n");
	   break;
	 }
   }

   // Turn speaker on, and set volume to max.
   setSpeaker(true, 3);

   // Go offhook.
   dp_offhook_cmd();

   printf("\nCall connected.\n");
}


#if TRY_INTERRUPTS

void catch_interrupts(void *data, size_t len)
{

 unsigned char rChar;

 // use args to get rid of compiler warning!
 if (len) data++;

 while (interrupt_enabled) {
   // Waits for an interrupt.
   //printf("Waiting for interrupt!\n");
   rChar = getc(irq_dev);
   // Call the ISR, locking out other threads.
   bb_threads_lock(1);
   //printf("Interrupt! ");

   if (modem_enabled) {
	 // Grab access to all the IO ports.
	 if (iopl(3) < 0) {
	   perror("portIO: iopl(3) failed");
	   fprintf(stderr, "This program must be run as root.\n");
	 }
	 dp_dsp_isr();
   }
   bb_threads_unlock(1);
 }

 printf("Interrupt thread terminated!\n");
 
}
#endif


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -