Beispiel #1
0
void CPiface2::doWork(boost::shared_ptr<yApi::IYPluginApi> api)
{
    std::cout << "Piface2 is starting..." << std::endl;

    bool initializationError = false;

    m_configuration.initializeWith(api->getConfiguration());

    shared::CDataContainer details;
    details.set("provider", "PiFace2");
    details.set("shortProvider", "pf2");

    try
    {
        m_factory.reset( new CPiface2Factory(api, m_deviceName, m_configuration, details));
        m_ioManager = m_factory->getIOManager();


    }
    catch (const CInitializationException& e)
    {
        api->setPluginState(yApi::historization::EPluginState::kCustom, "InitializationError");
        std::cerr << e.what() << std::endl;
        initializationError = true;
    }

    // the main loop
    std::cout << "Piface2 plugin is running..." << std::endl;

    while (true)
    {
        // Wait for an event
        switch (api->getEventHandler().waitForEvents())
        {
        case yApi::IYPluginApi::kEventStopRequested:
        {
            std::cout << "Stop requested" << std::endl;
            api->setPluginState(yApi::historization::EPluginState::kStopped);
            return;
        }
        case kEvtIOStateReceived:
        {
            //Value received from DI
            if (!initializationError)
                m_ioManager->onCommand(api, api->getEventHandler().getEventData<const int>() );
            break;
        }
        case yApi::IYPluginApi::kEventDeviceCommand:
        {
            // Command received from Yadoms
            auto command(api->getEventHandler().getEventData<boost::shared_ptr<const yApi::IDeviceCommand> >());

            if (!initializationError)
                m_ioManager->onCommand(api, command);
            break;
        }
        case yApi::IYPluginApi::kEventUpdateConfiguration:
        {
            api->setPluginState(yApi::historization::EPluginState::kCustom, "updateConfiguration");
            onUpdateConfiguration(api, api->getEventHandler().getEventData<shared::CDataContainer>(), details);
            api->setPluginState(yApi::historization::EPluginState::kRunning);
            break;
        }
        default:
        {
            std::cerr << "Unknown message id" << std::endl;
            break;
        }
        }
    }
}
Beispiel #2
0
void CTeleInfo::doWork(boost::shared_ptr<yApi::IYPluginApi> api)
{
   std::cout << "Teleinfo is starting..." << std::endl;

   m_isDeveloperMode = api->isDeveloperMode();

   // Load configuration values (provided by database)
   m_configuration.initializeWith(api->getConfiguration());

   // Create the transceiver
   m_transceiver = CTeleInfoFactory::constructTransceiver(api);

   // Create the buffer handler
   m_receiveBufferHandler = CTeleInfoFactory::GetBufferHandler(api->getEventHandler(),
                                                               kEvtPortDataReceived,
                                                               512);

   m_waitForAnswerTimer = api->getEventHandler().createTimer(kAnswerTimeout,
                                                             shared::event::CEventTimer::kOneShot,
                                                             boost::posix_time::seconds(15));
   m_waitForAnswerTimer->stop();

   // Create the connection
   createConnection(api);

   // the main loop
   std::cout << "Teleinfo plugin is running..." << std::endl;

   // Timer used to read periodically information
   api->getEventHandler().createTimer(kEvtTimerRefreshTeleInfoData,
                                      shared::event::CEventTimer::kPeriodic,
                                      boost::posix_time::seconds(30));

   while (1)
   {
      // Wait for an event
      switch (api->getEventHandler().waitForEvents())
      {
      case yApi::IYPluginApi::kEventStopRequested:
      {
         std::cout << "Stop requested" << std::endl;
         api->setPluginState(yApi::historization::EPluginState::kStopped);
         return;
      }
      case kEvtPortConnection:
      {
         std::cout << "Teleinfo plugin :  Port Connection" << std::endl;
         api->setPluginState(yApi::historization::EPluginState::kCustom, "connecting");

         if (api->getEventHandler().getEventData<bool>())
            processTeleInfoConnectionEvent(api);
         else
            processTeleInfoUnConnectionEvent(api);

         break;
      }
      case kEvtPortDataReceived:
      {
         std::cout << "TeleInfo plugin :  DataReceived" << std::endl;

         processDataReceived(api,
                             api->getEventHandler().getEventData<const shared::communication::CByteBuffer>());

         break;
      }
      case kEvtTimerRefreshTeleInfoData:
      {
         // When received this timer, we restart the reception through the serial port
         std::cout << "Teleinfo plugin :  Resume COM" << std::endl;
         m_transceiver->ResetRefreshTags();
         m_receiveBufferHandler->resume();

         //Lauch a new time the time out to detect connexion failure
         m_waitForAnswerTimer->start();

         break;
      }
      case yApi::IYPluginApi::kEventUpdateConfiguration:
      {
         api->setPluginState(yApi::historization::EPluginState::kCustom, "updateConfiguration");
         onUpdateConfiguration(api, api->getEventHandler().getEventData<shared::CDataContainer>());
         api->setPluginState(yApi::historization::EPluginState::kRunning);

         break;
      }
      case kErrorRetryTimer:
      {
         createConnection(api);
         break;
      }
      case kAnswerTimeout:
      {
         std::cerr << "No answer received, try to reconnect in a while..." << std::endl;
         errorProcess(api);
         break;
      }
      default:
      {
         std::cerr << "Unknown message id" << std::endl;
         break;
      }
      }
   }
}
Beispiel #3
0
HLSManager::HLSManager(QObject *parent) :
    SegmentationManager(APPLE_HLS, parent),
    m_segmenter(NULL)
{
    onUpdateConfiguration();
}
void CTemp::doWork(boost::shared_ptr<yApi::IYPluginApi> context)
{
   try
   {
      YADOMS_LOG(information) << "CTemp is starting...";


      m_configuration->initializeWith(context->getConfiguration());
      // Declaration of the device and Associated keywords
      declareDevice(context);

      // Timer used to send fake sensor states periodically
      boost::shared_ptr<shared::event::CEventTimer> timer = context->getEventHandler().createTimer(kSendSensorsStateTimerEventId, shared::event::CEventTimer::kPeriodic, boost::posix_time::seconds(m_configuration->getIntConfParam()));
      


      // the main loop
      YADOMS_LOG(information) << "CTemp plugin is running...";

      
      context->setPluginState(yApi::historization::EPluginState::kRunning);

      while (1)
      {
         // Wait for an event
         switch (context->getEventHandler().waitForEvents())
         {
            case yApi::IYPluginApi::kEventUpdateConfiguration:
            {
               onUpdateConfiguration(context, context->getEventHandler().getEventData<shared::CDataContainer>());
               break;
            }

            case yApi::IYPluginApi::kEventDeviceCommand:
            {
               // Command received
               boost::shared_ptr<const yApi::IDeviceCommand> command = context->getEventHandler().getEventData<boost::shared_ptr<const yApi::IDeviceCommand> >();
               YADOMS_LOG(debug) << "Command received :" << command->toString();

               //do anything with commad values
            }
            break;

            case kSendSensorsStateTimerEventId:
            {
               // Timer used here to send sensors state to Yadoms periodically

               // Read sensor value and send data to Yadoms (temperatures, battery level, Rssi measure...)
               int second = Poco::DateTime().second(); //for example read data from device, (here get the current second in the now datetime)
               m_temperatureKeyword.set(second);


               YADOMS_LOG(debug) << "Send the periodically sensors state...";
               context->historizeData(m_deviceName, m_temperatureKeyword);
               break;
            }

            default:
            {
               YADOMS_LOG(error) << "Unknown message id";
               break;
            }
         }
      }
   }
   // Plugin must catch this end-of-thread exception to make its cleanup.
   // If no cleanup is necessary, still catch it, or Yadoms will consider
   // as a plugin failure.
   catch (boost::thread_interrupted&)
   {
      YADOMS_LOG(information) << "CTemp is stopping..." << std::endl;
   }
}
Beispiel #5
0
void COneWire::doWork(boost::shared_ptr<yApi::IYPluginApi> api)
{
   api->setPluginState(yApi::historization::EPluginState::kCustom, "connecting");

   std::cout << "OneWire is starting..." << std::endl;

   m_configuration->initializeWith(api->getConfiguration());
   m_engine = CFactory::createEngine(api, m_configuration);

   // 1-wire Network devices
   std::map<std::string, boost::shared_ptr<device::IDevice> > devices;

   // Periodic network refresh
   api->getEventHandler().createTimer(kEvtTimerNetworkRefresh,
                                      shared::event::CEventTimer::kPeriodic,
                                      boost::posix_time::seconds(5));

   api->setPluginState(yApi::historization::EPluginState::kRunning);

   // the main loop
   std::cout << "OneWire plugin is running..." << std::endl;

   while (1)
   {
      try
      {
         // Wait for an event
         switch (api->getEventHandler().waitForEvents())
         {
         case yApi::IYPluginApi::kEventStopRequested:
         {
            std::cout << "Stop requested" << std::endl;
            api->setPluginState(yApi::historization::EPluginState::kStopped);
            return;
         }
         case kEvtTimerNetworkRefresh:
         {
            // Scan 1-wire network for new devices and update our network image
            updateNetwork(api, devices, m_engine->scanNetwork());

            // Now read all devices state and historize data
            for (auto device = devices.begin(); device != devices.end(); ++device)
            {
               // Set here an interruption point because it can take some time in case of big networks
               boost::this_thread::interruption_point();

               boost::shared_ptr<device::IDevice> newDevice = device->second;
               newDevice->read();
               if (!newDevice->keywords().empty())
                  api->historizeData(newDevice->ident()->deviceName(),
                                     newDevice->keywords());
            }

            break;
         }
         case yApi::IYPluginApi::kEventDeviceCommand:
         {
            // A command was received from Yadoms
            auto command = api->getEventHandler().getEventData<boost::shared_ptr<const yApi::IDeviceCommand> >();
            onCommand(devices, command);

            break;
         }
         case yApi::IYPluginApi::kEventUpdateConfiguration:
         {
            onUpdateConfiguration(api, api->getEventHandler().getEventData<shared::CDataContainer>());
            break;
         }
         default:
         {
            std::cerr << "Unknown message id" << std::endl;
            break;
         }
         }
      }
      catch (COneWireException& e)
      {
         std::cerr << e.what() << std::endl;
      }
   }
}