Пример #1
0
bool ejson::internal::Document::parse(const std::string& _data) {
	EJSON_VERBOSE("Start parsing document (type: string) size=" << _data.size());
	clear();
	ejson::FilePos filePos(1,0);
	size_t parsePos = 0;
	return iParse(_data, parsePos, filePos, *this);
}
Пример #2
0
///Must be called in your loop
///Process client requests in background
void TelnetServer::maintain()
{
	Ethernet.maintain();
	char buffer[FULLIP_TELNET_LINE_SIZE];

	delay(100);
	//Serial.println(iServer->available());
	
	if ((client = iServer->available()) && iTelnetState==0) {
#ifdef FULLIP_DEBUG_TELNET
		Serial.println("Telnet client connection");
#endif
		iTelnetState = 1;
		strcpy_P(buffer,PSTR(""));
		iParse(buffer);
		iTelnetTimeout = millis() + FULLIP_TELNET_TIMEOUT;
	}
	
	if (iTelnetState==1) {
		if (client.connected() && client.available()) {
			iTelnetTimeout = millis() + FULLIP_TELNET_TIMEOUT;
			char c = '\0';
			int charsReceived=0;
			while (client.available()>0 && charsReceived<FULLIP_TELNET_LINE_SIZE && c!=0x0d) {
				c = client.read();
				buffer[charsReceived] = c;
				charsReceived++;
			}

#ifdef FULLIP_DEBUG_TELNET
			Serial.print("buffer=<");
			Serial.print(buffer);
			Serial.println(">");
			Serial.print("charsReceived=<");
			Serial.print(charsReceived);
			Serial.println(">");
#endif

			//if CR found go look at received text and execute command
			if(c == 0x0d) {
				buffer[charsReceived-1]='\0';
	#ifdef FULLIP_DEBUG_TELNET
				Serial.print("buffer=<");
				Serial.print(buffer);
				Serial.println(">");
	#endif
				if (strlen(buffer)!=0) {
					iParse(buffer);
				}
				// after completing command, print a new prompt
				printPrompt();
			}

			// if textBuff full without reaching a CR, print an error message
			if(charsReceived >= FULLIP_TELNET_LINE_SIZE-1) {
				while (client.available()>0) {
					c = client.read();
				}
				client.println();
				strcpy_P(buffer,PSTR("Line too long"));
				client.println(buffer);
				printPrompt();
			}
			// if textBuff not full and no CR, do nothing else;  
			// go back to loop until more characters are received			  

		} else if ((long signed)(millis() - iTelnetTimeout) > 0) {
#ifdef FULLIP_DEBUG_TELNET
			Serial.println("Telnet timeout");
#endif
			disconnect();
		}
	} else if (iTelnetState==2 && (long signed)(millis() - iTelnetClose) > 0) {
		uint8_t c;
		while((client.available()) > 0)
			c=client.read();
		client.stop();
#ifdef FULLIP_DEBUG_TELNET
			Serial.println("Telnet client connection closed");
#endif
		iTelnetState = 0;
	}
}