31using ::apollo::v2x::StatusResponse;
32using ::apollo::v2x::obu::ObuRsi;
33using ::apollo::v2x::obu::ObuTrafficLight;
37 : node_(::
apollo::cyber::CreateNode(
"v2x_grpc_server")) {
40 AINFO <<
"GrpcServerImpl initial success";
46 StatusResponse *response) {
47 ADEBUG <<
"Received SendV2xRSI request from client!";
48 ADEBUG << request->DebugString();
50 if (!request->has_header()) {
51 response->set_status(
false);
52 response->set_info(
"error no header in RSI request");
53 AERROR <<
"SendV2xRSI request has no header";
54 return Status::CANCELLED;
57 std::lock_guard<std::mutex> guard(rsi_mutex_);
58 latest_rsi_.CopyFrom(*request);
59 auto obu_header = latest_rsi_.mutable_header();
60 if (obu_header->has_timestamp_sec()) {
61 AINFO <<
"Obu Timestamp: " << std::setiosflags(std::ios::fixed)
62 << std::setprecision(11) << obu_header->timestamp_sec();
63 AINFO <<
"SVB Timestamp: " << std::setiosflags(std::ios::fixed)
69 rsi_condition_.notify_one();
71 response->set_status(
true);
72 AINFO <<
"SendV2xRSI response success.";
77 StatusResponse *response) {
78 ADEBUG <<
"Received SendPerceptionObstacles request from client!";
80 std::lock_guard<std::mutex> guard(obstacles_mutex_);
81 latest_obstacles_.CopyFrom(*request);
82 response->set_status(
true);
84 ADEBUG <<
"SendPerceptionObstacles response success.";
86 obs_condition_.notify_one();
91 grpc::ServerContext * ,
const ObuTrafficLight *request,
92 StatusResponse *response) {
93 ADEBUG <<
"Received SendV2xTrafficLight request from client!";
94 ADEBUG << request->DebugString();
96 int num_current_light = request->road_traffic_light_size();
98 if (0 == num_current_light) {
99 response->set_status(
false);
100 response->set_info(
"error v2x current lane traffic light size == 0");
101 AERROR <<
"SendV2xTrafficLight request no current lane traffic light.";
102 return Status::CANCELLED;
104 if (!request->has_header()) {
105 response->set_status(
false);
107 "error no header in IntersectionTrafficLightData request");
108 AERROR <<
"SendV2xTrafficLight request has no header";
109 return Status::CANCELLED;
112 std::lock_guard<std::mutex> guard(traffic_light_mutex_);
113 latest_traffic_light_.CopyFrom(*request);
114 auto obu_header = latest_traffic_light_.mutable_header();
115 if (obu_header->has_timestamp_sec()) {
120 traffic_light_condition_.notify_one();
121 auto cur_junction_id = request->intersection_id();
122 ADEBUG <<
"recieved the junction id " << cur_junction_id;
123 response->set_status(
true);
128 grpc::ServerContext *context, const ::apollo::v2x::ObuAlarm *request,
129 StatusResponse *response) {
130 ADEBUG <<
"Received SendOBUAlarm request from client!";
133 AERROR <<
"OBU id:" << request->error_msg();
135 response->set_status(
true);
140 if (
nullptr == ptr) {
143 std::unique_lock<std::mutex> guard(rsi_mutex_);
144 rsi_condition_.wait(guard, [
this] {
return rsi_refresh_; });
145 rsi_refresh_ =
false;
146 *ptr = std::make_shared<ObuRsi>();
147 if (
nullptr == *ptr) {
150 (*ptr)->CopyFrom(latest_rsi_);
154 std::shared_ptr<::apollo::v2x::V2XObstacles> *ptr) {
155 if (
nullptr == ptr) {
158 std::unique_lock<std::mutex> guard(obstacles_mutex_);
159 obs_condition_.wait(guard, [
this] {
return obs_refresh_; });
160 obs_refresh_ =
false;
161 *ptr = std::make_shared<::apollo::v2x::V2XObstacles>();
162 if (
nullptr == *ptr) {
165 (*ptr)->CopyFrom(latest_obstacles_);
169 if (
nullptr == ptr) {
172 std::unique_lock<std::mutex> guard(traffic_light_mutex_);
173 if (!traffic_light_condition_.wait_for(
174 guard, std::chrono::milliseconds(FLAGS_msg_timeout),
175 [
this] { return refresh_; })) {
176 AERROR <<
"GetMsgFromGrpc IntersectionTrafficLightData is timeout";
180 *ptr = std::make_shared<ObuTrafficLight>();
181 if (
nullptr == *ptr) {
184 (*ptr)->CopyFrom(latest_traffic_light_);
185 latest_traffic_light_.Clear();
static Time Now()
get the current time.
double ToSecond() const
convert time to second.
grpc::Status SendPerceptionObstacles(grpc::ServerContext *context, const apollo::v2x::V2XObstacles *request, StatusResponse *response) override
grpc::Status SendObuAlarm(grpc::ServerContext *context, const ::apollo::v2x::ObuAlarm *request, ::apollo::v2x::StatusResponse *response) override
grpc::Status SendV2xRSI(grpc::ServerContext *context, const ::apollo::v2x::obu::ObuRsi *request, ::apollo::v2x::StatusResponse *response)
grpc::Status SendV2xTrafficLight(grpc::ServerContext *context, const ::apollo::v2x::obu::ObuTrafficLight *request, ::apollo::v2x::StatusResponse *response) override
void GetMsgFromGrpc(std::shared_ptr<::apollo::v2x::obu::ObuTrafficLight > *ptr)
define v2x proxy module and onboard unit interface grpc implement
The gflags used by v2x proxy module