bool
NIVissimSingleTypeParser_Auswertungsdefinition::parse(std::istream& from) {
    std::string id;
    from >> id; // "typ"

    if (id == "DATENBANK") { // !!! unverified
        return true;
    }

    std::string type = myRead(from);
    if (type == "abfluss") {
        while (type != "signalgruppe") {
            type = myRead(from);
        }
        while (type != "DATAEND") {
            type = readEndSecure(from, "messung");
        }
    } else if (type == "vbv") {} else if (type == "dichte") {} else if (type == "emissionen") {} else if (type == "fzprot") {} else if (type == "spwprot") {} else if (type == "segment") {
        while (type != "konfdatei") {
            type = myRead(from);
        }
    } else if (type == "wegeausw") {} else if (type == "knoten") {} else if (type == "konvergenz") {
        while (type != "zeit") {
            type = myRead(from);
        }
    }
    return true;
}
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);
    }
bool
NIVissimSingleTypeParser_Knotendefinition::parse(std::istream &from) {
    //
    int id;
    from >> id;
    //
    std::string tag;
    from >> tag;
    std::string name = readName(from);
    //
    tag = overrideOptionalLabel(from);
    //
    while (tag!="netzausschnitt") {
        tag = myRead(from);
    }
    //
    tag = myRead(from);
    if (tag=="strecke") {
        NIVissimNodeParticipatingEdgeVector edges;
        while (tag=="strecke") {
            int edgeid;
            SUMOReal from_pos, to_pos;
            from_pos = to_pos = -1.0;
            from >> edgeid;
            tag = readEndSecure(from, "strecke");
            if (tag=="von") {
                from >> from_pos; // type-checking is missing!
                from >> tag;
                from >> to_pos; // type-checking is missing!
                tag = readEndSecure(from, "strecke");
            }
            edges.push_back(new NIVissimNodeParticipatingEdge(edgeid, from_pos, to_pos));
        }
Beispiel #4
0
int main(int argc, char **argv) {
	// Basic init
	FILE * hittite = fopen("/dev/hittite", "w+");

	// Resetting GPIB bus
	fprintf(hittite, "*IDN?\n");
	char id[1024];
	efgets(id, 1023, hittite);
	printf("*IDN? : %s", id);

	char socketBuffer[1024];
	int sockfd = initServer(atoi(argv[1]));

	while(1) {
		int clientfd = eaccept(sockfd);
		int ret = myRead( clientfd, socketBuffer, 1024 );
		while( ret > 0 ) {
			printf("Received: %s\n", socketBuffer);
			handleRequest(socketBuffer, &clientfd, hittite);
			ret = myRead(clientfd, socketBuffer, 1024);
		}
		close(clientfd);

	}

	return EXIT_SUCCESS;
}
Beispiel #5
0
//#################################
Bool32 BackupPage::RestoreCompress(Handle from)
{
    Bool32 rc = FALSE;
    int count, i, position;
    backups_.Clear();
    rc = myRead(from, &count, sizeof(count)) == sizeof(count);

    if (count) {
        if (rc) rc = myRead(from, &position, sizeof(position)) == sizeof(position);

        for (i = 0; i < count && rc == TRUE; i++) {
            PAGE page;
            rc = page.RestoreCompress(from);

            if (rc)
                backups_.AddTail(page);
        }

        if (rc && position >= 0)
            hCurBackUp = backups_.GetHandle(position);
    }

    if (rc)
        rc = PAGE::RestoreCompress(from);

    return rc;
}
bool
NIVissimSingleTypeParser_Signalgeberdefinition::parse(std::istream& from) {
    //
    int id;
    from >> id;
    //
    std::string tag, name;
    tag = myRead(from);
    if (tag == "name") {
        name = readName(from);
        tag = myRead(from);
    }
    // skip optional "Beschriftung"
    tag = overrideOptionalLabel(from, tag);
    //
    int lsaid;
    std::vector<int> groupids;
    if (tag == "lsa") {
        int groupid;
        from >> lsaid; // type-checking is missing!
        from >> tag; // "Gruppe"
        do {
            from >> groupid;
            groupids.push_back(groupid);
            tag = myRead(from);
        } while (tag == "oder");
        //
    } else {
//##############################
Bool32 BLOCK::RestoreCompress(Handle from)
{
    if( myRead(from,&UserNum,sizeof(UserNum))==sizeof(UserNum) &&
            myRead(from,&Flags,sizeof(Flags))==sizeof(Flags) &&
            DATA::RestoreCompress(from) &&
            myRead(from,&InterNum,sizeof(InterNum))==sizeof(InterNum))
        return TRUE;

    return FALSE;
}
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;
}
bool
NIVissimSingleTypeParser_Signalgruppendefinition::parse(std::istream& from) {
    //
    int id;
    from >> id; // type-checking is missing!
    //
    std::string tag;
    tag = myRead(from);
    std::string name;
    if (tag == "name") {
        name = readName(from);
        tag = myRead(from);
    }
    //
    int lsaid;
    from >> lsaid;
    NIVissimTL* tl = NIVissimTL::dictionary(lsaid);
    if (tl == 0) {
        WRITE_ERROR("A traffic light group with an unknown traffic light occured.\n  Group-ID: " + toString<int>(id)
                    + "\n  TrafficLight-ID: " + toString<int>(lsaid));
        return false;
    }
    std::string type = tl->getType();
    if (type == "festzeit") {
        return parseFixedTime(id, name, lsaid, from);
    }
    if (type == "festzeit_fake") {
        return parseFixedTime(id, name, lsaid, from);
//        return parseExternFixedTime(id, name, lsaid, from);
    }
    if (type == "vas") {
        return parseVAS(id, name, lsaid, from);
    }
    if (type == "vsplus") {
        return parseVSPLUS(id, name, lsaid, from);
    }
    if (type == "trends") {
        return parseTRENDS(id, name, lsaid, from);
    }
    if (type == "vap") {
        return parseVAP(id, name, lsaid, from);
    }
    if (type == "tl") {
        return parseTL(id, name, lsaid, from);
    }
    if (type == "pos") {
        return parsePOS(id, name, lsaid, from);
    }
    WRITE_WARNING("Unsupported LSA-Type '" + type + "' occured.");
    return true;
}
Beispiel #10
0
std::string
NIImporter_Vissim::VissimSingleTypeParser::overrideOptionalLabel(std::istream &from,
        const std::string &tag) {
    std::string tmp;
    if (tag=="") {
        tmp = myRead(from);
    } else {
        tmp = tag;
    }
    if (tmp=="beschriftung") {
        tmp = myRead(from);
        if (tmp=="keine") {
            from >> tmp;
        }
Beispiel #11
0
//###########################################
CPAGE_FUNC(Handle)  CPAGE_RestorePage(Bool32 remove,char * lpName)
{
	PROLOG;
	Handle rc = NULL;
	Bool decompress=FALSE;

	SetReturnCode_cpage(IDS_ERR_NO);

	Handle file = myOpenRestore((char *)lpName);
	if(file)
	{
		int i;
		int count;

		uint32_t vers = 0;
		if(myRead(file,&vers,sizeof(vers))==sizeof(vers))
		{
			if (vers==VERSION_FILE_COMPRESSED)
			   decompress=TRUE;
			else
				if(vers!=VERSION_FILE)
				{
					SetReturnCode_cpage(IDS_ERR_OLDFILEVERSION);
					myClose(file);
					return FALSE;
				}
			{
				if(remove)
				{
					Page.Clear();
					NameData.Clear();
				}

				if(myRead(file,&count,sizeof(count))==sizeof(count))
					for(i=0;i<count ;i++)
					{
						BACKUPPAGE page;
						if(decompress ? page.RestoreCompress(file) : page.Restore(file))
							rc = Page.AddTail(page);
						else
							break;
					}
			}
		}
		myClose(file);
	}
	EPILOG;
return rc;
}
Beispiel #12
0
std::string
NIImporter_Vissim::VissimSingleTypeParser::readEndSecure(std::istream &from,
        const std::vector<std::string> &excl) {
    std::vector<std::string> myExcl;
    std::vector<std::string>::const_iterator i;
    for (i=excl.begin(); i!=excl.end(); i++) {
        std::string mes = StringUtils::to_lower_case(*i);
        myExcl.push_back(mes);
    }
    std::string tmp = myRead(from);
    if (tmp=="") {
        return "DATAEND";
    }

    bool equals = false;
    for (i=myExcl.begin(); i!=myExcl.end()&&!equals; i++) {
        if ((*i)==tmp) {
            equals = true;
        }
    }
    if (!equals
            &&
            (tmp.substr(0, 2)=="--"||!myVissimParent.admitContinue(tmp))
       ) {
        return "DATAEND";
    }
    return StringUtils::to_lower_case(tmp);
}
bool
NIVissimSingleTypeParser_Fahrzeugklassendefinition::parse(std::istream& from) {
    // id
    int id;
    from >> id; // type-checking is missing!
    // name
    std::string tag;
    from >> tag;
    std::string name = readName(from);
    // color
    from >> tag;
    std::string colorName = myRead(from);
    RGBColor color;
    NIImporter_Vissim::ColorMap::iterator i = myColorMap.find(colorName);
    if (i != myColorMap.end()) {
        color = (*i).second;
    } else {
        int r, g, b;
        r = TplConvert::_2int(colorName.c_str());
        from >> g; // type-checking is missing!
        from >> b; // type-checking is missing!
        color = RGBColor(r, g, b, 255);
    }
    // types
    from >> tag;
    if (tag == "ANM_ID") {
        readName(from);
        from >> tag;
    }
bool
NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::parsePositionDescribed(std::istream& from) {
    std::string tag = myRead(from);
    NIVissimExtendedEdgePoint edge = parsePos(from);
//    from >> tag; // "Durch"
    bool ok = true;
    do {
        from >> tag; // "Strecke"
        NIVissimExtendedEdgePoint by = parsePos(from);
        //
        SUMOReal timegap;
        from >> timegap;

        from >> tag;
        SUMOReal waygap;
        from >> waygap;

        SUMOReal vmax = -1;
        tag = readEndSecure(from);
        if (tag == "vmax") {
            from >> vmax;
        }
        ok = NIVissimDisturbance::dictionary(-1, "", edge, by,
                                             timegap, waygap, vmax);
        if (tag != "DATAEND") {
            tag = readEndSecure(from);
        }
    } while (tag != "DATAEND" && ok);
bool
NIVissimSingleTypeParser_Lichtsignalanlagendefinition::parse(std::istream& from) {
    //
    int id;
    from >> id;
    //
    std::string tag, name;
    tag = myRead(from);
    if (tag == "name") {
        name = readName(from);
        tag = myRead(from);
    }
    // type
    std::string type;
    type = myRead(from);
    if (type == "festzeit") {
        return parseFixedTime(id, name, from);
    }
    if (type == "vas") {
        return parseVAS(id, name, from);
    }
    if (type == "vsplus") {
        return parseRestActuated(id, name, from, type);
    }
    if (type == "trends") {
        return parseRestActuated(id, name, from, type);
    }
    if (type == "vap") {
        return parseRestActuated(id, name, from, type);
    }
    if (type == "tl") {
        return parseRestActuated(id, name, from, type);
    }
    if (type == "pos") {
        return parseRestActuated(id, name, from, type);
    }
    if (type == "nema") {
        return parseRestActuated(id, name, from, type);
    }
    if (type == "extern") {
        return parseRestActuated(id, name, from, type);
    }
    WRITE_ERROR("Unsupported LSA-Type '" + type + "' occured.");
    return false;
}
bool
NIVissimSingleTypeParser_Verlustzeitmessungsdefinition::parse(std::istream& from) {
    std::string tag = myRead(from);
    if (tag == "von") {
        while (tag != "DATAEND") {
            tag = readEndSecure(from);
        }
        return true;
    }

    while (tag != "fahrzeugklassen") {
        tag = myRead(from);
    }
    while (tag != "DATAEND") {
        tag = readEndSecure(from);
    }
    return true;
}
Beispiel #17
0
int main()
{
	int pipefd[2];
	int count = 15;
	if(pipe(pipefd) < 0) return -1;

	pid_t pid = fork();
	if(pid < 0) return -1;

	int pipeReadfd = pipefd[0];
	int pipeWritefd = pipefd[1];

	setFdNonblocking(pipeReadfd);

	if(0 == pid){
		int i = 0;
		int epfd = createEvent();

		if(addEvent(epfd, pipeReadfd, AE_READABLE) < -1) return -1;

		struct epoll_event *e = calloc(1024, sizeof(struct epoll_event));

		while(i++ < count){
			int ret = 0;
			if((ret = myRead(epfd, pipeReadfd, e)) < 0){
				//Here we do not check the situation that the "ret" less than 0
				//stracing or gdbing this process will trigger a siglarm which will cause "ret == -1"
			}
			//                              printf("ret val: %d\n", ret);
		}

		close(epfd);
		free(e);
		printf("child finished...\n");

	}else{
		int i = 0;

		while(i++ < count){
			usleep(100000);
			//                      char buf[1204];
			//                      memset(buf, 0x0, 1024);
			//                      fgets(buf, 10, stdin);
			write(pipeWritefd, "hello", 1024);
		}

		printf("parent finished...\n");
	}

	close(pipefd[0]);
	close(pipefd[1]);
	usleep(10000);
	return 0;
}
bool
NIVissimSingleTypeParser_Querschnittsmessungsdefinition::parse(std::istream& from) {
    std::string tag = myRead(from);
    if (tag == "von") {
        while (tag != "fahrzeugklassen" && tag != "konfdatei") {
            tag = myRead(from);
        }
        tag = myRead(from);
        while (tag != "DATAEND") {
            tag = readEndSecure(from);
        }
        return true;
    }
    tag = myRead(from);
    tag = myRead(from);
    while (tag != "DATAEND") {
        tag = readEndSecure(from);
    }
    return true;
}
bool
NIVissimSingleTypeParser_Signalgruppendefinition::parseFixedTime(
    int id, const std::string& name, int lsaid, std::istream& from) {
    //
    bool isGreenBegin;
    std::vector<SUMOReal> times;
    std::string tag = myRead(from);
    if (tag == "dauergruen") {
        isGreenBegin = true;
        from >> tag;
    } else if (tag == "dauerrot") {
bool
NIVissimSingleTypeParser_Detektordefinition::parse(std::istream& from) {
    std::string tag;
    while (tag != "strecke") {
        tag = myRead(from);
    }
    while (tag != "DATAEND") {
        tag = readEndSecure(from);
    }
    return true;
}
bool
NIVissimSingleTypeParser_Haltestellendefinition::parse(std::istream &from) {
    std::string tag;
    while (tag!="strecke") {
        tag = myRead(from);
    }
    while (tag!="laenge") {
        tag = myRead(from);
    }
    from >> tag;
    tag = readEndSecure(from);
    while (tag=="einsteiger"&&tag!="DATAEND") {
        while (tag!="linie") {
            tag = myRead(from);
        }
        while (tag!="einsteiger"&&tag!="DATAEND") {
            tag = readEndSecure(from);
        }
    }
    return true;
}
bool
NIVissimSingleTypeParser_Reisezeitmessungsdefinition::parse(std::istream& from) {
    std::string tag = myRead(from);
    if (tag == "aggregationsintervall") {
        while (tag != "DATAEND") {
            tag = readEndSecure(from);
        }
        return true;
    }

    while (tag != "strecke") {
        tag = myRead(from);
    }
    tag = myRead(from);
    while (tag != "strecke") {
        tag = myRead(from);
    }
    while (tag != "DATAEND") {
        tag = readEndSecure(from);
    }
    return true;
}
Beispiel #23
0
int main(int argc, char **argv) {
	setProgName(argv[0]);
	checkArgs(argc, 1, "port number");

	char socketBuffer[1024];
	int usbfd = initSerial(115200, "/dev/ttyUSB0" );
	int port = atoi(argv[1]);
	int serverfd =  initServer(port);

	while(1) {
		// Listen for incoming calls
		int clientfd = eaccept(serverfd);
		int ret = myRead( clientfd, socketBuffer, 1024 );
		while( ret > 0 ) {
			handleRequest(socketBuffer, &clientfd, &usbfd);
			ret = myRead(clientfd, socketBuffer, 1024);
		}
		close(clientfd);
	}

	return EXIT_SUCCESS;
}
bool
NIVissimSingleTypeParser_Routenentscheidungsdefinition::parse(std::istream& from) {
    std::string tag;
    while (tag != "fahrzeugklassen") {
        tag = myRead(from);
    }
    do {
        while (tag != "DATAEND" || tag == "route") {
            if (tag == "route") {
                while (tag != "strecke") {
                    tag = myRead(from);
                }
                tag = readEndSecure(from);
            } else {
                tag = readEndSecure(from);
            }
        }
        if (tag != "DATAEND") {
            tag = readEndSecure(from);
        }
    } while (tag != "DATAEND");
    return true;
}
bool
NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition::parse(std::istream& from) {
    std::string tag;
    tag = myRead(from);
    if (tag == "nureigenestrecke") {
        return parseOnlyMe(from);
    } else if (tag == "ort") {
        return parsePositionDescribed(from);
    } else if (tag == "nummer") {
        return parseNumbered(from);
    }
    WRITE_ERROR(
        "NIVissimSingleTypeParser_Querverkehrsstoerungsdefinition: format problem");
    throw 1;
}
Beispiel #26
0
std::string
NIImporter_Vissim::VissimSingleTypeParser::readEndSecure(std::istream &from,
        const std::string &excl) {
    std::string myExcl = StringUtils::to_lower_case(excl);
    std::string tmp = myRead(from);
    if (tmp=="") {
        return "DATAEND";
    }
    if (tmp!=myExcl
            &&
            (tmp.substr(0, 2)=="--"||!myVissimParent.admitContinue(tmp))
       ) {
        return "DATAEND";
    }
    return StringUtils::to_lower_case(tmp);
}
Beispiel #27
0
bool
NIVissimSingleTypeParser_Verbindungsdefinition::parse(std::istream& from) {
    int id;
    from >> id; // type-checking is missing!
    std::string tag;
    // Read optional value "Name", skip optional value "Beschriftung"
    std::string name;
    while (tag != "von") {
        tag = overrideOptionalLabel(from);
        if (tag == "name") {
            name = readName(from);
        }
    }
    // Read the geometry information
    NIVissimExtendedEdgePoint from_def = readExtEdgePointDef(from);
    PositionVector geom;
    tag = myRead(from); // "ueber"
    while (tag != "nach") {
        std::string x = myRead(from);
        std::string y = myRead(from);
        if (y != "nach") {
            geom.push_back_noDoublePos(
                Position(
                    TplConvert::_2SUMOReal(x.c_str()),
                    TplConvert::_2SUMOReal(y.c_str())
                ));
            tag = myRead(from);
            try {
                TplConvert::_2SUMOReal(tag.c_str());
                tag = myRead(from);
            } catch (NumberFormatException&) {}
        } else {
            tag = y;
        }
    }
    NIVissimExtendedEdgePoint to_def = readExtEdgePointDef(from);
    // read some optional values until mandatory "Fahrzeugklassen" occurs
    SUMOReal dxnothalt = 0;
    SUMOReal dxeinordnen = 0;
    SUMOReal zuschlag1, zuschlag2;
    zuschlag1 = zuschlag2 = 0;
    SUMOReal seglength = 0;
    tag = myRead(from);
    NIVissimConnection::Direction direction = NIVissimConnection::NIVC_DIR_ALL;
    while (tag != "fahrzeugklassen" && tag != "sperrung" && tag != "auswertung" && tag != "DATAEND") {
        if (tag == "rechts") {
            direction = NIVissimConnection::NIVC_DIR_RIGHT;
        } else if (tag == "links") {
            direction = NIVissimConnection::NIVC_DIR_LEFT;
        } else if (tag == "alle") {
            direction = NIVissimConnection::NIVC_DIR_ALL;
        } else if (tag == "dxnothalt") {
            from >> dxnothalt; // type-checking is missing!
        } else if (tag == "dxeinordnen") {
/* Test myRead and myWrite functions */
    int main()
    {
      int access, method, fd, file = 0;

      while(file != -1)
      {
        char buffer[10000];
        printf("Please choose a file within the directory to edit.\n");
        printf("For exploit.c, enter 1.\n");
        printf("For findMessage.java, enter 2.\n");
        printf("For hideMessage.java, enter 3.\n");
        printf("For shellcode.c, enter 4.\n");
        printf("For stack.c, enter 5.\n");
        printf("To exit, enter 0.\n");

  /* Exit if requested */
        scanf("%d", &file);
        if(file == 0)
          return 0;

        printf("Would you like to read(1) or write(2)?\n");
        scanf("%d", &method);

  /* Determine if user actually has permission to manipulate file how they'd like */
        if(userAccess() == 0) 
          access = 2;
        else if(userAccess() == 501)
          access = 1;
        else
          access = 0;

  /* Call read or write function */
        file = file - 1;
        if(method == 1)
          myRead(buffer, sizeof(buffer), file, access);
        else if(method == 2)
          myWrite(file, access);

        printf("\n");
      }
      return 0;
    }
bool
NIVissimSingleTypeParser_Streckendefinition::parse(std::istream& from) {
    // read in the id
    int id;
    from >> id;
    //
    std::string tag;
    // the following elements may occure: "Name", "Beschriftung", "Typ",
    //  followed by the mandatory "Laenge"
    std::string name, label, type;
    SUMOReal length = -1;
    while (length < 0) {
        tag = overrideOptionalLabel(from);
        if (tag == "name") {
            name = readName(from);
        } else if (tag == "typ") {
            type = myRead(from);
        } else if (tag == "laenge") {
            from >> length; // type-checking is missing!
        }
    }
bool
NIVissimSingleTypeParser_Zusammensetzungsdefinition::parse(std::istream& from) {
    std::string tag = myRead(from);
    while (tag != "fahrzeugtyp") {
        tag = readEndSecure(from, "fahrzeugtyp");
    }
    do {
        tag = myRead(from); // id
        tag = myRead(from); // "anteil"
        tag = myRead(from); // value
        tag = myRead(from); // "VWunsch"
        tag = myRead(from); // value
        tag = readEndSecure(from, "fahrzeugtyp"); // "fahrzeugtyp"?
    } while (tag == "fahrzeugtyp");
    return true;
}