void commandSimulationStep(double time) { // progress the simulation in SUMO // reset is used to initalize the global parameters reset(); // Send command writeUnsignedByte(1 + 1 + 4); // command length writeUnsignedByte(CMD_SIMSTEP2); // look up TraCIConstants.h // writeInt((int)(time*1000)); // TraCI accepts time in milli seconds writeInt((int)(time)); // TraCI accepts time in milli seconds sendExact(storageLength(storageStart)); extractCommandStatus(receiveExact(), CMD_SIMSTEP2, description); if (departed == NULL) { departed = (string_list*) malloc(sizeof(string_list)); // departed MUST point to HEAD departed->string = NULL; departed->next = NULL; } if (arrived == NULL) { arrived = (string_list*) malloc(sizeof(string_list)); // arrived MUST point to HEAD arrived->string = NULL; arrived->next = NULL; } /* if (departed == NULL) departed = (String_list)malloc(sizeof(String_list)); // departed MUST point to HEAD if (arrived == NULL) arrived = (String_list)malloc(sizeof(String_list)); // departed MUST point to HEAD */ processSubscriptions(); }
void commandGetVehicleVariable(char *vehID, int varID)// malloc for vehID and varID depends on speed or position { reset(); int domID = CMD_GET_VEHICLE_VARIABLE;//0xa4 specific for get vehicle variable command // command length writeUnsignedByte(1 + 1 + 1 + 4 + (int)strlen(vehID)); // command id writeUnsignedByte(CMD_GET_VEHICLE_VARIABLE); // variable id writeUnsignedByte(varID); // object id writeString(vehID); // send request message sendExact(storageLength(storageStart)); // receive answer message //receiveExact(); if (extractCommandStatus(receiveExact(), CMD_GET_VEHICLE_VARIABLE, description)){//<---RESPONSE_GET_VEHICLE_VARIABLE // validate result state if(tracker == NULL) { // LOG_E(OMG, " client_traci_OMG::commandGetVehicleVariable(): Tracker is NULL \n"); //printf(" client_traci_OMG::commandGetVehicleVariable(): Tracker is NULL \n"); return; } int length = readUnsignedByte(); if(length ==0) length = readInt(); int cmdId =readUnsignedByte(); if (cmdId != (CMD_GET_VEHICLE_VARIABLE+0x10)) { //LOG_E(OMG, " Wrong response recieved\n"); //printf(" Wrong response recieved\n"); return; } int VariableID = readUnsignedByte(); char* rs = readString(); int valueDataType = readUnsignedByte(); UNUSED_VARIABLE(VariableID); UNUSED_VARIABLE(rs); UNUSED_VARIABLE(valueDataType); UNUSED_VARIABLE(domID); } }
void commandClose() { reset(); // command length writeUnsignedByte(0x02); // command id writeUnsignedByte(CMD_CLOSE); // send request message #ifdef STANDALONE printf("closing the socket... \n"); #else LOG_N(OMG,"closing the socket... \n"); #endif sendExact(storageLength(storageStart)); extractCommandStatus(receiveExact(), CMD_CLOSE, description); }
void init(int max_sim_time) { #ifdef STANDALONE printf(" Initializing TraCI...\n"); #else LOG_N(OMG, " Initializing TraCI...\n"); #endif char *objID = " "; // size_t size = strlen(objID); int noSubscribedVars = 2; writeUnsignedByte(0); writeInt(1 + 4 + 1 + 4 + 4 + 4 + (int) strlen(objID) + 1 + noSubscribedVars); writeUnsignedByte(CMD_SUBSCRIBE_SIM_VARIABLE); // command id writeInt(0); // begin time writeInt(max_sim_time*1000); // end time writeString(objID); // object id writeUnsignedByte(noSubscribedVars); // variable number writeUnsignedByte(VAR_DEPARTED_VEHICLES_IDS); writeUnsignedByte(VAR_ARRIVED_VEHICLES_IDS); // send request message sendExact(storageLength(storageStart)); extractCommandStatus(receiveExact(), CMD_SUBSCRIBE_SIM_VARIABLE, description); if (departed == NULL) { departed = (string_list*) malloc(sizeof(string_list)); // departed MUST point to HEAD departed->string = NULL; departed->next = NULL; } if (arrived == NULL) { arrived = (string_list*) malloc(sizeof(string_list)); // arrived MUST point to HEAD arrived->string = NULL; arrived->next = NULL; } processSubscriptions(); reset(); }
cGenericBuffer& operator<< (unsigned char Data) {writeUnsignedByte(Data); return *this;}
// TODO not working for now..need to find a way to get the same info without using CMD_SCENARIO (as not implemented by SUMO) int commandGetMaxSUMONodesVariable() { reset(); int max_car = 0; // command length writeUnsignedByte(1 + 1 + 1 + 1 + 4 + 1 + 1 + 4); // command id writeUnsignedByte(CMD_SCENARIO); // flag writeUnsignedByte(0x00); // GET command for the generic environment-related values // command id //writeUnsignedByte(CMD_SCENARIO); // domain id writeUnsignedByte(0x01); // vehicle writeInt(0); // first vehicular domain // variable id writeUnsignedByte(DOMVAR_MAXCOUNT); // get maximum number of vehicles writeUnsignedByte(TYPE_INTEGER); // get maximum number of vehicles writeInt(max_car); // get maximum number of vehicles // send request message sendExact(storageLength(storageStart)); // receive answer message if (extractCommandStatus(receiveExact(), CMD_SCENARIO, description)){//<---RESPONSE_GET_VEHICLE_VARIABLE // validate result state if(tracker == NULL) { //LOG_E(OMG, " client_traci_OMG::commandGetMaxSUMONodesVariable(): Tracker is NULL \n"); return -1; } int res = readUnsignedByte(); int Length = readUnsignedByte(); // to check with Int int cmdId =readUnsignedByte(); if (cmdId != (CMD_SCENARIO)) { //LOG_E(OMG, " Wrong response recieved \n"); return -1; } int flag = readUnsignedByte(); int dom = readUnsignedByte(); // domain int domID = readInt(); // domain ID int VariableID = readUnsignedByte(); int valueDataType = readUnsignedByte(); if (valueDataType == TYPE_INTEGER) { max_car = readInt(); //LOG_N(OMG, " max Number SUMO nodes is: %f \n", max_car); } else { //LOG_W(OMG, " No Matching Data Type Value \n"); } UNUSED_VARIABLE(res); UNUSED_VARIABLE(Length); UNUSED_VARIABLE(flag); UNUSED_VARIABLE(dom); UNUSED_VARIABLE(domID); UNUSED_VARIABLE(VariableID); } return max_car; }