Esempio n. 1
0
TEST_F(ConversionsTests, test_ascii_true) {
    std::string unencoded = "HELLO";
    auto result = isPrintable(unencoded);
    EXPECT_TRUE(result);
}
Esempio n. 2
0
static void scanJSONBody(char *source)
{
    uint8_t m, dimLevel = ItsMaxLevel_ - 1;
    char thisChar;
    
    // breaks the JSON body up into separate records
    // and keeps up with levels
    jsonRecordStartPtr = 0;
    level = 0;
    keysFound = false;
    for(m = 0; m < ItsMaxLevel_; m++) isArray[m] = false;

    jsonBodyBuf = source;
    jsonBodyLength = strlen(jsonBodyBuf);
    
    jsonBodyPtr = 0;
    
    // for debugging
    // printf(" \"(1)");
    
    do {
        thisChar = jsonBodyBuf[jsonBodyPtr++];
        
        // for debugging
        // printf("%c", thisChar);
        
        if(isPrintable(thisChar)) switch(thisChar) {
            
            // check for JSON "control characters"
            case '[':
                isArray[dimLevel] = true;
                arrayIndex[dimLevel] = 0;
                break;
            case '{':
                processParseRecord(1);
                level++;
                dimLevel = level - 1;
                break;
            case ',':
                processParseRecord(2);
                if(isArray[dimLevel]) {
                    
                    arrayIndex[dimLevel]++;
                    
                    // for debugging
                    // printf("incremented arrayIndex(%d) is now: %d\n", dimLevel, arrayIndex[dimLevel]);
                }
                break;
            case '}':
                processParseRecord(3);
                level--;
                if(level) dimLevel = level - 1;
                else level = ItsMaxLevel_ - 1;
                break;
            case ']':
                isArray[dimLevel] = false;
                break;
        }
    } while(!keysFound && level && thisChar);
    
    // for debugging
    // printf("\" ");
}
Esempio n. 3
0
TEST_F(ConversionsTests, test_ascii_false) {
  std::string unencoded = "こんにちは";
  auto result = isPrintable(unencoded);
  EXPECT_FALSE(result);
}
Esempio n. 4
0
void loop( void )
{
//  Serial.write( '\n' ) ;   // send a char
//  Serial.write( '\r' ) ;   // send a char
//  Serial5.write( '-' ) ;   // send a char

  // adding a constant integer to a string:
  stringThree =  stringOne + 123;
  Serial.println(stringThree);    // prints "stringThree = 123"

  // adding a constant long interger to a string:
  stringThree = stringOne + 123456789;
  Serial.println(stringThree);    // prints " You added 123456789"

  // adding a constant character to a string:
  stringThree =  stringOne + 'A';
  Serial.println(stringThree);    // prints "You added A"

  // adding a constant string to a string:
  stringThree =  stringOne +  "abc";
  Serial.println(stringThree);    // prints "You added abc"

  stringThree = stringOne + stringTwo;
  Serial.println(stringThree);    // prints "You added this string"

  // adding a variable integer to a string:
  int sensorValue = analogRead(A0);
  stringOne = "Sensor value: ";
  stringThree = stringOne  + sensorValue;
  Serial.println(stringThree);    // prints "Sensor Value: 401" or whatever value analogRead(A0) has

  // adding a variable long integer to a string:
  long currentTime = millis();
  stringOne = "millis() value: ";
  stringThree = stringOne + millis();
  Serial.println(stringThree);    // prints "The millis: 345345" or whatever value currentTime has

  // do nothing while true:
  while (true);



#if 0
  // get any incoming bytes:
  if (Serial.available() > 0) {
    int thisChar = Serial.read();

////////    int thisChar = 'a';
    // say what was sent:
    Serial.print("You sent me: \'");
    Serial.write(thisChar);
    Serial.print("\'  ASCII Value: ");
    Serial.println(thisChar);

    // analyze what was sent:
    if (isAlphaNumeric(thisChar)) {
      Serial.println("it's alphanumeric");
    }
    if (isAlpha(thisChar)) {
      Serial.println("it's alphabetic");
    }
    if (isAscii(thisChar)) {
      Serial.println("it's ASCII");
    }
    if (isWhitespace(thisChar)) {
      Serial.println("it's whitespace");
    }
    if (isControl(thisChar)) {
      Serial.println("it's a control character");
    }
    if (isDigit(thisChar)) {
      Serial.println("it's a numeric digit");
    }
    if (isGraph(thisChar)) {
      Serial.println("it's a printable character that's not whitespace");
    }
    if (isLowerCase(thisChar)) {
      Serial.println("it's lower case");
    }
    if (isPrintable(thisChar)) {
      Serial.println("it's printable");
    }
    if (isPunct(thisChar)) {
      Serial.println("it's punctuation");
    }
    if (isSpace(thisChar)) {
      Serial.println("it's a space character");
    }
    if (isUpperCase(thisChar)) {
      Serial.println("it's upper case");
    }
    if (isHexadecimalDigit(thisChar)) {
      Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)");
    }

    // add some space and ask for another byte:
    Serial.println();
    Serial.println("Give me another byte:");
    Serial.println();
  }
#endif

#if 0
  sensorValue = analogRead(A0);

  // apply the calibration to the sensor reading
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
  Serial.print("sensor = " );
  Serial.print(sensorValue);

  // in case the sensor value is outside the range seen during calibration
  outputValue = constrain(sensorValue, 0, 255);


  // print the results to the serial monitor:
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // fade the LED using the calibrated value:
  analogWrite(9/*ledPin*/, sensorValue);
  
  delay(1);
#endif
#if 0
  // read the analog in value:
  sensorValue = analogRead(A0);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(9/*analogOutPin*/, outputValue);

  // print the results to the serial monitor:
  Serial.print("sensor = " );
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
 delay(2);
//  delay(1000);
#endif

#if 0
  digitalWrite( 0, HIGH ) ;  // set the red LED on
  digitalWrite( 0, LOW ) ;  // set the red LED on

  digitalWrite( 1, HIGH ) ;  // set the red LED on
  digitalWrite( 1, LOW ) ;  // set the red LED on

  digitalWrite( 4, HIGH ) ;  // set the red LED on
  digitalWrite( 4, LOW ) ;  // set the red LED on

  digitalWrite( 5, HIGH ) ;  // set the red LED on
  digitalWrite( 5, LOW ) ;  // set the red LED on

  digitalWrite( 6, HIGH ) ;  // set the red LED on
  digitalWrite( 6, LOW ) ;  // set the red LED on

  digitalWrite( 7, HIGH ) ;  // set the red LED on
  digitalWrite( 7, LOW ) ;  // set the red LED on

  digitalWrite( 8, HIGH ) ;  // set the red LED on
  digitalWrite( 8, LOW ) ;  // set the red LED on

  digitalWrite( 9, HIGH ) ;  // set the red LED on
  digitalWrite( 9, LOW ) ;  // set the red LED on

  digitalWrite( 10, HIGH ) ;  // set the red LED on
  digitalWrite( 10, LOW ) ;  // set the red LED on

  digitalWrite( 11, HIGH ) ;  // set the red LED on
  digitalWrite( 11, LOW ) ;  // set the red LED on

  digitalWrite( 12, HIGH ) ;  // set the red LED on
  digitalWrite( 12, LOW ) ;  // set the red LED on

  digitalWrite( 13, HIGH ) ;  // set the red LED on
  digitalWrite( 13, LOW ) ;  // set the red LED on
#endif

#if 0
//    int a = 123;
//    Serial.print(a, DEC);

//  for ( uint32_t i = A0 ; i <= A0+NUM_ANALOG_INPUTS ; i++ )
  for ( uint32_t i = 0 ; i <= NUM_ANALOG_INPUTS ; i++ )
  {

    int a = analogRead(i);
//    int a = 123;
    Serial.print(a, DEC);
    Serial.print(" ");
//   Serial.write( ' ' ) ;   // send a char
//   Serial.write( 0x30 + i ) ;   // send a char

//   Serial.write( 0x30 + ((a/1000)%10) ) ;   // send a char
//   Serial.write( 0x30 + ((a/100)%10) ) ;   // send a char
//   Serial.write( 0x30 + ((a/10)%10) ) ;   // send a char
//   Serial.write( 0x30 + (a%10) ) ;   // send a char
//   Serial.write( ' ' ) ;   // send a char
  }
  Serial.println();
#endif

#if 0
  volatile int pin_value=0 ;
  static volatile uint8_t duty_cycle=0 ;
  static volatile uint16_t dac_value=0 ;

  // Test digitalWrite
  led_step1() ;
  delay( 500 ) ;              // wait for a second
  led_step2() ;
  delay( 500 ) ;              // wait for a second

  // Test Serial output
  Serial5.write( '-' ) ;   // send a char
  Serial5.write( "test1\n" ) ;   // send a string
  Serial5.write( "test2" ) ;   // send another string

  // Test digitalRead: connect pin 2 to either GND or 3.3V. !!!! NOT on 5V pin !!!!
  pin_value=digitalRead( 2 ) ;
  Serial5.write( "pin 2 value is " ) ;
  Serial5.write( (pin_value == LOW)?"LOW\n":"HIGH\n" ) ;

  duty_cycle+=8 ;//=(uint8_t)(millis() & 0xff) ;
  analogWrite( 13, duty_cycle ) ;
  analogWrite( 12, duty_cycle ) ;
  analogWrite( 11, duty_cycle ) ;
  analogWrite( 10 ,duty_cycle ) ;
  analogWrite(  9, duty_cycle ) ;
  analogWrite(  8, duty_cycle ) ;

  dac_value += 64;
  analogWrite(A0, dac_value);



  Serial5.print("\r\nAnalog pins: ");

  for ( uint32_t i = A0 ; i <= A0+NUM_ANALOG_INPUTS ; i++ )
  {

    int a = analogRead(i);
    Serial5.print(a, DEC);
    Serial5.print(" ");

  }
  Serial5.println();

  Serial5.println("External interrupt pins:");
  if ( ul_Interrupt_Pin3 == 1 )
  {
    Serial5.println( "Pin 3 triggered (LOW)" ) ;
    ul_Interrupt_Pin3 = 0 ;
  }

  if ( ul_Interrupt_Pin4 == 1 )
  {
    Serial5.println( "Pin 4 triggered (HIGH)" ) ;
    ul_Interrupt_Pin4 = 0 ;
  }

  if ( ul_Interrupt_Pin5 == 1 )
  {
    Serial5.println( "Pin 5 triggered (FALLING)" ) ;
    ul_Interrupt_Pin5 = 0 ;
  }

  if ( ul_Interrupt_Pin6 == 1 )
  {
    Serial5.println( "Pin 6 triggered (RISING)" ) ;
    ul_Interrupt_Pin6 = 0 ;
  }

  if ( ul_Interrupt_Pin7 == 1 )
  {
    Serial5.println( "Pin 7 triggered (CHANGE)" ) ;
    ul_Interrupt_Pin7 = 0 ;
  }
#endif
}
Esempio n. 5
0
  HexState operator() (const char*& Ptr, llvm::raw_ostream& Stream,
                       bool ForceHex) {
    // Block allocate the next chunk
    if (!(m_Buf.size() % kBufSize))
      m_Buf.reserve(m_Buf.size() + kBufSize);

    HexState State = kText;
    const char* const Start = Ptr;
    char32_t Char;
    if (m_Utf8) {
      Char = utf8::next(Ptr);
      if (Ptr > m_End) {
        // Invalid/bad encoding: dump the remaining as hex
        Ptr = Start;
        while (Ptr < m_End)
          Stream << "\\x" << llvm::format_hex_no_prefix(uint8_t(*Ptr++), 2);
        m_HexRun = true;
        return kHex;
      }
    } else
      Char = (*Ptr++ & 0xff);

    // Assume more often than not -regular- strings are printed
    if (LLVM_UNLIKELY(!isPrintable(Char, m_Loc))) {
      m_HexRun = false;
      if (LLVM_UNLIKELY(ForceHex || !std::isspace(wchar_t(Char), m_Loc))) {
        if (Char > 0xffff)
          Stream << "\\U" << llvm::format_hex_no_prefix(uint32_t(Char), 8);
        else if (Char > 0xff)
          Stream << "\\u" << llvm::format_hex_no_prefix(uint16_t(Char), 4);
        else if (Char) {
          Stream << "\\x" << llvm::format_hex_no_prefix(uint8_t(Char), 2);
          m_HexRun = true;
          return kHex;
        } else
          Stream << "\\0";
        return kText;
      }

      switch (Char) {
        case '\b': Stream << "\\b"; return kEsc;
        // \r isn't so great on Unix, what about Windows?
        case '\r': Stream << "\\r"; return kEsc;
        default: break;
      }
      State = kEsc;
    }

    if (m_HexRun) {
      // If the last print was a hex code, and this is now a char that could
      // be interpreted as a continuation of that hex-sequence, close out
      // the string and use concatenation. {'\xea', 'B'} -> "\xea" "B"
      m_HexRun = false;
      if (std::isxdigit(wchar_t(Char), m_Loc))
        Stream << "\" \"";
    }
    if (m_Utf8)
      Stream << llvm::StringRef(Start, Ptr-Start);
    else
      Stream << char(Char);
    return State;
  }