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
/****************************************************************************/
7
// APIs for getting/setting areal detector values via TraCI
8
/****************************************************************************/
9
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10
// Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11
/****************************************************************************/
12
//
13
// This file is part of SUMO.
14
// SUMO is free software: you can redistribute it and/or modify
15
// it under the terms of the GNU General Public License as published by
16
// the Free Software Foundation, either version 3 of the License, or
17
// (at your option) any later version.
18
//
19
/****************************************************************************/
20
21
22
// ===========================================================================
23
// included modules
24
// ===========================================================================
25
#ifdef _MSC_VER
26
#include <
windows_config.h
>
27
#else
28
#include <
config.h
>
29
#endif
30
31
#ifndef NO_TRACI
32
33
#include "
TraCIConstants.h
"
34
#include <
microsim/output/MSDetectorControl.h
>
35
#include <
microsim/output/MSE3Collector.h
>
36
#include "
TraCIServerAPI_ArealDetector.h
"
37
38
#ifdef CHECK_MEMORY_LEAKS
39
#include <
foreign/nvwa/debug_new.h
>
40
#endif // CHECK_MEMORY_LEAKS
41
42
43
// ===========================================================================
44
// method definitions
45
// ===========================================================================
46
bool
47
TraCIServerAPI_ArealDetector::processGet
(
TraCIServer
& server,
tcpip::Storage
& inputStorage,
48
tcpip::Storage
& outputStorage) {
49
// variable & id
50
int
variable = inputStorage.
readUnsignedByte
();
51
std::string
id
= inputStorage.
readString
();
52
// check variable
53
if
(variable !=
ID_LIST
&& variable !=
ID_COUNT
&& variable !=
JAM_LENGTH_VEHICLE
&& variable !=
JAM_LENGTH_METERS
) {
54
return
server.
writeErrorStatusCmd
(
CMD_GET_AREAL_DETECTOR_VARIABLE
,
"Get Areal Detector Variable: unsupported variable specified"
, outputStorage);
55
}
56
57
// begin response building
58
tcpip::Storage
tempMsg;
59
// response-code, variableID, objectID
60
tempMsg.
writeUnsignedByte
(
RESPONSE_GET_AREAL_DETECTOR_VARIABLE
);
61
tempMsg.
writeUnsignedByte
(variable);
62
tempMsg.
writeString
(
id
);
63
if
(variable ==
ID_LIST
) {
64
std::vector<std::string> ids;
65
MSNet::getInstance
()->
getDetectorControl
().
getTypedDetectors
(
SUMO_TAG_LANE_AREA_DETECTOR
).
insertIDs
(ids);
66
tempMsg.
writeUnsignedByte
(
TYPE_STRINGLIST
);
67
tempMsg.
writeStringList
(ids);
68
}
else
if
(variable ==
ID_COUNT
) {
69
std::vector<std::string> ids;
70
MSNet::getInstance
()->
getDetectorControl
().
getTypedDetectors
(
SUMO_TAG_LANE_AREA_DETECTOR
).
insertIDs
(ids);
71
tempMsg.
writeUnsignedByte
(
TYPE_INTEGER
);
72
tempMsg.
writeInt
((
int
) ids.size());
73
}
else
{
74
MSE2Collector
* e2 =
static_cast<
MSE2Collector
*
>
(
MSNet::getInstance
()->
getDetectorControl
().
getTypedDetectors
(
SUMO_TAG_LANE_AREA_DETECTOR
).
get
(
id
));
75
if
(e2 == 0) {
76
return
server.
writeErrorStatusCmd
(
CMD_GET_AREAL_DETECTOR_VARIABLE
,
"Areal detector '"
+
id
+
"' is not known"
, outputStorage);
77
}
78
switch
(variable) {
79
case
ID_LIST
:
80
break
;
81
case
JAM_LENGTH_VEHICLE
:
82
tempMsg.
writeUnsignedByte
(
TYPE_INTEGER
);
83
tempMsg.
writeInt
((
int
) e2->
getCurrentJamLengthInVehicles
());
84
break
;
85
case
JAM_LENGTH_METERS
:
86
tempMsg.
writeUnsignedByte
(
TYPE_DOUBLE
);
87
tempMsg.
writeDouble
(e2->
getCurrentJamLengthInMeters
());
88
break
;
89
90
default
:
91
break
;
92
}
93
}
94
server.
writeStatusCmd
(
CMD_GET_AREAL_DETECTOR_VARIABLE
,
RTYPE_OK
,
""
, outputStorage);
95
server.
writeResponseWithLength
(outputStorage, tempMsg);
96
return
true
;
97
}
98
99
#endif
100
101
102
/****************************************************************************/
103
home
delphi
sumo
src
traci-server
TraCIServerAPI_ArealDetector.cpp
Generated by
1.8.2