home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 6
/
AACD06.ISO
/
AACD
/
Online
/
Dial
/
source
/
DialModem.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-20
|
7KB
|
264 lines
/* /// "includes" */
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/io.h>
#include <exec/libraries.h>
#include <devices/serial.h>
#include <hardware/cia.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <stdio.h>
#include <libraries/mui.h>
#include "GUI.h"
#include "listhooks.h"
#include "extern.h"
#include "OwnDevUnit.h"
/* /// */
#define SERDELAY 3
struct MsgPort *SerialMP; /* pointer to our message port */
struct IOExtSer *SerialIO; /* pointer to our IORequest */
int device;
extern struct Library * OwnDevUnitBase;
#include <inline/owndevunit.h>
/* /// "WriteSer" */
int WriteSer(struct IOExtSer *SerialIO, char *str)
{
/* device opened, write null-terminated string */
SerialIO->IOSer.io_Length = -1;
SerialIO->IOSer.io_Data = (APTR)str;
SerialIO->IOSer.io_Command = CMD_WRITE;
DoIO((struct IORequest *)SerialIO); /* execute write */
SerialIO->IOSer.io_Command=CMD_FLUSH;
DoIO((struct IORequest *)SerialIO);
return 1;
}
/* /// */
/* /// "ReadSer" */
int ReadSer(struct IOExtSer *SerialIO, char *str)
{
int n;
SerialIO->IOSer.io_Command=SDCMD_QUERY;
DoIO((struct IORequest *)SerialIO);
if (n=SerialIO->IOSer.io_Actual)
{
SerialIO->IOSer.io_Length = n;
SerialIO->IOSer.io_Data = (APTR)str;
SerialIO->IOSer.io_Command = CMD_READ;
DoIO((struct IORequest *)SerialIO); /* execute read */
return 1;
}
else
return 0;
}
/* /// */
/* /// "CloseAll" */
void CloseAll(struct ObjApp *App)
{
char *buf;
int unit;
get(App->STR_unit,MUIA_String_Contents,&buf);
sscanf(buf,"%d",&unit);
get(App->STR_device,MUIA_String_Contents,&buf);
if (!device) CloseDevice((struct IORequest *)SerialIO);
if (SerialIO) DeleteExtIO(SerialIO);
if (SerialMP) DeleteMsgPort(SerialMP);
if (OwnDevUnitBase) FreeDevUnit(buf, unit);
}
/* /// */
/* /// "OpenAll" */
int OpenAll(struct ObjApp *App)
{
char *buf, *str;
int unit;
get(App->STR_unit,MUIA_String_Contents,&buf);
sscanf(buf,"%d",&unit);
get(App->STR_device,MUIA_String_Contents,&buf);
if (OwnDevUnitBase && (str=AttemptDevUnit(buf, unit, "Dial v3", 0)))
{
char buf2[256];
sprintf(buf2, "%s unit %d\nis used by \"%s\"", buf, unit, str);
MUI_Request(App->App,App->window,0,"Dial","OK",buf2);
return 0;
}
if (!(SerialMP=CreateMsgPort()))
{ CloseAll(App); return(0); }
if (!(SerialIO = (struct IOExtSer *)CreateExtIO(SerialMP,sizeof(struct IOExtSer))))
{ CloseAll(App); return(0); }
SerialIO->io_SerFlags=SERF_SHARED | SERF_XDISABLED;
if (device=OpenDevice(buf,unit,(struct IORequest *)SerialIO,0L))
{ CloseAll(App); return(0); }
return(1);
}
/* /// */
/* /// "DialModem" */
int DialModem(struct ObjApp *App, char *nummer, int dialwin)
{
char buf[100]="\0";
char buf2[100]="\0";
char *DialCode;
char *TelSysCode;
LONG conceal,telsys;
LONG hangup;
int i;
char buf3[512];
struct ListEntry *LE;
char number[256];
ULONG sig, VoiceMode;
get(App->CH_Conceal, MUIA_Selected, &conceal);
get(App->CH_system, MUIA_Selected, &telsys);
get(App->STR_system, MUIA_String_Contents, &TelSysCode);
get(App->CH_voice, MUIA_Selected, &VoiceMode);
get(App->STR_DialCode, MUIA_String_Contents, &DialCode);
get(App->SL_HangUp, MUIA_Slider_Level, &hangup);
strcpy(number, nummer);
InsertCBC(App, number, 255);
if (!OpenAll(App)) return(0);
DoMethod(App->LV_main, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &LE);
sprintf(buf3, "\ec%s\n%s\n%s", GetString(MSG_TX_dialling), number, LE->Name);
set(App->TX_dialling, MUIA_Text_Contents, buf3);
if (!dialwin) set(App->WI_dialling, MUIA_Window_Open, TRUE);
WriteSer(SerialIO,"atz\r");
Delay(SERDELAY);
ReadSer(SerialIO, buf);
if (VoiceMode)
{
char *VoiceStr;
int i;
char buf[256] = "\0";
get(App->STR_voice, MUIA_String_Contents, &VoiceStr);
for (i=0; VoiceStr[i]!=0; i++)
if (VoiceStr[i]=='\\' && VoiceStr[i+1]=='r')
{
i++;
strcat(buf, "\r");
WriteSer(SerialIO, buf);
Delay(SERDELAY);
ReadSer(SerialIO, buf);
strcpy(buf, "\0");
continue;
}
else
strncat(buf, VoiceStr+i, 1);
}
if (DoMethod(App->App,MUIM_Application_Input,&sig)==ID_AbortDialling)
{
set(App->WI_dialling, MUIA_Window_Open, FALSE);
CloseAll(App);
return 0;
}
strcpy(buf, "\0");
strcpy(buf2,"atdt");
if (telsys) strcat(buf, TelSysCode);
if (conceal) strcat(buf, "*31#");
strcat(buf,number);
for(i=0;buf[i]!='\0';i++)
{
switch (buf[i])
{
case '+' : strcat(buf2,DialCode); break;
case '!' : strcat(buf2,"W"); break;
case '0' : strcat(buf2,"0"); break;
case '1' : strcat(buf2,"1"); break;
case '2' : case 'A' : case 'B' : case 'C' : strcat(buf2,"2"); break;
case '3' : case 'D' : case 'E' : case 'F' : strcat(buf2,"3"); break;
case '4' : case 'G' : case 'H' : case 'I' : strcat(buf2,"4"); break;
case '5' : case 'J' : case 'K' : case 'L' : strcat(buf2,"5"); break;
case '6' : case 'M' : case 'N' : case 'O' : strcat(buf2,"6"); break;
case '7' : case 'P' : case 'Q' : case 'R' : case 'S' : strcat(buf2,"7"); break;
case '8' : case 'T' : case 'U' : case 'V' : strcat(buf2,"8"); break;
case '9' : case 'W' : case 'X' : case 'Y' : case 'Z' : strcat(buf2,"9"); break;
case '*' : strcat(buf2,"*"); break;
case '#' : strcat(buf2,"#"); break;
}
}
#ifdef DEBUG
printf("dialling: %s\n", buf2);
#endif
strcat(buf2,"\r");
WriteSer(SerialIO,buf2);
Delay(SERDELAY);
ReadSer(SerialIO, buf);
if (DoMethod(App->App,MUIM_Application_Input,&sig)==ID_AbortDialling)
{
set(App->WI_dialling, MUIA_Window_Open, FALSE);
CloseAll(App);
return 0;
}
/* wait [hangup] seconds */
for (i=0; i<50; i++)
{
if (VoiceMode) i=0;
Delay(hangup);
if (DoMethod(App->App,MUIM_Application_Input,&sig)==ID_AbortDialling)
{
set(App->WI_dialling, MUIA_Window_Open, FALSE);
CloseAll(App);
return 0;
}
}
WriteSer(SerialIO,"ath\r");
Delay(SERDELAY);
ReadSer(SerialIO, buf);
CloseAll(App);
set(App->WI_dialling, MUIA_Window_Open, FALSE);
return(1);
}
/* /// */