diff --git a/src/network_systems/projects/local_transceiver/inc/at_cmds.h b/src/network_systems/projects/local_transceiver/inc/at_cmds.h index 88af36422..35dd21bfc 100644 --- a/src/network_systems/projects/local_transceiver/inc/at_cmds.h +++ b/src/network_systems/projects/local_transceiver/inc/at_cmds.h @@ -14,6 +14,7 @@ namespace AT const std::string DELIMITER = "\r\n"; const std::string STATUS_OK = "OK"; const std::string RSP_READY = "READY"; +const std::string GARBAGE = "\n"; const std::string CHECK_CONN = "AT"; const std::string SBD_SESSION = "AT+SBDIX"; // 5.144 diff --git a/src/network_systems/projects/local_transceiver/src/local_transceiver.cpp b/src/network_systems/projects/local_transceiver/src/local_transceiver.cpp index 2b4c976b8..cbe22ec0b 100644 --- a/src/network_systems/projects/local_transceiver/src/local_transceiver.cpp +++ b/src/network_systems/projects/local_transceiver/src/local_transceiver.cpp @@ -274,7 +274,7 @@ custom_interfaces::msg::Path LocalTransceiver::receive() continue; } - if (!rcvRsps({message_to_queue_cmd, AT::Line("\n")})) { + if (!rcvRsps({message_to_queue_cmd, AT::Line("\n"), AT::Line("+SBDRB:"), AT::Line("\n")})) { continue; } @@ -283,21 +283,22 @@ custom_interfaces::msg::Path LocalTransceiver::receive() continue; } - std::regex re( - R"(name=\"data\"; filename=\"[^\"]*\"\r?\n(?:.*\r?\n)*\r?\n([\s\S]*?)\r?\n--)", std::regex::ECMAScript); + std::string message_size_str; + std::string message; + std::string checksum; + uint16_t message_size_int = 0; - std::smatch match; - - if (std::regex_search(*buffer_data, match, re)) { - *buffer_data = match[1]; - std::stringstream ss; - ss << *buffer_data; - std::cout << ss.str() << std::endl; + if (buffer_data && buffer_data->size() >= 2) { + message_size_str = buffer_data->substr(0, 2); } else { - std::cout << "No match found." << std::endl; + continue; } - receivedDataBuffer = buffer_data.value(); + message_size_int = (static_cast(message_size_str[0]) << 8) | //NOLINT(readability-magic-numbers) + static_cast(message_size_str[1]); //NOLINT(readability-magic-numbers) + message = buffer_data->substr(2, message_size_int); + + receivedDataBuffer = message; break; } @@ -367,7 +368,7 @@ std::optional LocalTransceiver::readRsp() error_code ec; // Caution: will hang if another proccess is reading from serial port - bio::read_until(serial_, buf, AT::DELIMITER, ec); + bio::read_until(serial_, buf, AT::STATUS_OK, ec); if (ec) { return std::nullopt; } diff --git a/src/network_systems/projects/local_transceiver/test/test_local_transceiver.cpp b/src/network_systems/projects/local_transceiver/test/test_local_transceiver.cpp index 94914455c..d7b0dba7d 100644 --- a/src/network_systems/projects/local_transceiver/test/test_local_transceiver.cpp +++ b/src/network_systems/projects/local_transceiver/test/test_local_transceiver.cpp @@ -227,61 +227,71 @@ TEST_F(TestLocalTransceiver, parseInMsgValid) EXPECT_EQ(parsed_test.waypoints[1].longitude, holder); } -// std::mutex port_mutex; - -// TEST_F(TestLocalTransceiver, testMailboxBlackbox) -// { -// std::lock_guard lock(port_mutex); // because same port is being used - -// std::string holder = "curl -X POST -F \"test=1234\" http://localhost:8080"; -// std::string holder2 = "printf \"at+sbdix\r\" > $LOCAL_TRANSCEIVER_TEST_PORT"; - -// system(holder.c_str()); //NOLINT -// system(holder2.c_str()); //NOLINT - -// std::optional response = lcl_trns_->readRsp(); -// std::cout << *response << std::endl; -// } - -// TEST_F(TestLocalTransceiver, parseReceiveMessageBlackbox) -// { -// std::lock_guard lock(port_mutex); - -// constexpr float holder = 14.3; -// Polaris::GlobalPath sample_data; - -// Polaris::Waypoint * waypoint_a = sample_data.add_waypoints(); -// waypoint_a->set_latitude(holder); -// waypoint_a->set_longitude(holder); -// Polaris::Waypoint * waypoint_b = sample_data.add_waypoints(); -// waypoint_b->set_latitude(holder); -// waypoint_b->set_longitude(holder); - -// std::string serialized_data; -// ASSERT_TRUE(sample_data.SerializeToString(&serialized_data)); - -// std::ofstream outfile("/tmp/serialized_data.bin", std::ios::binary); -// outfile.write(serialized_data.data(), static_cast(serialized_data.size())); -// outfile.close(); - -// std::string holder2 = "curl -X POST -F \"data=@/tmp/serialized_data.bin\" http://localhost:8080"; -// std::system(holder2.c_str()); //NOLINT - -// custom_interfaces::msg::Path received_data = lcl_trns_->receive(); - -// Polaris::GlobalPath global_path; -// for (const auto & waypoint : received_data.waypoints) { -// Polaris::Waypoint * new_waypoint = global_path.add_waypoints(); -// new_waypoint->set_latitude(waypoint.latitude); -// new_waypoint->set_longitude(waypoint.longitude); -// } - -// if (global_path.waypoints_size() > 0) { -// ASSERT_EQ(global_path.waypoints_size(), sample_data.waypoints_size()) -// << "Mismatch in number of waypoints received."; -// ASSERT_EQ(global_path.waypoints(0).latitude(), holder); -// ASSERT_EQ(global_path.waypoints(0).longitude(), holder); -// } else { -// std::cout << "No waypoints received." << std::endl; -// } -// } +std::mutex port_mutex; + +TEST_F(TestLocalTransceiver, testMailboxBlackbox) +{ + std::lock_guard lock(port_mutex); // because same port is being used + + std::string holder = "curl -X POST -F \"test=1234\" http://localhost:8080"; + std::string holder2 = "printf \"at+sbdix\r\" > $LOCAL_TRANSCEIVER_TEST_PORT"; + + system(holder.c_str()); //NOLINT + system(holder2.c_str()); //NOLINT + + std::optional response = lcl_trns_->readRsp(); + std::cout << *response << std::endl; +} + +TEST_F(TestLocalTransceiver, parseReceiveMessageBlackbox) +{ + std::lock_guard lock(port_mutex); + + constexpr float holder = 10.3; + Polaris::GlobalPath sample_data; + + Polaris::Waypoint * waypoint_a = sample_data.add_waypoints(); + waypoint_a->set_latitude(holder); + waypoint_a->set_longitude(holder); + Polaris::Waypoint * waypoint_b = sample_data.add_waypoints(); + waypoint_b->set_latitude(holder); + waypoint_b->set_longitude(holder); + + std::string serialized_data; + ASSERT_TRUE(sample_data.SerializeToString(&serialized_data)); + + uint16_t message_size = static_cast(serialized_data.size()); + uint16_t message_size_be = htons(message_size); // Convert to big-endian + + std::string size_prefix(reinterpret_cast(&message_size_be), sizeof(message_size_be)); + + std::ofstream outfile("/tmp/serialized_data.bin", std::ios::binary); + outfile.write(size_prefix.data(), size_prefix.size()); //NOLINT + outfile.write(serialized_data.data(), static_cast(serialized_data.size())); + outfile.close(); + + outfile.close(); // Close the file after writing + + std::string holder2 = "curl -X POST --data-binary @/tmp/serialized_data.bin http://localhost:8080"; + std::system(holder2.c_str()); //NOLINT + std::string test_cmd = "hexdump -C /tmp/serialized_data.bin"; + std::system(test_cmd.c_str()); //NOLINT + + custom_interfaces::msg::Path received_data = lcl_trns_->receive(); + + Polaris::GlobalPath global_path; + for (const auto & waypoint : received_data.waypoints) { + Polaris::Waypoint * new_waypoint = global_path.add_waypoints(); + new_waypoint->set_latitude(waypoint.latitude); + new_waypoint->set_longitude(waypoint.longitude); + } + + if (global_path.waypoints_size() > 0) { + ASSERT_EQ(global_path.waypoints_size(), sample_data.waypoints_size()) + << "Mismatch in number of waypoints received."; + ASSERT_EQ(global_path.waypoints(0).latitude(), holder); + ASSERT_EQ(global_path.waypoints(0).longitude(), holder); + } else { + std::cout << "No waypoints received." << std::endl; + } +} diff --git a/src/website/views/components/DropDown/DropDown.module.css b/src/website/views/components/DropDown/Dropdown.module.css similarity index 99% rename from src/website/views/components/DropDown/DropDown.module.css rename to src/website/views/components/DropDown/Dropdown.module.css index 319627b98..25b4eca98 100644 --- a/src/website/views/components/DropDown/DropDown.module.css +++ b/src/website/views/components/DropDown/Dropdown.module.css @@ -100,4 +100,3 @@ position: absolute; right: 15px; } -