sample.cpp File Reference

WANPIPE(tm) API C++ Sample Code. More...

#include "sangoma_port.h"
#include "sangoma_port_configurator.h"
#include "sangoma_interface.h"

Include dependency graph for sample.cpp:

Go to the source code of this file.

Classes

struct  TDM_API_EVENT_THREAD_PARAM

Defines

#define MAX_PATH   100
#define DBG_MAIN   if(1)printf
#define ERR_MAIN   printf("%s():line:%d:Error:", __FUNCTION__, __LINE__);printf
#define INFO_MAIN   if(1)printf
#define MAIN_FUNC()   if(1)printf("%s():line:%d\n", __FUNCTION__, __LINE__)

Functions

void * TdmApiEventThreadFunc (void *lpdwParam)
 Event handling Function.
sangoma_interfaceinit (int wanpipe_number, int interface_number)
 Create a sangoma_interface class and setup callback functions.
void cleanup (sangoma_interface *sang_if)
 Free Sangoma Interface Object.
int start (sangoma_interface *sang_if)
 Run the main sangoma interface hanlder code.
void stop (sangoma_interface *sang_if)
 Stop the Sangoma Interface Object.
void PrintRxData (wp_api_hdr_t *hdr, void *pdata)
 Debug function used to print Rx Data.
int tx_file (sangoma_interface *sang_if)
 Transmit a file on a sangoma interface / device.
int __cdecl main (int argc, char *argv[])
 Main function that starts the sample code.

Variables

wp_program_settings_t program_settings
callback_functions_t callback_functions
CRITICAL_SECTION PrintCriticalSection
CRITICAL_SECTION TdmEventCriticalSection


Detailed Description

WANPIPE(tm) API C++ Sample Code.

Author(s): David Rokhvarg <davidr@sangoma.com> Nenad Corbic <ncorbic@sangoma.com>

Copyright: (c) 2005-2009 Sangoma Technologies

* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Sangoma Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY Sangoma Technologies ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Sangoma Technologies BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ===============================================================================

Definition in file sample.cpp.


Function Documentation

void * TdmApiEventThreadFunc ( void *  lpdwParam  ) 

Event handling Function.

Parameters:
lpdwParam pointer to the span/chan device
Returns:
void

Definition at line 302 of file sample.cpp.

References wp_api_event::channel, DBG_MAIN, sangoma_interface::device_name, EnterCriticalSection, ERR_MAIN, TDM_API_EVENT_THREAD_PARAM::event, LeaveCriticalSection, TDM_API_EVENT_THREAD_PARAM::sang_if_ptr, and TdmEventCriticalSection.

00304 { 
00305     TDM_API_EVENT_THREAD_PARAM  *param;
00306     sangoma_interface           *sang_if;
00307     wp_api_event_t          *wp_tdm_api_event;
00308 
00309     EnterCriticalSection(&TdmEventCriticalSection);
00310 
00311     param = (TDM_API_EVENT_THREAD_PARAM*)lpdwParam;
00312 
00313     wp_tdm_api_event = &param->event;
00314     sang_if = (sangoma_interface*)param->sang_if_ptr;
00315 
00316     DBG_MAIN( "TdmApiEventThreadFunc():ifname: %s: Channel: %d\n",
00317         sang_if->device_name, wp_tdm_api_event->channel);
00318 
00319     switch(wp_tdm_api_event->wp_api_event_type)
00320     {
00321     case WP_API_EVENT_DTMF:/* DTMF detected by Hardware */
00322         DBG_MAIN("DTMF Event: Digit: %c (Port: %s, Type:%s)!\n",
00323             wp_tdm_api_event->wp_api_event_dtmf_digit,
00324             (wp_tdm_api_event->wp_api_event_dtmf_port == WAN_EC_CHANNEL_PORT_ROUT)?"ROUT":"SOUT",
00325             (wp_tdm_api_event->wp_api_event_dtmf_type == WAN_EC_TONE_PRESENT)?"PRESENT":"STOP");
00326 
00327         break;
00328 
00329     case WP_API_EVENT_RXHOOK:
00330         DBG_MAIN("RXHOOK Event: %s! (0x%X)\n", 
00331             WAN_EVENT_RXHOOK_DECODE(wp_tdm_api_event->wp_api_event_hook_state),
00332             wp_tdm_api_event->wp_api_event_hook_state);
00333         break;
00334 
00335     case WP_API_EVENT_RING_DETECT:
00336         DBG_MAIN("RING Event: %s! (0x%X)\n",
00337             WAN_EVENT_RING_DECODE(wp_tdm_api_event->wp_api_event_ring_state),
00338             wp_tdm_api_event->wp_api_event_ring_state);
00339         break;
00340 
00341     case WP_API_EVENT_RING_TRIP_DETECT:
00342         DBG_MAIN("RING TRIP Event: %s! (0x%X)\n", 
00343             WAN_EVENT_RING_TRIP_DECODE(wp_tdm_api_event->wp_api_event_ring_state),
00344             wp_tdm_api_event->wp_api_event_ring_state);
00345         break;
00346 
00347     case WP_API_EVENT_RBS:
00348         DBG_MAIN("RBS Event: New bits: 0x%X!\n",    wp_tdm_api_event->wp_api_event_rbs_bits);
00349         DBG_MAIN( "RX RBS: A:%1d B:%1d C:%1d D:%1d\n",
00350             (wp_tdm_api_event->wp_api_event_rbs_bits & WAN_RBS_SIG_A) ? 1 : 0,
00351             (wp_tdm_api_event->wp_api_event_rbs_bits & WAN_RBS_SIG_B) ? 1 : 0,
00352             (wp_tdm_api_event->wp_api_event_rbs_bits & WAN_RBS_SIG_C) ? 1 : 0,
00353             (wp_tdm_api_event->wp_api_event_rbs_bits & WAN_RBS_SIG_D) ? 1 : 0);
00354         break;
00355 
00356     case WP_API_EVENT_LINK_STATUS:
00357         DBG_MAIN("Link Status Event: %s! (0x%X)\n", 
00358             WAN_EVENT_LINK_STATUS_DECODE(wp_tdm_api_event->wp_api_event_link_status),
00359             wp_tdm_api_event->wp_api_event_link_status);
00360         break;
00361 
00362     case WP_API_EVENT_ALARM:
00363         DBG_MAIN("New Alarm State: 0x%X\n", wp_tdm_api_event->wp_api_event_alarm);
00364         break;
00365 
00366     default:
00367         ERR_MAIN("Unknown TDM API Event: %d\n", wp_tdm_api_event->wp_api_event_type);
00368         break;
00369     }
00370 
00371     free(lpdwParam);
00372     LeaveCriticalSection(&TdmEventCriticalSection);
00373     //Done with the Event, exit the thread.
00374     return 0;
00375 }

sangoma_interface * init ( int  wanpipe_number,
int  interface_number 
)

Create a sangoma_interface class and setup callback functions.

Parameters:
wanpipe_number wanpipe device number obtained from the hardware probe info, span
interface_number wanpipe interface number, corresponds to a channel in a span
Returns:
sangoma_interface object pointer - ok or NULL if error.

Definition at line 114 of file sample.cpp.

References callback_functions, DBG_MAIN, and sangoma_interface::init().

Referenced by main().

00115 {
00116     sangoma_interface   *sang_if = NULL;
00117     DBG_MAIN("init()\n");
00118     sang_if = new sangoma_interface(wanpipe_number, interface_number);
00119     if(sang_if->init(&callback_functions)){
00120         delete sang_if;
00121         return NULL;
00122     }
00123     DBG_MAIN("init(): OK\n");
00124     return sang_if;
00125 }

Here is the call graph for this function:

Here is the caller graph for this function:

void cleanup ( sangoma_interface sang_if  ) 

Free Sangoma Interface Object.

Parameters:
sang_if Sangoma interface object pointer
Returns:
void

Definition at line 133 of file sample.cpp.

References DBG_MAIN.

00134 {
00135     DBG_MAIN("cleanup()\n");
00136     if(sang_if){
00137         delete sang_if;
00138     }
00139 }

int start ( sangoma_interface sang_if  ) 

Run the main sangoma interface hanlder code.

Parameters:
sang_if Sangoma interface object pointer
Returns:
0 - ok Non Zero - Error

Definition at line 147 of file sample.cpp.

References DBG_MAIN, and sangoma_interface::run().

Referenced by main().

00148 {
00149     DBG_MAIN("start()\n");
00150     return sang_if->run();
00151 }

Here is the call graph for this function:

Here is the caller graph for this function:

void stop ( sangoma_interface sang_if  ) 

Stop the Sangoma Interface Object.

Parameters:
sang_if Sangoma interface object pointer
Returns:
void

Definition at line 159 of file sample.cpp.

References DBG_MAIN, and sangoma_interface::stop().

Referenced by main().

00160 {
00161     DBG_MAIN("stop()\n");
00162     sang_if->stop();
00163 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PrintRxData ( wp_api_hdr_t hdr,
void *  data 
)

Debug function used to print Rx Data.

Parameters:
pRx API data element strcutre containt header + data
Returns:
void

Definition at line 171 of file sample.cpp.

References INFO_MAIN, and program_settings.

00172 {
00173     USHORT          datlen;
00174     PUCHAR          data;
00175     static unsigned int rx_counter = 0;
00176 
00177     //NOTE: if running in BitStream mode, there will be TOO MUCH to print 
00178     datlen = hdr->data_length;
00179     data = (unsigned char*)pdata;
00180 
00181     rx_counter++;
00182     if(program_settings.silent){
00183         if((rx_counter % 1000) == 0){
00184             INFO_MAIN("Rx counter:%d, Rx datlen : %d\n", rx_counter, datlen);
00185         }
00186         return;
00187     }else{
00188         INFO_MAIN("Rx counter:%d, Rx datlen : %d. Data :\n", rx_counter, datlen);
00189     }
00190 
00191 #if 1
00192     for(int ln = 0; ln < datlen; ln++){
00193         if((ln % 20 == 0)){
00194             if(ln){
00195                 INFO_MAIN("\n");
00196             }
00197             INFO_MAIN("%04d ", ln/20);
00198         }
00199         INFO_MAIN("%02X ", data[ln]);
00200     }
00201     INFO_MAIN("\n");
00202 #endif
00203 }

int tx_file ( sangoma_interface sang_if  ) 

Transmit a file on a sangoma interface / device.

Parameters:
sang_if_ptr sangoma interface pointer
Returns:
0 - ok non-zero - Error

Definition at line 385 of file sample.cpp.

References sangoma_interface::device_name, ERR_MAIN, INFO_MAIN, MAX_NO_DATA_BYTES_IN_FRAME, program_settings, SANG_STATUS_SUCCESS, SANG_STATUS_TX_TIMEOUT, and sangoma_interface::transmit().

Referenced by main().

00386 {
00387     FILE            *pFile;
00388     unsigned int    tx_counter=0, bytes_read_from_file, total_bytes_read_from_file=0;
00389     wp_api_hdr_t    hdr;
00390     unsigned char   local_tx_data[MAX_NO_DATA_BYTES_IN_FRAME];
00391 
00392     pFile = fopen( program_settings.szTxFileName, "rb" );
00393     if( pFile == NULL){
00394         ERR_MAIN( "Can't open file: [%s]\n", program_settings.szTxFileName );
00395         return 1;
00396     }
00397 
00398     do
00399     {
00400         //read tx data from the file. if 'bytes_read_from_file != txlength', end of file is reached
00401         bytes_read_from_file = fread( local_tx_data, 1, program_settings.txlength /* MTU size */, pFile );
00402         total_bytes_read_from_file += bytes_read_from_file;
00403 
00404         hdr.data_length = program_settings.txlength;//ALWAYS transmit MTU size over the BitStream/Voice interface
00405         hdr.operation_status = SANG_STATUS_TX_TIMEOUT;
00406         
00407         if(SANG_STATUS_SUCCESS != sang_if->transmit(&hdr, local_tx_data)){
00408             //error
00409             break;
00410         }
00411         
00412         tx_counter++;
00413         
00414         //DBG_MAIN("tx_counter: %u\r",tx_counter);
00415 
00416     }while(bytes_read_from_file == program_settings.txlength);
00417 
00418     INFO_MAIN("%s: Finished transmitting file \"%s\" (tx_counter: %u, total_bytes_read_from_file: %d)\n",
00419         sang_if->device_name, program_settings.szTxFileName, tx_counter, total_bytes_read_from_file);
00420 
00421     fclose( pFile );
00422     return 0;
00423 }

Here is the call graph for this function:

Here is the caller graph for this function:

int __cdecl main ( int  argc,
char *  argv[] 
)

Main function that starts the sample code.

Parameters:
argc number of arguments
argv argument list
Returns:
0 - ok non-zero - Error
Get user Input Set program settings based on user input Create SangomaInterface Class based on user span/chan input. Bind callback functions read/event to SangomaInteface class. Execute the SangomaInterface handling function -> start() The start function will read/write/event data. In Main thread prompt the user for commands.

Definition at line 624 of file sample.cpp.

References _getch, callback_functions, cleanup(), sangoma_interface::CreateSwDtmfTxThread(), DBG_MAIN, sangoma_interface::device_name, sangoma_interface::enable_rbs_monitoring(), EnterCriticalSection, sangoma_interface::flush_operational_stats(), sangoma_interface::fxo_go_off_hook(), sangoma_interface::fxo_go_on_hook(), sangoma_interface::get_adapter_type(), sangoma_interface::get_api_driver_version(), sangoma_interface::get_card_customer_id(), sangoma_interface::get_operational_stats(), sangoma_interface::get_rbs(), sangoma_interface::get_sub_media(), sangoma_interface::get_te1_56k_stat(), handle_span_chan(), INFO_MAIN, init(), InitializeCriticalSection, LeaveCriticalSection, _DRIVER_VERSION::major, MAX_NO_DATA_BYTES_IN_FRAME, _DRIVER_VERSION::minor, _DRIVER_VERSION::minor1, _DRIVER_VERSION::minor2, open_sangoma_device(), PrintCriticalSection, program_settings, pRxFile, sangoma_interface::resetFSKCID(), SANG_STATUS_SUCCESS, SANG_STATUS_TX_TIMEOUT, sangoma_msleep, sangoma_interface::sendCallerID(), sangoma_interface::sendSwDTMF(), sangoma_interface::set_fe_debug_mode(), sangoma_interface::set_lb_modes(), sangoma_interface::set_rbs(), sangoma_interface::set_tx_idle_flag(), start(), sangoma_interface::start_busy_tone(), sangoma_interface::start_congestion_tone(), sangoma_interface::start_dial_tone(), sangoma_interface::start_ring_tone(), sangoma_interface::start_ringing_phone(), stop(), sangoma_interface::stop_all_tones(), sangoma_interface::stop_ringing_phone(), sangoma_interface::tdm_disable_bri_bchan_loopback(), sangoma_interface::tdm_disable_dtmf_events(), sangoma_interface::tdm_disable_ring_detect_events(), sangoma_interface::tdm_disable_ring_trip_detect_events(), sangoma_interface::tdm_disable_rm_dtmf_events(), sangoma_interface::tdm_disable_rxhook_events(), sangoma_interface::tdm_enable_bri_bchan_loopback(), sangoma_interface::tdm_enable_dtmf_events(), sangoma_interface::tdm_enable_ring_detect_events(), sangoma_interface::tdm_enable_ring_trip_detect_events(), sangoma_interface::tdm_enable_rm_dtmf_events(), sangoma_interface::tdm_enable_rxhook_events(), sangoma_interface::tdm_front_end_activate(), sangoma_interface::tdm_front_end_deactivate(), sangoma_interface::tdm_get_front_end_status(), sangoma_interface::tdm_set_user_period(), TdmEventCriticalSection, TerminateHandler(), TEST_NUMBER_OF_OBJECTS, sangoma_interface::transmit(), TRUE, tx_file(), and WAN_BRI_BCHAN1.

00625 {
00626     int     rc, user_selection,err;
00627     sangoma_interface   *sang_if = NULL;
00628     wp_api_hdr_t        hdr;
00629     unsigned char       local_tx_data[MAX_NO_DATA_BYTES_IN_FRAME];
00630     UCHAR               tx_test_byte = 0;
00631 
00633     memset(&callback_functions, 0x00, sizeof(callback_functions));
00634     callback_functions.got_rx_data = got_rx_data;
00635     callback_functions.got_TdmApiEvent = got_TdmApiEvent;
00636 
00638     if(parse_command_line_args(argc, argv)){
00639         return 1;
00640     }
00641 
00643     //An OPTIONAL step of setting the port configuration to different values from
00644     //what is set in "Device Manager"-->"Sangoma Hardware Abstraction Driver".
00645 
00646     //set port configration and exit
00647     if (program_settings.driver_config) {
00648         err=set_port_configuration();
00649         if (err) {
00650             return err;
00651         }
00652     }
00653 
00655     //initialize critical section objects
00656     InitializeCriticalSection(&PrintCriticalSection);
00657     InitializeCriticalSection(&TdmEventCriticalSection);
00658 
00660     //User may provide Wanpipe Number and Interface Number as a command line arguments:
00661     INFO_MAIN("Using wanpipe_number: %d, interface_number: %d\n", program_settings.wanpipe_number, program_settings.interface_number);
00662 
00663     sang_if = init(program_settings.wanpipe_number, program_settings.interface_number);
00664 
00665     if(sang_if == NULL){
00666         return 1;
00667     }
00668 
00669     rc = start(sang_if);
00670     if(rc){
00671         cleanup(sang_if);
00672         return rc;
00673     }
00674 
00675     do{
00676         EnterCriticalSection(&PrintCriticalSection);
00677         INFO_MAIN("Press 'q' to quit the program.\n");
00678         INFO_MAIN("Press 't' to transmit data.\n");
00679         INFO_MAIN("Press 's' to get Operational Statistics.\n");
00680         INFO_MAIN("Press 'f' to reset (flush) Operational Statistics.\n");
00681         INFO_MAIN("Press 'v' to get API driver version.\n");
00682 
00683         if(sang_if->get_adapter_type() == WAN_MEDIA_T1 || sang_if->get_adapter_type() == WAN_MEDIA_E1){
00684             INFO_MAIN("Press 'a' to get T1/E1 alarms.\n");
00685             //RBS (CAS) commands
00686             INFO_MAIN("Press 'g' to get RBS bits.\n");
00687             INFO_MAIN("Press 'r' to set RBS bits.\n");
00688             INFO_MAIN("Press '1' to read FE register. Warning: used by Sangoma Techsupport only!\n");
00689             INFO_MAIN("Press '2' to write FE register.  Warning: used by Sangoma Techsupport only!\n");
00690         }
00691         INFO_MAIN("Press 'i' to set Tx idle data buffer (BitStream only).\n");
00692         switch(sang_if->get_adapter_type())
00693         {
00694         case WAN_MEDIA_T1:
00695             //those commands valid only for T1
00696             INFO_MAIN("Press 'l' to send 'activate remote loop back' signal.\n");
00697             INFO_MAIN("Press 'd' to send 'deactivate remote loop back' signal.\n");
00698             break;
00699         case WAN_MEDIA_FXOFXS:
00700             switch(sang_if->get_sub_media())
00701             {
00702             case MOD_TYPE_FXS:
00703                 INFO_MAIN("Press 'e' to listen to test tones on a phone connected to the A200-FXS\n");
00704                 INFO_MAIN("Press 'c' to ring/stop ring phone connected to the A200-FXS\n");
00705                 INFO_MAIN("Press 'n' to enable/disable reception of ON/OFF Hook events on A200-FXS\n");
00706                 INFO_MAIN("Press 'm' to enable DTMF events (on SLIC chip) on A200-FXS\n");
00707                 INFO_MAIN("Press 'j' to enable/disable reception of Ring Trip events on A200-FXS\n");
00708                 break;
00709 
00710             case MOD_TYPE_FXO:
00711                 INFO_MAIN("Press 'u' to enable/disable reception of Ring Detect events on A200-FXO\n");
00712                 INFO_MAIN("Press 'h' to transmit ON/OFF hook signals on A200-FXO\n");
00713                 INFO_MAIN("Press 'a' to get Line Status (Connected/Disconnected)\n");
00714                 break;
00715             }
00716             break;
00717         case WAN_MEDIA_BRI:
00718             INFO_MAIN("Press 'k' to Activate/Deactivate ISDN BRI line\n");
00719             INFO_MAIN("Press 'l' to enable  bri bchan loopback\n");
00720             INFO_MAIN("Press 'd' to disable bri bchan loopback\n");
00721             break;
00722         }
00723         INFO_MAIN("Press 'o' to enable DTMF events (on Octasic chip)\n");
00724         if (program_settings.encode_sw_dtmf) {
00725             INFO_MAIN("Press 'x' to send software DTMF\n");
00726         }
00727         if (program_settings.encode_fsk_cid) {
00728             INFO_MAIN("Press 'z' to send software FSK Caller ID\n");
00729         }
00730 
00731         LeaveCriticalSection(&PrintCriticalSection);
00732 
00733         user_selection = tolower(_getch());
00734         switch(user_selection)
00735         {
00736         case 'q':
00737             break;
00738         case 't':
00739             for(u_int32_t cnt = 0; cnt < program_settings.txcount; cnt++){
00740                 if(program_settings.szTxFileName[0]){
00741                     tx_file(sang_if);
00742                 }else{
00743                     hdr.data_length = program_settings.txlength;
00744                     hdr.operation_status = SANG_STATUS_TX_TIMEOUT;
00745                     //set the actual data for transmission
00746                     memset(local_tx_data, tx_test_byte, program_settings.txlength);
00747                     sang_if->transmit(&hdr, local_tx_data);
00748                     tx_test_byte++;
00749                 }
00750             }
00751             break;
00752         case 's':
00753             {
00754                 wanpipe_chan_stats_t stats;
00755                 sang_if->get_operational_stats(&stats);
00756             }
00757             break;
00758         case 'f':
00759             sang_if->flush_operational_stats();
00760             break;
00761         case 'v':
00762             {
00763                 DRIVER_VERSION version;
00764                 //read API driver version
00765                 sang_if->get_api_driver_version(&version);
00766                 INFO_MAIN("\nAPI version\t: %d,%d,%d,%d\n",
00767                     version.major, version.minor, version.minor1, version.minor2);
00768 
00769                 u_int8_t customer_id = 0;
00770                 sang_if->get_card_customer_id(&customer_id);
00771                 INFO_MAIN("\ncustomer_id\t: 0x%02X\n", customer_id);
00772             }
00773             break;
00774         case 'a':
00775             unsigned char cFeStatus;
00776 
00777             switch(sang_if->get_adapter_type())
00778             {
00779             case WAN_MEDIA_T1:
00780             case WAN_MEDIA_E1:
00781                 //read T1/E1/56k alarms
00782                 sang_if->get_te1_56k_stat();
00783                 break;
00784 
00785             case WAN_MEDIA_FXOFXS:
00786                 switch(sang_if->get_sub_media())
00787                 {
00788                 case MOD_TYPE_FXO:
00789                     cFeStatus = 0;
00790                     sang_if->tdm_get_front_end_status(&cFeStatus);
00791                     INFO_MAIN("cFeStatus: %s (%d)\n", FE_STATUS_DECODE(cFeStatus), cFeStatus);
00792                     break;
00793                 }
00794             }
00795             break;
00796         case 'l':
00797             switch(sang_if->get_adapter_type())
00798             {
00799             case WAN_MEDIA_T1:
00800             case WAN_MEDIA_E1:
00801                 //Activate Line/Remote Loopback mode:
00802                 sang_if->set_lb_modes(WAN_TE1_LINELB_MODE, WAN_TE1_LB_ENABLE);
00803                 //Activate Diagnostic Digital Loopback mode:
00804                 //sang_if->set_lb_modes(WAN_TE1_DDLB_MODE, WAN_TE1_LB_ENABLE);
00805                 //sang_if->set_lb_modes(WAN_TE1_PAYLB_MODE, WAN_TE1_LB_ENABLE);
00806                 break;
00807             case WAN_MEDIA_BRI:
00808                 sang_if->tdm_enable_bri_bchan_loopback(WAN_BRI_BCHAN1);
00809                 break;
00810             }
00811             break;
00812         case 'd':
00813             switch(sang_if->get_adapter_type())
00814             {
00815             case WAN_MEDIA_T1:
00816             case WAN_MEDIA_E1:
00817                 //Deactivate Line/Remote Loopback mode:
00818                 sang_if->set_lb_modes(WAN_TE1_LINELB_MODE, WAN_TE1_LB_DISABLE);
00819                 //Deactivate Diagnostic Digital Loopback mode:
00820                 //sang_if->set_lb_modes(WAN_TE1_DDLB_MODE, WAN_TE1_LB_DISABLE);
00821                 //sang_if->set_lb_modes(WAN_TE1_PAYLB_MODE, WAN_TE1_LB_DISABLE);
00822                 break;
00823             case WAN_MEDIA_BRI:
00824                 sang_if->tdm_disable_bri_bchan_loopback(WAN_BRI_BCHAN1);
00825                 break;
00826             }
00827             break;
00828         case 'g'://read RBS bits
00829             switch(sang_if->get_adapter_type())
00830             {
00831             case WAN_MEDIA_T1:
00832             case WAN_MEDIA_E1:
00833                 {
00834                     rbs_management_t rbs_management_struct = {0,0};
00835 
00836                     sang_if->enable_rbs_monitoring();
00837 
00838                     INFO_MAIN("Type Channel number and press <Enter>:\n");
00839                     rbs_management_struct.channel = get_user_decimal_number();//channels (Time Slots). Valid values: 1 to 24.
00840                     if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 24){
00841                         INFO_MAIN("Invalid RBS Channel number!\n");
00842                         break;
00843                     }
00844                     sang_if->get_rbs(&rbs_management_struct);
00845                 }
00846                 break;
00847             default:
00848                 INFO_MAIN("Command invalid for card type\n");
00849                 break;
00850             }//switch()
00851             break;
00852         case 'r'://set RBS bits
00853             switch(sang_if->get_adapter_type())
00854             {
00855             case WAN_MEDIA_T1:
00856             case WAN_MEDIA_E1:
00857                 {
00858                     static rbs_management_t rbs_management_struct = {0,0};
00859 
00860                     sang_if->enable_rbs_monitoring();
00861 
00862                     INFO_MAIN("Type Channel number and press <Enter>:\n");
00863                     rbs_management_struct.channel = get_user_decimal_number();//channels (Time Slots). Valid values: 1 to 24.
00864                     if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 24){
00865                         INFO_MAIN("Invalid RBS Channel number!\n");
00866                         break;
00867                     }
00868                     /*  bitmap - set as needed: WAN_RBS_SIG_A | WAN_RBS_SIG_B | WAN_RBS_SIG_C | WAN_RBS_SIG_D;
00869 
00870                     In this example make bits A and B to change each time,
00871                     so it's easy to see the change on the receiving side.
00872                     */
00873                     if(rbs_management_struct.ABCD_bits == WAN_RBS_SIG_A){
00874                         rbs_management_struct.ABCD_bits = WAN_RBS_SIG_B;
00875                     }else{
00876                         rbs_management_struct.ABCD_bits = WAN_RBS_SIG_A;
00877                     }
00878                     sang_if->set_rbs(&rbs_management_struct);
00879                 }
00880             default:
00881                 INFO_MAIN("Command invalid for card type\n");
00882                 break;
00883             }//switch()
00884             break;
00885         case 'i':
00886             {
00887                 INFO_MAIN("Type Idle Flag (HEX, for example: FE) and press <Enter>:\n");
00888                 unsigned char new_idle_flag = (unsigned char)get_user_hex_number();
00889                 sang_if->set_tx_idle_flag(new_idle_flag);
00890             }
00891             break;
00892         case 'c':
00893 user_retry_ring_e_d:
00894             INFO_MAIN("Press 'e' to START ring, 'd' to STOP ring, 't' to Toggle\n");
00895             INFO_MAIN("\n");
00896             user_selection = tolower(_getch());
00897             switch(user_selection)
00898             {
00899             case 'e':
00900                 INFO_MAIN("Starting Ring ...%c\n",user_selection);
00901                 sang_if->start_ringing_phone();//start
00902                 break;
00903             case 'd':
00904                 INFO_MAIN("Stopping Ring ... %c\n",user_selection);
00905                 sang_if->stop_ringing_phone();//stop
00906                 break;
00907             case 't':
00908                 {
00909                     int x;
00910                     for (x=0;x<500;x++) {
00911                         sang_if->start_ringing_phone();
00912                         sang_if->start_ringing_phone();
00913                         //sangoma_msleep(500);
00914                         sang_if->stop_ringing_phone();//stop
00915                         sang_if->stop_ringing_phone();//stop
00916                         //sangoma_msleep(500);
00917                         sang_if->start_busy_tone();
00918                         sangoma_msleep(50);
00919                         sang_if->stop_all_tones();
00920                         sangoma_msleep(50);
00921                     }
00922                 }
00923                 break;
00924             default:
00925                 goto user_retry_ring_e_d;
00926                 break;
00927             }
00928             break;
00929         case 'e':
00930             INFO_MAIN("Press 'e' to START a Tone, 'd' to STOP a Tone.\n");
00931             INFO_MAIN("\n");
00932 
00933             switch(tolower(_getch()))
00934             {
00935             case 'e':
00936                 INFO_MAIN("Press 'r' for Ring Tone, 'd' for Dial Tone, 'b' for Busy Tone, 'c' for Congestion Tone.\n");
00937                 INFO_MAIN("\n");
00938                 switch(tolower(_getch()))
00939                 {
00940                 case 'r':
00941                     sang_if->start_ring_tone();
00942                     break;
00943                 case 'd':
00944                     sang_if->start_dial_tone();
00945                     break;
00946                 case 'b':
00947                     sang_if->start_busy_tone();
00948                     break;
00949                 case 'c':
00950                 default:
00951                     sang_if->start_congestion_tone();
00952                     break;
00953                 }
00954                 break;
00955 
00956             case 'd':
00957             default:
00958                 sang_if->stop_all_tones();//stop all tones
00959             }
00960             break;
00961         case 'n':
00962             INFO_MAIN("Press 'e' to ENABLE Rx Hook Events, 'd' to DISABLE Rx Hook Events.\n");
00963             INFO_MAIN("\n");
00964             switch(tolower(_getch()))
00965             {
00966             case 'e':
00967                 sang_if->tdm_enable_rxhook_events();
00968                 break;
00969             case 'd':
00970             default:
00971                 sang_if->tdm_disable_rxhook_events();
00972             }
00973             break;
00974         case 'm':
00975             //Enable/Disable DTMF events on SLIC chip.
00976             //On Analog (A200) card only.
00977             INFO_MAIN("Press 'e' to ENABLE Remora DTMF Events, 'd' to DISABLE Remora DTMF Events.\n");
00978             INFO_MAIN("\n");
00979             switch(tolower(_getch()))
00980             {
00981             case 'e':
00982                 sang_if->tdm_enable_rm_dtmf_events();
00983                 break;
00984             case 'd':
00985             default:
00986                 sang_if->tdm_disable_rm_dtmf_events();
00987             }
00988             break;
00989         case 'o':
00990             {
00991                 //Enable DTMF events on Octasic chip. 
00992                 //For both Analog (A200) and T1/E1 (A104D) cards, but only if the chip is present.
00993                 INFO_MAIN("Press 'e' to ENABLE Octasic DTMF Events, 'd' to DISABLE Octasic DTMF Events.\n");
00994                 uint8_t channel;
00995 
00996                 INFO_MAIN("\n");
00997                 switch(tolower(_getch()))
00998                 {
00999                 case 'e':
01000                     INFO_MAIN("Type Channel number and press <Enter>:\n");
01001                     channel = (uint8_t)get_user_decimal_number();//channels (Time Slots). Valid values: 1 to 31.
01002 
01003                     sang_if->tdm_enable_dtmf_events(channel);
01004                     break;
01005                 case 'd':
01006                 default:
01007                     INFO_MAIN("Type Channel number and press <Enter>:\n");
01008                     channel = (uint8_t)get_user_decimal_number();//channels (Time Slots). Valid values: 1 to 31.
01009 
01010                     sang_if->tdm_disable_dtmf_events(channel);
01011                 }
01012             }
01013             break;
01014         case 'u':
01015             //Enable/Disable Ring Detect events on FXO. 
01016             INFO_MAIN("Press 'e' to ENABLE Rx Ring Detect Events, 'd' to DISABLE Rx Ring Detect Events.\n");
01017             INFO_MAIN("\n");
01018             switch(tolower(_getch()))
01019             {
01020             case 'e':
01021                 sang_if->tdm_enable_ring_detect_events();
01022                 break;
01023             case 'd':
01024             default:
01025                 sang_if->tdm_disable_ring_detect_events();
01026             }
01027             break;
01028         case 'j':
01029             //Enable/Disable Ring Trip events on FXS. 
01030             INFO_MAIN("Press 'e' to ENABLE Rx Ring Trip Events, 'd' to DISABLE Rx Ring Trip Events.\n");
01031             INFO_MAIN("\n");
01032             switch(tolower(_getch()))
01033             {
01034             case 'e':
01035                 sang_if->tdm_enable_ring_trip_detect_events();
01036                 break;
01037             case 'd':
01038             default:
01039                 sang_if->tdm_disable_ring_trip_detect_events();
01040             }
01041             break;
01042         case 'h':
01043             INFO_MAIN("Press 'e' to transmit OFF hook signal, 'd' to transmit ON hook signal.\n");
01044             INFO_MAIN("\n");
01045             switch(tolower(_getch()))
01046             {
01047             case 'e':
01048                 sang_if->fxo_go_off_hook();
01049                 break;
01050             case 'd':
01051             default:
01052                 sang_if->fxo_go_on_hook();
01053             }
01054             break;
01055         case 'k':
01056             INFO_MAIN("Press 'e' to Activate, 'd' to De-Activate line.\n");
01057             INFO_MAIN("\n");
01058             switch(tolower(_getch()))
01059             {
01060             case 'e':
01061                 sang_if->tdm_front_end_activate();
01062                 break;
01063             case 'd':
01064             default:
01065                 sang_if->tdm_front_end_deactivate();
01066             }
01067             break;
01068         case 'p':
01069             {
01070                 int user_period;//Milliseconds interval between receive of Voice Data
01071                 INFO_MAIN("Type User Period and press <Enter>. Valid values are: 10, 20, 40.\n");
01072                 user_period = get_user_decimal_number();
01073                 switch(user_period)
01074                 {
01075                 case 10:
01076                 case 20:
01077                 case 40:
01078                     sang_if->tdm_set_user_period(user_period);
01079                     break;
01080                 default:
01081                     INFO_MAIN("Invalid User Period value! Valid values are: 10, 20, 40.\n");
01082                     break;
01083                 }
01084             }
01085             break;
01086 #if USE_STELEPHONY_API
01087         case 'x':
01088             {   
01089                 INFO_MAIN("Press a key. Valid values are 0-9, A-C\n");
01090                 int user_char = _getch();
01091                 switch(tolower(user_char)) {
01092                     case '1': case '2': case '3':
01093                     case '4': case '5': case '6':
01094                     case '7': case '8': case '9':
01095                     case '0': case 'a': case 'b':
01096                     case 'c':
01097                         INFO_MAIN("Sending DTMF (%c).\n", user_char);
01098                         sang_if->sendSwDTMF((char)user_char);
01099                         break;
01100                     default:
01101                         INFO_MAIN("Invalid DTMF Char! Valid values are: 0-9, A-C\n");
01102                     break;
01103                 }
01104             }
01105             break;
01106         case 'z':
01107             {
01108                 INFO_MAIN("Sending CallerID.\n");
01109                 sang_if->sendCallerID("Sangoma Rocks", "9054741990");
01110             }
01111             break;
01112 #endif
01113         case '1':/* read FE register */
01114             {
01115                 int value;
01116                 sdla_fe_debug_t fe_debug;
01117 
01118                 fe_debug.type = WAN_FE_DEBUG_REG;
01119 
01120                 printf("Type Register number (hex) i.g. F8 and press Enter:");
01121                 value = get_user_hex_number();
01122 
01123                 fe_debug.fe_debug_reg.reg  = value;
01124                 fe_debug.fe_debug_reg.read = 1;
01125 
01126                 sang_if->set_fe_debug_mode(&fe_debug);
01127             }
01128             break;
01129 
01130         case '2':/* write FE register */
01131             {
01132                 int value;
01133                 sdla_fe_debug_t fe_debug;
01134                 fe_debug.type = WAN_FE_DEBUG_REG;
01135 
01136                 printf("WRITE: Type Register number (hex) i.g. F8 and press Enter:");
01137                 value = get_user_hex_number();
01138 
01139                 fe_debug.fe_debug_reg.reg  = value;
01140                 fe_debug.fe_debug_reg.read = 1;
01141 
01142                 printf("WRITE: Type value (hex) i.g. 1A and press Enter:");
01143                 value = get_user_hex_number();
01144 
01145                 fe_debug.fe_debug_reg.read = 0;
01146                 fe_debug.fe_debug_reg.value = (unsigned char)value;
01147 
01148                 sang_if->set_fe_debug_mode(&fe_debug);
01149             }
01150             break;
01151 
01152         default:
01153             INFO_MAIN("Invalid command.\n");
01154         }       
01155     }while(user_selection != 'q');
01156 
01157     stop(sang_if);
01158     cleanup(sang_if);
01159 
01160     return 0;
01161 }//main()

Here is the call graph for this function:


Generated on Fri Jun 26 12:46:24 2009 for libsangoma by  doxygen 1.4.7