Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support UNKNOWN for traffic light color/shape in TrafficSignalState #1219

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ auto toMsg(
return TrafficLightBulbMessageType::GREEN;
case TrafficLight_Color_WHITE:
return TrafficLightBulbMessageType::WHITE;
case TrafficLight_Color_UNKNOWN_COLOR:
return TrafficLightBulbMessageType::UNKNOWN;
default:
return TrafficLightBulbMessageType::UNKNOWN;
}
Expand Down Expand Up @@ -232,6 +234,8 @@ auto toMsg(
return TrafficLightBulbMessageType::DOWN_RIGHT_ARROW;
case TrafficLight_Shape_CROSS:
return TrafficLightBulbMessageType::CROSS;
case TrafficLight_Shape_UNKNOWN_SHAPE:
return TrafficLightBulbMessageType::UNKNOWN;
default:
return TrafficLightBulbMessageType::UNKNOWN;
}
Expand All @@ -246,6 +250,8 @@ auto toMsg(
return TrafficLightBulbMessageType::SOLID_ON;
case TrafficLight_Status_FLASHING:
return TrafficLightBulbMessageType::FLASHING;
case TrafficLight_Status_UNKNOWN_STATUS:
return TrafficLightBulbMessageType::UNKNOWN;
default:
return TrafficLightBulbMessageType::UNKNOWN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ struct TrafficLight
yellow,
red,
white,
unknown,
} value;

// clang-format off
static_assert(static_cast<std::uint8_t>(green ) == 0b0000'0000);
static_assert(static_cast<std::uint8_t>(yellow) == 0b0000'0001);
static_assert(static_cast<std::uint8_t>(red ) == 0b0000'0010);
static_assert(static_cast<std::uint8_t>(white ) == 0b0000'0011);
static_assert(static_cast<std::uint8_t>(green ) == 0b0000'0000);
static_assert(static_cast<std::uint8_t>(yellow ) == 0b0000'0001);
static_assert(static_cast<std::uint8_t>(red ) == 0b0000'0010);
static_assert(static_cast<std::uint8_t>(white ) == 0b0000'0011);
static_assert(static_cast<std::uint8_t>(unknown) == 0b0000'0100);
// clang-format on

constexpr Color(const Value value = green) : value(value) {}
Expand All @@ -64,6 +66,7 @@ struct TrafficLight
std::make_pair("red", red),
std::make_pair("white", white),
std::make_pair("yellow", yellow),
std::make_pair("unknown", unknown),

// BACKWARD COMPATIBILITY
std::make_pair("Green", green),
Expand Down Expand Up @@ -132,26 +135,29 @@ struct TrafficLight
circle,
cross,
arrow,
unknown,
};

// clang-format off
static_assert(static_cast<std::uint8_t>(Category::circle) == 0b0000'0000);
static_assert(static_cast<std::uint8_t>(Category::cross ) == 0b0000'0001);
static_assert(static_cast<std::uint8_t>(Category::arrow ) == 0b0000'0010);
static_assert(static_cast<std::uint8_t>(Category::circle ) == 0b0000'0000);
static_assert(static_cast<std::uint8_t>(Category::cross ) == 0b0000'0001);
static_assert(static_cast<std::uint8_t>(Category::arrow ) == 0b0000'0010);
static_assert(static_cast<std::uint8_t>(Category::unknown) == 0b0000'0011);
// clang-format on

enum Value : std::uint16_t {
// clang-format off
circle = static_cast<std::uint8_t>(Category::circle),
cross = static_cast<std::uint8_t>(Category::cross ),
left = (0b0000'1000 << 8) | static_cast<std::uint8_t>(Category::arrow ),
down = (0b0000'0100 << 8) | static_cast<std::uint8_t>(Category::arrow ),
up = (0b0000'0010 << 8) | static_cast<std::uint8_t>(Category::arrow ),
right = (0b0000'0001 << 8) | static_cast<std::uint8_t>(Category::arrow ),
lower_left = (0b0000'1100 << 8) | static_cast<std::uint8_t>(Category::arrow ),
upper_left = (0b0000'1010 << 8) | static_cast<std::uint8_t>(Category::arrow ),
lower_right = (0b0000'0101 << 8) | static_cast<std::uint8_t>(Category::arrow ),
upper_right = (0b0000'0011 << 8) | static_cast<std::uint8_t>(Category::arrow ),
circle = static_cast<std::uint8_t>(Category::circle ),
cross = static_cast<std::uint8_t>(Category::cross ),
left = (0b0000'1000 << 8) | static_cast<std::uint8_t>(Category::arrow ),
down = (0b0000'0100 << 8) | static_cast<std::uint8_t>(Category::arrow ),
up = (0b0000'0010 << 8) | static_cast<std::uint8_t>(Category::arrow ),
right = (0b0000'0001 << 8) | static_cast<std::uint8_t>(Category::arrow ),
lower_left = (0b0000'1100 << 8) | static_cast<std::uint8_t>(Category::arrow ),
upper_left = (0b0000'1010 << 8) | static_cast<std::uint8_t>(Category::arrow ),
lower_right = (0b0000'0101 << 8) | static_cast<std::uint8_t>(Category::arrow ),
upper_right = (0b0000'0011 << 8) | static_cast<std::uint8_t>(Category::arrow ),
unknown = static_cast<std::uint8_t>(Category::unknown),
// clang-format on
} value;

Expand All @@ -166,6 +172,7 @@ struct TrafficLight
static_assert(static_cast<std::uint16_t>(upper_left ) == 0b0000'1010'0000'0010);
static_assert(static_cast<std::uint16_t>(lower_right) == 0b0000'0101'0000'0010);
static_assert(static_cast<std::uint16_t>(upper_right) == 0b0000'0011'0000'0010);
static_assert(static_cast<std::uint16_t>(unknown ) == 0b0000'0000'0000'0011);
// clang-format on

constexpr Shape(const Value value = circle) : value(value) {}
Expand All @@ -183,6 +190,7 @@ struct TrafficLight
std::make_pair("upperLeft", Shape::upper_left),
std::make_pair("lowerRight", Shape::lower_right),
std::make_pair("upperRight", Shape::upper_right),
std::make_pair("unknown", Shape::unknown),

// BACKWARD COMPATIBILITY
std::make_pair("straight", Shape::up),
Expand Down Expand Up @@ -262,6 +270,8 @@ struct TrafficLight
return simulation_api_schema::TrafficLight_Color_RED;
case Color::white:
return simulation_api_schema::TrafficLight_Color_WHITE;
case Color::unknown:
return simulation_api_schema::TrafficLight_Color_UNKNOWN_COLOR;
default:
throw common::SyntaxError(std::get<Color>(value), " is not supported color.");
}
Expand Down Expand Up @@ -304,6 +314,8 @@ struct TrafficLight
return simulation_api_schema::TrafficLight_Shape_UP_LEFT_ARROW;
case Shape::upper_right:
return simulation_api_schema::TrafficLight_Shape_UP_RIGHT_ARROW;
case Shape::unknown:
return simulation_api_schema::TrafficLight_Shape_UNKNOWN_SHAPE;
default:
throw common::SyntaxError(std::get<Shape>(value), " is not supported as a shape.");
}
Expand Down
Loading