Beispiel #1
0
void parseInput()
{
  writeDebugStreamLine("Beging parsing...");

  ubyte BytesRead[20];
  ubyte currByte[] = {0};
  ubyte prevByte[] = {0};
  ubyte conn[] = {0};
  int cid;
  string tmpString;
  int index = 0;
  while (true)
  {
    alive();
	  if (nxtGetAvailHSBytes() > 0)
	  {
      nxtReadRawHS(currByte[0], 1);
      if ((prevByte[0] == 27) && (currByte[0] == 'S')) {
        index = 0;
        memset(rxbuffer, 0, sizeof(rxbuffer));
        wait1Msec(1);
        nxtReadRawHS(conn[0], 1);
        cid = conn[0] - 48;
        writeDebugStreamLine("Conn: %d", cid);
        while (true) {
          while (nxtGetAvailHSBytes() == 0) EndTimeSlice();
          nxtReadRawHS(currByte[0], 1);

					if ((prevByte[0] == 27) && (currByte[0] == 'E')) {
					  rxbuffer[index--] = 0;
					  rxbuffer[index--] = 0;
					  PlaySound(soundShortBlip);
					  while(bSoundActive) EndTimeSlice();
					  break;
					}
					prevByte[0] = currByte[0];
          rxbuffer[index++] = currByte[0];

				}
				for (int i = 0; i < ((index / 19) + 1); i++) {
					memset(BytesRead[0], 0, 20);
					memcpy(BytesRead[0], rxbuffer[i*19], 19);
					StringFromChars(tmpString, BytesRead);
					writeDebugStream(tmpString);

				}
				genResponse(cid);
      }
      prevByte[0] = currByte[0];
	  }
	}
}
////////////////////////////////////////////////////////////////////////
//  Receive - Receives a list of bytes.
//
//  ubyte** list - The received list.  The memory for this list is
//                 allocated from within the method.
//
//  int* bytesRead - The count of bytes read.
//
//  NOTES:
//    1. The list should be deallocated using the free method.
//    2. Check to ensure the list is not null before deallocating
//    3. Sets the global byteType attribute.
//
////////////////////////////////////////////////////////////////////////
void Receive()
{
  ubyte hByte = 0;

  if (byteType == BYTETYPE_NOTSET)
  {
     int ndx = nxtReadRawHS(headerList[0],sizeof(headerList));
     hByte = headerList[0];
     if ((hByte & 0x80) != 0)
     {
       //ASCII
       byteType = BYTETYPE_ASCII;
     }
     else
     {
       byteType = BYTETYPE_NUMBER;
     }
  }
  bytesRead = hByte & 0x7F;
  nxtReadRawHS(receiveList[0], bytesRead * sizeof(ubyte));
  byteType = BYTETYPE_NOTSET;
}
////////////////////////////////////////////////////////////////////////
//  Reads a Response from the XBee
//  Displays the response from the XBee
//  This reads any response from the XBee
////////////////////////////////////////////////////////////////////////
void ReadResponse(int line_to_display)
{
  byte BytesRead[8];                           // Array we'll be reading into.
	nxtReadRawHS(BytesRead[0], 8);      // Read the array.

	string sTemp = "";
	string sString = "";
  for (int i = 0; i < 8; ++i)
	{
  	StringFormat(sTemp, "%c", BytesRead[i]);
  	BytesRead[i] = ' ';
  	sString += sTemp;
  }
	nxtDisplayTextLine(line_to_display, sString);
}