Package it.polito.appeal.traci.protocol

Examples of it.polito.appeal.traci.protocol.Command


 
  public synchronized Object do_job_get(SumoCommand sc) throws IOException{
   
    Object output = null;
    ResponseContainer rc = queryAndVerifySingle(sc.cmd);
    Command resp = rc.getResponse();
 
    verifyGetVarResponse(resp, sc.response, sc.input2, sc.input3);
    verify("", sc.output_type, (int)resp.content().readUnsignedByte());
   
    if(sc.output_type == Constants.TYPE_INTEGER){output = resp.content().readInt();
    }else if(sc.output_type == Constants.TYPE_DOUBLE){output = resp.content().readDouble();
    }else if(sc.output_type == Constants.TYPE_STRING){output = resp.content().readStringUTF8();
    }else if(sc.output_type == Constants.POSITION_2D){
      double x = resp.content().readDouble();
      double y = resp.content().readDouble();
      output = new SumoPosition2D(x,y);
    }else if(sc.output_type == Constants.POSITION_3D){
      double x = resp.content().readDouble();
      double y = resp.content().readDouble();
      double z = resp.content().readDouble();
      output = new SumoPosition3D(x,y,z);
    }else if(sc.output_type == Constants.TYPE_STRINGLIST){
     
      SumoStringList ssl = new SumoStringList();
      int laenge = resp.content().readInt();
      for(int i=0; i<laenge; i++){
        ssl.add(resp.content().readStringASCII());
      }
      output = ssl;
   
    }else if(sc.output_type == Constants.TYPE_BOUNDINGBOX){
     
      double min_x = resp.content().readDouble();
      double min_y = resp.content().readDouble();
      double max_x = resp.content().readDouble();
      double max_y = resp.content().readDouble();
     
      output = new SumoBoundingBox(min_x, min_y, max_x, max_y);
     
    }else if(sc.output_type == Constants.TYPE_COMPOUND){
     
      Object[] obj = null;
     
      //decision making
      if(sc.input2 == Constants.TL_CONTROLLED_LINKS){
       
        SumoLinkList sll = new SumoLinkList();
       
        //read length
        resp.content().readUnsignedByte();
        resp.content().readInt();
       
        int laenge = resp.content().readInt();
        obj = new StringList[laenge];
       
        for(int i=0; i<laenge; i++){
       
          resp.content().readUnsignedByte();
          int anzahl = resp.content().readInt();
         
          for(int i1=0; i1<anzahl; i1++){
           
            resp.content().readUnsignedByte();
            resp.content().readInt(); //length
           
            String from = resp.content().readStringASCII();
            String to = resp.content().readStringASCII();
            String over = resp.content().readStringASCII();
            sll.add(new SumoLink(from, to, over));
           
          }
         
        }
       
        output = sll;
     
      }else if(sc.input2 == Constants.TL_COMPLETE_DEFINITION_RYG){
       
        resp.content().readUnsignedByte();
        resp.content().readInt();
       
        int length = resp.content().readInt();
        for(int i=0; i<length; i++){
         
          resp.content().readUnsignedByte();
          String subID = resp.content().readStringASCII();
         
          resp.content().readUnsignedByte();
          int type = resp.content().readInt();
         
          resp.content().readUnsignedByte();
          int subParameter = resp.content().readInt();
         
          resp.content().readUnsignedByte();
          int currentPhaseIndex = resp.content().readInt();
         
          SumoTLSLogic stl = new SumoTLSLogic(subID, type, subParameter, currentPhaseIndex);
         
          resp.content().readUnsignedByte();
          int nbPhases = resp.content().readInt();
         
          for(int i1=0; i1<nbPhases; i1++){
           
            resp.content().readUnsignedByte();
            int duration = resp.content().readInt();
           
            resp.content().readUnsignedByte();
            int duration1 = resp.content().readInt();
           
            resp.content().readUnsignedByte();
            int duration2 = resp.content().readInt();
           
            resp.content().readUnsignedByte();
            String phaseDef = resp.content().readStringASCII();
           
            stl.add(new  SumoTLSPhase(duration, duration1, duration2, phaseDef));
           
          }

          output = stl;
         
        }

       
      }else if(sc.input2 == Constants.LANE_LINKS)
      {
     
        resp.content().readUnsignedByte();
        resp.content().readInt();
       
        //number of links
        int length = resp.content().readInt();
        SumoLinkList links = new SumoLinkList();
        for(int i=0; i<length; i++){
         
          resp.content().readUnsignedByte();
          String notInternalLane = resp.content().readStringASCII();
         
          resp.content().readUnsignedByte();
          String internalLane = resp.content().readStringASCII();
         
          resp.content().readUnsignedByte();
          byte hasPriority = (byte)resp.content().readUnsignedByte();
         
          resp.content().readUnsignedByte();
          byte isOpened = (byte)resp.content().readUnsignedByte();
         
          resp.content().readUnsignedByte();
          byte hasFoes = (byte)resp.content().readUnsignedByte();
         
          //not implemented
          resp.content().readUnsignedByte();
          String state = resp.content().readStringASCII();
         
          resp.content().readUnsignedByte();
          String direction = resp.content().readStringASCII();
         
          resp.content().readUnsignedByte();
          double laneLength = resp.content().readDouble();
         
         
          links.add(new SumoLink(notInternalLane,internalLane,hasPriority,isOpened,hasFoes,laneLength, state, direction));
        }
        output = links;
      }
      else{
       
        int laenge = resp.content().readInt();
        obj = new Object[laenge];
       
        for(int i=0; i<laenge; i++){
         
          int k = resp.content().readUnsignedByte();
          obj[i] = this.get_value(k, resp);
         
        }
       
        output = obj;
      }
     
     
    }
    else if(sc.output_type == Constants.TYPE_POLYGON){
     
      int laenge = resp.content().readUnsignedByte();
     
      SumoGeometry sg = new SumoGeometry();
      for(int i=0; i<laenge; i++){
        double x =  (Double) this.get_value(Constants.TYPE_DOUBLE, resp);
        double y = (Double) this.get_value(Constants.TYPE_DOUBLE, resp);
        sg.add(new SumoPosition2D(x,y));
      }
     
      output = sg;
   
    }
    else if(sc.output_type == Constants.TYPE_COLOR){
     
      int r = resp.content().readUnsignedByte();
      int g = resp.content().readUnsignedByte();
      int b = resp.content().readUnsignedByte();
      int a = resp.content().readUnsignedByte();
     
      output = new SumoColor(r, g, b, a);
   
    }else if(sc.output_type == Constants.TYPE_UBYTE){
     
      output = resp.content().readUnsignedByte();
     
    }
   
   
     
View Full Code Here


    this.commandID = commandID;
  }

  @Override
  List<Command> getRequests() {
    Command cmd = new Command(commandID);
    writeRequestTo(cmd.content());
    return Collections.singletonList(cmd);
  }
View Full Code Here

    this.varID = varID;
  }
 
  @Override
  List<Command> getRequests() {
    Command cmd = new Command(commandID);
    Storage content = cmd.content();
    content.writeUnsignedByte(varID);
    content.writeStringASCII(objectID);
    return Collections.singletonList(cmd);
  }
View Full Code Here

  @Override
  void pickResponses(Iterator<ResponseContainer> responseIterator) throws TraCIException {
    ResponseContainer respc = responseIterator.next();
    StatusResponse statusResp = respc.getStatus();
    Utils.checkStatusResponse(statusResp, commandID);
    Command resp = respc.getResponse();
    Utils.checkByte(resp.content(), varID);
    Utils.checkObjectID(resp.content(), objectID);
   
    V value = readValue(resp);
    setDone(value);
  }
View Full Code Here

  List<Command> getRequests() {
    if (roadmapPos == null && cartesianPos == null)
      throw new IllegalStateException("position must be set first");
   
    List<Command> reqs = super.getRequests();
    Command req = reqs.iterator().next();
    req.content().writeByte(Constants.TYPE_COMPOUND);
    req.content().writeInt(2);
   
   

    if (cartesianPos != null) { // conversion 2D-to-2D
      int srcType;
      double x;
      double y;
      if (srcLonLat) {
        srcType = Constants.POSITION_LAT_LON;
        // TraCI wants lat-long, which is vertical-horizontal
        x = cartesianPos.getY();
        y = cartesianPos.getX();
      }
      else {
        srcType = Constants.POSITION_2D;
        x = cartesianPos.getX();
        y = cartesianPos.getY();
      }
           
      int destType = destLonLat ? Constants.POSITION_LAT_LON : Constants.POSITION_2D;
     
      req.content().writeUnsignedByte(srcType);
      req.content().writeDouble(x);     
      req.content().writeDouble(y);
      req.content().writeUnsignedByte(Constants.TYPE_UBYTE);
      req.content().writeUnsignedByte(destType);   
      setPositionType(destType);
    }
    else {
      req.content().writeUnsignedByte(Constants.POSITION_ROADMAP);
      req.content().writeStringUTF8(roadmapPos.edgeID);
      req.content().writeDouble(roadmapPos.pos);
      req.content().writeUnsignedByte(roadmapPos.laneID);
      req.content().writeUnsignedByte(Constants.TYPE_UBYTE);
      req.content().writeUnsignedByte(Constants.POSITION_LAT_LON);
      setPositionType(Constants.POSITION_LAT_LON);
    }
   
   
    return reqs;
View Full Code Here

TOP

Related Classes of it.polito.appeal.traci.protocol.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.