bool SensorFileSysWalker::commandMove( int change ) {
	String item;
	switch( curFocusType ) {
		case FOCUS_DISK :
			item = getDiskUpDown( curDisk , change );
			if( item.equals( curDisk ) )
				return( false );
			curDisk = item;
			return( true );
		case FOCUS_DIR :
			if( curDir.equals( curDisk + ":" ) )
				return( false );
			item = getFileUpDown( curDir , change );
			if( item.equals( curDir ) )
				return( false );
			curDir = item;
			return( true );
		case FOCUS_FILE :
			item = getFileUpDown( curFile , change );
			if( item.equals( curFile ) )
				return( false );
			curFile = item;
			return( true );
	}
	return( false );
}
void SocketServer::configure( Xml config ) {
	SocketListener::getProtocol().create( config );

	auth = config.getBooleanProperty( "auth" );
	String direction = config.getProperty( "direction" );
	wayIn = direction.equals( "in" ) || direction.equals( "duplex" );
	wayOut = direction.equals( "out" ) || direction.equals( "duplex" );

	if( wayIn )
		topicIn = config.getProperty( "topic-in" );
	if( wayOut )
		topicOut = config.getProperty( "topic-out" );

	contentType = config.getProperty( "msgtype" , "text" );
	if( contentType.equals( "text" ) )
		SocketListener::setMsgType( Message::MsgType_Text );
	else
	if( contentType.equals( "xmlcall" ) )
		SocketListener::setMsgType( Message::MsgType_XmlCall );
	else
		SocketListener::setMsgType( Message::MsgType_Xml );

	port = atoi( config.getProperty( "port" ) );

	// make instance
	Object::setInstance( SocketListener::getName() );
	attachLogger();
}
void
XMLOperationGeneric::XMLGetCIMElement(CIMXMLParser& parser)
{
	if (!parser.tokenIsId(CIMXMLParser::E_CIM))
	{
		OW_THROW(CIMErrorException, CIMErrorException::request_not_loosely_valid);
	}
	String str = parser.mustGetAttribute(CIMXMLParser::A_CIMVERSION);
	if (!str.equals(CIMXMLParser::AV_CIMVERSION20_VALUE) &&
		!str.equals(CIMXMLParser::AV_CIMVERSION21_VALUE) &&
	!str.equals(CIMXMLParser::AV_CIMVERSION22_VALUE))
	{
		OW_THROW(CIMErrorException,
			CIMErrorException::unsupported_cim_version);
	}
	str = parser.mustGetAttribute(CIMXMLParser::A_DTDVERSION);
	if (!str.equals(CIMXMLParser::AV_DTDVERSION20_VALUE) &&
		!str.equals(CIMXMLParser::AV_DTDVERSION21_VALUE))
	{
		OW_THROW(CIMErrorException,
			CIMErrorException::unsupported_dtd_version);
	}
	parser.getChild();
	if (!parser)
	{
		OW_THROW(CIMErrorException, CIMErrorException::request_not_loosely_valid);
	}
	return;
}
Example #4
0
/**
 *  Callback for messages, arrived from MQTT broker
 */
void onMessageReceived(String topic, String message) {

	Serial.println("Message received: " + message);

	// Messages from mobile-app
	if (message.equals("AUTH_REQUEST")) {

		authStartRequest();
	}

	if (message.equals("AUTH_REJECT")) {


		}

	if (message.equals("AUTH_END")) {

		setConfigMode(false);
	}

	// Messages from server
	if (message.equals("START_AUTH")) {

		startAuth();
	}
}
Example #5
0
// Callback for messages, arrived from MQTT server
void onMessageReceived(String topic, String message)
{
	if (topic.endsWith("Firmware"))
	{
		if (message.equals("UPDATE"))
		{
			OtaUpdate();
		}
	}
	if (topic.endsWith("Lunch"))
	{
		if (topic.equals(mqtt_client + "/Lunch"))
		{
			// My own message

		} else {
			messageSentByMe = false;
		}
		if (message.equals("ON"))
		{
			indicationState = INDICATION_LUNCH;
		}
		else
		{
			indicationState = INDICATION_CONNECTED;
		}
	}
	Serial.print(topic);
	Serial.print(":\r\n\t"); // Pretify alignment for printing
	Serial.println(message);
	WifiAccessPoint.enable(false);
}
Example #6
0
	/**
	 * Test string's toLowerCase
	 */
	void testToLowerCase() {
		// Lower case -> lower case
		{
			const String lowerCaseSource("hello there");
			const String lowerCase_toLower = lowerCaseSource.toLowerCase();

			// Identity:
			CPPUNIT_ASSERT_EQUAL(lowerCaseSource, lowerCase_toLower);
		}

		// Mixed case -> lower case
		{
			const String mixedCaseSource("Hello Out There!");
			const String mixedCaseSource_toLower = mixedCaseSource.toLowerCase();

			CPPUNIT_ASSERT(mixedCaseSource != mixedCaseSource_toLower);
			CPPUNIT_ASSERT(mixedCaseSource_toLower.equals("hello out there!"));
		}

		// Upper case -> lower case
		{
			const String upperCaseSource("THERE@OUT*HELLO*&^%");
			const String upperCaseSource_toLower = upperCaseSource.toLowerCase();

			CPPUNIT_ASSERT(upperCaseSource != upperCaseSource_toLower);
			CPPUNIT_ASSERT(upperCaseSource_toLower.equals("there@out*hello*&^%"));
		}
	}
Example #7
0
 int UdpSocket::create(String interface, Address::ADDRESS_TYPE iptype, unsigned short port) {
     char buffer[sizeof(sockaddr_in6)];
     
     memset(buffer, 0, sizeof(sizeof(sockaddr_in6)));
     
     if (interface.equals("ANY", true) || getIpAddr(interface, iptype, buffer)) {
         int fd = socket((iptype==Address::IPV4 ? AF_INET : AF_INET6), SOCK_DGRAM, 0);
         
         if (iptype==Address::IPV4) {
             
             ((sockaddr_in*)buffer)->sin_family = AF_INET;
             ((sockaddr_in*)buffer)->sin_port = htons(port);
             
             if (interface.equals("ANY", true))
                 ((sockaddr_in*)buffer)->sin_addr.s_addr = INADDR_ANY;
             
         } else {
             ((sockaddr_in6*)buffer)->sin6_family = AF_INET6;
             ((sockaddr_in6*)buffer)->sin6_port = htons(port);
             
             if (interface.equals("ANY", true))
                 ((sockaddr_in6*)buffer)->sin6_addr = in6addr_any;
         }
         
         if (bind(fd, (struct sockaddr *)buffer, iptype==Address::IPV4 ? sizeof(sockaddr_in) : sizeof(sockaddr_in6)) == 0) {
             return fd;
         }
     }
     return 0;
 }
Example #8
0
void loop() {
    if(stringComplete) {
        // Serial.println(inputString);
        
        if(inputString.equals("{open_valve}")) {
            // Serial.println("inputString equates :)");
            open_valve();
        }
        
        if(inputString.equals("{close_valve}")) {
            // Serial.println("close vavle.");
            close_valve();
        }
        if(valve_open) {
            // Serial.println("valve_open = true");
            inputString = "";
            stringComplete = false;
            while(getFlow4()) {
            }
            // Serial.println("I'm here now :)");
        }
        // clear the string:
        inputString = "";
        stringComplete = false;
    }
    //Serial.println("over and over");
}
Example #9
0
	void BeamSword::onAnimationFinish(const String&name)
	{
		if(name.equals("swing_left") || name.equals("swing_right")
		|| name.equals("swing2_left") || name.equals("swing2_right"))
		{
			active = false;
			Player*playr = getPlayer();
			if(playr!=null)
			{
				switch(playr->getPlayerDir())
				{
					case Player::LEFT:
					changeAnimation("carry_left",FORWARD);
					break;
					
					case Player::RIGHT:
					changeAnimation("carry_right",FORWARD);
					break;
				}
			}
			else
			{
				changeAnimation("normal",FORWARD);
			}
		}
	}
Example #10
0
void Parameters::setValue(int paramIndex, String val){
	parameter_t  param;
	val.trim();
	if(val.indexOf("\"")>=0){
		//This is a string
		param.val_type = string_type;
		val.replace("\"", "");
		val.toCharArray(param.val.strVal, 50);
	}else if(val.equals("true")){
		//Bool type true
		param.val_type = bool_type;
		param.val.boolVal = true;
	}else if(val.equals("false")){
		//Bool type false
		param.val_type = bool_type;
		param.val.boolVal = false;
	}else{
		//Should be an integer
		param.val_type = int_type;
		char buf[val.length()+1];
		val.toCharArray(buf,val.length()+1);
		param.val.intVal = atoi(buf);
	}
	parameters[paramIndex] = param;
}
Example #11
0
String ProjectData::createBundlenameFromName(const String&name)
{
	String bundleName = "";
	for(int i=0; i<name.length(); i++)
	{
		char c = name.charAt(i);
		if(!((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='_'))
		{
			if(bundleName.length()!=0)
			{
				if(bundleName.charAt(bundleName.length()-1)!='_')
				{
					bundleName += '_';
				}
			}
			else
			{
				bundleName += '_';
			}
		}
		else
		{
			bundleName += c;
		}
	}
	if(bundleName.equals("") || bundleName.equals("_"))
	{
		bundleName = "ProductName";
	}
	
	return bundleName;
}
Example #12
0
/*
* Process the serial data to check for incoming commands.
* A Response code is returned depending on the command processed.
*/
int BLEModule::processSerial()
{
  while (Serial.available())
  {
    // get the new byte:
    char inChar = (char)Serial.read(); 
    // add it to the inputString:
    if(!setupMode)
    {
      //If the incoming character is a newline
      //Then the string is complete.
      //##The teminating char is not added to the string##
      if (inChar == '\n')
      {
        bleStringComplete = true;
      }
      else
      {
        bleInputString += inChar;
      }
    }
  }

  int status = 0; 
  if(bleStringComplete)
  {
    if(bleInputString.equals("+"))
    {
      status = 2;
    }
    else if(bleInputString.equals("-"))
    {
      status = 3;
    }
    else if(bleInputString.equals("*"))
    {
      status = 4;
    }
    else if(bleInputString.equals("$!;"))
    {
      status = 5;
    }
    else
    {
      //No conditions were met.
      //Send the incoming data back for debugging.
      sendSerial(bleInputString);
      status = 1;
    }

    bleInputString = "";
    bleStringComplete = false;
  }

  //return the status of the serial data.
  return status;
}
Example #13
0
boolean TinyGSM::isConnected(){
	print("AT+CREG?\r");
	delay(100);
	while(_serial->available()){
		String input = _serial->readStringUntil('\n');
		input.trim();
		if (input.equals("+CREG: 0,1") || input.equals("+CREG: 0,5")) return true;
	}
	return false;
}
Example #14
0
void CommandInterpreter::setMode( String const & arguments )
{
    if( arguments.equals( "generic" ) )
    {
        m_mode = LogoModeGeneric;
    }
    else if( arguments.equals( "clock" ) )
    {
        m_mode = LogoModeClock;
    }
}
void NetworkConnectionClass::getConfigData()
{
  String name = "";
  String value = "";
  boolean isValue = false;
  char character;
  SensorData *data;
  while (client.available() > 0) {
    character = client.read();
    if (character == '{') {
      data = new SensorData();
      name = "";
      value = "";
      isValue = false;
      continue;
    }
    if (character == ',' || character == '}') {
      if (name.equals("name")) {
        data->name = value;
      }
      else if (name.equals("code")) {
        data->code = value.toInt();
      }
      else if (name.equals("threshold")) {
        data->treshold = value.toInt();
      }
      else if (name.equals("pin")) {
        data->pin = getIntValue(value);
      }
      Serial.println(value);
      name = "";
      value = "";
      isValue = false;
      if (character == '}') {
        data->oldValue = 0;
        sensorData->insert(data);
      }
      continue;
    }
    if (character == ':') {
      isValue = true;
      continue;
    }
    if (!isValue) {
      name.concat(character);
    }
    else {
      value.concat(character);
    }
  }
}
uint8_t NetworkConnectionClass::getIntValue(String pin) {
  uint8_t pin_uint = 0;

  if (pin.equals("A0")) {
    pin_uint = A0;
  }
  else if (pin.equals("A1")) {
    pin_uint = A1;
  }
  else if (pin.equals("A2")) {
    pin_uint = A2;
  }
  else if (pin.equals("A3")) {
    pin_uint = A3;
  }
  else if (pin.equals("A4")) {
    pin_uint = A4;
  }
  else if (pin.equals("A5")) {
    pin_uint = A5;
  }
  else if (pin.equals("A6")) {
    pin_uint = A6;
  }
  else if (pin.equals("A7")) {
    pin_uint = A7;
  }
  else {
    pin_uint = pin.toInt();
  }
  return pin_uint;
}
Example #17
0
int parse() {
	sBuffer = String((char *) buf);
	int port;
	if (sBuffer.equals("0")) {
		port = PORT_0;
	} else if (sBuffer.equals("1")) {
		port = PORT_1;
	} else if (sBuffer.equals("2")) {
		port = PORT_2;
	} else if (sBuffer.equals("3")) {
		port = PORT_3;
	} else
		port = -1;
	return port;
}
Example #18
0
void CommandInterpreter::messageToHSVColor(const String &valueName, const String &message, ColorHSV &color)
{
    if( valueName.equals( "Hue" ) )
    {
        color.h = message.toInt();
    }
    else if( valueName.equals( "Saturation" ) )
    {
        color.s = message.toInt();
    }
    else if( valueName.equals( "Value" ) )
    {
        color.v = message.toInt();
    }
}
int NerveTool::execute( int nargs , char **args ) {
	// parameters
	String url;
	String fin;
	String fout;
	for( int k = 0; k < nargs; k++ ) {
		String arg = args[ k ];
		if( arg.equals( "-i" ) ) {
			fin = args[ ++k ];
			continue;
		}

		if( arg.equals( "-o" ) ) {
			fout = args[ ++k ];
			continue;
		}

		printf( "unknown option: %s\n" , args[ k ] );
		return( -1 );
	}

	FILE *sin = NULL;
	if( !fin.isEmpty() ) {
		sin = fopen( fin , "rt" );
		if( sin == NULL ) {
			printf( "cannot open input file (%s)\n" , ( const char * )fin );
			return( -2 );
		}
	}

	FILE *sout = NULL;
	if( !fout.isEmpty() ) {
		sout = fopen( fout , "at" );
		if( sout == NULL ) {
			printf( "cannot open output file (%s)\n" , ( const char * )fout );
			return( -2 );
		}
	}

	execute_file( sin , sout );

	if( sin != NULL )
		fclose( sin );
	if( sout != NULL )
		fclose( sout );

	return( 0 );
}
Example #20
0
bool WebServer::authenticate(const char * username, const char * password)
{
  if(_autorization.length()>0)
  {
    String authReq = _autorization;
    if(authReq.startsWith("Basic")){
      authReq = authReq.substring(6);
      authReq.trim();
      char toencodeLen = strlen(username)+strlen(password)+1;
      char *toencode = new char[toencodeLen + 1];
      if(toencode == NULL){
        return false;
      }
      char *encoded = new char[base64_encode_expected_len(toencodeLen)+1];
      if(encoded == NULL){
        delete[] toencode;
        return false;
      }
      sprintf(toencode, "%s:%s", username, password);
      if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equals(encoded)){
        delete[] toencode;
        delete[] encoded;
        return true;
      }
      delete[] toencode;
      delete[] encoded;
    }
  }
  return false;
}
bool ESP8266WebServer::authenticate(const char * username, const char * password){
  if(hasHeader(AUTHORIZATION_HEADER)){
    String authReq = header(AUTHORIZATION_HEADER);
    if(authReq.startsWith("Basic")){
      authReq = authReq.substring(6);
      authReq.trim();
      char toencodeLen = strlen(username)+strlen(password)+1;
      char *toencode = new char[toencodeLen];
      if(toencode == NULL){
        authReq = String();
        return false;
      }
      char *encoded = new char[base64_encode_expected_len(toencodeLen)+1];
      if(encoded == NULL){
        authReq = String();
        delete[] toencode;
        return false;
      }
      sprintf(toencode, "%s:%s", username, password);
      if(base64_encode_chars(toencode, toencodeLen, encoded) > 0 && authReq.equals(encoded)){
        authReq = String();
        delete[] toencode;
        delete[] encoded;
        return true;
      }
      delete[] toencode;
      delete[] encoded;
    }
    authReq = String();
  }
  return false;
}
Example #22
0
bool parseBool(const String &val, bool &valAsBool) {
	if (val.equalsIgnoreCase("true") ||
		val.equalsIgnoreCase("yes") ||
		val.equals("1")) {
		valAsBool = true;
		return true;
	}
	if (val.equalsIgnoreCase("false") ||
		val.equalsIgnoreCase("no") ||
		val.equals("0")) {
		valAsBool = false;
		return true;
	}

	return false;
}
Example #23
0
String Xbee::executeSequence() {
  
  String dataReceived = "";
  
  Serial.begin(9600);
  Serial3.begin(9600);
  Serial.flush();
  Serial3.flush();
  
  Serial3.println("SEQUENCE?\r");
  while (Serial3.available()) {
    char data = Serial3.read();
    dataReceived += data;
  }
  //check if there is any message (it must be finish with END_COMMAND)
  int index = dataReceived.indexOf(END_COMMAND);
  if (index != -1) {
    //get message, execute it and remove from receive bytes
    String message = dataReceived.substring(0, index);
    dataReceived = dataReceived.substring(index + 1);
    Serial.println("Msg. Received: " + message);  
    //get command and execute the concrete action
    String command = getCommand(message);
    Serial.println("Command: " + command);
    if (command.equals("SEQUENCE")) {
      String parameters = getParameters(message);
      Serial.println("Parameters: " + parameters);
      Serial.write(END_COMMAND);
      return parameters;
    }
  }
  
  Serial3.end();
}
Example #24
0
	void HeartContainer::onAnimationFinish(const String&n)
	{
		if(n.equals("sparkle"))
		{
			destroy();
		}
	}
void rcBaseDelegate::delegate(String cmd, int cmdval)
{

	if (cmd.equals("<") || cmd.equals(">") || cmd.equals("^")) {
    	//handlerumbling(cmd, cmdval);
	}

	if(cmd.equals("S")) {
	    if(cmdval == 0) {
	      //digitalWrite(13, LOW);
	    } else if (cmdval == 1) {
	      //digitalWrite(13, HIGH);
	    }
	}

}
Example #26
0
File: test.cpp Project: nandai/slog
void JsonTest::test02()
{
    SLOG(CLS_NAME, "test01");

    String str;
    Json* json1 = Json::getNewObject();

    Json* json2 = Json::getNewObject();
    json2->add("addr", "Tokyo");
    json2->add("tel", "03");
    json1->add(json2);

    Json* json3 = Json::getNewObject();
    json3->add("addr", "Osaka");
    json3->add("tel", "06");
    json1->add(json3);

    json1->serialize(&str);
    SMSG(slog::DEBUG, "%s", str.getBuffer());
    SASSERT("01", str.equals(
        "["
            "{\"addr\":\"Tokyo\",\"tel\":\"03\"},"
            "{\"addr\":\"Osaka\",\"tel\":\"06\"}"
        "]"));

    delete json1;
}
String Utility::findValue(String input, String key) {
  Serial.println("Got: " + input);

  String ret = "Key not found: " + key;
  int eqIndex = input.indexOf('=');
  while (eqIndex > -1) {
    String k = input.substring(0, eqIndex);
    Serial.println("Found key: " + k);
    String v;
    int ampIndex = input.indexOf('&');
    if (ampIndex > -1) {
      v = input.substring(eqIndex + 1, ampIndex);
      input = input.substring(ampIndex + 1);
    } else {
      v = input.substring(eqIndex + 1);
      input = v;
    }
    Serial.println("Found value: " + v);
    if (k.equals(key)) {
      ret = v;
      break;
    } else {
      eqIndex = input.indexOf('=');
    }
  }

  return ret;
}
Example #28
0
void readCredentials(Stream& port){
  port.setTimeout(10000);
  port.println("Enter SSID:");
  String ssid = port.readStringUntil('\r');
  ssid.trim();
  port.println("Enter AP security (0=Open, 1=WEP, 2=WPA, 3=WPA2):");
  String auth = port.readStringUntil('\r');
  auth.trim();
  port.println("Enter password:"******"SSID: [");
  port.print(ssid);
  port.print("] Auth: [");
  port.print(auth);
  port.print("] Password: [");
  port.print(pass);
  port.println("]");
  port.println("Type yes to confirm");
  String yes = port.readStringUntil('\r');
  port.setTimeout(1000);
  if(yes.equals("yes"))
    connection.setCredentials(ssid.c_str(), pass.c_str(), auth.c_str());
  else
    port.println("Cancelled");
}
Example #29
0
void WikiAreaPages::execute() {
	bool createAreaPages = wm -> checkCreateAreaPages();
	if( createAreaPages == false ) {
		logger.logInfo( "skip creating area pages" );
		return;
	}

	// get wiki file
	String wikiDir = wm -> getWikiPath();
	String selectedArea = wm -> getSelectedArea();

	MindService *ms = MindService::getService();

	// by area
	MapStringToClass<MindArea>& areaMap = ms -> getMindAreas();
	for( int k = 0; k < areaMap.count(); k++ ) {
		MindArea *area = areaMap.getClassByIndex( k );

		if( !selectedArea.isEmpty() ) {
			if( !selectedArea.equals( area -> getAreaId() ) )
				continue;
		}

		createAreaPages_createArea( wikiDir , area );
	}
}
Example #30
0
uint8_t StaticGame::loadGame(int timeout) {

  long startTime = millis();

  this->readExisting();
  _dataReceived = "";
  this->writeMessage("GET_GAMEID");
  do {
    delay(5);
    if (this->available()){
      String reply = this->readMessage();
#ifdef DEBUG
      Serial.println("Game reply: " + reply);
#endif
      String command = getCommand(reply);
      if (command.equals("GAMEID")) {
        String parameters = getParameters(reply);
        if (numberOfParameters(parameters) == 1){
          uint8_t temp = getParameter(parameters, 1).toInt();
          if (temp != NO_GAME) {
            this->_gameId = temp;
#ifdef DEBUG
            Serial.print("Game ID: ");
            Serial.println(_gameId, DEC);
#endif
            return this->_gameId;
          }
        }
      }
      break;
    }
  } 
  while ((millis() - startTime) < timeout);
  return NO_GAME;
}