gusimplewhiteboard
SwitchSubsumptionTrafficLights.hpp
Go to the documentation of this file.
1/*
2 * SwitchSubsumptionTrafficLights.h
3 * gusimplewhiteboard
4 *
5 * Created by Vlad Estivill-Castro on 16/03/2016.
6 * Copyright © 2015 Vlad Estivill-Castro. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgement:
22 *
23 * This product includes software developed by Rene Hexel.
24 *
25 * 4. Neither the name of the author nor the names of contributors
26 * may be used to endorse or promote products derived from this
27 * software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * -----------------------------------------------------------------------
42 * This program is free software; you can redistribute it and/or
43 * modify it under the above terms or under the terms of the GNU
44 * General Public License as published by the Free Software Foundation;
45 * either version 2 of the License, or (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License
53 * along with this program; if not, see http://www.gnu.org/licenses/
54 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
55 * Fifth Floor, Boston, MA 02110-1301, USA.
56 *
57 */
58
59#ifndef SwitchSubsumptionTrafficLights_DEFINED
60#define SwitchSubsumptionTrafficLights_DEFINED
61
62
64#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
65#include <sstream>
66#include <ctype.h>
67#endif
68
69namespace guWhiteboard
70{
76 {
77 public:
79
80#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
82 SwitchSubsumptionTrafficLights(const std::string &light_configuration): wb_switch_subsumption_traffic_lights()
83 { from_string(light_configuration); }
84
86 std::string description() const
87 {
88 std::ostringstream ss;
89 for (int i=0 ; i< TL_SUBSUMPTION_LEVELS; i++)
90 switch (theConfigurations(i))
91 { case LIGHT_NO_COMMAND : ss << "null, "; break;
92 case LIGHT_NS_GREEN : ss << "ns_green, "; break;
93 case LIGHT_EW_GREEN : ss << "ew_green, "; break;
94 case LIGHT_NS_AMBER : ss << "ns_amber, "; break;
95 case LIGHT_EW_AMBER : ss << "ew_amber, "; break;
96 case LIGHT_NS_RED : ss << "ns_red, "; break;
97 case LIGHT_EW_RED : ss << "ew_red, "; break;
98 case LIGHT_EW_OFF : ss << "ew_off, "; break;
99 case LIGHT_NS_OFF : ss << "ns_off, "; break;
100 case LIGHT_ALL_OFF : ss << "all_off, "; break;
101 case LIGHT_BOTH_AMBER : ss << "b_amber, "; break;
102 }
103 return ss.str();
104 }
105
107 void from_string(const std::string &str)
108 { std::istringstream iss(str);
109 std::string token;
110 for (int i = 0; i < TL_SUBSUMPTION_LEVELS && getline(iss, token, ',') ; i++)
111 { const int n = atoi(token.c_str());
112 enum TrafficLightConfigurationValues &configuration = theConfigurations(i);
113 if (n<=0) configuration=LIGHT_NO_COMMAND;
114 switch (n)
115 { case 1 : configuration=LIGHT_NS_GREEN; break;
116 case 2 : configuration=LIGHT_EW_GREEN; break;
117 case 3 : configuration=LIGHT_NS_AMBER; break;
118 case 4 : configuration=LIGHT_EW_AMBER; break;
119 case 5 : configuration=LIGHT_NS_RED; break;
120 case 6 : configuration=LIGHT_EW_RED; break;
121 case 7 : configuration=LIGHT_ALL_OFF; break;
122 case 8 : configuration=LIGHT_NS_OFF; break;
123 case 9 : configuration=LIGHT_EW_OFF; break;
124 case 10 : configuration=LIGHT_BOTH_AMBER; break;
125 }
126 }
127 }
128#endif
129 };
130
135 {
136 public:
138
139#ifdef WHITEBOARD_POSTER_STRING_CONVERSION
141 TrafficLightConfiguration(const std::string &light_configuration): wb_traffic_light_configuration()
142 { from_string(light_configuration); }
143
145 std::string description() const
146 {
147 std::ostringstream ss;
148 switch (_lightConfiguration)
149 { case LIGHT_NO_COMMAND : ss << "null, "; break;
150 case LIGHT_NS_GREEN : ss << "ns_green, "; break;
151 case LIGHT_EW_GREEN : ss << "ew_green, "; break;
152 case LIGHT_NS_AMBER : ss << "ns_amber, "; break;
153 case LIGHT_EW_AMBER : ss << "ew_amber, "; break;
154 case LIGHT_NS_RED : ss << "ns_red, "; break;
155 case LIGHT_EW_RED : ss << "ew_red, "; break;
156 case LIGHT_ALL_OFF : ss << "all_off, "; break;
157 case LIGHT_EW_OFF : ss << "ew_off, "; break;
158 case LIGHT_NS_OFF : ss << "ns_off, "; break;
159 case LIGHT_BOTH_AMBER : ss << "b_amber, "; break;
160 }
161 return ss.str();
162 }
163
165 void from_string(const std::string &str)
166 { std::istringstream iss(str);
167 std::string token;
168 for (int i = 0; i < 1 && getline(iss, token, ',') ; i++)
169 { const int n = atoi(token.c_str());
170 if (n<=0) _lightConfiguration=LIGHT_NO_COMMAND;
171 switch (n)
172 { case 1 : _lightConfiguration=LIGHT_NS_GREEN; break;
173 case 2 : _lightConfiguration=LIGHT_EW_GREEN; break;
174 case 3 : _lightConfiguration=LIGHT_NS_AMBER; break;
175 case 4 : _lightConfiguration=LIGHT_EW_AMBER; break;
176 case 5 : _lightConfiguration=LIGHT_NS_RED; break;
177 case 6 : _lightConfiguration=LIGHT_EW_RED; break;
178 case 7 : _lightConfiguration=LIGHT_ALL_OFF; break;
179 case 8 : _lightConfiguration=LIGHT_NS_OFF; break;
180 case 9 : _lightConfiguration=LIGHT_EW_OFF; break;
181 case 10 : _lightConfiguration=LIGHT_BOTH_AMBER; break;
182 }
183 }
184 }
185#endif
186 };
187
188}
189#endif /* SwitchSubsumptionTrafficLights_DEFINED */
Subsumption SWITCH that select highest priority command.
SwitchSubsumptionTrafficLights(const std::string &light_configuration)
string constructor
void from_string(const std::string &str)
convert from a string
std::string description() const
convert to a string
TrafficLightConfiguration(const std::string &light_configuration)
string constructor
void from_string(const std::string &str)
convert from a string
/file APM_Interface.h
#define TL_SUBSUMPTION_LEVELS
/file wb_switch_subsumption_traffic_lights.h