?? ltmodem.c
字號:
/*
* $Id: ltmodem.c,v 1.7 1999/12/19 21:52:09 root Exp root $
*
* Lucent modem diagnostics tool.
*
* Copyright (c) 1999 Richard J.M. Close
* Copyright (c) 1999 Pavel Machek <pavel@suse.cz>
* Copyright (c) 1999 Jamie Lokier
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include "ltmodem.h"
//void show_modem(void); ??
// Include the DSP code.
#include "dsp.c"
// Main program.
int main(int argc, char **argv)
{
char c;
sync(); // it's for your own protection!
setvbuf(stdout, NULL, _IONBF, 0);
puts("ltmodem version " LTMODEM_VERSION);
// Try to find an ISA modem.
init_isa();
if (!isapnp_modem)
// No ISA modem found so try PCI.
init_pci();
#if TRY_INTERRUPTS
// Open the IRQ device node for reading.
irq_dev = fopen(IRQ_DEV, "r");
if (irq_dev) {
printf ("Opened %s for reading.\n", IRQ_DEV);
// Set up bb threads.
bb_threads_stacksize(65536);
bb_threads_shared_sighandlers(0);
bb_threads_mutexcreate(0);
bb_threads_mutexcreate(1);
interrupt_enabled = 1;
modem_enabled = 0;
bb_threads_lock(1);
irq_pid = bb_threads_newthread(catch_interrupts, NULL);
printf("Spawned interrupt handler thread pid= %d\n", irq_pid);
bb_threads_unlock(1);
}
else
printf ("Failed to open %s.\n", IRQ_DEV);
#endif
/* If modem is found then it sets modem_dev to device structure
for modem, and modem =1 */
if ( (!isapnp_modem) && !find_modem() ) {
printf ("Sorry, no Lucent PCI modem that I know of was found.\n");
printf ("If you have one fitted then please mail me with the details\n");
printf ("at: richard@close.u-net.com please include an output from\n");
printf ("cat /proc/pci and as much info. on the card as possible.\n");
printf ("If you have an ISA modem please see README.ISA.\n");
exit(1);
}
while ((c = getopt(argc, argv, "zimovtrhpd:uc" )) != -1) {
switch(c) {
case 'z':
show_modem();
setup_irq();
io_init();
break;
case 'i':
show_modem();
main_menu();
break;
case 'c':
command_mode();
break;
case 't':
show_modem();
setup_irq();
io_init();
hangup();
break;
case 'r':
show_modem();
setup_irq();
io_init();
hangup();
waitForCall();
break;
case 'u': /* Full duplex transmit/receive */
// show_modem();
setup_irq();
io_init();
voice_init();
dp_offhook_cmd();
voice_transmit(-1);
die( "Should be unreachable\n" ); // ???
break;
case 'd':
show_modem();
setup_irq();
io_init();
dp_update_modem_options();
// Turn speaker on, and set volume to max.
setSpeaker(true, 3);
/*{ // Keep an eye on how long going offhook takes!
unsigned short my_timer;
my_timer = x_current_time(); */
dp_offhook_cmd();
/* printf ("dp_offhook_cmd took %dmS.\n", x_elapsed_time(my_timer));
}*/
// Initialise the dial state.
bodge_init_dial();
#if WAIT_FOR_DIALTONE
// Wait for dial tone.
printf( "Waiting for dialtone... ");
if (waitForDialTone())
printf("got it!\n");
else {
printf("no dial tone detected, is the phone plugged in?\n");
hangup();
break;
}
#endif
// Dial how you want.
printf( "About to dial %s: ...", optarg );
dial(optarg);
printf( " done.\n");
#if WAIT_FOR_ANSWER
{
unsigned short local_timer;
bool modemDetected = false;
bool lineBusy = false;
// Set up for call related detection.
bodge_after_dial_init();
dp_answer_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 answer tone detected or 10 seconds has expired.
while (x_elapsed_time(local_timer) < 10000) {
if (dp_busy_tone_detected()) {
lineBusy = true;
break;
}
if (x_elapsed_time(local_timer) > 1000)
// After 1 sec. also check for answer.
if (dp_answer_tone_detected()) {
printf("Answer detected.\n");
modemDetected = true;
break;
}
}
if (modemDetected)
// Set up modem data connection.
connect_to_modem();
else if (lineBusy){
printf("The line is busy! hanging up...\n");
hangup();
}
else
printf("No answer tone, bummer!\n");
}
#endif
#if HANGUP_AFTER_DIAL
// Delay before hanging up, make this long enough to hear
// any response from line when messing around with dialling.
sleep(5);
printf( "About to hangup\n" );
hangup();
#endif
break;
case 'o':
show_modem();
setup_irq();
io_init();
big_init();
voice_init();
printf("Ready\n" );
dp_offhook_cmd();
dp_pulse_dial_cmd(3); /* How do you prove that number PI does not exist? */
dp_pulse_dial_cmd(1); /* You take telephone and dial 3 1 4 1 5 9 2 6 5 4 */
dp_pulse_dial_cmd(4); /* and then you hear ta da da called number does */
dp_pulse_dial_cmd(1); /* not exist. (It works in Prague at least :-) */
dp_pulse_dial_cmd(5);
dp_pulse_dial_cmd(9);
dp_pulse_dial_cmd(2);
dp_pulse_dial_cmd(6);
dp_pulse_dial_cmd(5);
dp_pulse_dial_cmd(4);
dp_DTMF_dial_cmd(1);
#if 0
sleep(1);
dp_synth_ring_init();
sleep(1);
dp_synth_ring_on();
sleep(1);
dp_synth_ring_off();
#endif
sleep(1);
#if 1
printf( "Staring tad\n" );
dp_start_tad(0xf0);
expect_irqs();
#endif
#if 0
printf( "X_output(13)\n" );
x_output(0x13);
expect_irqs();
x_output(0x1a);
printf( "Should be ready?\n" );
#endif
expect_irqs();
printf( "Should dial 2\n" );
dp_DTMF_dial_cmd(2);
expect_irqs();
#if 0
printf( "Really should dial 2\n" );
dp_offhook_cmd();
dial("2");
expect_irqs();
#endif
#if 0
expect_irqs();
printf( "init hdsp\n" );
dp_init_hdsp();
expect_irqs();
printf( "Starting speakerphone\n" );
dp_start_hdsp();
expect_irqs();
printf( "Switching fdsp\n" );
dp_switch_fdsp();
expect_irqs();
{
int i = 0;
for (i = 0; i<5; i++) {
dp_mute_fdsp(1);
sleep(1);
dp_mute_fdsp(0);
sleep(1);
}
}
printf( "Stop fdsp:\n" );
dp_stop_fdsp();
sleep(3);
printf( "About to hangup.\n" );
dp_onhook_cmd();
/* go_offhook(); -- seems to do something slightly different */
/* dp_download_fax(); */
#endif
break;
case 'm':
continous_monitoring(3, 1000);
break;
case 'p':
pulseDial = true;
break;
case 'v':
verbose++;
break;
case 'h':
default:
printf( "Usage: ltmodem [-imovthpd]\n" );
printf( "-i interative use.\n-m monitoring ports/registers.\n");
printf( "-o prove PI does not exist and turn modem into microwave owen.\n");
/* -o is really meant for debugging only, and it does strange
things. Not a toy for people who read help. It does different
things in every release. */
printf( "-v increase level of verbosity.\n");
printf( "-t basic test, display checksum etc. then hangup.\n");
printf( "-r receive call, initialises modem then waits for incoming call.\n");
printf( "-c enter command mode, read commands from fd#3.\n");
printf( "-u put phone offhook, then start transmitting data from stdin\n"
" and receive data from modem to stdout. You _must_ provide data on stdin\n" );
printf( "-p enable Pulse dialling, default is Tone.\n");
printf( "-d dial the specified number.\n");
printf( "-h print this message!\n");
goto exit;
}
}
exit:
#if TRY_INTERRUPTS
// Request termination.
interrupt_enabled = 0;
// Close device node;
if (irq_dev)
fclose(irq_dev);
else {
printf("Cannot close IRQ device as it is not open!.\n");
printf("Have you done: 'modprobe usirq' ?.\n");
}
kill(irq_pid, SIGQUIT);
// Clean up the thread.
bb_threads_cleanup(wait(NULL));
#endif
if (isapnp_modem)
cleanup_isa();
else
cleanup_pci();
return 0;
}
void command_mode(void)
{
char buf[10240];
FILE *cmd = fdopen(3, "r");
fprintf(stderr, "PROTOCOL 0.0\n" );
fprintf(stderr, "SWVERSION ltmodem " LTMODEM_VERSION "\n" );
// show_modem();
setup_irq();
io_init();
voice_init();
dp_update_modem_options();
fprintf(stderr, "HWVERSION mars V%x.%x (rom checksum %x)\n",
x_chip_version, dp_version, rom_checksum );
//fprintf(stderr, "+ Command mode ready\n" );
while (fgets(buf, 10235, cmd) != NULL) {
fprintf(stderr, "# Got command %s\n", buf );
if (!strncmp(buf, "help", 4) || (buf[0] == '?')) {
fprintf(stderr, "Available commands:
help Displays command summary.
? Same as help.
quit Exit command mode back to shell.
exit Guess what! (yes the same as quit).
onhook Go onhook.
offhook Go offhook.
dial xxx Dial the number xxx.
duplex Perform duplex voice transmission.
ringin Wait for a call to come in.
reset Hang up and reset the modem.
speaker on Turn internal speaker on.
speaker off Turn internal speaker off.
" );
} else if (!strncmp(buf, "onhook", 6)) {
dp_onhook_cmd();
fprintf(stderr, "+ OK\n" );
} else if (!strncmp(buf, "offhook", 7)) {
dp_offhook_cmd();
fprintf(stderr, "+ OK\n" );
} else if (!strncmp(buf, "ringin", 6)) {
waitForCall();
fprintf(stderr, "+ OK\n" );
} else if (!strncmp(buf, "expect dialtone", 15)) {
// Make sure we are off hook.
if (x_status[0] != 0) {
fprintf(stderr, "- Error: You must go offhook first!\n" );
continue;
}
// Initialise the dial state.
bodge_init_dial();
// Wait for dial tone.
if (waitForDialTone())
fprintf(stderr, "+ got dialtone OK\n" );
else
fprintf(stderr, "- No dial tone detected, is the phone plugged in?\n");
} else if (!strncmp(buf, "dial", 4)) {
// Make sure we are off hook.
if (x_status[0] != 0) {
fprintf(stderr, "- Error: You must go offhook first!\n" );
continue;
}
// Initialise the dial state.
bodge_init_dial();
dial(buf + 5);
fprintf(stderr, "# ringing... " );
#if WAIT_FOR_ANSWER
// Set up for call related detection.
bodge_after_dial_init();
// Wait for answer tone.
if (waitForAnswerTone())
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -