📄 projectorctl.c
字号:
{
cc = URT_Write( uartPortPC, nbt, (uint08*)&Msg, 0, &nbt );
if( cc != PASS )
dbmsg_ftrace( DBM_ALWAYS, "UART Write error %d\r\n", cc );
}
}
}
}
/****************************************************************************/
/* USB interface task. */
/* */
/* This task waits for command messages on a USB endpoint and passes what */
/* it believes to be complete message buffers to the command handler for */
/* processing. */
/****************************************************************************/
static void cmdTaskUSB( void )
{
uint08 *mPtr; /* byte transfer pointer into message */
uint16 msize; /* received message size */
uint16 expect; /* expected message size */
uint16 bcount; /* count of bytes in current packet */
uint16 cc; /* completion code */
for(;;)
{
/********************************************/
/* Setup to receive a message. If a packet */
/* with < 5 bytes is returned, the packet */
/* is not a packet containing a message */
/* header so it is discarded. Note that if */
/* a message is garbled, the packet just */
/* received may not be the first packet of */
/* a message. The message protocol does not */
/* provide a means to detect this, so a */
/* timeout is the only means provided to */
/* get back into sync. */
/********************************************/
mPtr = (uint08*)&Msg; /* point to head of message */
msize = usbIO_GetCmdPacket( mPtr, 0 ); /* wait for packet */
if( msize < 5 ) /* not a header */
continue;
expect = 6 + _pctlLengthGet(); /* total expected size */
while( msize < expect )
{
mPtr = (uint08*)&Msg + msize; /* start of next packet store */
bcount = usbIO_GetCmdPacket( mPtr, 200 ); /* get with timeout */
if( bcount == 0 ) /* if timeout */
break;
msize += bcount; /* bump received message size */
}
if( msize < expect ) /* if timeout */
continue;
/********************************************/
/* Handle message. */
/********************************************/
msize = cmdExecute(); /* exec */
if( msize > 0 ) /* if not checksum error */
cc = usbIO_PutCmdResponse( msize, (uint08*)&Msg );
if( cc != PASS )
dbmsg_ftrace( DBM_ALWAYS, "USB Write error %d\r\n", cc );
}
}
/****************************************************************************/
/* Examine message checksum, return TRUE on error. */
/****************************************************************************/
static BOOL _pctlCksumCheck( void )
{
uint08 cksum = 0; /* checksum */
uint16 count = 4 + _pctlLengthGet(); /* check range */
uint08 *p = &Msg.head.seq; /* check start */
while( count-- ) cksum += *p++; /* calculate checksum */
return cksum != *p; /* test and return */
}
/****************************************************************************/
/* Generate message checksum. */
/****************************************************************************/
static void _pctlCksumGen( void )
{
uint08 cksum = 0; /* checksum */
uint16 count = 4 + _pctlLengthGet(); /* check range */
uint08 *p = &Msg.head.seq; /* check start */
while( count-- ) cksum += *p++; /* calculate checksum */
*p = cksum; /* write checksum */
}
/****************************************************************************/
/* Handle read command. */
/* */
/* 0 1 2 3 4 5 6 . . . */
/* ______________ _______________________ */
/* |C1|Sq|--| Len |--|--|--|C2|C3|Text. . . */
/* Header Request */
/* */
/* */
/* 0 1 2 3 4 5 6 . . . */
/* ______________ _______________________ */
/* |C1|Sq| 0| Len | 0| 0|Text. . . */
/* Header Response */
/* */
/* Parse out the command key, set up the parameter parser, then vector to */
/* the command processor. */
/* */
/* With one exception: */
/* The "Status" request from DLP Composer is in an irregular format. If */
/* the message text length is 3 bytes, the request most likey is a Status */
/* request. Format a local, fixed, response in this case. */
/****************************************************************************/
static CMD1_TYPE _pctlCmdRead( void )
{
CMD1_TYPE cc; /* response message code */
uint32 key;
if( 3 == _pctlLengthGet()) /* special case "Status" */
{
_pctlLengthSet( 5 ); /* set length */
Msg.text[3] = Msg.text[1]; /* place byte in regular location */
Msg.text[4] = Msg.text[2]; /* place byte in regular location */
}
key = CMD_KEY( Msg.text[3], Msg.text[4], Msg.head.cmd1 );
rdp = &Msg.text[5]; /* pointer to next message byte to read */
wrp = &Msg.text[2]; /* pointer to next message byte to write */
nRemReadPC = _pctlLengthGet() - 5; /* number of read bytes */
nRemWritePC = (uint16)( sizeof( Msg.text ) - 2 ); /* no. of write bytes */
nWritten = 0; /* number of written bytes */
dbmsg_ftrace( DBM_MSG, "pctl read: %04x\r\n", key >> 8 );
cc = _pctlVector( CMD1_READ_RESPONSE, key );
if( CMD1_READ_RESPONSE == cc ) /* if valid response */
{
_pctlLengthSet( 2 + nWritten ); /* set length */
Msg.head.cmd1 = CMD1_READ_RESPONSE; /* set response */
Msg.head.nada = 0; /* zero bytes */
Msg.text[0] = 0;
Msg.text[1] = 0;
}
return cc;
}
/****************************************************************************/
/* Handle write command. */
/* */
/* 0 1 2 3 4 5 6 . . . */
/* ______________ _______________________ */
/* |C1|Sq|--| Len |--|C2|C3|Text. . . */
/* Header Request */
/* */
/* */
/* 0 1 2 3 4 5 6 . . . */
/* ______________ _______________________ */
/* |C1|Sq| 0| Len |Text. . . */
/* Header Response */
/* */
/* Parse out the command key, set up the paremeter parser, then vector to */
/* the command processor. */
/****************************************************************************/
static CMD1_TYPE _pctlCmdWrite( void )
{
CMD1_TYPE cc; /* response message code */
uint32 key = CMD_KEY( Msg.text[1], Msg.text[2], Msg.head.cmd1 );
rdp = &Msg.text[3]; /* pointer to next message byte to read */
wrp = &Msg.text[0]; /* pointer to next message byte to write */
nRemReadPC = _pctlLengthGet() - 3; /* number of read bytes */
nRemWritePC = (uint16)sizeof( Msg.text ); /* number of write bytes */
nWritten = 0; /* number of written bytes */
dbmsg_ftrace( DBM_MSG, "pctl write: %04x\r\n", key >> 8 );
cc = _pctlVector( CMD1_WRITE_RESPONSE,
CMD_KEY( Msg.text[1], Msg.text[2], Msg.head.cmd1 ));
if( CMD1_WRITE_RESPONSE == cc ) /* if valid response */
{
_pctlLengthSet( nWritten ); /* set length */
Msg.head.cmd1 = CMD1_WRITE_RESPONSE; /* set response */
Msg.head.nada = 0; /* zero byte */
}
return cc;
}
/****************************************************************************/
/* Format message ACK. */
/****************************************************************************/
static void _pctlFormatAck( void )
{
Msg.head.cmd1 = CMD1_ACK;
_pctlLengthSet( 0 );
}
/****************************************************************************/
/* Format message NACK. */
/****************************************************************************/
static void _pctlFormatNack( void )
{
Msg.head.cmd1 = CMD1_NACK;
_pctlLengthSet( 0 );
}
/****************************************************************************/
/* Get message length. */
/****************************************************************************/
static uint16 _pctlLengthGet( void )
{
return Msg.head.length[0] + ( Msg.head.length[1] << 8 );
}
/****************************************************************************/
/* Set message length. */
/****************************************************************************/
static void _pctlLengthSet( uint16 length )
{
Msg.head.length[0] = (uint08)( length );
Msg.head.length[1] = (uint08)( length >> 8 );
}
/****************************************************************************/
/* Locate and vector to command handler. */
/****************************************************************************/
static CMD1_TYPE _pctlVector( CMD1_TYPE ctype, uint32 key )
{
size_t dax; /* dictionary array index */
size_t low;
size_t high;
size_t probe;
CMD_DICT_ENTRY *pDict; /* pointer to head of dictionary */
for( dax = 0; dax < DICTMAX; dax++ ) /* search all arrays */
{
low = -1;
high = dictArray[dax].dictSize; /* size of a dictionary */
pDict = dictArray[dax].pDict; /* head of a dictionary */
while(( high - low ) > 1 ) /* binary search */
{
probe = ( high + low ) / 2;
if ( pDict[probe].key > key )
high = probe;
else
low = probe;
}
if(( low == -1 ) || ( pDict[low].key != key ))
continue;
else if( (*pDict[low].pFunc )()) /* exec */
return ctype; /* no handler error */
else
return CMD1_ACK; /* if handler error */
};
return projectorCtlExt( ctype, key ); /* try extended projector control */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -