int ppp_modem_init(const char *number, int blind, int *conn_rate) { uint64_t timeout; /* Initialize the modem. */ if(!modem_init()) return -1; /* Set the modem up to connect to a remote machine. */ modem_set_mode(MODEM_MODE_REMOTE, MODEM_SPEED_V8_AUTO); /* If we aren't doing blind dialing, wait up to 5 seconds for a dialtone. */ if(!blind) { if(modem_wait_dialtone(5000)) { modem_shutdown(); return -2; } } /* Dial the specified phone number. */ if(!modem_dial(number)) { modem_shutdown(); return -3; } /* Give ourselves a 60 second timeout to establish a connection. */ timeout = timer_ms_gettime64() + 60 * 1000; while(timer_ms_gettime64() < timeout && modem_is_connecting()) { thd_pass(); } /* Did we connect successfully? */ if(!modem_is_connected()) { modem_shutdown(); return -4; } /* Does the user want the connection rate back? If so give it to them. */ if(conn_rate) { *conn_rate = modem_get_connection_rate(); } dbglog(DBG_KDEBUG, "ppp_modem: connected at %lu bps\n", modem_get_connection_rate()); /* We connected to the peer successfully, set our device with libppp. */ ppp_set_device(&modem_dev); return 0; }
int main() { int answerMode = 0; unsigned char data[DATA_BUFFER_LENGTH]; int i; int byteCount; if (!modem_init()) { printf("modem_init failed!\n"); return 1; } printf("\nDreamcast modem - example 1\n"); printf("Press START to exit\n\n"); if (answerMode) printf("Answer mode - Call the Dreamcast. It will pick up after one ring.\n\n"); else printf("Remote mode - Connect the phone line to your computer's modem and use ATA to\n \"answer\" the Dreamcast.\n\n"); printf("Once the modems are connected you can send data to the Dreamcast,\n"); printf("and the Dreamcast can send data to the remote modem by pressing the\n"); printf("A button.\n\n"); while (!buttonPressed(CONT_START)) { modem_set_mode(answerMode ? MODEM_MODE_ANSWER : MODEM_MODE_REMOTE, MODEM_SPEED_V8_AUTO); printf("Waiting for a connection..\n"); while (modem_is_connecting()) { if (buttonPressed(CONT_START)) { printf("Connection aborted\n"); return 0; } } if (modem_is_connected()) { printf("Connected at %dbps\n", (int)modem_get_connection_rate()); while (!buttonPressed(CONT_START) && modem_is_connected()) { /* Receive data */ if (modem_has_data()) { byteCount = modem_read_data(data, DATA_BUFFER_LENGTH); for (i=0; i<byteCount; i++) printf("%c", (data[i] >= 32 && data[i] <= 126) ? data[i] : ' '); } /* Send data */ if (buttonPressed(CONT_A)) { for (i=0; i<8; i++) data[i] = (int)'a' + i; modem_write_data(data, 8); } } if (modem_is_connected()) { printf("Disconnecting..\n"); modem_disconnect(); while (buttonPressed(CONT_START)); } else printf("Disconnected\n"); } else printf("Connection failed\n"); } return 0; }