Hi Michael,

Subscription in TraaS is supported. I written and tested examples based on
the TraaS source code. May be need to update the documentation? and also if
wanted I can share the example.

If anyone interested, they can try out with following way:

    Implement your class with java.util.Observer  and add the following
code in constructor.

            SumoTraciConnection conn = new SumoTraciConnection(sumo_app,
config_file);
            conn.addOption("step-length", step_length+"");
            conn.addOption("start",null); //start sumo immediately
            conn.runServer();
            conn.addObserver(this);
            VariableSubscription vs = new
VariableSubscription(SubscribtionVariable.simulation,0,100000 * 60, "veh0");
            vs.addCommand(Constants.VAR_ARRIVED_VEHICLES_IDS);
            vs.addCommand(Constants.VAR_DEPARTED_VEHICLES_IDS);
            conn.do_subscription(vs);
            VariableSubscription vs1= new
VariableSubscription(SubscribtionVariable.vehicle,0,100000 * 60, "veh0");
            vs1.addCommand(Constants.VAR_POSITION);
            vs1.addCommand(Constants.VAR_SPEED);
            vs1.addCommand(Constants.VAR_DISTANCE);
            conn.do_subscription(vs1);

and listen the events in your class as follows:

public void update(Observable arg0, Object arg1) {
        SubscriptionObject so = (SubscriptionObject) arg1;
        if (so.response.id ==
Constants.RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE) {
            if (so.variable == Constants.VAR_SPEED) {
                SumoPrimitive sp = (SumoPrimitive) so.object;
                System.out.println("Speed of the vehicle " + sp.val);

            } else if (so.variable == Constants.VAR_POSITION) {
                SumoPosition2D sc = (SumoPosition2D) so.object;
                System.out.println("Position of the vehicle x = " + sc.x +
" y = " + sc.y);
            } else if (so.variable == Constants.VAR_DISTANCE) {
                SumoPrimitive sp = (SumoPrimitive) so.object;
                System.out.println("Distance of the vehicle " + sp.val);
            }

        } else if (so.response.id ==
Constants.RESPONSE_SUBSCRIBE_SIM_VARIABLE) {
            SumoStringList ssl=(SumoStringList) so.object;
            if(ssl.size()>0) {
                if (so.variable == Constants.VAR_DEPARTED_VEHICLES_IDS) {
                    System.out.println("subscription Departed vehicles:
"+ssl.size());
                } else if (so.variable ==
Constants.VAR_ARRIVED_VEHICLES_IDS) {
                    System.out.println("subscription Arrived vehicles:
"+ssl.size());
                }
            }
        }
    }

Br,
Satyam

On Thu, Feb 1, 2018 at 11:36 PM, Michael Behrisch <[email protected]> wrote:

> Hi Satyam,
> there is at least subscription code in the traas sources but I don't know
> of any exmaples and did not try it myself. The documentation
> http://traas.sourceforge.net/cms/index.php?id=documentation says it is
> not supported, but I am forwarding this to the mailing list and the
> original TraaS author, maybe someone there can help.
>
> Best regards,
> Michael
>
>
> Am 2018-02-02 07:22, schrieb satyam bandarapu:
>
>> Hi Michael,
>>
>> Thank you for the email. Implementing proxy seems to work for me. is it
>> subscription working in TraaS(Java)? if yes, any examples?
>>
>> Br,
>> Satyam
>>
>> On Wed, Jan 31, 2018 at 11:56 PM, Michael Behrisch <[email protected]>
>> wrote:
>>
>> Dear Satyam,
>>> the problem is that SUMO is currently not multithreaded and so cannot
>>> wait
>>> for connections and execute simultaneously. One could introduce a
>>> waitforconnect command but this seems rather clumsy and we would prefer
>>> to
>>> introduce multithreading which is not that hard but still needs some days
>>> to implement correctly. If you are willing to try we can help you here at
>>> least by giving pointers where to start. The much easier solution is of
>>> course to write a simple proxy in the programming language of your choice
>>> which will connect as the only instance to sumo and will itself accept
>>> connections and route them through.
>>>
>>> Best regards,
>>> Michael
>>>
>>>
>>> Am 2018-01-31 23:52, schrieb satyam bandarapu:
>>>
>>> Hi,
>>>>
>>>> I am trying to connect multiple clients to the SUMO(SUMO-GUI) 0.32.0. I
>>>> got
>>>> to know from the following link that "When using multi client setups the
>>>> number of clients needs to be known when starting SUMO and all clients
>>>> need
>>>> to connect before the first simulation step".
>>>>
>>>> http://sumo.dlr.de/wiki/TraCI/Protocol
>>>>
>>>> My requirement is to add the clients dynamically after starting the
>>>> SUMO.
>>>> Can anyone explain, is it architecturally possible to extend the SUMO
>>>> source code to support above feature? if yes, how big is the changes and
>>>> where is the modifications required in the source files?
>>>>
>>>> I am looking to write clients in TracAPI(C++) or TraaS(Java).
>>>>
>>>> Appreciate your help.
>>>>
>>>> Thanks
>>>> Satyam
>>>>
>>>> _______________________________________________
>>>> sumo-user mailing list
>>>> [email protected]
>>>> To change your delivery options, retrieve your password, or
>>>> unsubscribe from this list, visit
>>>> https://dev.eclipse.org/mailman/listinfo/sumo-user
>>>>
>>>>
>>>
_______________________________________________
sumo-user mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/sumo-user

Reply via email to