Windows mobile gps 串口通信 NMEA命令和数据处理
2010-06-22 03:15:00 来源:WEB开发网case NMEAState.NP_STATE_SOM :
if(btData == '$')
{
checksum = 0; // reset checksum
index = 0; // reset index
nState = NMEAState.NP_STATE_CMD;
}
break;
///////////////////////////////////////////////////////////////////////
// Retrieve command (NMEA Address)
case NMEAState.NP_STATE_CMD :
if(btData != ',' && btData != '*')
{
command[index++] = btData;
checksum ^= btData;
// Check for command overflow
if(index >= NP_MAX_CMD_LEN)
{
nState = NMEAState.NP_STATE_SOM;
}
}
else
{
command[index] = (byte)''; // terminate command
checksum ^= btData;
index = 0;
nState = NMEAState.NP_STATE_DATA; // goto get data state
}
break;
///////////////////////////////////////////////////////////////////////
// Store data and check for end of sentence or checksum flag
case NMEAState.NP_STATE_DATA:
if(btData == '*') // checksum flag?
{
data[index] = (byte)'';
nState = NMEAState.NP_STATE_CHECKSUM_1;
}
else // no checksum flag, store data
{
//
// Check for end of sentence with no checksum
//
if(btData == '')
{
data[index] = (byte) '';
ProcessCommand(EncodeToString( command), data);
nState = NMEAState.NP_STATE_SOM;
return;
}
//
// Store data and calculate checksum
//
checksum ^= btData;
data[index] = btData;
if(++index >= NP_MAX_DATA_LEN) // Check for buffer overflow
{
nState = NMEAState.NP_STATE_SOM;
}
更多精彩
赞助商链接