<commit_before>#include <iostream>
#include <memory>
#include <thread>
#include <chrono>
#include <unordered_map>

#include <Eigen/Geometry>

#include <lcm/lcm-cpp.hpp>
#include <lcmtypes/drc/data_request_list_t.hpp>
#include <lcmtypes/drc/map_request_t.hpp>
#include <lcmtypes/drc/shaper_data_request_t.hpp>

#include <ConciseArgs>
#include <drc_utils/Clock.hpp>
#include <affordance/AffordanceUpWrapper.h>

using namespace std;

struct Worker {
  typedef std::shared_ptr<Worker> Ptr;

  bool mActive;
  drc::data_request_t mRequest;
  std::shared_ptr<lcm::LCM> mLcm;
  std::shared_ptr<affordance::AffordanceUpWrapper> mAffordanceWrapper;
  std::thread mThread;

  ~Worker() {
    stop();
  }

  void start() {
    if (mActive) return;
    if (mThread.joinable()) mThread.join();
    mActive = true;
    mThread = std::thread(std::ref(*this));
  }

  void stop() {
    mActive = false;
    mThread.join();
  }

  void operator()() {
    mActive = true;
    while (mActive) {

      switch(mRequest.type) {
      case drc::data_request_t::CAMERA_IMAGE:
        sendCameraImageRequest();
        break;
      case drc::data_request_t::MINIMAL_ROBOT_STATE:
        sendMinimalRobotStateRequest();
        break;
      case drc::data_request_t::AFFORDANCE_LIST:
        sendAffordanceListRequest();
        break;
      case drc::data_request_t::MAP_CATALOG:
        sendMapViewCatalogRequest();
        break;
      case drc::data_request_t::OCTREE_SCENE:
        sendOctreeSceneRequest();
        break;
      case drc::data_request_t::HEIGHT_MAP_SCENE:
        sendHeightMapSceneRequest();
        break;
      case drc::data_request_t::HEIGHT_MAP_CORRIDOR:
        sendHeightMapCorridorRequest();
        break;
      case drc::data_request_t::HEIGHT_MAP_COARSE:
        sendHeightMapCoarseRequest();
      case drc::data_request_t::DEPTH_MAP_SCENE:
        sendDepthMapSceneRequest();
        break;
      case drc::data_request_t::DEPTH_MAP_WORKSPACE:
        sendDepthMapWorkspaceRequest();
        break;
      case drc::data_request_t::TERRAIN_COST:
        sendTerrainCostRequest();
        break;
      default:
        cout << "Unknown request type" << endl;
        break;
      }

      // see if this is just a one-shot request
      if (mRequest.period == 0) {
        mActive = false;
        break;
      }

      // wait for timer expiry
      // period is in tenths of seconds, so conversion to milli = x100
      int millis = mRequest.period*100;
      std::this_thread::sleep_for(std::chrono::milliseconds(millis));
    }
  }

  void sendCameraImageRequest() {
    mLcm->publish("TRIGGER_CAMERA", &mRequest);
    cout << "Sent camera image request" << endl;
  }

  void sendMinimalRobotStateRequest() {
    mLcm->publish("TRIGGER_STATE", &mRequest);
    cout << "Sent minimal robot state request" << endl;
  }

  void sendAffordanceListRequest() {
    std::vector<affordance::AffPlusPtr> affordances;
    mAffordanceWrapper->getAllAffordancesPlus(affordances);
    drc::affordance_plus_collection_t msg;
    msg.name = "updateFromDataRequestServer";
    msg.utime = drc::Clock::instance()->getCurrentTime();
    msg.map_id = -1;
    msg.naffs = affordances.size();
    for (int i = 0; i < affordances.size(); ++i) {
      drc::affordance_plus_t affPlus;
      affordances[i]->toMsg(&affPlus);
      affPlus.aff.aff_store_control = drc::affordance_t::UPDATE;
      msg.affs_plus.push_back(affPlus);
    }
    mLcm->publish(affordance::AffordanceServer::
                  AFFORDANCE_PLUS_BASE_OVERWRITE_CHANNEL, &msg);
    cout << "Sent affordance list" << endl;
  }

  void sendMapViewCatalogRequest() {
    mLcm->publish("TRIGGER_MAP_CATALOG", &mRequest);
    cout << "Sent map catalog" << endl;
  }<commit_msg>only send affordance state updates from robot to base<commit_after>#include <iostream>
#include <memory>
#include <thread>
#include <chrono>
#include <unordered_map>

#include <Eigen/Geometry>

#include <lcm/lcm-cpp.hpp>
#include <lcmtypes/drc/data_request_list_t.hpp>
#include <lcmtypes/drc/map_request_t.hpp>
#include <lcmtypes/drc/shaper_data_request_t.hpp>

#include <ConciseArgs>
#include <drc_utils/Clock.hpp>
#include <affordance/AffordanceUpWrapper.h>

using namespace std;

struct Worker {
  typedef std::shared_ptr<Worker> Ptr;

  bool mActive;
  drc::data_request_t mRequest;
  std::shared_ptr<lcm::LCM> mLcm;
  std::shared_ptr<affordance::AffordanceUpWrapper> mAffordanceWrapper;
  std::thread mThread;

  ~Worker() {
    stop();
  }

  void start() {
    if (mActive) return;
    if (mThread.joinable()) mThread.join();
    mActive = true;
    mThread = std::thread(std::ref(*this));
  }

  void stop() {
    mActive = false;
    mThread.join();
  }

  void operator()() {
    mActive = true;
    while (mActive) {

      switch(mRequest.type) {
      case drc::data_request_t::CAMERA_IMAGE:
        sendCameraImageRequest();
        break;
      case drc::data_request_t::MINIMAL_ROBOT_STATE:
        sendMinimalRobotStateRequest();
        break;
      case drc::data_request_t::AFFORDANCE_LIST:
        sendAffordanceListRequest();
        break;
      case drc::data_request_t::MAP_CATALOG:
        sendMapViewCatalogRequest();
        break;
      case drc::data_request_t::OCTREE_SCENE:
        sendOctreeSceneRequest();
        break;
      case drc::data_request_t::HEIGHT_MAP_SCENE:
        sendHeightMapSceneRequest();
        break;
      case drc::data_request_t::HEIGHT_MAP_CORRIDOR:
        sendHeightMapCorridorRequest();
        break;
      case drc::data_request_t::HEIGHT_MAP_COARSE:
        sendHeightMapCoarseRequest();
      case drc::data_request_t::DEPTH_MAP_SCENE:
        sendDepthMapSceneRequest();
        break;
      case drc::data_request_t::DEPTH_MAP_WORKSPACE:
        sendDepthMapWorkspaceRequest();
        break;
      case drc::data_request_t::TERRAIN_COST:
        sendTerrainCostRequest();
        break;
      default:
        cout << "Unknown request type" << endl;
        break;
      }

      // see if this is just a one-shot request
      if (mRequest.period == 0) {
        mActive = false;
        break;
      }

      // wait for timer expiry
      // period is in tenths of seconds, so conversion to milli = x100
      int millis = mRequest.period*100;
      std::this_thread::sleep_for(std::chrono::milliseconds(millis));
    }
  }

  void sendCameraImageRequest() {
    mLcm->publish("TRIGGER_CAMERA", &mRequest);
    cout << "Sent camera image request" << endl;
  }

  void sendMinimalRobotStateRequest() {
    mLcm->publish("TRIGGER_STATE", &mRequest);
    cout << "Sent minimal robot state request" << endl;
  }

  void sendAffordanceListRequest() {
    std::vector<affordance::AffPlusPtr> affordances;
    mAffordanceWrapper->getAllAffordancesPlus(affordances);
    drc::affordance_plus_collection_t msg;
    msg.name = "updateFromDataRequestServer";
    msg.utime = drc::Clock::instance()->getCurrentTime();
    msg.map_id = -1;
    msg.naffs = affordances.size();
    for (int i = 0; i < affordances.size(); ++i) {
      drc::affordance_plus_t affPlus;
      affPlus.npoints = affPlus.ntriangles = 0;
      affordances[i]->aff->toMsg(&affPlus.aff);
      affPlus.aff.aff_store_control = drc::affordance_t::UPDATE;
      msg.affs_plus.push_back(affPlus);
    }
    mLcm->publish(affordance::AffordanceServer::
                  AFFORDANCE_PLUS_BASE_OVERWRITE_CHANNEL, &msg);
    cout << "Sent affordance list" << endl;
  }

  void sendMapViewCatalogRequest() {
    mLcm->publish("TRIGGER_MAP_CATALOG", &mRequest);
    cout << "Sent map catalog" << endl;
  }
{'fraction_non_alphanumeric': 0.12170922079640165, 'fraction_numerical': 0.0025135599947082947, 'mean_word_length': 3.3548387096774195, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3403197', 'n_tokens_mistral': 2628, 'n_tokens_neox': 2565, 'n_words': 449}