sample.cpp File Reference

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

#include "sample.h"
#include "sangoma_port.h"
#include "sangoma_port_configurator.h"
#include "sangoma_interface.h"
#include <conio.h>

Include dependency graph for sample.cpp:

Go to the source code of this file.

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

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

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 107 of file sample.cpp.

References sangoma_interface::init().

00108 {
00109     sangoma_interface   *sang_if = NULL;
00110     DBG_MAIN("%s()\n", __FUNCTION__);
00111 
00112     if(program_settings.use_ctrl_dev == 1){
00113         sang_if = new sangoma_api_ctrl_dev();
00114     }else if(program_settings.use_logger_dev == 1){
00115         sang_if = new sangoma_api_logger_dev();
00116     }else{
00117         sang_if = new sangoma_interface(wanpipe_number, interface_number);
00118     }
00119 
00120     if(sang_if->init(&callback_functions)){
00121         delete sang_if;
00122         return NULL;
00123     }
00124 
00125     DBG_MAIN("init(): OK\n");
00126     return sang_if;
00127 }

Here is the call 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 135 of file sample.cpp.

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

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 149 of file sample.cpp.

References sangoma_interface::run().

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

Here is the call 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 161 of file sample.cpp.

References sangoma_interface::stop().

00162 {
00163     DBG_MAIN("stop()\n");
00164     sang_if->stop();
00165 }

Here is the call 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 173 of file sample.cpp.

References wp_api_hdr::data_length, wp_api_hdr::time_stamp_sec, and wp_api_hdr::time_stamp_usec.

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

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 381 of file sample.cpp.

References wp_api_hdr::data_length, sangoma_interface::device_name, MAX_NO_DATA_BYTES_IN_FRAME, wp_api_hdr::operation_status, SANG_STATUS_SUCCESS, SANG_STATUS_TX_TIMEOUT, and sangoma_interface::transmit().

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

Here is the call graph for this function:

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

Main function that starts the sample code.

Main function start of the applicatoin.

Parameters:
argc number of arguments
argv argument list
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 679 of file sample.cpp.

References _getch, cleanup(), handle_span_chan(), MAX_NO_DATA_BYTES_IN_FRAME, open_sangoma_device(), TerminateHandler(), TEST_NUMBER_OF_OBJECTS, and TRUE.

00680 {
00681     int     rc, user_selection,err;
00682     sangoma_interface   *sang_if = NULL;
00683     wp_api_hdr_t        hdr;
00684     unsigned char       local_tx_data[MAX_NO_DATA_BYTES_IN_FRAME];
00685     UCHAR               tx_test_byte = 0;
00686 
00688     memset(&callback_functions, 0x00, sizeof(callback_functions));
00689     callback_functions.got_rx_data = got_rx_data;
00690     callback_functions.got_tdm_api_event = got_tdm_api_event;
00691 #if USE_WP_LOGGER
00692     callback_functions.got_logger_event = got_logger_event;
00693 #endif
00695     if(parse_command_line_args(argc, argv)){
00696         return 1;
00697     }
00698 
00700     //An OPTIONAL step of setting the port configuration to different values from
00701     //what is set in "Device Manager"-->"Sangoma Hardware Abstraction Driver".
00702 
00703     //set port configration and exit
00704     if (program_settings.driver_config) {
00705         err=set_port_configuration();
00706         if (err) {
00707             return err;
00708         }
00709     }
00710 
00712     //initialize critical section objects
00713     InitializeCriticalSection(&PrintCriticalSection);
00714     InitializeCriticalSection(&TdmEventCriticalSection);
00715 
00716     if (program_settings.real_time) {
00717         sng_set_process_priority_to_real_time();
00718     }
00719 
00721     //User may provide Wanpipe Number and Interface Number as a command line arguments:
00722     INFO_MAIN("Using wanpipe_number: %d, interface_number: %d\n", program_settings.wanpipe_number, program_settings.interface_number);
00723 
00724     sang_if = init(program_settings.wanpipe_number, program_settings.interface_number);
00725 
00726     if(sang_if == NULL){
00727         return 1;
00728     }
00729 
00730     rc = start(sang_if);
00731     if(rc){
00732         cleanup(sang_if);
00733         return rc;
00734     }
00735     if(program_settings.txgain !=  0xFFFF) {
00736         INFO_MAIN("Applying  txgain...\n");
00737         if (sang_if->tdm_control_rm_txgain(program_settings.txgain)){
00738             INFO_MAIN("Failed to apply txgain!\n");
00739         }
00740     }
00741     
00742     /* FXS cannot detect if phone is connected or not when the card is started
00743         therefore tranmit following two events for Set Polarity to work */
00744     if(sang_if->get_adapter_type() == WAN_MEDIA_FXOFXS && sang_if->get_sub_media() == MOD_TYPE_FXS) {
00745             INFO_MAIN("Setting Proper hookstates on FXS\n");
00746             sang_if->tdm_txsig_offhook();
00747             sang_if->tdm_txsig_onhook();
00748     }
00749 
00750     if(program_settings.rxgain !=  0xFFFF) {
00751         INFO_MAIN("Applying rxgain...\n");
00752         if (sang_if->tdm_control_rm_rxgain(program_settings.rxgain)){
00753             INFO_MAIN("Failed to apply rxgain!\n");
00754         }
00755     }
00756     do{
00757         EnterCriticalSection(&PrintCriticalSection);
00758         
00759         INFO_MAIN("Press 'q' to quit the program.\n");
00760         INFO_MAIN("Press 's' to get Operational Statistics.\n");
00761         INFO_MAIN("Press 'f' to reset (flush) Operational Statistics.\n");
00762 
00763         if(program_settings.use_logger_dev != 1){
00764             /* these options valid for non-logger api devices */
00765             INFO_MAIN("Press 't' to transmit data.\n");
00766             INFO_MAIN("Press 'v' to get API driver version.\n");
00767 
00768             if(sang_if->get_adapter_type() == WAN_MEDIA_T1 || sang_if->get_adapter_type() == WAN_MEDIA_E1){
00769                 INFO_MAIN("Press 'a' to get T1/E1 alarms.\n");
00770                 //RBS (CAS) commands
00771                 INFO_MAIN("Press 'g' to get RBS bits.\n");
00772                 INFO_MAIN("Press 'r' to set RBS bits.\n");
00773                 INFO_MAIN("Press '1' to read FE register. Warning: used by Sangoma Techsupport only!\n");
00774                 INFO_MAIN("Press '2' to write FE register.  Warning: used by Sangoma Techsupport only!\n");
00775             }
00776             INFO_MAIN("Press 'i' to set Tx idle data buffer (BitStream only).\n");
00777             switch(sang_if->get_adapter_type())
00778             {
00779             case WAN_MEDIA_T1:
00780                 //those commands valid only for T1
00781                 INFO_MAIN("Press 'l' to send 'activate remote loop back' signal.\n");
00782                 INFO_MAIN("Press 'd' to send 'deactivate remote loop back' signal.\n");
00783                 break;
00784             case WAN_MEDIA_FXOFXS:
00785                 switch(sang_if->get_sub_media())
00786                 {
00787                 case MOD_TYPE_FXS:
00788                     INFO_MAIN("Press 'e' to listen to test tones on a phone connected to the A200-FXS\n");
00789                     INFO_MAIN("Press 'c' to ring/stop ring phone connected to the A200-FXS\n");
00790                     INFO_MAIN("Press 'n' to enable/disable reception of ON/OFF Hook events on A200-FXS\n");
00791                     INFO_MAIN("Press 'm' to enable DTMF events (on SLIC chip) on A200-FXS\n");
00792                     INFO_MAIN("Press 'j 'to enable/disable reception of Ring Trip events on A200-FXS\n");
00793                     INFO_MAIN("Press 'k' to transmit kewl - drop line voltage on the line connected to the A200-FXS\n");
00794                     INFO_MAIN("Press 'h' to set polarity on the line connected to the A200-fXS\n");
00795                     INFO_MAIN("Press 'u' to transmit onhooktransfer on the line connected to the A200-FXS\n");
00796                     break;
00797 
00798                 case MOD_TYPE_FXO:
00799                     INFO_MAIN("Press 'u' to enable/disable reception of Ring Detect events on A200-FXO\n");
00800                     INFO_MAIN("Press 'h' to transmit ON/OFF hook signals on A200-FXO\n");
00801                     INFO_MAIN("Press 'a' to get Line Status (Connected/Disconnected)\n");
00802                     break;
00803                 }
00804                 break;
00805             case WAN_MEDIA_BRI:
00806                 INFO_MAIN("Press 'k' to Activate/Deactivate ISDN BRI line\n");
00807                 INFO_MAIN("Press 'l' to enable  bri bchan loopback\n");
00808                 INFO_MAIN("Press 'd' to disable bri bchan loopback\n");
00809                 break;
00810             }
00811             INFO_MAIN("Press 'o' to control DTMF events on DSP (Octasic)\n");
00812             if (program_settings.encode_sw_dtmf) {
00813                 INFO_MAIN("Press 'x' to send software DTMF\n");
00814             }
00815             if (program_settings.encode_fsk_cid) {
00816                 INFO_MAIN("Press 'z' to send software FSK Caller ID\n");
00817             }
00818         }//if(program_settings.use_logger_dev != 1)
00819 
00820         LeaveCriticalSection(&PrintCriticalSection);
00821         user_selection = tolower(_getch());
00822         switch(user_selection)
00823         {
00824         case 'q':
00825             break;
00826         case 't':
00827             for(u_int32_t cnt = 0; cnt < program_settings.txcount; cnt++){
00828                 if(program_settings.szTxFileName[0]){
00829                     tx_file(sang_if);
00830                 }else{
00831                     hdr.data_length = program_settings.txlength;
00832                     hdr.operation_status = SANG_STATUS_TX_TIMEOUT;
00833                     //set the actual data for transmission
00834                     memset(local_tx_data, tx_test_byte, program_settings.txlength);
00835                     sang_if->transmit(&hdr, local_tx_data);
00836                     tx_test_byte++;
00837                 }
00838             }
00839             break;
00840         case 's':
00841             if(program_settings.use_logger_dev == 1){
00842                 wp_logger_stats_t stats;
00843                 /* Warning: for demonstration purposes only, it is assumed,
00844                  *          that 'sang_if' is 'sangoma_api_logger_dev'. */
00845                 ((sangoma_api_logger_dev*)sang_if)->get_logger_dev_operational_stats(&stats);
00846             }else{
00847                 wanpipe_chan_stats_t stats;
00848                 sang_if->get_operational_stats(&stats);
00849             }
00850             break;
00851         case 'f':
00852             sang_if->flush_operational_stats();
00853             break;
00854         case 'v':
00855             {
00856                 DRIVER_VERSION version;
00857                 //read API driver version
00858                 sang_if->get_api_driver_version(&version);
00859                 INFO_MAIN("\nAPI version\t: %d,%d,%d,%d\n",
00860                     version.major, version.minor, version.minor1, version.minor2);
00861 
00862                 u_int8_t customer_id = 0;
00863                 sang_if->get_card_customer_id(&customer_id);
00864                 INFO_MAIN("\ncustomer_id\t: 0x%02X\n", customer_id);
00865             }
00866             break;
00867         case 'a':
00868             unsigned char cFeStatus;
00869 
00870             switch(sang_if->get_adapter_type())
00871             {
00872             case WAN_MEDIA_T1:
00873             case WAN_MEDIA_E1:
00874                 //read T1/E1/56k alarms
00875                 sang_if->get_te1_56k_stat();
00876                 break;
00877 
00878             case WAN_MEDIA_FXOFXS:
00879                 switch(sang_if->get_sub_media())
00880                 {
00881                 case MOD_TYPE_FXO:
00882                     cFeStatus = 0;
00883                     sang_if->tdm_get_front_end_status(&cFeStatus);
00884                     INFO_MAIN("cFeStatus: %s (%d)\n", FE_STATUS_DECODE(cFeStatus), cFeStatus);
00885                     break;
00886                 }
00887             }
00888             break;
00889         case 'l':
00890             switch(sang_if->get_adapter_type())
00891             {
00892             case WAN_MEDIA_T1:
00893             case WAN_MEDIA_E1:
00894                 //Activate Line/Remote Loopback mode:
00895                 sang_if->set_lb_modes(WAN_TE1_LINELB_MODE, WAN_TE1_LB_ENABLE);
00896                 //Activate Diagnostic Digital Loopback mode:
00897                 //sang_if->set_lb_modes(WAN_TE1_DDLB_MODE, WAN_TE1_LB_ENABLE);
00898                 //sang_if->set_lb_modes(WAN_TE1_PAYLB_MODE, WAN_TE1_LB_ENABLE);
00899                 break;
00900             case WAN_MEDIA_BRI:
00901                 sang_if->tdm_enable_bri_bchan_loopback(WAN_BRI_BCHAN1);
00902                 break;
00903             }
00904             break;
00905         case 'd':
00906             switch(sang_if->get_adapter_type())
00907             {
00908             case WAN_MEDIA_T1:
00909             case WAN_MEDIA_E1:
00910                 //Deactivate Line/Remote Loopback mode:
00911                 sang_if->set_lb_modes(WAN_TE1_LINELB_MODE, WAN_TE1_LB_DISABLE);
00912                 //Deactivate Diagnostic Digital Loopback mode:
00913                 //sang_if->set_lb_modes(WAN_TE1_DDLB_MODE, WAN_TE1_LB_DISABLE);
00914                 //sang_if->set_lb_modes(WAN_TE1_PAYLB_MODE, WAN_TE1_LB_DISABLE);
00915                 break;
00916             case WAN_MEDIA_BRI:
00917                 sang_if->tdm_disable_bri_bchan_loopback(WAN_BRI_BCHAN1);
00918                 break;
00919             }
00920             break;
00921         case 'g'://read RBS bits
00922             switch(sang_if->get_adapter_type())
00923             {
00924             case WAN_MEDIA_T1:
00925             case WAN_MEDIA_E1:
00926                 {
00927                     rbs_management_t rbs_management_struct = {0,0};
00928 
00929                     sang_if->enable_rbs_monitoring();
00930 
00931                     INFO_MAIN("Type Channel number and press <Enter>:\n");
00932                     rbs_management_struct.channel = get_user_decimal_number();//channels (Time Slots). Valid values: 1 to 24.
00933 
00934                     if(WAN_MEDIA_T1 == sang_if->get_adapter_type()){
00935                         if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 24){
00936                             INFO_MAIN("Invalid T1 RBS Channel number!\n");
00937                             break;
00938                         }
00939                     }
00940 
00941                     if(WAN_MEDIA_E1 == sang_if->get_adapter_type()){
00942                         if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 31){
00943                             INFO_MAIN("Invalid E1 CAS Channel number!\n");
00944                             break;
00945                         }
00946                     }
00947 
00948                     sang_if->get_rbs(&rbs_management_struct);
00949                 }
00950                 break;
00951             default:
00952                 INFO_MAIN("Command invalid for card type\n");
00953                 break;
00954             }//switch()
00955             break;
00956         case 'r'://set RBS bits
00957             switch(sang_if->get_adapter_type())
00958             {
00959             case WAN_MEDIA_T1:
00960             case WAN_MEDIA_E1:
00961                 {
00962                     static rbs_management_t rbs_management_struct = {0,0};
00963                     int chan_no;
00964 
00965                     sang_if->enable_rbs_monitoring();
00966 
00967                     INFO_MAIN("Type Channel number and press <Enter>:\n");
00968                     rbs_management_struct.channel = chan_no = get_user_decimal_number();//channels (Time Slots). Valid values: T1: 1 to 24; E1: 1-15 and 17-31.
00969 
00970                     if(WAN_MEDIA_T1 == sang_if->get_adapter_type()){
00971                         if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 24){
00972                             INFO_MAIN("Invalid T1 RBS Channel number!\n");
00973                             break;
00974                         }
00975                     }
00976 
00977                     if(WAN_MEDIA_E1 == sang_if->get_adapter_type()){
00978                         if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 31){
00979                             INFO_MAIN("Invalid E1 CAS Channel number!\n");
00980                             break;
00981                         }
00982                     }
00983 
00984                     /*  bitmap - set as needed: WAN_RBS_SIG_A | WAN_RBS_SIG_B | WAN_RBS_SIG_C | WAN_RBS_SIG_D;
00985 
00986                     In this example make bits A and B to change each time,
00987                     so it's easy to see the change on the receiving side.
00988                     */
00989                     if(rbs_management_struct.ABCD_bits == WAN_RBS_SIG_A){
00990                         rbs_management_struct.ABCD_bits = WAN_RBS_SIG_B;
00991                     }else{
00992                         rbs_management_struct.ABCD_bits = WAN_RBS_SIG_A;
00993                     }
00994                     sang_if->set_rbs(&rbs_management_struct);
00995 
00996 #if 0
00997 #define RBS_CAS_TX_AND_WAIT(chan, abcd) \
00998 {   \
00999     rbs_management_struct.channel = chan;   \
01000     rbs_management_struct.ABCD_bits = abcd;     \
01001     INFO_MAIN("Press any key to transmit bits:");   \
01002     wp_print_rbs_cas_bits(abcd);    \
01003     _getch();   \
01004     sang_if->set_rbs(&rbs_management_struct);   \
01005 }
01006 
01007                     //for ESF lines test all all combinations of 4 bits
01008                     RBS_CAS_TX_AND_WAIT(chan_no, 0x00);
01009 
01010                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A);
01011 
01012                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_B);
01013 
01014                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_B);
01015 
01016                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_C);
01017 
01018                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_C);
01019 
01020                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_B | WAN_RBS_SIG_C);
01021 
01022                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_B | WAN_RBS_SIG_C);
01023 
01024                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_D);
01025 
01026                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_D);
01027 
01028                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_B | WAN_RBS_SIG_D);
01029 
01030                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_B | WAN_RBS_SIG_D);
01031 
01032                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_C | WAN_RBS_SIG_D);
01033 
01034                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_C | WAN_RBS_SIG_D);
01035 
01036                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_B | WAN_RBS_SIG_C | WAN_RBS_SIG_D);
01037 
01038                     RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_B | WAN_RBS_SIG_C | WAN_RBS_SIG_D);
01039 #endif
01040                 }
01041             default:
01042                 INFO_MAIN("Command invalid for card type\n");
01043                 break;
01044             }//switch()
01045             break;
01046         case 'i':
01047             {
01048                 INFO_MAIN("Type Idle Flag (HEX, for example: FE) and press <Enter>:\n");
01049                 unsigned char new_idle_flag = (unsigned char)get_user_hex_number();
01050                 sang_if->set_tx_idle_flag(new_idle_flag);
01051             }
01052             break;
01053         case 'c':
01054 user_retry_ring_e_d:
01055             INFO_MAIN("Press 'e' to START ring, 'd' to STOP ring, 't' to Toggle\n");
01056             INFO_MAIN("\n");
01057             user_selection = tolower(_getch());
01058             switch(user_selection)
01059             {
01060             case 'e':
01061                 INFO_MAIN("Starting Ring ...%c\n",user_selection);
01062                 sang_if->start_ringing_phone();//start
01063                 break;
01064             case 'd':
01065                 INFO_MAIN("Stopping Ring ... %c\n",user_selection);
01066                 sang_if->stop_ringing_phone();//stop
01067                 break;
01068             case 't':
01069                 {
01070                     int x;
01071                     for (x=0;x<500;x++) {
01072                         sang_if->start_ringing_phone();
01073                         sang_if->start_ringing_phone();
01074                         //sangoma_msleep(500);
01075                         sang_if->stop_ringing_phone();//stop
01076                         sang_if->stop_ringing_phone();//stop
01077                         //sangoma_msleep(500);
01078                         sang_if->start_busy_tone();
01079                         sangoma_msleep(50);
01080                         sang_if->stop_all_tones();
01081                         sangoma_msleep(50);
01082                     }
01083                 }
01084                 break;
01085             default:
01086                 goto user_retry_ring_e_d;
01087                 break;
01088             }
01089             break;
01090         case 'e':
01091             INFO_MAIN("Press 'e' to START a Tone, 'd' to STOP a Tone.\n");
01092             INFO_MAIN("\n");
01093 
01094             switch(tolower(_getch()))
01095             {
01096             case 'e':
01097                 INFO_MAIN("Press 'r' for Ring Tone, 'd' for Dial Tone, 'b' for Busy Tone, 'c' for Congestion Tone.\n");
01098                 INFO_MAIN("\n");
01099                 switch(tolower(_getch()))
01100                 {
01101                 case 'r':
01102                     sang_if->start_ring_tone();
01103                     break;
01104                 case 'd':
01105                     sang_if->start_dial_tone();
01106                     break;
01107                 case 'b':
01108                     sang_if->start_busy_tone();
01109                     break;
01110                 case 'c':
01111                 default:
01112                     sang_if->start_congestion_tone();
01113                     break;
01114                 }
01115                 break;
01116 
01117             case 'd':
01118             default:
01119                 sang_if->stop_all_tones();//stop all tones
01120             }
01121             break;
01122         case 'n':
01123             INFO_MAIN("Press 'e' to ENABLE Rx Hook Events, 'd' to DISABLE Rx Hook Events.\n");
01124             INFO_MAIN("\n");
01125             switch(tolower(_getch()))
01126             {
01127             case 'e':
01128                 sang_if->tdm_enable_rxhook_events();
01129                 break;
01130             case 'd':
01131             default:
01132                 sang_if->tdm_disable_rxhook_events();
01133             }
01134             break;
01135         case 'm':
01136             //Enable/Disable DTMF events on SLIC chip.
01137             //On Analog (A200) card only.
01138             INFO_MAIN("Press 'e' to ENABLE Remora DTMF Events, 'd' to DISABLE Remora DTMF Events.\n");
01139             INFO_MAIN("\n");
01140             switch(tolower(_getch()))
01141             {
01142             case 'e':
01143                 sang_if->tdm_enable_rm_dtmf_events();
01144                 break;
01145             case 'd':
01146             default:
01147                 sang_if->tdm_disable_rm_dtmf_events();
01148             }
01149             break;
01150         case 'o':
01151             {
01152                 //Enable DTMF events on Octasic chip. 
01153                 //For both Analog (A200) and T1/E1 (A104D) cards, but only if the chip is present.
01154                 INFO_MAIN("Press 'e' to ENABLE Octasic DTMF Events, 'd' to DISABLE Octasic DTMF Events.\n");
01155                 uint8_t channel;
01156 
01157                 INFO_MAIN("\n");
01158                 switch(tolower(_getch()))
01159                 {
01160                 case 'e':
01161                     INFO_MAIN("Type Channel number and press <Enter>:\n");
01162                     channel = (uint8_t)get_user_decimal_number();//channels (Time Slots). Valid values: 1 to 31.
01163 
01164                     sang_if->tdm_enable_dtmf_events(channel);
01165                     break;
01166                 case 'd':
01167                 default:
01168                     INFO_MAIN("Type Channel number and press <Enter>:\n");
01169                     channel = (uint8_t)get_user_decimal_number();//channels (Time Slots). Valid values: 1 to 31.
01170 
01171                     sang_if->tdm_disable_dtmf_events(channel);
01172                 }
01173             }
01174             break;
01175         case 'u':
01176             //Enable/Disable Ring Detect events on FXO. 
01177             if(sang_if->get_sub_media()==MOD_TYPE_FXO){
01178                 INFO_MAIN("Press 'e' to ENABLE Rx Ring Detect Events, 'd' to DISABLE Rx Ring Detect Events.\n");
01179                 INFO_MAIN("\n");
01180                 switch(tolower(_getch()))
01181                 {
01182                 case 'e':
01183                     sang_if->tdm_enable_ring_detect_events();
01184                     break;
01185                 case 'd':
01186                 default:
01187                     sang_if->tdm_disable_ring_detect_events();
01188                 }
01189             }else if(sang_if->get_sub_media()==MOD_TYPE_FXS){
01190                     sang_if->tdm_txsig_onhooktransfer();
01191             }
01192             break;
01193         case 'j':
01194             //Enable/Disable Ring Trip events on FXS. 
01195             INFO_MAIN("Press 'e' to ENABLE Rx Ring Trip Events, 'd' to DISABLE Rx Ring Trip Events.\n");
01196             INFO_MAIN("\n");
01197             switch(tolower(_getch()))
01198             {
01199             case 'e':
01200                 sang_if->tdm_enable_ring_trip_detect_events();
01201                 break;
01202             case 'd':
01203             default:
01204                 sang_if->tdm_disable_ring_trip_detect_events();
01205             }
01206             break;
01207         case 'h':
01208             if(sang_if->get_sub_media()==MOD_TYPE_FXO) {
01209                 INFO_MAIN("Press 'e' to transmit OFF hook signal, 'd' to transmit ON hook signal.\n");
01210                 INFO_MAIN("\n");
01211                 switch(tolower(_getch()))
01212                 {
01213                 case 'e':
01214                     sang_if->fxo_go_off_hook();
01215                     break;
01216                 case 'd':
01217                 default:
01218                     sang_if->fxo_go_on_hook();
01219                 }
01220             }else if(sang_if->get_sub_media() == MOD_TYPE_FXS) {
01221                 INFO_MAIN("Press 'f' for forward, 'r' to for reverse.\n");
01222                 INFO_MAIN("\n");
01223                 switch(tolower(_getch()))
01224                 {
01225                 case 'f':
01226                     sang_if->tdm_set_rm_polarity(0);
01227                     break;
01228                 case 'r':
01229                     sang_if->tdm_set_rm_polarity(1);
01230                     break;
01231                 default:
01232                     //toggle polarity 
01233                     int polarity_wait, two_second_ring_repetion_counter;
01234 
01235                     INFO_MAIN("Type Polarity Reverse/Forward delay and press <Enter>:\n");
01236                     polarity_wait = get_user_decimal_number();
01237                     if (!polarity_wait) {
01238                         ERR_MAIN("Invalid User-specified Polarity Reverse/Forward delay: %d!\n", polarity_wait);
01239                         polarity_wait = 400;
01240                     }
01241                     /* polarity_wait of 30 ms will ring Analog phone or FXO
01242                      * polarity_wait of 400 ms will cause Polarity reversal event on FXO */
01243                     INFO_MAIN("User specified Polarity Reverse/Forward delay: %d. Press <Enter> to continue.\n", polarity_wait);
01244                     _getch();
01245 
01246                     /* calculate number of iterations for a 2-second test */
01247                     two_second_ring_repetion_counter = 2000 / (polarity_wait * 2);
01248                     INFO_MAIN("two_second_ring_repetion_counter: %d. Press <Enter> to continue.\n", two_second_ring_repetion_counter);
01249                     _getch();
01250 
01251                     for (int ii = 0; ii < two_second_ring_repetion_counter; ii++) {
01252                         INFO_MAIN("Reversing polarity %d...\n", ii);
01253                         sang_if->tdm_set_rm_polarity(1);
01254                         sangoma_msleep(polarity_wait);
01255                         INFO_MAIN("Forwarding polarity %d...\n", ii);
01256                         sang_if->tdm_set_rm_polarity(0);
01257                         sangoma_msleep(polarity_wait);
01258                     }
01259 
01260                     //sleep 4 seconds between the rings
01261                     INFO_MAIN("4 seconds between the rings...\n");
01262                     sangoma_msleep(4000);
01263 
01264                     for (int ii = 0; ii < two_second_ring_repetion_counter; ii++) {
01265                         INFO_MAIN("Reversing polarity %d...\n", ii);
01266                         sang_if->tdm_set_rm_polarity(1);
01267                         sangoma_msleep(polarity_wait);
01268                         INFO_MAIN("Forwarding polarity %d...\n", ii);
01269                         sang_if->tdm_set_rm_polarity(0);
01270                         sangoma_msleep(polarity_wait);
01271                     }//for()
01272                 }//switch()
01273             }
01274             break;
01275         case 'k':
01276             if( sang_if->get_adapter_type() == WAN_MEDIA_BRI ) {
01277                 INFO_MAIN("Press 'e' to Activate, 'd' to De-Activate line.\n");
01278                 INFO_MAIN("\n");
01279                 switch(tolower(_getch()))
01280                 {
01281                 case 'e':
01282                     sang_if->tdm_front_end_activate();
01283                     break;
01284                 case 'd':
01285                 default:
01286                     sang_if->tdm_front_end_deactivate();
01287                 }
01288             }else if(sang_if->get_adapter_type()== WAN_MEDIA_FXOFXS) {
01289                 if(sang_if->get_sub_media()==MOD_TYPE_FXS) {
01290                     printf("calling tdm_txsig_kewl()...\n");
01291                     sang_if->tdm_txsig_kewl();
01292                     sangoma_msleep(5000);
01293                     //to restore line current after txsig kewl
01294                     printf("restoring line current after txsig kewl...\n");
01295                     sang_if->tdm_txsig_offhook();
01296                 }
01297             }
01298             break;
01299         case 'p':
01300             {
01301                 int user_period;//Milliseconds interval between receive of Voice Data
01302                 INFO_MAIN("Type User Period and press <Enter>. Valid values are: 10, 20, 40.\n");
01303                 user_period = get_user_decimal_number();
01304                 switch(user_period)
01305                 {
01306                 case 10:
01307                 case 20:
01308                 case 40:
01309                     sang_if->tdm_set_user_period(user_period);
01310                     break;
01311                 default:
01312                     INFO_MAIN("Invalid User Period value! Valid values are: 10, 20, 40.\n");
01313                     break;
01314                 }
01315             }
01316             break;
01317 #if USE_STELEPHONY_API
01318         case 'x':
01319             {   
01320                 INFO_MAIN("Press a key. Valid values are 0-9, A-C\n");
01321                 int user_char = _getch();
01322                 switch(tolower(user_char)) {
01323                     case '1': case '2': case '3':
01324                     case '4': case '5': case '6':
01325                     case '7': case '8': case '9':
01326                     case '0': case 'a': case 'b':
01327                     case 'c':
01328                         INFO_MAIN("Sending DTMF (%c).\n", user_char);
01329                         sang_if->sendSwDTMF((char)user_char);
01330                         break;
01331                     default:
01332                         INFO_MAIN("Invalid DTMF Char! Valid values are: 0-9, A-C\n");
01333                     break;
01334                 }
01335             }
01336             break;
01337         case 'z':
01338             {
01339                 if(WAN_MEDIA_FXOFXS == sang_if->get_adapter_type() &&  MOD_TYPE_FXS == sang_if->get_sub_media() ){
01340                     //Ring the line
01341                     sang_if->start_ringing_phone();
01342                     sangoma_msleep(2000);
01343                     //txsig offhook
01344                     sang_if->fxs_txsig_offhook();
01345                     INFO_MAIN("Sending CallerID.\n");
01346                     sang_if->sendCallerID("Sangoma Rocks", "9054741990");
01347                 }else{
01348                     INFO_MAIN("Sending CallerID.\n");
01349                     sang_if->sendCallerID("Sangoma Rocks", "9054741990");
01350                 }               
01351             }
01352             break;
01353 #endif
01354         case '1':/* read FE register */
01355             {
01356                 int value;
01357                 sdla_fe_debug_t fe_debug;
01358 
01359                 fe_debug.type = WAN_FE_DEBUG_REG;
01360 
01361                 printf("Type Register number (hex) i.g. F8 and press Enter:");
01362                 value = get_user_hex_number();
01363 
01364                 fe_debug.fe_debug_reg.reg  = value;
01365                 fe_debug.fe_debug_reg.read = 1;
01366 
01367                 sang_if->set_fe_debug_mode(&fe_debug);
01368             }
01369             break;
01370 
01371         case '2':/* write FE register */
01372             {
01373                 int value;
01374                 sdla_fe_debug_t fe_debug;
01375                 fe_debug.type = WAN_FE_DEBUG_REG;
01376 
01377                 printf("WRITE: Type Register number (hex) i.g. F8 and press Enter:");
01378                 value = get_user_hex_number();
01379 
01380                 fe_debug.fe_debug_reg.reg  = value;
01381                 fe_debug.fe_debug_reg.read = 1;
01382 
01383                 printf("WRITE: Type value (hex) i.g. 1A and press Enter:");
01384                 value = get_user_hex_number();
01385 
01386                 fe_debug.fe_debug_reg.read = 0;
01387                 fe_debug.fe_debug_reg.value = (unsigned char)value;
01388 
01389                 sang_if->set_fe_debug_mode(&fe_debug);
01390             }
01391             break;
01392 
01393         default:
01394             INFO_MAIN("Invalid command.\n");
01395         }       
01396     }while(user_selection != 'q');
01397 
01398     stop(sang_if);
01399     cleanup(sang_if);
01400 
01401     return 0;
01402 }//main()

Here is the call graph for this function:


Generated on Wed Jun 1 17:30:46 2011 for libsangoma by  doxygen 1.5.6