"Fossies" - the Fresh Open Source Software Archive

Member "bayonne-1.2.16/drivers/phonedev/dial.cpp" (30 May 2002, 3648 Bytes) of package /linux/misc/old/bayonne-1.2.16.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "dial.cpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2000 Open Source Telecom Corporation.
    2 //  
    3 // This program is free software; you can redistribute it and/or modify
    4 // it under the terms of the GNU General Public License as published by
    5 // the Free Software Foundation; either version 2 of the License, or
    6 // (at your option) any later version.
    7 // 
    8 // This program is distributed in the hope that it will be useful,
    9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11 // GNU General Public License for more details.
   12 // 
   13 // You should have received a copy of the GNU General Public License
   14 // along with this program; if not, write to the Free Software 
   15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   16 
   17 #include "driver.h"
   18 #include <sys/ioctl.h>
   19 #include <ctype.h>
   20 
   21 #ifdef  CCXX_NAMESPACES
   22 using namespace std;
   23 namespace ost {
   24 #endif
   25 
   26 bool PhonedevTrunk::waitHandler(TrunkEvent *event)
   27 {
   28     switch(event->id)
   29     {
   30     case TRUNK_TIMER_EXPIRED:
   31         setSymbol(SYM_TONE, "fail");
   32         if(!trunkSignal(TRUNK_SIGNAL_CANCEL))
   33             if(!trunkSignal(TRUNK_SIGNAL_TONE))
   34                 return false;
   35         handler = &PhonedevTrunk::stepHandler;
   36         return true;
   37     case TRUNK_ENTER_STATE:
   38         setCPADetect(CPA_DIALTONE, true);
   39         setDTMFDetect(false);
   40         setHookState(true);
   41         setTimer(1000);
   42         return true;
   43     case TRUNK_CPA_BUSYTONE:
   44         return dialHandler(event);
   45     case TRUNK_CPA_DIALTONE:
   46         setCPADetect(CPA_DIALTONE, false);
   47         handler = &PhonedevTrunk::dialHandler;
   48         return true;
   49     }
   50     return false;       
   51 }
   52 
   53 bool PhonedevTrunk::dialHandler(TrunkEvent *event)
   54 {
   55     unsigned short mask;
   56     int dial;
   57     int ctrl;
   58 
   59     switch(event->id)
   60     {
   61     case TRUNK_CPA_BUSYTONE:
   62         setSymbol(SYM_TONE, "busy");
   63         if(trunkSignal(TRUNK_SIGNAL_BUSY))
   64         {
   65             handler = &PhonedevTrunk::stepHandler;
   66             return true;
   67         }
   68         if(trunkSignal(TRUNK_SIGNAL_TONE))
   69         {
   70             handler = &PhonedevTrunk::stepHandler;
   71             return true;
   72         }
   73         return true;
   74     case TRUNK_ENTER_STATE:
   75         enterState("dial");
   76         flags.dsp = DSP_MODE_VOICE;
   77         setSymbol(SYM_TONE, "none");
   78         setCPADetect(CPA_DIALTONE, false);
   79         setCPADetect(CPA_BUSYTONE, true);
   80         setDTMFDetect(false);
   81         status[id] = 'd';
   82     case TRUNK_TIMER_EXPIRED:
   83         if(!flags.offhook)
   84             setHookState(true);
   85 #ifdef  POSIX_PHONEDEV
   86         ioctl(dev, PHONE_GET_TONE_STATE, &ctrl);
   87 #else
   88         ctrl = ioctl(dev, PHONE_GET_TONE_STATE);
   89 #endif
   90         if(ctrl)
   91         {
   92             setTimer(36);
   93             return true;
   94         }
   95         switch(*data.dialxfer.digit)
   96         {
   97         case 0:
   98             setCPADetect(CPA_BUSYTONE, false);
   99             if(data.dialxfer.exit)
  100                 trunkSignal(TRUNK_SIGNAL_HANGUP);
  101             else
  102                 trunkSignal(TRUNK_SIGNAL_STEP);
  103             handler = &PhonedevTrunk::stepHandler;
  104             return true;
  105         case 'w':
  106         case 'W':
  107             handler = &PhonedevTrunk::waitHandler;
  108             ++data.dialxfer.digit;
  109             return true;
  110         case 'f':
  111         case 'F':
  112             setTimer(group->getFlash());
  113             ++data.dialxfer.digit;
  114             return true;
  115         case 'A':
  116         case 'B':
  117         case 'C':
  118         case 'D':
  119             *data.dialxfer.digit = tolower(*data.dialxfer.digit);
  120         case 'a':
  121         case 'b':
  122         case 'c':
  123         case 'd':
  124             dial = 28 + *data.dialxfer.digit - 'a';
  125             break;                  
  126         case '0':
  127             dial = 10;
  128             break;
  129         case '1':
  130         case '2':
  131         case '3':
  132         case '4':
  133         case '5':
  134         case '6':
  135         case '7':
  136         case '8':
  137         case '9':
  138             dial = *data.dialxfer.digit - '0';
  139             break;
  140         case '*':
  141             dial = 11;
  142             break;
  143         case '#':
  144             dial = 12;
  145             break;
  146         default:
  147             ++data.dialxfer.digit;
  148             setTimer(1000);
  149             return true;    
  150         }
  151         ++data.dialxfer.digit;
  152         setTimer(data.dialxfer.interdigit);
  153 #ifdef  POSIX_PHONEDEV
  154         ioctl(dev, PHONE_PLAY_TONE, &dial);
  155 #else
  156         ioctl(dev, PHONE_PLAY_TONE, dial);
  157 #endif
  158         return true;
  159     }
  160     return false;
  161 }
  162 
  163 #ifdef  CCXX_NAMESPACES
  164 };
  165 #endif