35 #include "sangoma_port.h"
36 #include "sangoma_port_configurator.h"
39 #if defined(__LINUX__)
40 # include "sample_linux_compat.h"
59 wp_program_settings_t program_settings;
60 callback_functions_t callback_functions;
67 static int got_rx_data(
void *sang_if_ptr,
void *rxhdr,
void *rx_data);
68 static void got_tdm_api_event(
void *sang_if_ptr,
void *event_data);
70 static void got_logger_event(
void *sang_if_ptr, wp_logger_event_t *logger_event);
74 #if USE_STELEPHONY_API
79 static void FSKCallerIDEvent(
void *callback_context,
char * Name,
char * CallerNumber,
char * CalledNumber,
char * DateTime);
80 static void DTMFEvent(
void *callback_context,
long Key);
81 static void Q931Event(
void *callback_context, stelephony_q931_event *pQ931Event);
82 static void FSKCallerIDTransmit (
void *callback_context,
void* buffer);
83 static void SwDtmfTransmit (
void *callback_context,
void* buffer);
87 CRITICAL_SECTION PrintCriticalSection;
89 CRITICAL_SECTION TdmEventCriticalSection;
95 #define DBG_MAIN if(1)printf
96 #define ERR_MAIN printf("%s():line:%d:Error:", __FUNCTION__, __LINE__);printf
97 #define INFO_MAIN if(1)printf
99 #define MAIN_FUNC() if(1)printf("%s():line:%d\n", __FUNCTION__, __LINE__)
101 static int set_port_configuration();
114 DBG_MAIN(
"%s()\n", __FUNCTION__);
116 if(program_settings.use_ctrl_dev == 1){
118 }
else if(program_settings.use_logger_dev == 1){
124 if(sang_if->init(&callback_functions)){
129 DBG_MAIN(
"init(): OK\n");
141 DBG_MAIN(
"cleanup()\n");
155 DBG_MAIN(
"start()\n");
156 return sang_if->run();
167 DBG_MAIN(
"stop()\n");
179 unsigned short datlen;
180 unsigned char * data;
181 static unsigned int rx_counter = 0;
185 data = (
unsigned char*)pdata;
188 if(program_settings.silent){
189 if((rx_counter % 1000) == 0){
190 INFO_MAIN(
"Rx counter: %d, Rx datlen: %d\n", rx_counter, datlen);
192 INFO_MAIN(
"Timestamp: Seconds: %d, Microseconds: %d\n",
198 INFO_MAIN(
"Rx counter: %d, Rx datlen: %d. Data:\n", rx_counter, datlen);
202 for(
int ln = 0; ln < datlen; ln++){
207 INFO_MAIN(
"%04d ", ln/20);
209 INFO_MAIN(
"%02X ", data[ln]);
226 static int got_rx_data(
void *sang_if_ptr,
void *rxhdr,
void *rx_data)
232 static struct timeval tv_start;
233 static int elapsed_b4=0;
238 gettimeofday(&tv_start, NULL);
239 elapsed = abs(elapsed_b4);
240 elapsed_b4 = abs((((last.tv_sec * 1000) + last.tv_usec / 1000) - ((tv_start.tv_sec * 1000) + tv_start.tv_usec / 1000)));
241 if (abs(elapsed - elapsed_b4) > 1) {
242 INFO_MAIN(
"wanpipe%d: Elapsed %i %i diff=%i\n", program_settings.wanpipe_number, elapsed,elapsed_b4,abs(elapsed-elapsed_b4));
249 if(program_settings.Rx_to_Tx_loopback == 1){
253 EnterCriticalSection(&PrintCriticalSection);
255 LeaveCriticalSection(&PrintCriticalSection);
273 static void got_tdm_api_event(
void *sang_if_ptr,
void *event_data)
280 EnterCriticalSection(&TdmEventCriticalSection);
290 DBG_MAIN(
"%s(): Span: %d, Channel: %d (Seconds:%u, Microseconds:%u)\n", __FUNCTION__,
291 wp_tdm_api_event->wp_api_event_span, wp_tdm_api_event->wp_api_event_channel,
294 switch(wp_tdm_api_event->wp_api_event_type)
297 DBG_MAIN(
"DTMF Event: Digit: %c (Port: %s, Type:%s)!\n",
298 wp_tdm_api_event->wp_api_event_dtmf_digit,
299 WAN_EC_DECODE_CHANNEL_PORT(wp_tdm_api_event->wp_api_event_dtmf_port),
300 WAN_EC_DECODE_TONE_TYPE(wp_tdm_api_event->wp_api_event_dtmf_type) );
303 case WP_API_EVENT_RXHOOK:
304 DBG_MAIN(
"RXHOOK Event: %s! (0x%X)\n",
305 WAN_EVENT_RXHOOK_DECODE(wp_tdm_api_event->wp_api_event_hook_state),
306 wp_tdm_api_event->wp_api_event_hook_state);
309 case WP_API_EVENT_RING_DETECT:
310 DBG_MAIN(
"RING Event: %s! (0x%X)\n",
311 WAN_EVENT_RING_DECODE(wp_tdm_api_event->wp_api_event_ring_state),
312 wp_tdm_api_event->wp_api_event_ring_state);
315 case WP_API_EVENT_RING_TRIP_DETECT:
316 DBG_MAIN(
"RING TRIP Event: %s! (0x%X)\n",
317 WAN_EVENT_RING_TRIP_DECODE(wp_tdm_api_event->wp_api_event_ring_state),
318 wp_tdm_api_event->wp_api_event_ring_state);
322 DBG_MAIN(
"RBS Event: New bits: 0x%X!\n", wp_tdm_api_event->wp_api_event_rbs_bits);
323 DBG_MAIN(
"RX RBS/CAS: ");
324 wp_print_rbs_cas_bits(wp_tdm_api_event->wp_api_event_rbs_bits);
327 case WP_API_EVENT_LINK_STATUS:
328 DBG_MAIN(
"Link Status Event: %s! (0x%X)\n",
329 WAN_EVENT_LINK_STATUS_DECODE(wp_tdm_api_event->wp_api_event_link_status),
330 wp_tdm_api_event->wp_api_event_link_status);
333 case WP_API_EVENT_ALARM:
334 DBG_MAIN(
"New Alarm State: 0x%X\n", wp_tdm_api_event->wp_api_event_alarm);
337 case WP_API_EVENT_POLARITY_REVERSE:
343 DBG_MAIN(
"Polarity Reversal Event: %s\n",
348 ERR_MAIN(
"Unknown TDM API Event: %d\n", wp_tdm_api_event->wp_api_event_type);
352 LeaveCriticalSection(&TdmEventCriticalSection);
364 static void got_logger_event(
void *sang_if_ptr, wp_logger_event_t *logger_event)
366 char *timestamp_str =
sangoma_ctime( &logger_event->time_stamp_sec );
368 INFO_MAIN(
"Logger Event Type:\t%s (Logger:%d BitMap: 0x%08X)\n",
369 wp_decode_logger_event_type(logger_event->logger_type, logger_event->event_type),
370 logger_event->logger_type, logger_event->event_type);
372 INFO_MAIN(
"Time and Date:\t\t%s\n",
373 (timestamp_str == NULL ?
"Invalid Timestamp" : timestamp_str));
374 INFO_MAIN(
"Logger Event Data: %s\n\n", logger_event->data);
388 unsigned int tx_counter=0, bytes_read_from_file, total_bytes_read_from_file=0;
390 unsigned char local_tx_data[SAMPLE_CPP_MAX_DATA_LEN];
392 pFile = fopen( program_settings.szTxFileName,
"rb" );
394 ERR_MAIN(
"Can't open file: [%s]\n", program_settings.szTxFileName );
401 bytes_read_from_file = fread( local_tx_data, 1, program_settings.txlength , pFile );
402 total_bytes_read_from_file += bytes_read_from_file;
416 }
while(bytes_read_from_file == program_settings.txlength);
418 INFO_MAIN(
"%s: Finished transmitting file \"%s\" (tx_counter: %u, total_bytes_read_from_file: %d)\n",
419 sang_if->device_name, program_settings.szTxFileName, tx_counter, total_bytes_read_from_file);
430 static int get_user_decimal_number()
433 int retry_counter = 0;
435 while(scanf(
"%d", &result) == 0){
437 INFO_MAIN(
"\nError: Not a numerical input!!\n");
438 if(retry_counter++ > 10){
439 INFO_MAIN(
"giving up...\n");
445 INFO_MAIN(
"User input: %d\n", result);
454 static int get_user_hex_number()
457 int retry_counter = 0;
459 while(scanf(
"%x", &result) == 0){
461 INFO_MAIN(
"\nError: Not a HEX input!!\n");
462 if(retry_counter++ > 10){
463 INFO_MAIN(
"giving up...\n");
469 INFO_MAIN(
"User input: 0x%X\n", result);
480 static int parse_command_line_args(
int argc,
char* argv[])
483 const char *USAGE_STR =
485 "Usage: sample [-c] [-i] [options]\n"
487 "\t-c number Wanpipe (Port/Span) number: 1,2,3...\n"
488 "\t-i number Interface number 1,2,3,....\n"
490 "\t-silent Disable display of Rx data\n"
491 "\t-driver_config \tStop/Set Configuration/Start a Port....\n"
492 "\t-rx2tx All received data automatically transmitted on\n"
493 "\t the SAME interface\n"
494 "\t-txlength\tnumber\tLength of data frames to be transmitted when 't'\n"
495 "\t \t \tkey is pressed\n"
496 "\t-txcount\tnumber Number of test data frames to be transmitted when 't'\n"
497 "\t \t \tkey is pressed\n"
498 "\t-tx_file_name\tstring\tFile to be transmitted when 't' key is pressed\n"
499 #if USE_STELEPHONY_API
500 "\t-decode_fsk_cid\t\tDecode FSK Caller ID on an Analog line.\n"
501 "\t \t\tFor Voice data only.\n"
502 "\t-encode_fsk_cid\t\tEncode FSK Caller ID on an Analog line.\n"
503 "\t \t\tFor Voice data only.\n"
504 "\t-encode_sw_dtmf\t\tEncode SW DTMF on an line. For Voice data only.\n"
505 "\t-sw_dtmf Enable Sangoma Software DTMF decoder. For Voice data only.\n"
506 "\t-decode_q931 Enable Sangoma Q931 decoder. For HDLC (Dchannel) data only.\n"
507 "\t-alaw\t\t Use Alaw codec instead of default MuLaw codec for Voice data.\n"
508 "\t-rm_txgain\t Set txgain for FXS/FXO modules.\n"
509 "\t \t\tFXO range from -150 to 120, FXS 35 or -35\n"
510 "\t-rm_rxgain\t Set txgain for FXS/FXO modules.\n"
511 "\t \t\tFXO range from -150 to 120, FXS 35 or -35\n"
514 "\t-use_ctrl_dev \tUse the global 'wptdm_ctrl' device to Get events from\n"
515 "\t \tall API devices.\n"
517 "\t-use_logger_dev \tUse the global Logger device to Get Log Messages\n"
518 "\t \tfrom API driver.\n"
519 #ifdef WP_API_FEATURE_LIBSNG_HWEC
520 "\t-use_hwec \tInitialize/Configure/Use the Hardware Echo Canceller\n"
521 "\t-hwec_chan \tA 1-based channel number to be used by per-channel (vs. global)\n"
522 "\t \tHWEC functions. Valid values: 1-31\n"
524 #if USE_BUFFER_MULTIPLIER
525 "\t-buff_mult\tnumber\tBuffer Multiplier coefficient\n"
527 "\t-real_time \tRun the Program at real-time priority. This maybe\n"
528 "\t \t\timportant when Audio stream is used for timing.\n"
530 "Example: sample -c 1 -i 1\n";
532 memset(&program_settings, 0,
sizeof(wp_program_settings_t));
533 program_settings.wanpipe_number = 1;
534 program_settings.interface_number = 1;
535 program_settings.txlength = 80;
536 program_settings.txcount = 1;
537 program_settings.rxgain = 0xFFFF;
538 program_settings.txgain = 0xFFFF;
539 program_settings.hwec_channel = 1;
540 #if USE_BUFFER_MULTIPLIER
541 program_settings.buffer_multiplier = MIN_BUFFER_MULTIPLIER_FACTOR;
544 for(i = 1; i < argc;){
546 if(
_stricmp(argv[i],
"-silent") == 0){
547 INFO_MAIN(
"disabling Rx data display...\n");
548 program_settings.silent = 1;
550 INFO_MAIN(USAGE_STR);
552 }
else if(
_stricmp(argv[i],
"-c") == 0){
554 INFO_MAIN(
"No Wanpipe number was provided!\n");
557 program_settings.wanpipe_number = (uint16_t)atoi(argv[i+1]);
558 INFO_MAIN(
"Using wanpipe number %d\n", program_settings.wanpipe_number);
560 }
else if(
_stricmp(argv[i],
"-i") == 0){
562 INFO_MAIN(
"No Interface number was provided!\n");
565 program_settings.interface_number = (uint16_t)atoi(argv[i+1]);
566 INFO_MAIN(
"Using interface number %d\n", program_settings.interface_number);
567 if(program_settings.interface_number < 1){
568 ERR_MAIN(
"Invalid interface number %d!!\n", program_settings.interface_number);
572 }
else if(strcmp(argv[i],
"-rx2tx") == 0){
573 INFO_MAIN(
"enabling Rx to Tx loopback...\n");
574 program_settings.Rx_to_Tx_loopback = 1;
575 }
else if(strcmp(argv[i],
"-driver_config") == 0){
576 INFO_MAIN(
"enabling driver config start/stop\n");
577 program_settings.driver_config = 1;
579 }
else if(
_stricmp(argv[i],
"-txlength") == 0){
581 INFO_MAIN(
"No txlength provided!\n");
584 program_settings.txlength = (uint16_t)atoi(argv[i+1]);
585 INFO_MAIN(
"Setting txlength to %d bytes.\n", program_settings.txlength);
587 }
else if(
_stricmp(argv[i],
"-txcount") == 0){
589 INFO_MAIN(
"No txcount provided!\n");
592 program_settings.txcount = atoi(argv[i+1]);
594 INFO_MAIN(
"Setting txcount to %d.\n", program_settings.txcount);
595 #if USE_STELEPHONY_API
596 }
else if(
_stricmp(argv[i],
"-decode_fsk_cid") == 0){
597 INFO_MAIN(
"enabling FSK Caller ID decoder...\n");
598 program_settings.decode_fsk_cid = 1;
599 callback_functions.FSKCallerIDEvent = FSKCallerIDEvent;
600 }
else if(
_stricmp(argv[i],
"-sw_dtmf") == 0){
601 INFO_MAIN(
"enabling Software DTMF decoder...\n");
602 program_settings.sw_dtmf = 1;
603 callback_functions.DTMFEvent = DTMFEvent;
604 }
else if(
_stricmp(argv[i],
"-decode_q931") == 0){
605 INFO_MAIN(
"enabling Q931 decoder...\n");
606 program_settings.decode_q931 = 1;
607 callback_functions.Q931Event = Q931Event;
608 }
else if(
_stricmp(argv[i],
"-encode_fsk_cid") == 0){
609 INFO_MAIN(
"enabling FSK Caller ID encoder...\n");
610 program_settings.encode_fsk_cid = 1;
611 callback_functions.FSKCallerIDTransmit = FSKCallerIDTransmit;
612 }
else if(
_stricmp(argv[i],
"-encode_sw_dtmf") == 0){
613 INFO_MAIN(
"enabling Software DTMF encoder...\n");
614 program_settings.encode_sw_dtmf = 1;
615 callback_functions.SwDtmfTransmit = SwDtmfTransmit;
616 }
else if(
_stricmp(argv[i],
"-alaw") == 0){
617 INFO_MAIN(
"enabling ALaw codec...\n");
618 program_settings.voice_codec_alaw = 1;
619 #endif//USE_STELEPHONY_API
620 }
else if(
_stricmp(argv[i],
"-tx_file_name") == 0){
622 INFO_MAIN(
"No TxFileName provided!\n");
625 strcpy(program_settings.szTxFileName, argv[i+1]);
627 INFO_MAIN(
"Setting szTxFileName to '%s'.\n", program_settings.szTxFileName);
628 }
else if(
_stricmp(argv[i],
"-use_ctrl_dev") == 0){
629 INFO_MAIN(
"Using ctrl_dev...\n");
630 program_settings.use_ctrl_dev = 1;
631 }
else if(
_stricmp(argv[i],
"-use_logger_dev") == 0){
632 INFO_MAIN(
"Using logger_dev...\n");
633 program_settings.use_logger_dev = 1;
634 }
else if(
_stricmp(argv[i],
"-rm_txgain") == 0){
636 INFO_MAIN(
"No Tx gain provided!\n");
639 program_settings.txgain = atoi(argv[i+1]);
641 INFO_MAIN(
"Setting Tx gain to %d.\n", program_settings.txgain);
642 }
else if(
_stricmp(argv[i],
"-rm_rxgain") == 0){
644 INFO_MAIN(
"No Rx gain provided!\n");
647 program_settings.rxgain = atoi(argv[i+1]);
649 INFO_MAIN(
"Setting Rx gain to %d.\n", program_settings.txgain);
650 }
else if(
_stricmp(argv[i],
"-use_hwec") == 0){
651 INFO_MAIN(
"Using hardware echo canceller...\n");
652 program_settings.use_hardware_echo_canceller = 1;
653 }
else if(
_stricmp(argv[i],
"-hwec_chan") == 0){
655 INFO_MAIN(
"No hwec_chan provided!\n");
658 program_settings.hwec_channel = atoi(argv[i+1]);
660 INFO_MAIN(
"Setting hwec_chan to %d.\n", program_settings.hwec_channel);
661 }
else if(
_stricmp(argv[i],
"-real_time") == 0){
662 INFO_MAIN(
"Will be running at real-time priority...\n");
663 program_settings.real_time = 1;
664 #if USE_BUFFER_MULTIPLIER
665 }
else if(
_stricmp(argv[i],
"-buff_mult") == 0){
667 INFO_MAIN(
"No buff_mult provided!\n");
670 program_settings.buffer_multiplier = atoi(argv[i+1]);
672 INFO_MAIN(
"Setting buff_mult to %d.\n", program_settings.buffer_multiplier);
675 INFO_MAIN(
"Error: Invalid Argument %s\n",argv[i]);
686 string str_input =
"";
688 std::getline(cin, str_input);
690 return str_input.c_str()[0];
711 int rc, user_selection,err;
714 unsigned char local_tx_data[SAMPLE_CPP_MAX_DATA_LEN];
715 UCHAR tx_test_byte = 0;
718 memset(&callback_functions, 0x00,
sizeof(callback_functions));
719 callback_functions.got_rx_data = got_rx_data;
720 callback_functions.got_tdm_api_event = got_tdm_api_event;
722 callback_functions.got_logger_event = got_logger_event;
724 if(parse_command_line_args(argc, argv)){
734 if (program_settings.driver_config) {
735 err=set_port_configuration();
743 InitializeCriticalSection(&PrintCriticalSection);
744 InitializeCriticalSection(&TdmEventCriticalSection);
746 if (program_settings.real_time) {
747 sng_set_process_priority_to_real_time();
752 INFO_MAIN(
"Using wanpipe_number: %d, interface_number: %d\n", program_settings.wanpipe_number, program_settings.interface_number);
754 sang_if =
init(program_settings.wanpipe_number, program_settings.interface_number);
766 if(program_settings.txgain != 0xFFFF) {
767 INFO_MAIN(
"Applying txgain...\n");
768 if (sang_if->tdm_control_rm_txgain(program_settings.txgain)){
769 INFO_MAIN(
"Failed to apply txgain!\n");
775 if(sang_if->get_adapter_type() == WAN_MEDIA_FXOFXS && sang_if->get_sub_media() == MOD_TYPE_FXS) {
776 INFO_MAIN(
"Setting Proper hookstates on FXS\n");
777 sang_if->tdm_txsig_offhook();
778 sang_if->tdm_txsig_onhook();
781 if(program_settings.rxgain != 0xFFFF) {
782 INFO_MAIN(
"Applying rxgain...\n");
783 if (sang_if->tdm_control_rm_rxgain(program_settings.rxgain)){
784 INFO_MAIN(
"Failed to apply rxgain!\n");
788 EnterCriticalSection(&PrintCriticalSection);
790 INFO_MAIN(
"Press 'q' to quit the program.\n");
791 INFO_MAIN(
"Press 's' to get Operational Statistics.\n");
792 INFO_MAIN(
"Press 'f' to reset (flush) Operational Statistics.\n");
794 if(program_settings.use_logger_dev != 1){
796 INFO_MAIN(
"Press 't' to transmit data.\n");
797 INFO_MAIN(
"Press 'v' to get API driver version.\n");
799 if(sang_if->get_adapter_type() == WAN_MEDIA_T1 || sang_if->get_adapter_type() == WAN_MEDIA_E1){
800 INFO_MAIN(
"Press 'a' to get T1/E1 alarms.\n");
802 INFO_MAIN(
"Press 'g' to get RBS bits.\n");
803 INFO_MAIN(
"Press 'r' to set RBS bits.\n");
804 INFO_MAIN(
"Press '1' to read FE register. Warning: used by Sangoma Techsupport only!\n");
805 INFO_MAIN(
"Press '2' to write FE register. Warning: used by Sangoma Techsupport only!\n");
807 INFO_MAIN(
"Press 'i' to set Tx idle data buffer (BitStream only).\n");
808 switch(sang_if->get_adapter_type())
812 INFO_MAIN(
"Press 'l' to send 'activate remote loop back' signal.\n");
813 INFO_MAIN(
"Press 'd' to send 'deactivate remote loop back' signal.\n");
815 case WAN_MEDIA_FXOFXS:
816 switch(sang_if->get_sub_media())
819 INFO_MAIN(
"Press 'e' to listen to test tones on a phone connected to the A200-FXS\n");
820 INFO_MAIN(
"Press 'c' to ring/stop ring phone connected to the A200-FXS\n");
821 INFO_MAIN(
"Press 'n' to enable/disable reception of ON/OFF Hook events on A200-FXS\n");
822 INFO_MAIN(
"Press 'm' to enable DTMF events (on SLIC chip) on A200-FXS\n");
823 INFO_MAIN(
"Press 'j 'to enable/disable reception of Ring Trip events on A200-FXS\n");
824 INFO_MAIN(
"Press 'k' to transmit kewl - drop line voltage on the line connected to the A200-FXS\n");
825 INFO_MAIN(
"Press 'h' to set polarity on the line connected to the A200-fXS\n");
826 INFO_MAIN(
"Press 'u' to transmit onhooktransfer on the line connected to the A200-FXS\n");
830 INFO_MAIN(
"Press 'u' to enable/disable reception of Ring Detect events on A200-FXO\n");
831 INFO_MAIN(
"Press 'h' to transmit ON/OFF hook signals on A200-FXO\n");
832 INFO_MAIN(
"Press 'a' to get Line Status (Connected/Disconnected)\n");
837 INFO_MAIN(
"Press 'k' to Activate/Deactivate ISDN BRI line\n");
838 INFO_MAIN(
"Press 'l' to enable bri bchan loopback\n");
839 INFO_MAIN(
"Press 'd' to disable bri bchan loopback\n");
842 INFO_MAIN(
"Press 'o' to control DTMF events on DSP (Octasic)\n");
843 if (program_settings.encode_sw_dtmf) {
844 INFO_MAIN(
"Press 'x' to send software DTMF\n");
846 if (program_settings.encode_fsk_cid) {
847 INFO_MAIN(
"Press 'z' to send software FSK Caller ID\n");
851 LeaveCriticalSection(&PrintCriticalSection);
852 user_selection = tolower(my_getch());
853 switch(user_selection)
858 for(u_int32_t cnt = 0; cnt < program_settings.txcount; cnt++){
859 if(program_settings.szTxFileName[0]){
865 memset(local_tx_data, tx_test_byte, program_settings.txlength);
866 sang_if->
transmit(&hdr, local_tx_data);
872 if(program_settings.use_logger_dev == 1){
873 wp_logger_stats_t stats;
879 sang_if->get_operational_stats(&stats);
883 sang_if->flush_operational_stats();
889 sang_if->get_api_driver_version(&version);
890 INFO_MAIN(
"\nAPI version\t: %d,%d,%d,%d\n",
891 version.major, version.minor, version.minor1, version.minor2);
893 u_int8_t customer_id = 0;
894 sang_if->get_card_customer_id(&customer_id);
895 INFO_MAIN(
"\ncustomer_id\t: 0x%02X\n", customer_id);
899 unsigned char cFeStatus;
901 switch(sang_if->get_adapter_type())
906 sang_if->get_te1_56k_stat();
909 case WAN_MEDIA_FXOFXS:
910 switch(sang_if->get_sub_media())
914 sang_if->tdm_get_front_end_status(&cFeStatus);
915 INFO_MAIN(
"cFeStatus: %s (%d)\n", FE_STATUS_DECODE(cFeStatus), cFeStatus);
921 switch(sang_if->get_adapter_type())
926 sang_if->set_lb_modes(WAN_TE1_LINELB_MODE, WAN_TE1_LB_ENABLE);
937 switch(sang_if->get_adapter_type())
942 sang_if->set_lb_modes(WAN_TE1_LINELB_MODE, WAN_TE1_LB_DISABLE);
953 switch(sang_if->get_adapter_type())
958 rbs_management_t rbs_management_struct = {0,0};
960 sang_if->enable_rbs_monitoring();
962 INFO_MAIN(
"Type Channel number and press <Enter>:\n");
963 rbs_management_struct.channel = get_user_decimal_number();
965 if(WAN_MEDIA_T1 == sang_if->get_adapter_type()){
966 if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 24){
967 INFO_MAIN(
"Invalid T1 RBS Channel number!\n");
972 if(WAN_MEDIA_E1 == sang_if->get_adapter_type()){
973 if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 31){
974 INFO_MAIN(
"Invalid E1 CAS Channel number!\n");
979 sang_if->get_rbs(&rbs_management_struct);
983 INFO_MAIN(
"Command invalid for card type\n");
988 switch(sang_if->get_adapter_type())
993 static rbs_management_t rbs_management_struct = {0,0};
996 sang_if->enable_rbs_monitoring();
998 INFO_MAIN(
"Type Channel number and press <Enter>:\n");
999 rbs_management_struct.channel = chan_no = get_user_decimal_number();
1001 if(WAN_MEDIA_T1 == sang_if->get_adapter_type()){
1002 if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 24){
1003 INFO_MAIN(
"Invalid T1 RBS Channel number!\n");
1008 if(WAN_MEDIA_E1 == sang_if->get_adapter_type()){
1009 if(rbs_management_struct.channel < 1 || rbs_management_struct.channel > 31){
1010 INFO_MAIN(
"Invalid E1 CAS Channel number!\n");
1020 if(rbs_management_struct.ABCD_bits == WAN_RBS_SIG_A){
1021 rbs_management_struct.ABCD_bits = WAN_RBS_SIG_B;
1023 rbs_management_struct.ABCD_bits = WAN_RBS_SIG_A;
1025 sang_if->set_rbs(&rbs_management_struct);
1028 #define RBS_CAS_TX_AND_WAIT(chan, abcd) \
1030 rbs_management_struct.channel = chan; \
1031 rbs_management_struct.ABCD_bits = abcd; \
1032 INFO_MAIN("Press any key to transmit bits:"); \
1033 wp_print_rbs_cas_bits(abcd); \
1035 sang_if->set_rbs(&rbs_management_struct); \
1039 RBS_CAS_TX_AND_WAIT(chan_no, 0x00);
1041 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A);
1043 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_B);
1045 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_B);
1047 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_C);
1049 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_C);
1051 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_B | WAN_RBS_SIG_C);
1053 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_B | WAN_RBS_SIG_C);
1055 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_D);
1057 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_D);
1059 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_B | WAN_RBS_SIG_D);
1061 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_B | WAN_RBS_SIG_D);
1063 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_C | WAN_RBS_SIG_D);
1065 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_C | WAN_RBS_SIG_D);
1067 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_B | WAN_RBS_SIG_C | WAN_RBS_SIG_D);
1069 RBS_CAS_TX_AND_WAIT(chan_no, WAN_RBS_SIG_A | WAN_RBS_SIG_B | WAN_RBS_SIG_C | WAN_RBS_SIG_D);
1074 INFO_MAIN(
"Command invalid for card type\n");
1080 INFO_MAIN(
"Type Idle Flag (HEX, for example: FE) and press <Enter>:\n");
1081 unsigned char new_idle_flag = (
unsigned char)get_user_hex_number();
1082 sang_if->set_tx_idle_flag(new_idle_flag);
1086 user_retry_ring_e_d:
1087 INFO_MAIN(
"Press 'e' to START ring, 'd' to STOP ring, 't' to Toggle\n");
1089 user_selection = tolower(my_getch());
1090 switch(user_selection)
1093 INFO_MAIN(
"Starting Ring ...%c\n",user_selection);
1094 sang_if->start_ringing_phone();
1097 INFO_MAIN(
"Stopping Ring ... %c\n",user_selection);
1098 sang_if->stop_ringing_phone();
1103 for (x=0;x<500;x++) {
1104 sang_if->start_ringing_phone();
1105 sang_if->start_ringing_phone();
1107 sang_if->stop_ringing_phone();
1108 sang_if->stop_ringing_phone();
1110 sang_if->start_busy_tone();
1112 sang_if->stop_all_tones();
1118 goto user_retry_ring_e_d;
1123 INFO_MAIN(
"Press 'e' to START a Tone, 'd' to STOP a Tone.\n");
1126 switch(tolower(my_getch()))
1129 INFO_MAIN(
"Press 'r' for Ring Tone, 'd' for Dial Tone, 'b' for Busy Tone, 'c' for Congestion Tone.\n");
1131 switch(tolower(my_getch()))
1134 sang_if->start_ring_tone();
1137 sang_if->start_dial_tone();
1140 sang_if->start_busy_tone();
1144 sang_if->start_congestion_tone();
1151 sang_if->stop_all_tones();
1155 INFO_MAIN(
"Press 'e' to ENABLE Rx Hook Events, 'd' to DISABLE Rx Hook Events.\n");
1157 switch(tolower(my_getch()))
1160 sang_if->tdm_enable_rxhook_events();
1164 sang_if->tdm_disable_rxhook_events();
1170 INFO_MAIN(
"Press 'e' to ENABLE Remora DTMF Events, 'd' to DISABLE Remora DTMF Events.\n");
1172 switch(tolower(my_getch()))
1175 sang_if->tdm_enable_rm_dtmf_events();
1179 sang_if->tdm_disable_rm_dtmf_events();
1186 INFO_MAIN(
"Press 'e' to ENABLE Octasic DTMF Events, 'd' to DISABLE Octasic DTMF Events.\n");
1190 switch(tolower(my_getch()))
1193 INFO_MAIN(
"Type Channel number and press <Enter>:\n");
1194 channel = (uint8_t)get_user_decimal_number();
1196 sang_if->tdm_enable_dtmf_events(channel);
1200 INFO_MAIN(
"Type Channel number and press <Enter>:\n");
1201 channel = (uint8_t)get_user_decimal_number();
1203 sang_if->tdm_disable_dtmf_events(channel);
1209 if(sang_if->get_sub_media()==MOD_TYPE_FXO){
1210 INFO_MAIN(
"Press 'e' to ENABLE Rx Ring Detect Events, 'd' to DISABLE Rx Ring Detect Events.\n");
1212 switch(tolower(my_getch()))
1215 sang_if->tdm_enable_ring_detect_events();
1219 sang_if->tdm_disable_ring_detect_events();
1221 }
else if(sang_if->get_sub_media()==MOD_TYPE_FXS){
1222 sang_if->tdm_txsig_onhooktransfer();
1227 INFO_MAIN(
"Press 'e' to ENABLE Rx Ring Trip Events, 'd' to DISABLE Rx Ring Trip Events.\n");
1229 switch(tolower(my_getch()))
1232 sang_if->tdm_enable_ring_trip_detect_events();
1236 sang_if->tdm_disable_ring_trip_detect_events();
1240 if(sang_if->get_sub_media()==MOD_TYPE_FXO) {
1241 INFO_MAIN(
"Press 'e' to transmit OFF hook signal, 'd' to transmit ON hook signal.\n");
1243 switch(tolower(my_getch()))
1246 sang_if->fxo_go_off_hook();
1250 sang_if->fxo_go_on_hook();
1252 }
else if(sang_if->get_sub_media() == MOD_TYPE_FXS) {
1253 INFO_MAIN(
"Press 'f' for forward, 'r' to for reverse.\n");
1255 switch(tolower(my_getch()))
1258 sang_if->tdm_set_rm_polarity(0);
1261 sang_if->tdm_set_rm_polarity(1);
1265 int polarity_wait, two_second_ring_repetion_counter;
1267 INFO_MAIN(
"Type Polarity Reverse/Forward delay and press <Enter>:\n");
1268 polarity_wait = get_user_decimal_number();
1269 if (!polarity_wait) {
1270 ERR_MAIN(
"Invalid User-specified Polarity Reverse/Forward delay: %d!\n", polarity_wait);
1271 polarity_wait = 400;
1275 INFO_MAIN(
"User specified Polarity Reverse/Forward delay: %d. Press <Enter> to continue.\n", polarity_wait);
1279 two_second_ring_repetion_counter = 2000 / (polarity_wait * 2);
1280 INFO_MAIN(
"two_second_ring_repetion_counter: %d. Press <Enter> to continue.\n", two_second_ring_repetion_counter);
1283 for (
int ii = 0; ii < two_second_ring_repetion_counter; ii++) {
1284 INFO_MAIN(
"Reversing polarity %d...\n", ii);
1285 sang_if->tdm_set_rm_polarity(1);
1287 INFO_MAIN(
"Forwarding polarity %d...\n", ii);
1288 sang_if->tdm_set_rm_polarity(0);
1293 INFO_MAIN(
"4 seconds between the rings...\n");
1296 for (
int ii = 0; ii < two_second_ring_repetion_counter; ii++) {
1297 INFO_MAIN(
"Reversing polarity %d...\n", ii);
1298 sang_if->tdm_set_rm_polarity(1);
1300 INFO_MAIN(
"Forwarding polarity %d...\n", ii);
1301 sang_if->tdm_set_rm_polarity(0);
1308 if( sang_if->get_adapter_type() == WAN_MEDIA_BRI ) {
1309 INFO_MAIN(
"Press 'e' to Activate, 'd' to De-Activate line.\n");
1311 switch(tolower(my_getch()))
1314 sang_if->tdm_front_end_activate();
1318 sang_if->tdm_front_end_deactivate();
1320 }
else if(sang_if->get_adapter_type()== WAN_MEDIA_FXOFXS) {
1321 if(sang_if->get_sub_media()==MOD_TYPE_FXS) {
1322 printf(
"calling tdm_txsig_kewl()...\n");
1323 sang_if->tdm_txsig_kewl();
1326 printf(
"restoring line current after txsig kewl...\n");
1327 sang_if->tdm_txsig_offhook();
1334 INFO_MAIN(
"Type User Period and press <Enter>. Valid values are: 10, 20, 40.\n");
1335 user_period = get_user_decimal_number();
1341 sang_if->tdm_set_user_period(user_period);
1344 INFO_MAIN(
"Invalid User Period value! Valid values are: 10, 20, 40.\n");
1349 #if USE_STELEPHONY_API
1352 INFO_MAIN(
"Press a key. Valid values are 0-9, A-C\n");
1353 int user_char = my_getch();
1354 switch(tolower(user_char)) {
1355 case '1':
case '2':
case '3':
1356 case '4':
case '5':
case '6':
1357 case '7':
case '8':
case '9':
1358 case '0':
case 'a':
case 'b':
1360 INFO_MAIN(
"Sending DTMF (%c).\n", user_char);
1361 sang_if->sendSwDTMF((
char)user_char);
1364 INFO_MAIN(
"Invalid DTMF Char! Valid values are: 0-9, A-C\n");
1371 if(WAN_MEDIA_FXOFXS == sang_if->get_adapter_type() && MOD_TYPE_FXS == sang_if->get_sub_media() ){
1373 sang_if->start_ringing_phone();
1376 sang_if->fxs_txsig_offhook();
1377 INFO_MAIN(
"Sending CallerID.\n");
1378 sang_if->sendCallerID(
"Sangoma Rocks",
"9054741990");
1380 INFO_MAIN(
"Sending CallerID.\n");
1381 sang_if->sendCallerID(
"Sangoma Rocks",
"9054741990");
1389 sdla_fe_debug_t fe_debug;
1391 fe_debug.type = WAN_FE_DEBUG_REG;
1393 printf(
"Type Register number (hex) i.g. F8 and press Enter:");
1394 value = get_user_hex_number();
1396 fe_debug.fe_debug_reg.reg = value;
1397 fe_debug.fe_debug_reg.read = 1;
1399 sang_if->set_fe_debug_mode(&fe_debug);
1406 sdla_fe_debug_t fe_debug;
1407 fe_debug.type = WAN_FE_DEBUG_REG;
1409 printf(
"WRITE: Type Register number (hex) i.g. F8 and press Enter:");
1410 value = get_user_hex_number();
1412 fe_debug.fe_debug_reg.reg = value;
1413 fe_debug.fe_debug_reg.read = 1;
1415 printf(
"WRITE: Type value (hex) i.g. 1A and press Enter:");
1416 value = get_user_hex_number();
1418 fe_debug.fe_debug_reg.read = 0;
1419 fe_debug.fe_debug_reg.value = (
unsigned char)value;
1421 sang_if->set_fe_debug_mode(&fe_debug);
1426 INFO_MAIN(
"Invalid command.\n");
1428 }
while(user_selection !=
'q');
1436 static int set_port_configuration()
1438 int rc = 0, user_selection;
1443 int is_te1_port = 0, is_analog_port = 0, is_bri_port = 0, is_serial_port = 0, is_gsm_port=0;
1444 hardware_info_t hardware_info;
1445 port_cfg_t port_cfg;
1447 sangoma_port_configurator *sng_port_cfg_obj;
1449 sng_port_cfg_obj =
new sangoma_port_configurator();
1450 if(sng_port_cfg_obj == NULL || sng_port_cfg_obj->init((
unsigned short)program_settings.wanpipe_number)){
1451 ERR_MAIN(
"Failed to initialize 'sangoma_port_configurator'\n");
1455 rc = sng_port_cfg_obj->get_hardware_info(&hardware_info);
1459 INFO_MAIN(
"card_model : %s (%d)\n",
1460 SDLA_ADPTR_NAME(hardware_info.card_model), hardware_info.card_model);
1461 INFO_MAIN(
"firmware_version\t: 0x%02X\n", hardware_info.firmware_version);
1462 INFO_MAIN(
"pci_bus_number\t\t: %d\n", hardware_info.pci_bus_number);
1463 INFO_MAIN(
"pci_slot_number\t\t: %d\n", hardware_info.pci_slot_number);
1464 INFO_MAIN(
"max_hw_ec_chans\t\t: %d\n", hardware_info.max_hw_ec_chans);
1465 INFO_MAIN(
"port_number\t\t: %d\n", hardware_info.port_number);
1468 ERR_MAIN(
"Failed to get hardware information\n");
1469 delete sng_port_cfg_obj;
1474 memset(&port_cfg, 0x00,
sizeof(port_cfg_t));
1476 switch(hardware_info.card_model)
1478 case A101_ADPTR_1TE1:
1479 case A101_ADPTR_2TE1:
1480 case A104_ADPTR_4TE1:
1481 case A108_ADPTR_8TE1:
1483 INFO_MAIN(
"T1/E1 Port on non-Hybrid Card (A10[1/2/4/8]).\n");
1485 case A200_ADPTR_ANALOG:
1486 case A400_ADPTR_ANALOG:
1487 case AFT_ADPTR_A600:
1489 INFO_MAIN(
"Analog Port on non-Hybrid Card (A200/A400).\n");
1491 case AFT_ADPTR_ISDN:
1493 INFO_MAIN(
"BRI Port on non-Hybrid Card (A500).\n");
1495 case AFT_ADPTR_FLEXBRI:
1497 if (hardware_info.bri_modtype == MOD_TYPE_NT ||
1498 hardware_info.bri_modtype == MOD_TYPE_TE) {
1500 INFO_MAIN(
"BRI Port on Hybrid Card.\n");
1503 INFO_MAIN(
"Analog Port on Hybrid Card.\n");
1506 case AFT_ADPTR_2SERIAL_V35X21:
1507 case AFT_ADPTR_4SERIAL_V35X21:
1508 case AFT_ADPTR_2SERIAL_RS232:
1509 case AFT_ADPTR_4SERIAL_RS232:
1511 INFO_MAIN(
"Serial Port on non-Hybrid Card (A14[2/4]).\n");
1513 case AFT_ADPTR_W400:
1515 INFO_MAIN(
"GSM Port on GSM Card (W400).\n");
1518 INFO_MAIN(
"Warning: configuration of card model 0x%08X can not be changed!\n",
1519 hardware_info.card_model);
1526 INFO_MAIN(
"Press 't' to set T1 configration.\n");
1527 INFO_MAIN(
"Press 'e' to set E1 configration.\n");
1529 user_selection = tolower(my_getch());
1530 switch(user_selection)
1533 rc=sng_port_cfg_obj->initialize_t1_tdm_span_voice_api_configration_structure(&port_cfg,&hardware_info,program_settings.wanpipe_number);
1537 rc=sng_port_cfg_obj->initialize_e1_tdm_span_voice_api_configration_structure(&port_cfg,&hardware_info,program_settings.wanpipe_number);
1545 INFO_MAIN(
"Invalid command %c.\n",user_selection);
1551 if (is_analog_port) {
1553 if(sng_port_cfg_obj->get_configration(&port_cfg)){
1557 sng_port_cfg_obj->print_port_cfg_structure(&port_cfg);
1559 sng_port_cfg_obj->initialize_interface_mtu_mru(&port_cfg, 16, 16);
1563 rc=sng_port_cfg_obj->control_analog_rm_lcm(&port_cfg, 1);
1567 rc=sng_port_cfg_obj->set_analog_opermode(&port_cfg,
"TBR21");
1573 rc=sng_port_cfg_obj->initialize_bri_tdm_span_voice_api_configration_structure(&port_cfg,&hardware_info,program_settings.wanpipe_number);
1576 if (is_serial_port) {
1577 rc=sng_port_cfg_obj->initialize_serial_api_configration_structure(&port_cfg,&hardware_info,program_settings.wanpipe_number);
1581 rc=sng_port_cfg_obj->initialize_gsm_tdm_span_voice_api_configration_structure(&port_cfg,&hardware_info,program_settings.wanpipe_number);
1584 if(!is_te1_port && !is_analog_port && !is_bri_port && !is_serial_port && !is_gsm_port){
1585 INFO_MAIN(
"Unsupported Card %d\n", hardware_info.card_model);
1591 ERR_MAIN(
"Failed to Initialize Port Configuratoin structure!\n");
1595 INFO_MAIN(
"Stopping PORT for re-configuration!\n");
1596 if ((rc = sng_port_cfg_obj->stop_port())) {
1597 ERR_MAIN(
"Failed to Stop Port! rc: %d\n", rc);
1601 INFO_MAIN(
"Configuring PORT!\n");
1602 if ((rc = sng_port_cfg_obj->set_volatile_configration(&port_cfg))) {
1603 ERR_MAIN(
"Failed to Configure Port! rc: %d\n", rc);
1607 INFO_MAIN(
"Starting PORT!\n");
1608 if ((rc = sng_port_cfg_obj->start_port())) {
1609 ERR_MAIN(
"Failed to Start Port! rc: %d\n", rc);
1615 if (rc = sng_port_cfg_obj->write_configration_on_persistent_storage(
1616 &port_cfg, &hardware_info, program_settings.wanpipe_number)) {
1617 ERR_MAIN(
"Failed to write configuration on persistant storage! rc: %d\n", rc);
1623 if(sng_port_cfg_obj != NULL){
1624 delete sng_port_cfg_obj;
1633 #if USE_STELEPHONY_API
1634 static void FSKCallerIDEvent(
void *callback_context,
1635 char * Name,
char * CallerNumber,
1636 char * CalledNumber,
char * DateTime)
1641 INFO_MAIN(
"\n%s: %s() - Start\n", sang_if->device_name, __FUNCTION__);
1644 INFO_MAIN(
"Name: %s\n", Name);
1646 printf(
"caller name in SINGLE byte hex:\n");
1647 for(
unsigned int ind = 0; ind < strlen(Name); ind++){
1648 printf(
"Name[%02d]: 0x%02X\n", ind, Name[ind]);
1652 printf(
"caller name in DOUBLE byte (unicode) hex:\n");
1653 for(
unsigned int ind = 0; ind < strlen(Name); ind += 2){
1654 printf(
"Name[%02d]: 0x%04X\n", ind, *(
unsigned short*)&Name[ind]);
1662 INFO_MAIN(
"CallerNumber: %s\n", CallerNumber);
1665 INFO_MAIN(
"CalledNumber: %s\n", CalledNumber);
1668 INFO_MAIN(
"DateTime: %s\n", DateTime);
1671 INFO_MAIN(
"Resetting FSK Caller ID\n");
1672 sang_if->resetFSKCID();
1674 INFO_MAIN(
"%s() - End\n\n", __FUNCTION__);
1677 static void DTMFEvent(
void *callback_context,
long Key)
1682 INFO_MAIN(
"\n%s: %s() - Start\n", sang_if->device_name, __FUNCTION__);
1684 INFO_MAIN(
"Key: %c\n", (
char) Key);
1686 INFO_MAIN(
"%s() - End\n\n", __FUNCTION__);
1689 static void Q931Event(
void *callback_context, stelephony_q931_event *pQ931Event)
1694 INFO_MAIN(
"\n%s: %s() - Start\n", sang_if->device_name, __FUNCTION__);
1696 INFO_MAIN(
"\nFound %d bytes of data: ", pQ931Event->dataLength);
1697 for (
int i=0; i < pQ931Event->dataLength;i++){
1698 INFO_MAIN(
"%02X ",pQ931Event->data[i]);
1704 INFO_MAIN(
"Message Received on: %02d/%02d/%02d @ %02d:%02d:%02d\n",pQ931Event->tv.wMonth,pQ931Event->tv.wDay,pQ931Event->tv.wYear,
1705 pQ931Event->tv.wHour,pQ931Event->tv.wMinute,pQ931Event->tv.wSecond);
1707 INFO_MAIN(
"Message Type is: %s\n",pQ931Event->msg_type);
1708 INFO_MAIN(
"Length of Call Reference Field is: %d\n", pQ931Event->len_callRef);
1709 INFO_MAIN(
"Message Call Reference is : 0X%s\n",pQ931Event->callRef);
1711 if (pQ931Event->cause_code > 0){
1712 INFO_MAIN(
"Cause code found = %d \n", pQ931Event->cause_code);
1715 if (pQ931Event->chan > 0){
1716 INFO_MAIN(
"B-channel used = %d \n", pQ931Event->chan);
1719 if (pQ931Event->calling_num_digits_count > 0 ){
1720 INFO_MAIN(
"Found %d digits for calling number \n", pQ931Event->calling_num_digits_count);
1721 INFO_MAIN(
"Presentation indicator is = %d \n",pQ931Event->calling_num_presentation);
1722 INFO_MAIN(
"Screening indicator is = %d \n",pQ931Event->calling_num_screening_ind);
1723 INFO_MAIN(
"Calling number is = %s\n",pQ931Event->calling_num_digits);
1726 if (pQ931Event->called_num_digits_count > 0 ){
1727 INFO_MAIN(
"Found %d digits for called number \n", pQ931Event->called_num_digits_count);
1728 INFO_MAIN(
"Called number is = %s\n",pQ931Event->called_num_digits);
1731 if (pQ931Event->rdnis_digits_count > 0 ){
1732 INFO_MAIN(
"Found %d digits for RDNIS\n", pQ931Event->rdnis_digits_count);
1733 INFO_MAIN(
"RDNIS is = %s\n",pQ931Event->rdnis_string);
1740 static void SwDtmfTransmit (
void *callback_context,
void *DtmfBuffer)
1743 DBG_MAIN(
"%s(): %s:\n", __FUNCTION__, sang_if->device_name);
1747 sang_if->CreateSwDtmfTxThread(DtmfBuffer);
1751 static void FSKCallerIDTransmit (
void *callback_context,
void *FskCidBuffer)
1754 DBG_MAIN(
"%s(): %s:\n", __FUNCTION__, sang_if->device_name);
1758 sang_if->CreateFskCidTxThread(FskCidBuffer);
1762 #warning "REMOVE LATER"
1763 int slin2ulaw(
void* data,
size_t max,
size_t *datalen)
1765 int16_t sln_buf[512] = {0}, *sln = sln_buf;
1766 uint8_t *lp = (uint8_t*)data;
1768 size_t len = *datalen;
1774 memcpy(sln, data, max);
1776 for(i = 0; i < max; i++) {
1777 *lp++ = linear_to_ulaw(*sln++);
1789 LONG Win32FaultHandler(
struct _EXCEPTION_POINTERS * ExInfo)
1793 switch(ExInfo->ExceptionRecord->ExceptionCode)
1795 case EXCEPTION_ACCESS_VIOLATION:
1796 FaultTx =
"ACCESS VIOLATION";
1798 case EXCEPTION_DATATYPE_MISALIGNMENT:
1799 FaultTx =
"DATATYPE MISALIGNMENT";
1801 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
1802 FaultTx =
"FLT DIVIDE BY ZERO";
1804 default: FaultTx =
"(unknown)";
1808 FILE *sgLogFile = fopen(
"Win32Fault.log",
"w");
1809 int wsFault = ExInfo->ExceptionRecord->ExceptionCode;
1810 PVOID CodeAddress = ExInfo->ExceptionRecord->ExceptionAddress;
1812 sgLogFile = fopen(
"Win32Fault.log",
"w");
1813 if(sgLogFile != NULL)
1815 fprintf(sgLogFile,
"****************************************************\n");
1816 fprintf(sgLogFile,
"*** A Program Fault occurred:\n");
1817 fprintf(sgLogFile,
"*** Error code %08X: %s\n", wsFault, FaultTx);
1818 fprintf(sgLogFile,
"****************************************************\n");
1819 fprintf(sgLogFile,
"*** Address: %08X\n", (
int)CodeAdress);
1820 fprintf(sgLogFile,
"*** Flags: %08X\n",
1821 ExInfo->ExceptionRecord->ExceptionFlags);
1822 LogStackFrames(CodeAddress, (
char *)ExInfo->ContextRecord->Ebp);
1831 return EXCEPTION_EXECUTE_HANDLER;
void cleanup(void)
Protperly shutdown single device.
Sangoma Interface Class that deals with span/chan IO (read/write/events)
u_int8_t operation_status
sangoma_interface * init(int wanpipe_number, int interface_number)
Create a sangoma_interface class and setup callback functions.
Used with Sample.cpp Code.
#define __cdecl
Ported from Windows.
#define _stricmp
_stricmp type mapped to _stricmp, Ported from Windows
#define sangoma_msleep(x)
milisecond sleep function
void PrintRxData(wp_api_hdr_t *hdr, void *pdata)
Debug function used to print Rx Data.
TDM API channel statistics.
Wanpipe API Event Structure.
int start(sangoma_interface *sang_if)
Run the main sangoma interface hanlder code.
u_int32_t time_stamp_usec
#define WP_API_EVENT_POLARITY_REVERSE_DECODE(polarity_reverse)
Print out the Polarity state.
int __cdecl main(int argc, char *argv[])
Main function that starts the sample code.
u_int32_t time_stamp_usec
void stop(sangoma_interface *sang_if)
Stop the Sangoma Interface Object.
Wanpipe API Header Structure.
int transmit(wp_api_hdr_t *hdr, void *data)
int tx_file(sangoma_interface *sang_if)
Transmit a file on a sangoma interface / device.
#define WAN_BRI_BCHAN1
BRI Channel 1.
#define sangoma_ctime(time)
Convert a time value to a string.