Ejemplo n.º 1
0
void VisionSystem::pipeLineDetectorOn()
{
    addDownwardDetector(m_pipelineDetector);
    publish(EventType::PIPELINE_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 2
0
void Telemetry::pub(const char * topic, const char * msg)
{
    publish(topic,msg);
}
bool SynapseSimulatorUpdater<MType>::
start(std::function<bool()> thread_init,
      std::function<bool()> thread_destroy) {
  struct Synchronizer : public DataBuffer {
    DeviceNeuronStateBuffer<MType>* neuron_state;
    SynapticFireVectorBuffer<MType>* synaptic_fire;
    SynapticCurrentBuffer<MType>* synaptic_current;
    float simulation_time;
    float time_step;
  };
  auto synchronizer_publisher = new SpecificPublisher<Synchronizer>();
  for (size_t i = 0; i < num_buffers_; ++i) {
    synchronizer_publisher->addBlank(new Synchronizer());
  }
  auto master_function = [this,
                          synchronizer_publisher,
                          thread_init,
                          thread_destroy]() {
    thread_init();
    float simulation_time = 0.0f;
    float time_step = simulation_parameters_->getTimeStep();
    unsigned int simulation_step = 0;
    Mailbox mailbox;
    while(true) {
      DeviceNeuronStateBuffer<MType>* neuron_state = nullptr;
      neuron_state_subscription_->pull(&neuron_state, &mailbox);
      SynapticFireVectorBuffer<MType>* synaptic_fire = nullptr;
      fire_subscription_->pull(&synaptic_fire, &mailbox);
      if (!mailbox.wait(&neuron_state, &synaptic_fire)) {
        neuron_state_subscription_->cancel();
        fire_subscription_->cancel();
        if (neuron_state) {
          neuron_state->release();
        }
        if (synaptic_fire) {
          synaptic_fire->release();
        }
        delete synchronizer_publisher;
        break;
      }
      auto synchronizer = synchronizer_publisher->getBlank();
      auto synaptic_current = this->getBlank();
      synaptic_current->simulation_step = simulation_step;
      if (!synaptic_current->clear()) {
        std::cerr << "Failed to clear SynapticCurrentBuffer." <<
          std::endl;
      }
      synchronizer->neuron_state = neuron_state;
      synchronizer->synaptic_fire = synaptic_fire;
      synchronizer->synaptic_current = synaptic_current;
      synchronizer->time_step = time_step;
      synchronizer->simulation_time = simulation_time;
      auto prerelease_function = [this, synchronizer]() {
        this->publish(synchronizer->synaptic_current);
        synchronizer->neuron_state->release();
        synchronizer->synaptic_fire->release();
      };
      synchronizer->setPrereleaseFunction(prerelease_function);
      synchronizer_publisher->publish(synchronizer);
      simulation_time += time_step;
      ++simulation_step;
    }
    thread_destroy();
  };
  master_thread_ = std::thread(master_function);

  for (size_t i = 0; i < simulators_.size(); ++i) {
    auto simulator = simulators_[i];
    auto unit_offset = device_synaptic_vector_offsets_[i];
    auto subscription = synchronizer_publisher->subscribe();
    auto worker_function = [subscription, 
                            simulator, 
                            unit_offset,
                            thread_init,
                            thread_destroy]() {
      thread_init();
      auto word_offset = Bit::num_words(unit_offset);
      while (true) {
        auto synchronizer = subscription->pull();
        if (nullptr == synchronizer) {
          delete subscription;
          break;
        }
        SynapseUpdateParameters parameters;
        parameters.synaptic_fire =
          synchronizer->synaptic_fire->getFireBits() + word_offset;
        parameters.neuron_voltage =
          synchronizer->neuron_state->getVoltages();
        parameters.device_neuron_fire =
          synchronizer->neuron_state->getFireBits();
        parameters.synaptic_current =
          synchronizer->synaptic_current->getCurrents();
        parameters.write_lock =
          synchronizer->synaptic_current->getWriteLock();
        parameters.simulation_time = synchronizer->simulation_time;
        parameters.time_step = synchronizer->time_step;
        if (!simulator->update(&parameters)) {
          std::cerr << "An error occurred updating a SynapseSimulator." <<
            std::endl;
        }
        synchronizer->release();
      }
      thread_destroy();
    };
    worker_threads_.push_back(std::thread(worker_function));
  }
  return true;
}
Ejemplo n.º 4
0
void rice::tutorial::splitstream::MySplitStreamClient::deliver(::rice::p2p::commonapi::Id* id, ::rice::p2p::commonapi::Message* message)
{
    if(dynamic_cast< MySplitStreamClient_PublishContent* >(message) != nullptr) {
        publish();
    }
}
Ejemplo n.º 5
0
 void metadataSubscriptionCallback(ros::pub_sub_conn* conn)
 {
   publish( "map_metadata", meta_data_message_ );
 }
Ejemplo n.º 6
0
void VisionSystem::hedgeDetectorOn()
{
    addForwardDetector(m_hedgeDetector);
    publish(EventType::HEDGE_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 7
0
bool MQTT::publish(String& topic, const char* buf, uint32_t buf_len, int qos, int retain)
{
	return publish(topic.c_str(), buf, buf_len, qos, retain);
}
Ejemplo n.º 8
0
void VisionSystem::gateDetectorOn()
{
    addForwardDetector(m_gateDetector);
    publish(EventType::GATE_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 9
0
void VisionSystem::redLightDetectorOn()
{
    addForwardDetector(m_redLightDetector);
    publish(EventType::RED_LIGHT_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 10
0
void VisionSystem::downwardSafeDetectorOn()
{
    addDownwardDetector(m_downwardSafeDetector);
    publish(EventType::SAFE_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 11
0
void VisionSystem::downwardSafeDetectorOff()
{
    m_downward->removeDetector(m_downwardSafeDetector);
    publish(EventType::SAFE_DETECTOR_OFF,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 12
0
void VisionSystem::ductDetectorOff()
{
    m_forward->removeDetector(m_ductDetector);
    publish(EventType::DUCT_DETECTOR_OFF,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 13
0
void VisionSystem::ductDetectorOn()
{
    addForwardDetector(m_ductDetector);
    publish(EventType::DUCT_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 14
0
void VisionSystem::pipeLineDetectorOff()
{
    m_downward->removeDetector(m_pipelineDetector);
    publish(EventType::PIPELINE_DETECTOR_OFF,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 15
0
void VisionSystem::barbedWireDetectorOn()
{
    addForwardDetector(m_barbedWireDetector);
    publish(EventType::BARBED_WIRE_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 16
0
void VisionSystem::redLightDetectorOff()
{
    m_forward->removeDetector(m_redLightDetector);
    publish(EventType::RED_LIGHT_DETECTOR_OFF,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 17
0
void VisionSystem::barbedWireDetectorOff()
{
    m_forward->removeDetector(m_barbedWireDetector);
    publish(EventType::BARBED_WIRE_DETECTOR_OFF,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 18
0
void VisionSystem::buoyDetectorOn()
{
    addForwardDetector(m_buoyDetector);
    publish(EventType::BUOY_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 19
0
void VisionSystem::hedgeDetectorOff()
{
    m_forward->removeDetector(m_hedgeDetector);
    publish(EventType::HEDGE_DETECTOR_OFF,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 20
0
void VisionSystem::buoyDetectorOff()
{
    m_forward->removeDetector(m_buoyDetector);
    publish(EventType::BUOY_DETECTOR_OFF,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 21
0
bool MQTT::publish(const char* topic, String& data, int qos, int retain)
{
	return publish(topic, data.c_str(), data.length(), qos, retain);
}
Ejemplo n.º 22
0
void VisionSystem::targetDetectorOn()
{
    addForwardDetector(m_targetDetector);
    publish(EventType::TARGET_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 23
0
bool MQTTclient::publish(const String& topic, const float& msg) {
	return publish(topic, String(msg));
}
Ejemplo n.º 24
0
void VisionSystem::targetDetectorOff()
{
    m_forward->removeDetector(m_targetDetector);
    publish(EventType::TARGET_DETECTOR_OFF,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 25
0
void MosqConnect::pub(QString topic, QString subject)
{
    publish(NULL, topic.toAscii(), subject.size(), subject.toAscii());
}
Ejemplo n.º 26
0
void VisionSystem::windowDetectorOn()
{
    addForwardDetector(m_windowDetector);
    publish(EventType::WINDOW_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}
String MessageChannel::publish( MessageSession *p_session , MessagePublisher *pub , const char *msg ) {
	TextMessage *l_msg = new TextMessage();
	l_msg -> setMessageType( pub -> msgtype );
	l_msg -> setText( msg );
	return( publish( p_session , pub , l_msg ) );
}
Ejemplo n.º 28
0
void VisionSystem::windowDetectorOff()
{
    m_forward->removeDetector(m_windowDetector);
    publish(EventType::WINDOW_DETECTOR_OFF,
            core::EventPtr(new core::Event()));
}
Ejemplo n.º 29
0
/*!
 * \brief Publish a message
 * \param topic The topic of the publish
 * \param msg The (ASCII) message to publish
 *
 * Create a PUBLISH packet and send it to the MQTT server
 *
 * \returns false if sending the message failed somehow
 */
bool MQTT::publish(const char * topic, const char * msg, uint8_t qos)
{
    return publish(topic, (const uint8_t *)msg, strlen(msg), qos);
}
Ejemplo n.º 30
0
void VisionSystem::binDetectorOn()
{
    addDownwardDetector(m_binDetector);
    publish(EventType::BIN_DETECTOR_ON,
            core::EventPtr(new core::Event()));
}