// -------------------------------------------------------------------------- // proof.c // by Christopher Trudeau, copyright 1997 // // This file contains the c code to attach to the tcl/tk script 'pr1' and // to execute CU like operations on the trunk equipment. // // Comments and criticism on this program are greatly appreciated. Feel free // to send me a note at ctrudeau@etude.uwaterloo.ca. This material is // copyright but non-commercial institutes have permission to reproduce the // program in its entirety, all other uses require explicit written // permission of the author. // // -------------------------------------------------------------------------- // Include Files #include #include #include #include #include #include #include #include "../pbx2.h" #include "../he2.h" // -------------------------------------------------------------------------- // Global Variables struct ifmem_t *ifmem_p; // pointer to shared hardware memory // -------------------------------------------------------------------------- // Function Prototypes int InitProc(Tcl_Interp* interp); int cmdDoIt( ClientData clientData, Tcl_Interp *pInterp, int argc, char *argv[] ); // -------------------------------------------------------------------------- int main() { char *ppszArg[2]; int iMemId; printf( "Starting proof...\n" ); // get pointer to shared interface memory iMemId = shmget( IFMEM_KEY, sizeof( struct ifmem_t ), 0644); ifmem_p = (struct ifmem_t *)shmat( iMemId, 0, 0); if( (int)ifmem_p == -1 ) { printf( "Error: unable to access shared interface memory\n" ); exit( 0 ); } // end if -- failed to get interface memory // initialize arguments for Tk_Main ppszArg[0] = (char *)malloc( sizeof( char ) * 8 ); ppszArg[1] = (char *)malloc( sizeof( char ) * 65 ); strcpy( ppszArg[0], "proof" ); strcpy( ppszArg[1], "/home3/ctrudeau/s/tcl/proof/pr1" ); printf( "Executing tcl/tk script\n" ); Tk_Main( 2, ppszArg, InitProc ); return( 0 ); } // end main // -------------------------------------------------------------------------- int InitProc( Tcl_Interp *interp ) { int iRet; // Initialize tk first iRet = Tk_Init( interp ); if( iRet != TCL_OK) { printf( "Unable to Initialize TK!\n" ); return( iRet ); } // end if // register any new tcl/tk commands Tcl_CreateCommand( interp, "cmdDoIt", cmdDoIt, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL ); return( TCL_OK ); } // end InitProc // ---------------------------------------------------------------------------- // cmdDoIt // // This function is called as a command from tcl/tk. It is issued when the // user pushes the "Do it" button. Each of the entry fields is checked // for their contents and the interface memory is updated accordingly. // The update to i/f mem is used to make connections between various cards // and to put values into those cards (digits, loop back bits, etc) // int cmdDoIt( ClientData clientData, Tcl_Interp *pInterp, int argc, char *argv[] ) { int iSlot, iValue, iTrunk, iChan; char sText[64]; fprintf( stderr, "****** Doing it\n" ); for( iTrunk=FIRST_TRUNK; iTrunk<=LAST_TRUNK; iTrunk++ ) { sprintf( sText, "entryTrunk(%d)", iTrunk ); iValue = atoi( Tcl_GetVar( pInterp, sText, 0 ) ); ifmem_p->serv_shelf[iTrunk] = iValue; fprintf( stderr, "card(2)(%d)=%d\n", iTrunk, iValue ); sprintf( sText, "entryTrunkCard(%d)", iTrunk ); iSlot = atoi( Tcl_GetVar( pInterp, sText, 0 ) ); sprintf( sText, "entryTrunkChan(%d)", iTrunk ); iChan = atoi( Tcl_GetVar( pInterp, sText, 0 ) ); if( iSlot == 0 || iSlot > 30 ) continue; if( iChan == 0 || iChan > 30 ) continue; ifmem_p->timesw_in_ctrl[2][iChan] = iTrunk; fprintf( stderr, "TM2_IN(%d)=%d\n", iChan, iTrunk ); ifmem_p->timesw_out_ctrl[2][iSlot] = iChan; fprintf( stderr, "TM2_OUT(%d)=%d\n", iSlot, iChan ); ifmem_p->spacesw_ctrl[iChan] = 10; fprintf( stderr, "SS(%d)=10\n", iChan ); } // end for -- loop through MFSenders fprintf( stderr, "\n\n" ); for( iSlot=FIRST_MFSEND; iSlot<=LAST_MFSEND; iSlot++ ) { sprintf( sText, "entryMFS(%d)", iSlot ); iValue = atoi( Tcl_GetVar( pInterp, sText, 0 ) ); ifmem_p->serv_shelf[iSlot] = iValue; fprintf( stderr, "card(2)(%d)=%d\n", iSlot, iValue ); sprintf( sText, "entryMFSTrunk(%d)", iSlot ); iTrunk = atoi( Tcl_GetVar( pInterp, sText, 0 ) ); sprintf( sText, "entryMFSChan(%d)", iSlot ); iChan = atoi( Tcl_GetVar( pInterp, sText, 0 ) ); if( iTrunk < FIRST_TRUNK || iTrunk > LAST_TRUNK ) continue; if( iChan == 0 || iChan > 30 ) continue; ifmem_p->timesw_in_ctrl[2][iChan] = iSlot; fprintf( stderr, "TM2_IN(%d)=%d\n", iChan, iSlot ); ifmem_p->timesw_out_ctrl[2][iTrunk] = iChan; fprintf( stderr, "TM2_OUT(%d)=%d\n", iTrunk, iChan ); ifmem_p->spacesw_ctrl[iChan] = 10; fprintf( stderr, "SS(%d)=10\n", iChan ); } // end for -- loop through MFSenders // 0 - don't update the MFRs as the code should do it if( !atoi( argv[1] ) ) return( TCL_OK ); fprintf( stderr, "\n\n" ); for( iSlot=FIRST_MFRCV; iSlot<=LAST_MFRCV; iSlot++ ) { sprintf( sText, "entryMFR(%d)", iSlot ); iValue = atoi( Tcl_GetVar( pInterp, sText, 0 ) ); ifmem_p->serv_shelf[iSlot] = iValue; fprintf( stderr, "card(2)(%d)=%d\n", iSlot, iValue ); } // end for -- loop through MFSenders return( TCL_OK ); } // end cmdDoIt // ----------------------------------------------------------------------------