73 {
74 switch (sd.type_case()) {
75 case config::Stream::kSerial:
76 if (!sd.serial().has_device()) {
77 AERROR <<
"Serial def has no device field.";
78 return nullptr;
79 }
80 if (!sd.serial().has_baud_rate()) {
81 AERROR <<
"Serial def has no baud_rate field. Use default baud rate "
82 << sd.serial().baud_rate();
83 return nullptr;
84 }
85 return Stream::create_serial(sd.serial().device().c_str(),
86 sd.serial().baud_rate());
87
88 case config::Stream::kTcp:
89 if (!sd.tcp().has_address()) {
90 AERROR <<
"tcp def has no address field.";
91 return nullptr;
92 }
93 if (!sd.tcp().has_port()) {
94 AERROR <<
"tcp def has no port field.";
95 return nullptr;
96 }
97 return Stream::create_tcp(sd.tcp().address().c_str(),
98 static_cast<uint16_t>(sd.tcp().port()));
99
100 case config::Stream::kUdp:
101 if (!sd.udp().has_address()) {
102 AERROR <<
"tcp def has no address field.";
103 return nullptr;
104 }
105 if (!sd.udp().has_port()) {
106 AERROR <<
"tcp def has no port field.";
107 return nullptr;
108 }
109 return Stream::create_udp(sd.udp().address().c_str(),
110 static_cast<uint16_t>(sd.udp().port()));
111
112 case config::Stream::kNtrip:
113 if (!sd.ntrip().has_address()) {
114 AERROR <<
"ntrip def has no address field.";
115 return nullptr;
116 }
117 if (!sd.ntrip().has_port()) {
118 AERROR <<
"ntrip def has no port field.";
119 return nullptr;
120 }
121 if (!sd.ntrip().has_mount_point()) {
122 AERROR <<
"ntrip def has no mount point field.";
123 return nullptr;
124 }
125 if (!sd.ntrip().has_user()) {
126 AERROR <<
"ntrip def has no user field.";
127 return nullptr;
128 }
129 if (!sd.ntrip().has_password()) {
130 AERROR <<
"ntrip def has no passwd field.";
131 return nullptr;
132 }
133 return Stream::create_ntrip(
134 sd.ntrip().address(), static_cast<uint16_t>(sd.ntrip().port()),
135 sd.ntrip().mount_point(), sd.ntrip().user(), sd.ntrip().password(),
136 sd.ntrip().timeout_s());
137 case config::Stream::kCanCardParameter:
138 if (!sd.can_card_parameter().has_brand()) {
139 AERROR <<
"can_card_parameter def has no brand field.";
140 return nullptr;
141 }
142 if (!sd.can_card_parameter().has_type()) {
143 AERROR <<
"can_card_parameter def has no type field.";
144 return nullptr;
145 }
146 if (!sd.can_card_parameter().has_channel_id()) {
147 AERROR <<
"can_card_parameter def has no channel_id field.";
148 return nullptr;
149 }
150 if (!sd.can_card_parameter().has_channel_id()) {
151 AERROR <<
"can_card_parameter def has no channel_id field.";
152 return nullptr;
153 }
154 return Stream::create_can(sd.can_card_parameter());
155 default:
156 return nullptr;
157 }
158}