SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
TraCIServerAPI_ArealDetector.cpp
Go to the documentation of this file.
1
/****************************************************************************/
10
// APIs for getting/setting areal detector values via TraCI
11
/****************************************************************************/
12
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13
// Copyright (C) 2014 DLR (http://www.dlr.de/) and contributors
14
/****************************************************************************/
15
//
16
// This file is part of SUMO.
17
// SUMO is free software: you can redistribute it and/or modify
18
// it under the terms of the GNU General Public License as published by
19
// the Free Software Foundation, either version 3 of the License, or
20
// (at your option) any later version.
21
//
22
/****************************************************************************/
23
24
25
// ===========================================================================
26
// included modules
27
// ===========================================================================
28
#ifdef _MSC_VER
29
#include <
windows_config.h
>
30
#else
31
#include <
config.h
>
32
#endif
33
34
#ifndef NO_TRACI
35
36
#include "
TraCIConstants.h
"
37
#include <
microsim/output/MSDetectorControl.h
>
38
#include <
microsim/output/MSE3Collector.h
>
39
#include "
TraCIServerAPI_ArealDetector.h
"
40
41
#ifdef CHECK_MEMORY_LEAKS
42
#include <
foreign/nvwa/debug_new.h
>
43
#endif // CHECK_MEMORY_LEAKS
44
45
46
// ===========================================================================
47
// method definitions
48
// ===========================================================================
49
bool
50
TraCIServerAPI_ArealDetector::processGet
(
TraCIServer
& server,
tcpip::Storage
& inputStorage,
51
tcpip::Storage
& outputStorage) {
52
// variable & id
53
int
variable = inputStorage.
readUnsignedByte
();
54
std::string
id
= inputStorage.
readString
();
55
// check variable
56
if
(variable !=
ID_LIST
&& variable !=
ID_COUNT
&& variable !=
JAM_LENGTH_VEHICLE
&& variable !=
JAM_LENGTH_METERS
&&
57
variable !=
LAST_STEP_VEHICLE_NUMBER
&& variable !=
LAST_STEP_MEAN_SPEED
&& variable !=
LAST_STEP_VEHICLE_ID_LIST
58
&& variable !=
LAST_STEP_VEHICLE_HALTING_NUMBER
&& variable !=
ID_COUNT
&& variable !=
LAST_STEP_OCCUPANCY
) {
59
return
server.
writeErrorStatusCmd
(
CMD_GET_AREAL_DETECTOR_VARIABLE
,
"Get Areal Detector Variable: unsupported variable specified"
, outputStorage);
60
}
61
62
// begin response building
63
tcpip::Storage
tempMsg;
64
// response-code, variableID, objectID
65
tempMsg.
writeUnsignedByte
(
RESPONSE_GET_AREAL_DETECTOR_VARIABLE
);
66
tempMsg.
writeUnsignedByte
(variable);
67
tempMsg.
writeString
(
id
);
68
if
(variable ==
ID_LIST
) {
69
std::vector<std::string> ids;
70
MSNet::getInstance
()->
getDetectorControl
().
getTypedDetectors
(
SUMO_TAG_LANE_AREA_DETECTOR
).
insertIDs
(ids);
71
tempMsg.
writeUnsignedByte
(
TYPE_STRINGLIST
);
72
tempMsg.
writeStringList
(ids);
73
}
else
if
(variable ==
ID_COUNT
) {
74
std::vector<std::string> ids;
75
MSNet::getInstance
()->
getDetectorControl
().
getTypedDetectors
(
SUMO_TAG_LANE_AREA_DETECTOR
).
insertIDs
(ids);
76
tempMsg.
writeUnsignedByte
(
TYPE_INTEGER
);
77
tempMsg.
writeInt
((
int
) ids.size());
78
}
else
{
79
MSE2Collector
* e2 =
static_cast<
MSE2Collector
*
>
(
MSNet::getInstance
()->
getDetectorControl
().
getTypedDetectors
(
SUMO_TAG_LANE_AREA_DETECTOR
).
get
(
id
));
80
if
(e2 == 0) {
81
return
server.
writeErrorStatusCmd
(
CMD_GET_AREAL_DETECTOR_VARIABLE
,
"Areal detector '"
+
id
+
"' is not known"
, outputStorage);
82
}
83
std::vector<std::string> ids;
84
switch
(variable) {
85
case
ID_LIST
:
86
break
;
87
case
LAST_STEP_VEHICLE_NUMBER
:
88
tempMsg.
writeUnsignedByte
(
TYPE_INTEGER
);
89
tempMsg.
writeInt
((
int
) e2->
getCurrentVehicleNumber
());
90
break
;
91
case
LAST_STEP_MEAN_SPEED
:
92
tempMsg.
writeUnsignedByte
(
TYPE_DOUBLE
);
93
tempMsg.
writeDouble
(e2->
getCurrentMeanSpeed
());
94
break
;
95
case
LAST_STEP_VEHICLE_ID_LIST
:
96
tempMsg.
writeUnsignedByte
(
TYPE_STRINGLIST
);
97
ids = e2->
getCurrentVehicleIDs
();
98
tempMsg.
writeStringList
(ids);
99
break
;
100
case
LAST_STEP_VEHICLE_HALTING_NUMBER
:
101
tempMsg.
writeUnsignedByte
(
TYPE_INTEGER
);
102
tempMsg.
writeInt
((
int
) e2->
getCurrentHaltingNumber
());
103
break
;
104
case
JAM_LENGTH_VEHICLE
:
105
tempMsg.
writeUnsignedByte
(
TYPE_INTEGER
);
106
tempMsg.
writeInt
((
int
) e2->
getCurrentJamLengthInVehicles
());
107
break
;
108
case
JAM_LENGTH_METERS
:
109
tempMsg.
writeUnsignedByte
(
TYPE_DOUBLE
);
110
tempMsg.
writeDouble
(e2->
getCurrentJamLengthInMeters
());
111
break
;
112
case
LAST_STEP_OCCUPANCY
:
113
tempMsg.
writeUnsignedByte
(
TYPE_DOUBLE
);
114
tempMsg.
writeDouble
(e2->
getCurrentOccupancy
());
115
break
;
116
default
:
117
break
;
118
}
119
}
120
server.
writeStatusCmd
(
CMD_GET_AREAL_DETECTOR_VARIABLE
,
RTYPE_OK
,
""
, outputStorage);
121
server.
writeResponseWithLength
(outputStorage, tempMsg);
122
return
true
;
123
}
124
125
#endif
126
127
128
/****************************************************************************/
129
tmp
buildd
sumo-0.21.0+dfsg
src
traci-server
TraCIServerAPI_ArealDetector.cpp
Generated on Thu Nov 20 2014 19:49:59 for SUMO - Simulation of Urban MObility by
1.8.1.2