Beispiel #1
0
bool TwitterParser::Parse(char a)
{
  // move everything in the buffer down a slot
  for (int i = 0; i < TWITTER_BUFFER_SIZE-2; i++)
  {
    m_buffer[i] = m_buffer[i+1];
  }
  
  // and add the new character
  m_buffer[TWITTER_BUFFER_SIZE-2] = a;
  m_buffer[TWITTER_BUFFER_SIZE-1] = '\0';

  if (!m_foundTrigger)
  {
    // keep looking for the 'created_at":"' in the twitter stream
    if (strstr(m_buffer, TWITTER_TRIGGER))
    {
        m_foundTrigger = true;

#ifdef DEBUG  
        m_printer->println("found trigger");
#endif // #ifdef DEBUG

        m_printer->println(" ");

        m_counter++;
    }
  }
  else
  {
    // found 'created_at":"'
    // look for tweet time, XX:XX:XX
    if (isTimeFormat(m_buffer))
    {
#ifdef DEBUG      
      m_printer->println("found time");
#endif // #ifdef DEBUG

      // now found time of tweet, XX:XX:XX
      m_foundTrigger = false;

      if (m_counter == 1)
      {
        setTimeFromBuffer(m_time1, m_buffer);
      }
      else
      {
        setTimeFromBuffer(m_time2, m_buffer);
        if (m_counter >= m_tweetsPerPage - 1)
        {
          return true;
        }
      }
    }
  }

  return false;
}
/*
 * SERIAL_HandleCalibrationData
 * Reads calibration settings from serial and hands off processing to appropriate functions
 */
void SERIAL_HandleCalibrationData()
{
    char next_byte = '\0';
    if (Serial.available() > 0) 
    {
        while(Serial.available() && next_byte != 'E')
        {
            next_byte = Serial.read(); 
            s_strBuffer[s_index++] = next_byte;
        }

        if (next_byte=='E')    // We read everything up to the byte 'E' which stands for END
        {
            int buffer_length = strlen(s_strBuffer);  // We also find the length of the string so we know how many char to display 
            // Depending upon what came before we update different values
            // To change the reference number we enter R00E, where 00 can be any number up to 99 

            for (int i = buffer_length; i>=0; i--)  // Check the buffer from the end of the data, working backwards
            {
                if (s_strBuffer[i]=='R')
                {
                    setReferenceFromBuffer(i);
                }

                if(s_strBuffer[i]=='T')
                {
                    setTimeFromBuffer(i);
                }

                if(s_strBuffer[i]=='D')
                {
                    setDateFromBuffer(i);
                }           

                if(s_strBuffer[i]=='S')
                {          
                    setSampleTimeFromBuffer(i);
                }

                if(s_strBuffer[i]=='O')
                {    
                    VA_StoreNewCurrentOffset();
                }

                if(s_strBuffer[i]=='V' && s_strBuffer[i+1]=='1')
                {
                    char temp[] = "000";
                    temp[0] = s_strBuffer[i+2];
                    temp[1] = s_strBuffer[i+3];
                    temp[2] = s_strBuffer[i+4];
                    int value = atoi(temp);
                    VA_StoreNewResistor1(value);
                }

                if(s_strBuffer[i]=='V' && s_strBuffer[i+1]=='2')
                {    
                    char temp[] = "000";
                    temp[0] = s_strBuffer[i+2];
                    temp[1] = s_strBuffer[i+3];
                    temp[2] = s_strBuffer[i+4];
                    int value = atoi(temp);
                    VA_StoreNewResistor2(value);
                }

                if(s_strBuffer[i]=='I')
                {    
                    char temp[] = "000";
                    temp[0] = s_strBuffer[i+1];
                    temp[1] = s_strBuffer[i+2];
                    temp[2] = s_strBuffer[i+3];
                    int value = atoi(temp);
                    VA_StoreNewCurrentGain(value);
                }   

                if(s_strBuffer[i]=='W')
                {    
                    if (s_strBuffer[i+1]=='1')
                    {
                        WIND_SetWindvanePosition(true);
                    }
                    else if (s_strBuffer[i+1]=='0')
                    {
                        WIND_SetWindvanePosition(false);
                    }
                }       
            }
            s_strBuffer[0] = '\0';
            s_index = 0;  // Reset the buffer to be filled again 
        }
    }
}