diff --git a/app/exe/spark b/app/exe/spark index 2ed784a..63d44a7 100755 Binary files a/app/exe/spark and b/app/exe/spark differ diff --git a/app/src/Spark.cpp b/app/src/Spark.cpp index 021f00b..1c0f443 100644 --- a/app/src/Spark.cpp +++ b/app/src/Spark.cpp @@ -262,7 +262,7 @@ void get_patches(int event, int x, int y, int flags, void *param) display_header1_header2(frame_copy, DRAG_MESSAGE, UNDO_MESSAGE); for (const auto &parking_spot : parking_spots) { - putText(frame_copy, "id: " + parking_spot.slot_id, parking_spot.coords.tl(), FONT_HERSHEY_DUPLEX, 1.0, AVNET_COMPLEMENTARY, 2); + putText(frame_copy, "id: " + std::to_string(parking_spot.slot_id), parking_spot.coords.tl(), FONT_HERSHEY_DUPLEX, 1.0, AVNET_COMPLEMENTARY, 2); rectangle(frame_copy, parking_spot.coords, AVNET_COMPLEMENTARY, 2); } box_end = Point2f(x, y); @@ -333,40 +333,6 @@ void addButtonCallback(int, void *) goto redraw_rectangle; } -/***************************************** - * Function Name : removeButtonCallback - * Description : remove slot from the parking_spots vector based on the user input(comma separated input) - ******************************************/ -void removeButtonCallback(int, void *) -{ - Mat frame = Mat::zeros(600, 600, CV_8UC3); - putText(frame, "Enter comma separated integers to remove:", Point(50, 50), FONT_HERSHEY_SIMPLEX, 0.5, AVNET_COMPLEMENTARY, 1, LINE_AA); - imshow("Frame", frame); - string inputText; - int key = -1; - while (key != 13) - { - key = waitKey(0); - if (key != 13) - inputText += (char)key; - putText(frame, inputText, Point(100, 100), FONT_HERSHEY_SIMPLEX, 0.5, AVNET_GREEN, 1); - imshow("Frame", frame); - } - vector indicesToRemove; - stringstream ss(inputText); - int index; - while (ss >> index) - { - indicesToRemove.push_back(index); - if (ss.peek() == ',') - ss.ignore(); - } - for (int i = indicesToRemove.size() - 1; i >= 0; i--) - { - parking_spots.erase(parking_spots.begin() + indicesToRemove[i - 1]); - } -} - /***************************************** * Function Name : main_window_mouse_callback * Description : Handles edit slot / start inference state transitions/forwarding @@ -564,9 +530,9 @@ void process_frames(queue &frames, bool &stop, std::shared_ptrsendOccupancyDataDebounced(parking_spots)) + if (producerSocket && producerSocket->sendOccupancyDataThrottled(parking_spots)) { - std::cout << "Sent occupancy data" << std::endl; + // std::cout << "Sent occupancy data" << std::endl; } } } diff --git a/app/src/utils/SparkProducerSocket.cpp b/app/src/utils/SparkProducerSocket.cpp index b67e786..68612d6 100644 --- a/app/src/utils/SparkProducerSocket.cpp +++ b/app/src/utils/SparkProducerSocket.cpp @@ -195,13 +195,10 @@ SparkProducerSocket::~SparkProducerSocket() } } -/** - * @brief DEPRECATED IN FAVOR OF "sendOccupancyData(const std::vector &data)" - * Sends occupancy data to the server. - * @param data The data to be sent, represented as a pair of integers (taken, empty). - * @return True if the data is sent successfully, false otherwise. - */ -bool SparkProducerSocket::sendOccupancyData(const std::pair &data) +/// @brief Sends relevant telemetry to SPARK Datagram socket. If you have that socket configured with IoT connect, you can see the data in the IoT connect dashboard. +/// @param data Parking spots data, but for demo purposes, only 14 slots matter +/// @return True if the data is sent successfully, false otherwise. +bool SparkProducerSocket::sendOccupancyDataThrottled(const std::vector &data) { if (std::chrono::system_clock::now() < next_transmit_time) { @@ -212,43 +209,6 @@ bool SparkProducerSocket::sendOccupancyData(const std::pair &data) return false; } - std::string payload = std::to_string(data.first) + "," + std::to_string(data.second) + "\n"; - - int total = 0; - int bytes_sent; - int bytes_remaining = payload.length(); - while (total < payload.length()) - { - bytes_sent = sendto(sockfd, payload.c_str() + total, bytes_remaining, 0, spark_addrinfo->ai_addr, spark_addrinfo->ai_addrlen); - if (bytes_sent == -1) - { - break; - } - total += bytes_sent; - bytes_remaining -= bytes_sent; - } - bool success = bytes_sent != -1; - if (success) - { - next_transmit_time = std::chrono::system_clock::now() + min_transmit_period; - } - return success; -} - -/// @brief Sends relevant telemetry to SPARK Datagram socket. If you have that socket configured with IoT connect, you can see the data in the IoT connect dashboard. -/// @param data Parking spots data, but for demo purposes, only 14 slots matter -/// @return True if the data is sent successfully, false otherwise. -bool SparkProducerSocket::sendOccupancyDataDebounced(const std::vector &data) -{ - // if (std::chrono::system_clock::now() < next_transmit_time) - // { - // std::cout << "Telemetry not sent: too soon since last transmission. Time remaining: " - // << std::chrono::duration_cast(next_transmit_time - std::chrono::system_clock::now()).count() - // << "ms" - // << std::endl; - // return false; - // } - const auto taken = std::accumulate(begin(data), end(data), 0, [](const int &acc, const ParkingSpot &ps) { return acc + (ps.is_occupied ? 1 : 0); }); const auto empty = data.size() - taken; @@ -290,7 +250,7 @@ bool SparkProducerSocket::sendOccupancyDataDebounced(const std::vector &data); - bool sendOccupancyDataDebounced(const std::vector &data); + bool sendOccupancyDataThrottled(const std::vector &data); private: int sockfd;