Esempio n. 1
0
bool baseStructureParser<streamT>::readProperty(std::string& name, std::string& val, char& termChar) {
    string readTxt; // Generic string to hold read data

    // Skip until the next non-whitespace character
    if(!readUntil(false, " \t\r\n", 4, termChar, readTxt)) return false;
    if(!nextChar()) return false;
//cout << "    rp1: readTxt=\""<<readTxt<<"\" termChar=\""<<termChar<<"\""<<" buf[bufIdx]=\""<<buf[bufIdx]<<"\""<<endl;

    // Read until the next '='
    if(!readUntil(true, "=", 1, termChar, name)) return false;
    if(!nextChar()) return false;

//cout << "    rp2: name=\""<<name<<"\", termChar=\""<<termChar<<"\""<<endl;
    // Read until the next non-'='
    if(!readUntil(false, "=", 1, termChar, readTxt)) return false;

    //if(readTxt.length()!=1) { cerr << "ERROR: multiple = chars in property "<<name<<"! read \""<<readTxt<<"\" termChar=\""<<termChar<<"\""<<endl; return false; }
//cout << "    rp3: readTxt=\""<<readTxt<<"\", termChar=\""<<termChar<<"\" buf[bufIdx]=\""<<buf[bufIdx]<<"\""<<endl;

    // Read the " that immediately follows
    if(!readUntil(true, "\"", 1, termChar, readTxt)) return false;
    if(!nextChar()) return false;
//cout << "    rp4: readTxt=\""<<readTxt<<"\", termChar=\""<<termChar<<"\" buf[bufIdx]=\""<<buf[bufIdx]<<"\""<<endl;

    if(termChar!='\"' && readTxt.length()!=0) {
        cerr << "ERROR: erroneous chars between = and \" in tag property "<<name<<"! read \""<<readTxt<<"\" termChar=\""<<termChar<<"\""<<endl;
        return false;
    }

    // Read until the following "
    if(!readUntil(true, "\"", 1, termChar, val)) return false;
//cout << "    rp5: val=\""<<val<<"\", termChar=\""<<termChar<<"\" buf[bufIdx]=\""<<buf[bufIdx]<<"\""<<endl;

    return true;
}
Esempio n. 2
0
/** @see BencSerializer.h */
static int32_t parseDictionary(const struct Reader* reader,
                               const struct Allocator* allocator,
                               Dict* output)
{
    uint8_t nextChar;
    readUntil('{', reader);

    String* key;
    Object* value;
    struct Dict_Entry* entryPointer;
    struct Dict_Entry* lastEntryPointer = NULL;
    int ret = 0;

    for (;;) {
        while (!ret) {
            ret = reader->read(&nextChar, 0, reader);
            switch (nextChar) {
                case '"':
                    break;

                case '}':
                    reader->skip(1, reader);
                    *output = lastEntryPointer;
                    return 0;

                case '/':
                    parseComment(reader);
                    continue;

                default:
                    reader->skip(1, reader);
                    continue;
            }
            break;
        }
        if (ret) {
            printf("Unterminated dictionary\n");
            return OUT_OF_CONTENT_TO_READ;
        }

        // Get key and value.
        if ((ret = parseString(reader, allocator, &key)) != 0) {
            return ret;
        }

        readUntil(':', reader);

        if ((ret = parseGeneric(reader, allocator, &value)) != 0) {
            return ret;
        }

        /* Allocate the entry. */
        entryPointer = allocator->malloc(sizeof(struct Dict_Entry), allocator);

        entryPointer->next = lastEntryPointer;
        entryPointer->key = key;
        entryPointer->val = value;
        lastEntryPointer = entryPointer;
    }
}
Esempio n. 3
0
bool parseRange(TNum & beginPos, TNum & endPos, seqan::CharString const & rangeStr)
{
    seqan::DirectionIterator<seqan::CharString const, seqan::Input>::Type reader = directionIterator(rangeStr, seqan::Input());

    // Parse out begin position.
    seqan::CharString buffer;
    readUntil(buffer, reader, seqan::EqualsChar<'-'>(), seqan::EqualsChar<','>());
    if (!lexicalCast(beginPos, buffer))
        return false;

    if (atEnd(reader))
        return false;

    skipOne(reader);    // Skip '-'.

    // Parse out end position.
    clear(buffer);
    readUntil(buffer, reader, seqan::False(), seqan::EqualsChar<','>());

    if (empty(buffer))
    {
        endPos = seqan::maxValue<TNum>();
        return true;
    }

    if (!lexicalCast(endPos, buffer))
        return false;

    return (beginPos <= endPos);
}
Esempio n. 4
0
// reads the database specified by path and searches for username
// if found, returns nonzero and passwd
int lookupUser(char *path, char *username, char *passwd, size_t max)
{
    char user[64], pswd[max];
    user[0] = pswd[0] = 0;
    int fd, res = 1;
    if ((fd = open(path, O_RDONLY)) == -1)
        return (-1);
    // reads username and password
    while ((readUntil(user, fd, ':', 64)) != -1) {
        if (readUntil(pswd, fd, '\n', 64) == -1) {
            res = 1;
            break;
        }
        // match
        if (strcmp(username, user) == 0) {
            res = 0;
            break;
        }
    }
    // nothing found
    if (pswd[0] == 0) {
        return (1);
    }
    // bad parameter provided
    if (passwd == NULL)
        return (res);
    strcpy(passwd, pswd);
    return (res);
}
Esempio n. 5
0
bool EspDrv::sendDataUdp(uint8_t sock, const char* host, uint16_t port, const uint8_t *data, uint16_t len)
{
	LOGDEBUG2(F("> sendDataUdp:"), sock, len);
	LOGDEBUG2(F("> sendDataUdp:"), host, port);

	char cmdBuf[40];
	sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%u,\"%s\",%u"), sock, len, host, port);
	//LOGDEBUG1(F("> sendDataUdp:"), cmdBuf);
	espSerial->println(cmdBuf);

	int idx = readUntil(1000, (char *)">", false);
	if(idx!=NUMESPTAGS)
	{
		LOGERROR(F("Data packet send error (1)"));
		return false;
	}

	espSerial->write(data, len);

	idx = readUntil(2000);
	if(idx!=TAG_SENDOK)
	{
		LOGERROR(F("Data packet send error (2)"));
		return false;
	}

    return true;
}
Esempio n. 6
0
bool EspDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len, bool appendCrLf)
{
	LOGDEBUG2(F("> sendData:"), sock, len);

	char cmdBuf[20];
	sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%d"), sock, len);
	espSerial->println(cmdBuf);

	int idx = readUntil(1000, (char *)">", false);
	if(idx!=NUMESPTAGS)
	{
		LOGERROR(F("Data packet send error (1)"));
		return false;
	}

	espSerial->write(data, len);

	idx = readUntil(2000);
	if(idx!=TAG_SENDOK)
	{
		LOGERROR(F("Data packet send error (2)"));
		return false;
	}

    return true;
}
Esempio n. 7
0
/**
 * Parse a comment in with "slash splat" or double slash notation,
 * leave the reader on the first character after the last end of comment mark.
 */
static inline int parseComment(const struct Reader* reader)
{
    char chars[2];
    int ret = reader->read(&chars, 2, reader);
    if (ret) {
        printf("Warning: expected comment\n");
        return OUT_OF_CONTENT_TO_READ;
    }
    if (chars[0] != '/') {
        printf("Warning: expected a comment starting with '/', instead found '%c'\n",chars[0]);
        return UNPARSABLE;
    }
    switch (chars[1]) {
        case '*':;
            do {
                readUntil('*', reader);
            } while (!(ret = reader->read(&chars, 1, reader)) && chars[0] != '/');
            if (ret) {
                printf("Unterminated multiline comment\n");
                return OUT_OF_CONTENT_TO_READ;
            }
            return 0;
        case '/':;
            return readUntil('\n', reader);
        default:
            printf("Warning: expected a comment starting with \"//\" or \"/*\", "
                   "instead found \"/%c\"\n",chars[1]);
            return UNPARSABLE;
    }
}
Esempio n. 8
0
/*
* Sends the AT command and stops if any of the TAGS is found.
* Extract the string enclosed in the passed tags and returns it in the outStr buffer.
* Returns true if the string is extracted, false if tags are not found of timed out.
*/
bool EspDrv::sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, const char* endTag, char* outStr, int outStrLen)
{
    int idx;
	bool ret = false;

	outStr[0] = 0;

	espEmptyBuf();

	LOGDEBUG(F("----------------------------------------------"));
	LOGDEBUG1(F(">>"), cmd);

	// send AT command to ESP
	espSerial->println(cmd);

	// read result until the startTag is found
	idx = readUntil(1000, startTag);

	if(idx==NUMESPTAGS)
	{
		// clean the buffer to get a clean string
		ringBuf.init();

		// start tag found, search the endTag
		idx = readUntil(500, endTag);

		if(idx==NUMESPTAGS)
		{
			// end tag found
			// copy result to output buffer avoiding overflow
			ringBuf.getStrN(outStr, strlen(endTag), outStrLen-1);

			// read the remaining part of the response
			readUntil(2000);

			ret = true;
		}
		else
		{
			LOGWARN(F("End tag not found"));
		}
	}
	else if(idx>=0 and idx<NUMESPTAGS)
	{
		// the command has returned but no start tag is found
		LOGDEBUG1(F("No start tag found:"), idx);
	}
	else
	{
		// the command has returned but no tag is found
		LOGWARN(F("No tag found"));
	}

	LOGDEBUG1(F("---------------------------------------------- >"), outStr);
	LOGDEBUG();

	return ret;
}
Esempio n. 9
0
uint8_t EspDrv::getScanNetworks()
{
    uint8_t ssidListNum = 0;
    int idx;
	bool ret = false;
	

	espEmptyBuf();

	LOGDEBUG(F("----------------------------------------------"));
	LOGDEBUG(F(">> AT+CWLAP"));
	
	espSerial->println(F("AT+CWLAP"));

	char buf[100];
	
	idx = readUntil(10000, "+CWLAP:(");
	
	while (idx == NUMESPTAGS)
	{
		_networkEncr[ssidListNum] = espSerial->parseInt();
		//LOGDEBUG1("enc:", _networkEncr[ssidListNum]);
		
		// discard , and " characters
		readUntil(1000, "\"");

		idx = readUntil(1000, "\"", false);
		if(idx==NUMESPTAGS)
		{
			ringBuf.getStr(_networkSsid[ssidListNum], 1);  // 1 = strlen ("\"")
		}
		//LOGDEBUG1("ssid:", _networkSsid[ssidListNum]);
		
		// discard , character
		readUntil(1000, ",");
		
		_networkRssi[ssidListNum] = espSerial->parseInt();
		//LOGDEBUG1("rssi:", _networkRssi[ssidListNum]);
		
		idx = readUntil(1000, "+CWLAP:(");

		if(ssidListNum==WL_NETWORKS_LIST_MAXNUM-1)
			break;

		ssidListNum++;
	}
	
	if (idx==-1)
		return -1;

	LOGDEBUG1(F("---------------------------------------------- >"), ssidListNum);
	LOGDEBUG();
    return ssidListNum;
}
bool
NIVissimSingleTypeParser_Langsamfahrbereichdefinition::parse(std::istream& from) {
    std::string id;
    from >> id;
    readUntil(from, "fahrzeugklasse");
    std::string tag = "fahrzeugklasse";
    while (tag == "fahrzeugklasse") {
        readUntil(from, "maxverzoegerung");
        tag = myRead(from);
        tag = myRead(from);
    }
    return true;
}
Esempio n. 11
0
void Compass::readCompass(){
  // The serial data buffer can get filled up with previous readings,
  // but when we go to read the compass we really want the most recent
  // reading, so flush the buffer and then start reading  This may add 
  // some lag inresonse while we wait for the new reading to come in.
  tcflush(fd,TCIOFLUSH);
  
  //read to start of compass sentence
  readUntil('$',0);
  // read to the end of the compass sentence, and then two more chars
  readUntil('*',2);
  // parse our read buffer
  sscanf(buf,"C%fP%fR%fT%fD%f*", &heading, &pitch, &roll, &temperature, &depth); 
 //"C%.1fP%.1fR%.1fT%.1f*
}
bool
NIVissimSingleTypeParser_Parkplatzdefinition::parse(std::istream& from) {
    int id;
    from >> id;

    std::string tag;
    from >> tag;
    std::string name = readName(from);

    // parse the districts
    //  and allocate them if not done before
    //  A district may be already saved when another parking place with
    //  the same district was already build.
    std::vector<int> districts;
    std::vector<double> percentages;
    readUntil(from, "bezirke"); // "Bezirke"
    while (tag != "ort") {
        double perc = -1;
        int districtid;
        from >> districtid;
        tag = myRead(from);
        if (tag == "anteil") {
            from >> perc;
        }
        districts.push_back(districtid);
        percentages.push_back(perc);
        tag = myRead(from);
    }
Esempio n. 13
0
GPSReading UBloxNEO7::readGPS() {
  // Read all available bytes until the newline character. NMEA dictates that
  // messages should end with a CRLF, but we'll only look for the LF.
  std::size_t len = readUntil(NMEA_LF);

  //static int loop = 0;
  //if (loop % 100 == 0) {
  //  chprintf((BaseSequentialStream*)sd, "$PUBX,00*33\r\n");
  //}
  //loop = (loop+1) % 100;

  // Check if a full line is ready to be processed
  if(len > 0) {
    char *start = reinterpret_cast<char *>(rxbuf.data());
    //chprintf((BaseSequentialStream*)&SD4, "%s", rxbuf.data());

    // Skip over the leading "$"
    start += 1;

    char *token = std::strtok(start, NMEA_DELIMS);

    // Only care about GPGLL messages
    if(std::strcmp("GPGLL", token) == 0) {
      GPGLLMessage message;
      int position = 0;

      while((token = std::strtok(nullptr, NMEA_DELIMS)) != nullptr) {
        switch(position++) {
          case 0:
            message.lat = atof(token);
            break;
          case 1:
            message.latDir = token[0];
            break;
          case 2:
            message.lon = atof(token);
            break;
          case 3:
            message.lonDir = token[0];
            break;
          case 4:
            message.utc = atof(token);
            break;
          case 5:
            message.valid = token[0];
            break;
        };
      }

      return GPSReading {
        // Make sure we got all parts of the message. If fields are omitted in
        // the message then `strtok` will skip over repeated delimiters and the
        // above loop will complete before all delimiters were found.
        .valid = message.valid && position == 7,
        .lat = dmd2float(message.lat, message.latDir),
        .lon = dmd2float(message.lon, message.lonDir),
        .utc = message.utc
      };
    }
  }
bool
NIVissimSingleTypeParser_Streckentypdefinition::parse(std::istream& from) {
    readUntil(from, "default");
    std::string tag;
    from >> tag;
    return true;
}
Esempio n. 15
0
int main(void) {
	char cmd[MAX_CMD];
	ShellCmds *c;

	bzero(CWD, MAX_CMD);
	strcpy(CWD, "/");

	if (InitFS(512*1024)) {
		puts("Failed to initialize the RAM file system\n");
		return(-1);
	}

	puts("Welcome to the cgcfs shell!");
	puts("Type help for a list of available commands.");
	printf("% ");
	bzero(cmd, MAX_CMD);
	while (readUntil(cmd, MAX_CMD-1, '\n') != -1) {
		ParseArgs(cmd);

		// parse failure
		if (ARGC == 0) {
			FreeArgs();
			bzero(cmd, MAX_CMD);
			printf("% ");
			continue;
		}

		// find the command being requested
		if (ARGV[0] != NULL) {
			c = cmds;
			while (c->command != NULL) {
				if (!strcmp(c->command, ARGV[0])) {
					// run the command
					c->handler();

					break;
				}
				c++;
			}
		}
		if (c == NULL) {
			puts("Invalid command");
		}
		if (c->command == NULL) {
			puts("Invalid command");
		}

		FreeArgs();
		bzero(cmd, MAX_CMD);
		printf("% ");
	}

	if (DestroyFS()) {
		puts("Failed to destroy the RAM file system\n");
		return(-1); 
	}

	return(0);

}
Esempio n. 16
0
static inline int parseString(const struct Reader* reader,
                              const struct Allocator* allocator,
                              String** output)
{
    #define BUFF_SZ (1<<8)
    #define BUFF_MAX (1<<20)

    int curSize = BUFF_SZ;
    struct Allocator* localAllocator = Allocator_child(allocator);
    uint8_t* buffer = localAllocator->malloc(curSize, localAllocator);
    if (readUntil('"', reader) || reader->read(buffer, 1, reader)) {
        printf("Unterminated string\n");
        localAllocator->free(localAllocator);
        return OUT_OF_CONTENT_TO_READ;
    }
    for (int i = 0; i < BUFF_MAX - 1; i++) {
        if (buffer[i] == '\\') {
            // \x01 (skip the x)
            reader->skip(1, reader);
            uint8_t hex[2];
            if (reader->read((char*)hex, 2, reader)) {
                printf("Unexpected end of input parsing escape sequence\n");
                localAllocator->free(localAllocator);
                return OUT_OF_CONTENT_TO_READ;
            }
            int byte = Hex_decodeByte(hex[0], hex[1]);
            if (byte == -1) {
                printf("Invalid escape \"%c%c\" after \"%.*s\"\n",hex[0],hex[1],i+1,buffer);
                localAllocator->free(localAllocator);
                return UNPARSABLE;
            }
            buffer[i] = (uint8_t) byte;
        } else if (buffer[i] == '"') {
            *output = String_newBinary((char*)buffer, i, allocator);
            localAllocator->free(localAllocator);
            return 0;
        }
        if (i == curSize - 1) {
            curSize <<= 1;
            buffer = localAllocator->realloc(buffer, curSize, localAllocator);
        }
        if (reader->read(buffer + i + 1, 1, reader)) {
            if (i+1 <= 20) {
                printf("Unterminated string \"%.*s\"\n", i+1, buffer);
            } else {
                printf("Unterminated string starting with \"%.*s...\"\n", 20, buffer);
            }
            localAllocator->free(localAllocator);
            return OUT_OF_CONTENT_TO_READ;
        }
    }

    printf("Maximum string length of %d bytes exceeded.\n",BUFF_SZ);
    localAllocator->free(localAllocator);
    return UNPARSABLE;

    #undef BUFF_SZ
    #undef BUFF_MAX
}
Esempio n. 17
0
 VRISKA_ACCESSIBLE
 int 			BlockingClient::readLine(std::string& buffer)
 {
   if (!_isBlocking)
     return (SimpleClient::readLine(buffer));
   else
     return (readUntil(buffer, "\n"));
 }
Esempio n. 18
0
 VRISKA_ACCESSIBLE
 int 			BlockingClient::readUntil(std::string& buffer, std::string const & delim)
 {
   if (!_isBlocking)
     return (SimpleClient::readUntil(buffer, delim));
   else
     return (readUntil(buffer, delim));
 }
Esempio n. 19
0
// retrieves the data from the server - control path
void d_retr(char **params, short *abor, int fd,
	struct state *cstate, struct config *configuration) {
	int accepted, retcode, file, r, subn = 0;
	char filepath[PATH_LENGTH], buf[2 * BUFSIZE];
	// accepts / connects to the client
	if (spawnConnection(cstate, &accepted)) {
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		return;
	}
	// loads filepath of the given file
	readUntil(filepath, fd, 0, PATH_LENGTH);
	// check the file status
	if (isFileOk(filepath) == -1) {
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		close(accepted);
		return;
	}
	// opens the file
	if ((file = open(filepath, O_RDONLY)) == -1) {
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		close(accepted);
		return;
	}
	// read blocks of data from the file
	// and sends it through the data connection
	while ((r = read(file, buf, BUFSIZE)) > 0) {
		// ASCII type transfer
		if (cstate->transfer_type == ASCII) {
			char tmp[2 * BUFSIZE];
			// converts \n to \r\n sequence,
			// return how much is the result longer
			if ((subn = im2as(tmp, buf, BUFSIZE)) == -1) {
				retcode = 5;
				write(fd, &retcode, sizeof (int));
				close(accepted);
				break;
			}
			r += subn;
			memcpy(buf, tmp, BUFSIZE * 2);
		}
		if (write(accepted, buf, r) == -1) {
			retcode = 5;
			write(fd, &retcode, sizeof (int));
			close(accepted);
			break;
		}
	}
	// closes the connection
	close(file);
	close(accepted);
	// reads and reports the result
	retcode = 2;
	write(fd, &retcode, sizeof (int));

}
Esempio n. 20
0
bool		readCChar(void)
{
  int		nTmp;

  readWs();
  nTmp = getPos();
  if (readChar('\'') && readUntil('\'', '\\'))
    return (true);
  return (false);
}
Esempio n. 21
0
void readTweet(Tweet* t)
{
    t->flags = ACTIVE;
    printf("Novo Tweet:\n");
    printf("VIEWS: ");
    scanf(" %u", &(t->views));
    printf("RETWEETS: ");
    scanf(" %u", &(t->retweets));
    printf("FAVORITES: ");
    scanf(" %u", &(t->favs));
    printf("USER: "******"LANG: ");
    readUntil(t->language, TW_LANG_LEN, '\n');
    printf("COORDINATES: ");
    readUntil(t->coordinates, TW_COORDINATES_LEN, '\n');
    printf("TEXT: (CTRL+D para terminar)\n");
    readUntil(t->text, TW_TEXT_LEN, '\0');
}
Esempio n. 22
0
// strores the received file on the server - data part
void d_stor(char **params, short *abor, int fd,
	struct state *cstate, struct config *configuration) {
	int accepted, retcode, file, r, subn = 0;
	char filepath[PATH_LENGTH], buf[BUFSIZE];
	accepted = 0;
	// accepts/ connects to the client
	if (spawnConnection(cstate, &accepted)) {
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		return;
	}
	// reads the filepath from the ctrl thread
	readUntil(filepath, fd, 0, PATH_LENGTH);
	// if (isFileOk(filepath) == -1){
	// 	retcode = 5;
	// 	write(fd, &retcode, sizeof (int));
	// 	return;
	// }
	// creates the file
	if ((file = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, 0700)) == -1) {
		retcode = 5;
		write(fd, &retcode, sizeof (int));
		close(accepted);
		return;
	}
	// reads the data and saves it to the file
	while ((r = read(accepted, buf, BUFSIZE)) > 0) {
		// ASCII data transfer
		if (cstate->transfer_type == 6) {
			char tmp[BUFSIZE];
			// converts \r\n sequence to \n,
			// return how much is the result shorter
			if ((subn = as2im(tmp, buf, BUFSIZE)) == -1) {
				retcode = 5;
				write(fd, &retcode, sizeof (int));
				close(accepted);
				break;
			}
			r -= subn;
			memcpy(buf, tmp, BUFSIZE);
		}
		if (write(file, buf, r) == -1) {
			retcode = 5;
			write(fd, &retcode, sizeof (int));
			close(accepted);
			break;
		}
	}
	// closes the file
	close(file);
	// reports result and closes the connection
	retcode = 2;
	close(accepted);
	write(fd, &retcode, sizeof (int));
}
bool
NIVissimSingleTypeParser_DynUml::parse(std::istream& from) {
    std::vector<std::string> tmp;
    tmp.push_back("reisezeit");
    tmp.push_back("kante");
    readUntil(from, "kirchhoffexponent");
    std::string tag = readEndSecure(from, tmp);
    while (tag != "DATAEND") {
        tag = readEndSecure(from, tmp);
    }
    return true;
}
Esempio n. 24
0
// Overrided sendData method for __FlashStringHelper strings
bool EspDrv::sendData(uint8_t sock, const __FlashStringHelper *data, uint16_t len, bool appendCrLf)
{
	LOGDEBUG2(F("> sendData:"), sock, len);

	char cmdBuf[20];
	uint16_t len2 = len + 2*appendCrLf;
	sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%u"), sock, len2);
	espSerial->println(cmdBuf);

	int idx = readUntil(1000, (char *)">", false);
	if(idx!=NUMESPTAGS)
	{
		LOGERROR(F("Data packet send error (1)"));
		return false;
	}

	//espSerial->write(data, len);
	PGM_P p = reinterpret_cast<PGM_P>(data);
	for (int i=0; i<len; i++)
	{
		unsigned char c = pgm_read_byte(p++);
		espSerial->write(c);
	}
	if (appendCrLf)
	{
		espSerial->write('\r');
		espSerial->write('\n');
	}

	idx = readUntil(2000);
	if(idx!=TAG_SENDOK)
	{
		LOGERROR(F("Data packet send error (2)"));
		return false;
	}

    return true;
}
Esempio n. 25
0
bool GPRS::quality(Stream* stream)
{
  
  int buflen = 100;
  char buffer[buflen];

  stream->println("AT+CSQ");
  readUntil(stream, buffer, buflen, '+');
  readUntil(stream, buffer, buflen, '\n');

  #ifdef GPRS_DEBUG
    Serial.print("B: ");
    Serial.println(buffer);
  #endif
  if (!readOK(stream))
  {
    #ifdef GPRS_DEBUG
      Serial.println("No OK");
    #endif
    return false;
  }
  return true;
}
bool
NIVissimSingleTypeParser_Fahrverhaltendefinition::parse(std::istream& from) {
    std::string tmp;
    from >> tmp;
    // in the both next cases, we do not have to overread anything
    if (tmp == "BEHALT_ALTE_PARA" || tmp == "ANZ_VM") {
        return true;
    }
    //
    from >> tmp;
    if (tmp == "NAME") {
        readUntil(from, "gelbverhalten");
    }
    return true;
}
Esempio n. 27
0
void VersionsT::load()
{
	auto Path = mStore.getVersionsPath();

	struct stat Stats;
	auto Error = stat(Path.c_str(), &Stats);
	if (Error == -1)
	{
		// Its ok if versions.gz doesnt exist, we just begin empty
		if (errno == ENOENT) return;
		else throw std::runtime_error{"Error loading versions.gz"};
	}

	auto Buffer = GzipT::readFile(Path);
	auto First = Buffer.begin();
	auto Last = Buffer.end();

	// Read all entries
	while (First != Last)
	{
		auto Tag = readUntil(First, Last, ',');
		auto Hexed = readUntil(First, Last, ',');
		auto Depends = readUntil(First, Last, ',');
		auto Name = readUntil(First, Last, '\n');

		ArchiveEntryT Entry;
		if (Hexed.size() != 32) throw std::runtime_error{"Error loading versions.gz"};
		Hex::decode(Hexed.data(), Entry.Digest.Buffer, 16);
		Entry.Name = std::move(Name);

		// Split depends into vector
		Entry.Depends = splitDepends(Depends);

		mEntries.insert({std::move(Tag), std::move(Entry)});
	}
}
Esempio n. 28
0
/*
* Sends the AT command and returns the id of the TAG.
* Return -1 if no tag is found.
*/
int EspDrv::sendCmd(const __FlashStringHelper* cmd, int timeout)
{
    espEmptyBuf();

	LOGDEBUG(F("----------------------------------------------"));
	LOGDEBUG1(F(">>"), cmd);

	espSerial->println(cmd);

	int idx = readUntil(timeout);

	LOGDEBUG1(F("---------------------------------------------- >"), idx);
	LOGDEBUG();

    return idx;
}
bool
NIVissimSingleTypeParser_Stopschilddefinition::parse(std::istream& from) {
    readUntil(from, "strecke");
    std::string tag;
    from >> tag; // edge name
    from >> tag; // "spur"
    from >> tag; // lane no
    from >> tag; // "bei"
    from >> tag; // pos
    from >> tag;
    if (tag == "RTOR") {
        from >> tag; // "lsa"
        from >> tag; // lsa id
        from >> tag; // "gruppe"
        from >> tag; // gruppe id
    } else {
Esempio n. 30
0
std::string getRhythm(std::string line)
{   // Maps a line of poem into a rhythm string of the form "001001001" or similar
    std::string output;
    std::stringstream ss;
    ss << std::noskipws << line;
    bool e = false;
    std::pair<std::string, char> p;
    while(ss)
    {
        p = readUntil(ss, "- []");
        if(p.first.size() > 0)
            output.push_back(e ? '1' : '0');
        e = p.second == '[';
    }
    return output;
}