Beispiel #1
0
void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Read tuples for data
  Tuple *temp_tuple = dict_find(iterator, MESSAGE_KEY_TEMPERATURE);
  Tuple *conditions_tuple = dict_find(iterator, MESSAGE_KEY_CONDITION_DESC);

  // If all data is available, use it
  if(temp_tuple && conditions_tuple) {
    signalSuccessfulWeatherUpdate();
    updateWeather((int)temp_tuple->value->int32, conditions_tuple->value->cstring);
  }
  
  bool requestWeatherUpdate = false;
  Tuple *app_id_tuple = dict_find(iterator, MESSAGE_KEY_OWM_APPID);
  if (app_id_tuple) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config App-ID: %s", app_id_tuple->value->cstring);
    if (setApiKey(app_id_tuple->value->cstring)) {
      APP_LOG(APP_LOG_LEVEL_DEBUG, "API key initialized, requesting weather update.");
      requestWeatherUpdate = true;
    }
  }
  
  Tuple *js_ready_tuple = dict_find(iterator, MESSAGE_KEY_JS_KIT_READY);
  if (js_ready_tuple) {
    setJsReady();
    requestWeatherUpdate = true;
  }
  
  Tuple *update_frequency_tuple = dict_find(iterator, MESSAGE_KEY_UPDATE_FREQ);
  if (update_frequency_tuple) {
    int32_t frequency = update_frequency_tuple->value->int32;
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Received update frequency %i", (unsigned int)frequency);
    setUpdateFrequencyInMinutes((unsigned int)frequency);
    requestWeatherUpdate = true;
  }
  
  Tuple *unit_temp_tuple = dict_find(iterator, MESSAGE_KEY_UNIT_TEMP);
  if (unit_temp_tuple) {
    char *unit = unit_temp_tuple->value->cstring;
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Received %s as temperature unit.", unit);
    bool useCelsius = strncmp(unit, "C", 1) == 0;
    setTemperatureUnitToCelsius(useCelsius);
    requestWeatherUpdate = true;
  }
  
  Tuple *weather_locale_tuple = dict_find(iterator, MESSAGE_KEY_WEATHER_LOCALE);
  if (weather_locale_tuple) {
    int32_t localeAsInt = weather_locale_tuple->value->int32;
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Received %i as locale.", (unsigned int)localeAsInt);
    setWeatherLocale(localeAsInt);
    requestWeatherUpdate = true;
  }
  
  
  if (requestWeatherUpdate) {
    checkWeatherUpdate();
  }
}
Beispiel #2
0
void SessionTimer::timerTimeout()
{
//    if (!counterMode)
    {
        EventData &eventData = EventData::getInstance();
        if (eventData.isSessionStarted() && !eventData.isQualiBreak())
        {
            if (timerDelay != 0)
            {
                --timerDelay;
                emit synchronizingTimer(timerDelay != 0 ? true : false);
            }

            else if (!(eventData.getEventType() == LTPackets::RACE_EVENT && eventData.getCompletedLaps() == eventData.getEventInfo().laps) &&
                !((eventData.getEventType() == LTPackets::QUALI_EVENT || eventData.getEventType() == LTPackets::RACE_EVENT) && eventData.getFlagStatus() == LTPackets::RED_FLAG))
            {
                int hours = eventData.getRemainingTime().hour();
                int mins = eventData.getRemainingTime().minute();
                int secs = eventData.getRemainingTime().second();
                --secs;
                if (secs < 0)
                {
                    secs = 59;
                    --mins;
                    eventData.saveWeather();
                    emit updateWeather();

                    if (mins < 0)
                    {
                        --hours;
                        mins = 59;

                        if (hours < 0)
                        {
                            secs = mins = hours = 0;

                            if (eventData.getEventType() == LTPackets::QUALI_EVENT && eventData.getQualiPeriod() < 3)
                                eventData.setQualiBreak(true);

                            else
                                eventData.setSessionFinished(true);
                        }
                    }
                }
                eventData.setRemainingTime(QTime(hours, mins, secs));
            }
        }
    }
    emit timeout();
}
Beispiel #3
0
void Weather::TimerHit()
{
    if (!isConnected())
        return;

    if (updateTimerID > 0)
        RemoveTimer(updateTimerID);

    IPState state = updateWeather();

    // Override weather state if required
    if (OverrideS[0].s == ISS_ON)
        state = IPS_OK;

    switch (state)
    {
        // Ok
        case IPS_OK:

            syncCriticalParameters();

            if (OverrideS[0].s == ISS_ON)
                critialParametersLP.s = IPS_OK;

            ParametersNP.s = state;
            IDSetNumber(&ParametersNP, nullptr);

            // If update period is set, then set up the timer
            if (UpdatePeriodN[0].value > 0)
                updateTimerID = SetTimer(static_cast<int>(UpdatePeriodN[0].value * 1000));

            return;

        // Alert
        // We retry every 5000 ms until we get OK
        case IPS_ALERT:
            ParametersNP.s = state;
            IDSetNumber(&ParametersNP, nullptr);
            break;

        // Weather update is in progress
        default:
            break;
    }

    updateTimerID = SetTimer(5000);
}
Beispiel #4
0
int MSNet::simulate(SUMOTime start, SUMOTime stop)
{
  OptionsCont &oc = OptionsCont::getOptions();
  if(oc.getSimulationVerbosity()>1)
    std::cout<<"----> void MSNet::simulate(...)"<<std::endl;  
  //if((oc.getString("net-file").find("munchen"))||
  // (oc.getString("net-file").find("munich")))
  if(oc.getSafeBool("ger"))
    setCity("munchen");
  //else if(oc.getString("net-file").find("cambiano"))
  else if(oc.getSafeBool("ita"))
    setCity("cambiano");
  else
    setCity("unknown");
  // the simulation loop
  MSNet::SimulationState state = SIMSTATE_RUNNING;
  myStep = start;
#ifndef NO_TRACI
#ifdef HAVE_PYTHON
  if(OptionsCont::getOptions().isSet("python-script")) {
    traci::TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
    WRITE_MESSAGE("Simulation End: Script ended");
    closeSimulation(start);
    return 0;
  }
#endif
#endif
  // Initialize weather conditions
  if(oc.isSet("fiet"))
    setCurrentEnvTemp(oc.getFloat("fiet"));
  else
    setCurrentEnvTemp(5.3);
  if(oc.isSet("fieh"))
    setCurrentEnvHum(oc.getFloat("fieh"));
  else
    setCurrentEnvHum(67.8);
  while(state == SIMSTATE_RUNNING)
  {
    if(myLogStepNumber)
        preSimStepOutput();
    simulationStep();
    // FIXME Custom wait
    //for(int i=0;i++<0x00003fff;)for(int j=0;j++<0x00000fff;);
    if(oc.getSafeBool("rwc") || oc.getSafeBool("rlwc"))
      updateWeather();
    if(myLogStepNumber)
        postSimStepOutput();
    state = simulationState(stop);
#ifndef NO_TRACI
    if(state != SIMSTATE_RUNNING)
    {
      if(OptionsCont::getOptions().getInt("remote-port") != 0 && !traci::TraCIServer::wasClosed())
        state = SIMSTATE_RUNNING;
    }
#endif
  }
  WRITE_MESSAGE("Simulation End: " + getStateMessage(state));
  // exit simulation loop
  closeSimulation(start);
  return 0;
}
Beispiel #5
0
LTWindow::LTWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::LTWindow), eventData(EventData::getInstance())
{    
    ui->setupUi(this);    

    currDriver = -1;

    streamReader = new DataStreamReader(this);
    prefs = new PreferencesDialog(this);
    settings = new QSettings(F1LTCore::iniFile(), QSettings::IniFormat, this);
    loginDialog = new LoginDialog(this);
    ltFilesManagerDialog = new LTFilesManagerDialog(this);
    trackRecordsDialog = new TrackRecordsDialog(this);
    saw = new SessionAnalysisWidget();
    stw = new SessionTimesWidget();
    driverTrackerWidget = new DriverTrackerWidget();
    aboutDialog = new AboutDialog(this);
    updatesCheckerDialog = new UpdatesCheckerDialog(this);

//    ui->trackStatusWidget->setupItems();

    connect(streamReader, SIGNAL(tryAuthorize()), this, SLOT(tryAuthorize()));
    connect(streamReader, SIGNAL(authorized(QString)), this, SLOT(authorized(QString)));
    connect(streamReader, SIGNAL(eventDataChanged(const DataUpdates&)), this, SLOT(eventDataChanged(const DataUpdates&)));
    connect(streamReader, SIGNAL(driverDataChanged(int, const DataUpdates&)), this, SLOT(driverDataChanged(int, const DataUpdates&)));
    connect(streamReader, SIGNAL(dataChanged(const DataUpdates&)), this, SLOT(dataChanged(const DataUpdates&)));
    connect(streamReader, SIGNAL(sessionStarted()), this, SLOT(sessionStarted()));
    connect(streamReader, SIGNAL(authorizationError()), this, SLOT(authorizationError()));
    connect(streamReader, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));
    connect(streamReader, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(error(QNetworkReply::NetworkError)));
    connect(streamReader, SIGNAL(noLiveSession(bool, QString)), this, SLOT(showNoSessionBoard(bool, QString)));

    connect(updatesCheckerDialog, SIGNAL(newVersionAvailable()), this, SLOT(onNewVersionAvailable()));

    sessionTimer = new SessionTimer(this);
    connect(sessionTimer, SIGNAL(updateWeather()), this, SLOT(updateWeather()));

    connect(&SeasonData::getInstance(), SIGNAL(seasonDataChanged()), &ImagesFactory::getInstance(), SLOT(reloadGraphics()));
    connect(&SeasonData::getInstance(), SIGNAL(seasonDataChanged()), &ColorsManager::getInstance(), SLOT(calculateDefaultDriverColors()));
    connect(&SeasonData::getInstance(), SIGNAL(seasonDataChanged()), saw, SLOT(setupColors()));


    connect(prefs, SIGNAL(driversColorsChanged()), saw, SLOT(setupColors()));

    eventRecorder = new EventRecorder(sessionTimer, this);
    eventPlayer = new EventPlayer(this);

    delayWidget = new DelayWidget(this);
    connect(delayWidget, SIGNAL(delayChanged(int, int)), streamReader, SLOT(setDelay(int, int)));
    connect(delayWidget, SIGNAL(delayChanged(int, int)), sessionTimer, SLOT(setDelay(int, int)));
    connect(sessionTimer, SIGNAL(synchronizingTimer(bool)), delayWidget, SLOT(synchronizingTimer(bool)));
    connect(sessionTimer, SIGNAL(synchronizingTimer(bool)), driverTrackerWidget, SLOT(pauseTimer(bool)));

    connect(ui->messageBoardWidget, SIGNAL(connectClicked()), this, SLOT(on_actionConnect_triggered()));
    connect(ui->messageBoardWidget, SIGNAL(playClicked()), this, SLOT(on_actionOpen_triggered()));
    connect(ui->messageBoardWidget, SIGNAL(loadClicked()), this, SLOT(on_actionLT_files_data_base_triggered()));

    loadSettings();
    ColorsManager::getInstance().calculateDefaultDriverColors();
    saw->setupColors();

    delayWidgetAction = ui->mainToolBar->addWidget(delayWidget);
    delayWidgetAction->setVisible(true);

    eventPlayerAction = ui->mainToolBar->addWidget(eventPlayer);
    eventPlayerAction->setVisible(false);
    recording = false;
    playing = false;

    connectionProgress = new QProgressDialog(this);

    connect(sessionTimer, SIGNAL(timeout()), this, SLOT(timeout()));
    connect(eventRecorder, SIGNAL(recordingStopped()), this, SLOT(autoStopRecording()));
    connect(eventPlayer, SIGNAL(playClicked(int)), this, SLOT(eventPlayerPlayClicked(int)));
    connect(eventPlayer, SIGNAL(pauseClicked()), this, SLOT(eventPlayerPauseClicked()));
    connect(eventPlayer, SIGNAL(rewindToStartClicked()), this, SLOT(eventPlayerRewindToStartClicked()));
    connect(eventPlayer, SIGNAL(forwardToEndClicked()), this, SLOT(eventPlayerForwardToEndClicked()));
    connect(eventPlayer, SIGNAL(rewindClicked()), this, SLOT(eventPlayerRewindClicked()));
    connect(eventPlayer, SIGNAL(stopClicked()), this, SLOT(eventPlayerStopClicked()));
    connect(eventPlayer, SIGNAL(nextPackets(QVector<Packet>)), streamReader, SLOT(parsePackets(QVector<Packet>)));

    connect(ui->ltWidget, SIGNAL(driverSelected(int)), ui->driverDataWidget, SLOT(printDriverData(int)));
    connect(ui->ltWidget, SIGNAL(driverDoubleClicked(int)), this, SLOT(ltWidgetDriverSelected(int)));


    ui->messageBoardWidget->setVisible(false);

    QStringList args = qApp->arguments();
    if (args.size() > 1)
    {
        if (eventPlayer->loadFromFile(args.at(1)) == false)
        {
            QMessageBox::critical(this, "Error opening file!", "Could not open specified file, or the file is corrupted.");
            connectToServer();
            return;
        }
        setWindowTitle("FILT - " + args.at(1));
        ui->actionRecord->setVisible(false);
        ui->actionStop_recording->setVisible(false);
        eventPlayerAction->setVisible(true);
        delayWidgetAction->setVisible(false);

        playing = true;

        eventPlayer->startPlaying();
    }
    else
    {
    	if (settings->value("ui/auto_connect").toBool())
    		connectToServer();
    	else
    	{
    		ui->messageBoardWidget->showStartupBoard();
    		showSessionBoard(true);
    	}
    }    

}