?? mtp3app.c
字號:
/* kbHandler
*
* Keyboard event handler routine, to be called by "tx_core" whenever an asynchronous
* keyboard input is detected.
*/
short kbHandler(TX_HANDLE handle, short events)
{
char c;
/* check if input event really did occur */
if (tx_core_process_events(TX_CORE_INPUT, events) == FALSE)
return (TX_CORE_SUCCESS);
/* make sure a key was hit */
if (tx_core_kbhit())
{
c = getchar();
if( c == 'q' || c == 'Q' )
return (TX_CORE_EXIT_POLL_LOOP);
else
cmdPrompt();
}
return (TX_CORE_SUCCESS);
}
/* mtp3Handler
*
* MTP3 event handler routine, to be called by "tx_core" whenever an asynchronous
* event message from MTP3 is pending.
*/
short mtp3Handler(TX_HANDLE handle, short events)
{
short status;
short len;
union
{
U8 msgCode; /* overlays "code" field of DATA_IND/STAT_IND */
DATA_IND dataind; /* incoming data event */
STAT_IND statind; /* incoming status event */
XSTAT_IND xstatind; /* incoming extended status indication */
BIND_CFM bindcfm; /* Bind confirmation */
} msg;
len = sizeof( msg );
status = MTP3RetrieveMessage( (U8) Board, (void *) &msg, (U16 *)&len );
if( status != MTP3_SUCCESS )
{
if( status == MTP3_NO_MSG )
{
/* "NO_MSG" unexpected, but not fatal */
printf( "Warning: Mtp3RetrieveMessage returned NO_MSG\n" );
return (TX_CORE_SUCCESS);
}
else
{
printf( "Mtp3RetrieveMessage failed, status %d\n" );
return (TX_CORE_EXIT_POLL_LOOP); /* fatal */
}
}
/* got an incoming message, decode it */
switch( msg.msgCode )
{
case MTP3_BIND_CFM:
printf ("Bind Confirm received. spId = %d, suId = %d\n",
msg.bindcfm.spId, msg.bindcfm.suId);
break;
case MTP3_DATA_IND:
/* Subtract off size of header fields to get actual data length */
/* Note that the header is packed, spares in the structure are not included. Also the message "code" field
* in the DATA_IND structure has already been stripped (and placed into the msgCode field) and is not included
* in the length returned from MTP3RetrieveMsg(). Therefore it is not included in the DATA_IND_HDR_SIZE define
* either. */
len -= DATA_IND_HDR_SIZE; /* Changed from -= (sizeof(DATA_IND) - MAXDATA) due to lack of spare packing */
printf( "Packet received from 0x%lx, length %d\n", msg.dataind.opc, len );
showHex( msg.dataind.data, (unsigned short) len );
printf( "\n" );
break;
case MTP3_XSTAT_IND :
switch ( msg.xstatind.status )
{
case XStatLinkUp:
printf("MTP Link (%d) Up\n", msg.xstatind.link);
break;
case XStatLinkDown:
printf("MTP Link (%d) Down\n", msg.xstatind.link);
break;
case XStatLinkInhDen:
printf("MTP Link (%d) Inhibited and Denied\n", msg.xstatind.link);
break;
case XStatLinkInh:
printf("MTP Link (%d) Inhibited\n", msg.xstatind.link);
break;
case XStatLinkUninh:
printf("MTP Link (%d) Uninhibited\n", msg.xstatind.link);
break;
case XStatLinkUninhDen:
printf("MTP Link (%d) Uninhibited and Denied\n", msg.xstatind.link);
break;
case XStatLinkRemBlock:
printf("MTP Link (%d) Remotely Blocked\n", msg.xstatind.link);
break;
case XStatLinkRemUnblock:
printf("MTP Link (%d) Remotely Unblocked\n", msg.xstatind.link);
break;
case XStatLinkLocBlock:
printf("MTP Link (%d) Locally Blocked\n", msg.xstatind.link);
break;
case XStatLinkLocUnblock:
printf("MTP Link (%d) Locally Unblocked\n", msg.xstatind.link);
break;
default:
printf( "Unknown MTP Extended Status indication received, status %d\n",
msg.xstatind.status );
break;
}
break;
case MTP3_STAT_IND:
/* print out status indication message */
switch( msg.statind.status )
{
case StatPaused:
printf( "MTP Pause: 0x%lx\n", msg.statind.pc );
break;
case StatResumed:
printf( "MTP Resume: 0x%lx\n", msg.statind.pc );
break;
case StatCongested:
printf( "MTP Destination Congested 0x%lx, Priority %d\n",
msg.statind.pc, msg.statind.priority );
break;
case StatUsrUnavail:
printf( "MTP Remote User Unavailable: 0x%lx\n", msg.statind.pc );
break;
case StatRestart:
printf( "MTP Restart Begins\n" );
break;
case StatRestartEnds:
printf( "MTP Restart Ends\n" );
break;
case StatCongestionEnds:
printf( "MTP Destination Congestion Ended 0x%lx, Priority %d\n",
msg.statind.pc, msg.statind.priority );
break;
case StatPrimary:
printf( "MTP Now Primary\n" );
break;
case StatBackup:
printf( "MTP Now Backup\n" );
break;
case StatStandAlone:
printf( "MTP Now Stand-Alone\n" );
break;
default:
printf( "Unknown MTP Status indication received, status %d, PC=0x%lx \n",
msg.statind.status, msg.statind.pc );
break;
} /* switch( msg.statind.status ) */
break;
default:
printf( "Unknown MTP message received, msgcode %d\n", msg.msgCode );
break;
} /* switch( msg.msgcode ) */
return (TX_CORE_SUCCESS);
}
/*
* Main routine
*
* Parse command line arguments, start main processing loop
*/
void main(int argc, char *argv[])
{
short n;
int i, j, k;
short status;
char *ap;
int sio;
OS_HSYNC hSync; /* synchronization handle for MTP3 API */
short bOpc = 0; /* Has required OPC been specified */
/* process arguments */
for(n = 1; n < argc; n++)
{
ap = argv[n];
if (*ap == '-')
{
switch (*++ap)
{
case 'o' : /* OPC */
n++;
i = j = k = -1;
sscanf(argv[n], "%d.%d.%d", &i, &j, &k);
if (i == -1 || j == -1 || k == -1) {
printf( "Invalid originating point code\n");
exit( 1 );
}
Opc = (((U32) i << 16) + ((U32) j << 8) + (U32) k);
bOpc = 1; /* They specified required OPC */
break;
case 's' : /* SIO */
n++;
sscanf(argv[n], "%i", &sio);
if ( sio < 0 || sio > 255 ) {
printf("SIO must be in range 0 - 0xFF\n");
exit( 1 );
}
Sio = (unsigned char) sio;
break;
case 'b' : /* board number */
n++;
Board = atoi(argv[n]);
if( Board < 1 || Board > 8 ) {
printf("Board must be in range 1 - 8\n");
exit(1);
}
break;
case 'n' : /* NSAP number */
n++;
MySap = atoi(argv[n]);
if( MySap < 0 || MySap > 15 ) {
printf("NSAP must be in range 0-15\n");
exit(1);
}
break;
case '?' : /* Help */
printf ("mtp3app -o <opc> [-s <sio>] [-b <board>] [-n <nsap> ] -?\n");
printf (" <opc> originating point code to use for outgoing packets: required\n");
printf (" <sio> Service Information Octet value; default: 0x85 (ISUP)\n");
printf (" <board> Board number to use (defaults to 1)\n");
printf (" <nsap> MTP network SAP number to bind to\n");
exit (1);
break;
default:
printf("Unrecogized Parameter: %s\n", argv[n]);
exit(1);
} /* end switch */
} else {
printf("Unrecogized Parameter: %s\n", argv[n]);
exit(1);
}
} /* end for loop */
if (!bOpc)
{
printf ("Required parameter OPC not specified\n");
exit (1);
}
/* Bind this application as a user of the MTP3 layer */
MyEnt = DFLT_ENT + MySap;
status = MTP3Bind( (U8) Board, Sio, MySap, MyEnt, DFLT_INST, 0 );
if( status != 0 )
{
printf( "Mtp3Bind failed, status = %d\n", status );
exit(1);
}
hSync = MTP3SyncObj( (U8) Board, &status );
if( hSync == OS_NULL_HSYNC )
{
printf( "Mtp3SyncObj failed, status = %d\n", status );
MTP3Unbind( (U8) Board );
exit(1);
}
/* install keyboard and MTP3 event handlers with "tx_core" and let it
* perform the main "wait for event" loop
*/
tx_core_init();
tx_core_install_handler( stdInput, TX_CORE_UNUSED, kbHandler );
tx_core_install_handler( hSync, TX_CORE_UNUSED, mtp3Handler );
tx_core_set_poll(stdInput, TX_CORE_INPUT);
tx_core_set_poll(hSync, TX_CORE_INPUT);
tx_core_poll_loop( TX_CORE_INFINITE );
/* when tx_core_poll_loop returns, user has selected "quit" */
MTP3Unbind( (U8) Board );
} /* end of main */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -