📄 ui_serial.c
字号:
//! predetermined range.
//!
//! \return None.
//
//*****************************************************************************
static void
UISerialRangeCheck(unsigned long ulIdx)
{
unsigned long *pulValue;
unsigned short *pusValue;
long *plValue, lCheck;
short *psValue, sCheck;
char *pcValue, cCheck;
//
// See if a range exists for this parameter. If not, then return without
// checking the parameter's value.
//
if(((g_sUIParameters[ulIdx].ulMin == 0) &&
(g_sUIParameters[ulIdx].ulMax == 0)) ||
(g_sUIParameters[ulIdx].ucSize > 4))
{
return;
}
//
// See if the value of this parameter is signed or unsigned.
//
if(g_sUIParameters[ulIdx].ulMin > g_sUIParameters[ulIdx].ulMax)
{
//
// This is a signed parameter. Determine the size of the parameter.
//
switch(g_sUIParameters[ulIdx].ucSize)
{
//
// This parameter is a signed character.
//
case 1:
{
//
// Get the signed value of this parameter.
//
pcValue = (char *)(g_sUIParameters[ulIdx].pucValue);
//
// Clamp the parameter value to the minimum if it is below the
// minimum.
//
cCheck = (char)g_sUIParameters[ulIdx].ulMin;
if(*pcValue < cCheck)
{
*pcValue = cCheck;
}
//
// Clamp the parameter value to the maximum if it is above the
// maximum.
//
cCheck = (char)g_sUIParameters[ulIdx].ulMax;
if(*pcValue > cCheck)
{
*pcValue = cCheck;
}
//
// This parameter value has been handled.
//
break;
}
//
// This parameter is a signed short.
//
case 2:
{
//
// Get the signed value of this parameter.
//
psValue = (short *)(g_sUIParameters[ulIdx].pucValue);
//
// Clamp the parameter value to the minimum if it is below the
// minimum.
//
sCheck = (short)g_sUIParameters[ulIdx].ulMin;
if(*psValue < sCheck)
{
*psValue = sCheck;
}
//
// Clamp the parameter value to the maximum if it is above the
// maximum.
//
sCheck = (short)g_sUIParameters[ulIdx].ulMax;
if(*psValue > sCheck)
{
*psValue = sCheck;
}
//
// This parameter value has been handled.
//
break;
}
//
// This parameter is a signed long.
//
case 4:
default:
{
//
// Get the signed value of this parameter.
//
plValue = (long *)(g_sUIParameters[ulIdx].pucValue);
//
// Clamp the parameter value to the minimum if it is below the
// minimum.
//
lCheck = (long)g_sUIParameters[ulIdx].ulMin;
if(*plValue < lCheck)
{
*plValue = lCheck;
}
//
// Clamp the parameter value to the maximum if it is above the
// maximum.
//
lCheck = (long)g_sUIParameters[ulIdx].ulMax;
if(*plValue > lCheck)
{
*plValue = lCheck;
}
//
// This parameter value has been handled.
//
break;
}
}
}
else
{
//
// This is an unsigned parameter. Determine the size of the parameter.
//
switch(g_sUIParameters[ulIdx].ucSize)
{
//
// This parameter is an unsigned character.
//
case 1:
{
//
// Clamp the parameter value to the minimum if it is below the
// minimum.
//
if(g_sUIParameters[ulIdx].pucValue[0] <
g_sUIParameters[ulIdx].ulMin)
{
g_sUIParameters[ulIdx].pucValue[0] =
g_sUIParameters[ulIdx].ulMin;
}
//
// Clamp the parameter value to the maximum if it is above the
// maximum.
//
if(g_sUIParameters[ulIdx].pucValue[0] >
g_sUIParameters[ulIdx].ulMax)
{
g_sUIParameters[ulIdx].pucValue[0] =
g_sUIParameters[ulIdx].ulMax;
}
//
// This parameter value has been handled.
//
break;
}
//
// This parameter is an unsigned short.
//
case 2:
{
//
// Get the value of this parameter.
//
pusValue = (unsigned short *)(g_sUIParameters[ulIdx].pucValue);
//
// Clamp the parameter value to the minimum if it is below the
// minimum.
//
if(*pusValue < g_sUIParameters[ulIdx].ulMin)
{
*pusValue = g_sUIParameters[ulIdx].ulMin;
}
//
// Clamp the parameter value to the maximum if it is above the
// maximum.
//
if(*pusValue > g_sUIParameters[ulIdx].ulMax)
{
*pusValue = g_sUIParameters[ulIdx].ulMax;
}
//
// This parameter value has been handled.
//
break;
}
//
// This parameter is an unsigned long.
//
case 4:
default:
{
//
// Get the value of this parameter.
//
pulValue = (unsigned long *)(g_sUIParameters[ulIdx].pucValue);
//
// Clamp the parameter value to the minimum if it is below the
// minimum.
//
if(*pulValue < g_sUIParameters[ulIdx].ulMin)
{
*pulValue = g_sUIParameters[ulIdx].ulMin;
}
//
// Clamp the parameter value to the maximum if it is above the
// maximum.
//
if(*pulValue > g_sUIParameters[ulIdx].ulMax)
{
*pulValue = g_sUIParameters[ulIdx].ulMax;
}
//
// This parameter value has been handled.
//
break;
}
}
}
}
//*****************************************************************************
//
//! Scans for packets in the receive buffer.
//!
//! This function will scan through g_pucUISerialReceive looking for valid
//! command packets. When found, the command packets will be handled.
//!
//! \return None.
//
//*****************************************************************************
static void
UISerialScanReceive(void)
{
unsigned char ucSum, ucSize;
unsigned long ulIdx;
//
// Loop while there is data in the receive buffer.
//
while(g_ulUISerialReceiveRead != g_ulUISerialReceiveWrite)
{
//
// See if this character is the tag for the start of a command packet.
//
if(g_pucUISerialReceive[g_ulUISerialReceiveRead] != TAG_CMD)
{
//
// Skip this character.
//
g_ulUISerialReceiveRead =
(g_ulUISerialReceiveRead + 1) % UISERIAL_MAX_RECV;
//
// Keep scanning for a start of command packet tag.
//
continue;
}
//
// See if there are additional characters in the receive buffer.
//
if(((g_ulUISerialReceiveRead + 1) % UISERIAL_MAX_RECV) ==
g_ulUISerialReceiveWrite)
{
//
// There are no additional characters in the receive buffer after
// the start of command packet byte, so stop scanning for now.
//
break;
}
//
// See if the packet size byte is valid. A command packet must be at
// least four bytes and can not be larger than the receive buffer size.
//
ucSize = g_pucUISerialReceive[(g_ulUISerialReceiveRead + 1) %
UISERIAL_MAX_RECV];
if((ucSize < 4) || (ucSize > (UISERIAL_MAX_RECV - 1)))
{
//
// The packet size is too large, so either this is not the start of
// a packet or an invalid packet was received. Skip this start of
// command packet tag.
//
g_ulUISerialReceiveRead =
(g_ulUISerialReceiveRead + 1) % UISERIAL_MAX_RECV;
//
// Keep scanning for a start of command packet tag.
//
continue;
}
//
// Determine the number of bytes in the receive buffer.
//
ulIdx = g_ulUISerialReceiveWrite - g_ulUISerialReceiveRead;
if(g_ulUISerialReceiveRead > g_ulUISerialReceiveWrite)
{
ulIdx += UISERIAL_MAX_RECV;
}
//
// If the entire command packet is not in the receive buffer then stop
// scanning for now.
//
if(ulIdx < ucSize)
{
break;
}
//
// The entire command packet is in the receive buffer, so compute its
// checksum.
//
for(ulIdx = 0, ucSum = 0; ulIdx < ucSize; ulIdx++)
{
ucSum += g_pucUISerialReceive[(g_ulUISerialReceiveRead + ulIdx) %
UISERIAL_MAX_RECV];
}
//
// Skip this packet if the checksum is not correct (that is, it is
// probably not really the start of a packet).
//
if(ucSum != 0)
{
//
// Skip this character.
//
g_ulUISerialReceiveRead =
(g_ulUISerialReceiveRead + 1) % UISERIAL_MAX_RECV;
//
// Keep scanning for a start of command packet tag.
//
continue;
}
//
// A valid command packet was received, so process it now.
//
switch(g_pucUISerialReceive[(g_ulUISerialReceiveRead + 2) %
UISERIAL_MAX_RECV])
{
//
// The command to get the target type.
//
case CMD_ID_TARGET:
{
//
// Fill in the response.
//
g_pucUISerialResponse[0] = TAG_STATUS;
g_pucUISerialResponse[1] = 0x05;
g_pucUISerialResponse[2] = CMD_ID_TARGET;
g_pucUISerialResponse[3] = g_ulUITargetType;
//
// Send the response.
//
UISerialTransmit(g_pucUISerialResponse);
//
// Done with this command.
//
break;
}
//
// The command to upgrade the firmware.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -