MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / communicate_with_device_slow

Function communicate_with_device_slow

OpenHD/ohd_interface/src/microhard_link.cpp:228–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226}
227
228void communicate_with_device_slow(const std::string& ip,
229 const std::string& command2) {
230 openhd::log::get_default()->warn(
231 "Starting slower communication with device at IP: {}", ip);
232
233 try {
234 std::this_thread::sleep_for(std::chrono::seconds(5));
235 Poco::Net::SocketAddress address(ip, 23);
236 Poco::Net::StreamSocket socket(address);
237 Poco::Net::SocketStream stream(socket);
238
239 // Login to the device
240 std::this_thread::sleep_for(std::chrono::seconds(1));
241 openhd::log::get_default()->debug("Sending username: {}", username);
242 stream << username << std::flush;
243 std::this_thread::sleep_for(std::chrono::seconds(1));
244
245 openhd::log::get_default()->debug("Sending password: {}", password);
246 stream << password << std::flush;
247 std::this_thread::sleep_for(std::chrono::seconds(3));
248
249 const std::vector<std::pair<std::string, std::regex>> commands = {
250 {command2, std::regex(R"(([-\d]+) dBm)", std::regex::icase)},
251 {command3, std::regex(R"(\b(\d+)\s*MHz\b)", std::regex::icase)},
252 {command4, std::regex(R"(\b(\d+)\s*MHz\b)", std::regex::icase)},
253 {command5, std::regex(R"(\b(\d+)\b)", std::regex::icase)},
254 {command6, std::regex(R"((-?\d+)\s*dBm\b)", std::regex::icase)},
255 {command7, std::regex(R"(\b(\d+)\s*dB\b)", std::regex::icase)}};
256
257 const std::vector<std::string> value_names = {
258 "TX-Power", "Bandwidth", "Frequency", "Rate Mode", "NoiseFloor", "SNR"};
259
260 while (true) {
261 for (size_t i = 0; i < commands.size(); ++i) {
262 send_command_and_process_response(stream, commands[i].first,
263 commands[i].second, value_names[i]);
264 }
265 std::this_thread::sleep_for(std::chrono::seconds(3));
266 }
267
268 } catch (const Poco::Exception& e) {
269 openhd::log::get_default()->warn("POCO Exception: {}", e.displayText());
270 } catch (const std::exception& e) {
271 openhd::log::get_default()->warn("Standard Exception: {}", e.what());
272 }
273}
274
275void MicrohardLink::monitor_gateway_signal_strength(
276 const std::string& gateway_ip) {

Callers

nothing calls this directly

Calls 3

debugMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected