Ejemplo n.º 1
0
  void
  LocomotiveFactory::update(void)
  {
    if (!isPermitted())
      return;

    //check to see if we need to emit a producer identified event
    if (_producer_identified_flag)
      {
        OLCB_Event e(COMMAND_STATION_EVENT);
        while (!_link->sendProducerIdentified(NID, &e))
          ;
        _producer_identified_flag = false;
      }

    //This is where we should force a verifiedID from any recently created loco, as it would have missed
    // the initial request.
    for (uint8_t i = 0; i < NUM_SLOTS; ++i)
      {
        if (!_trains[i].verified && _trains[i].NID->alias) //"verified" is just a flag to let us know that it hasn't verified its
        // NID yet; checking alias ensures that it has been assigned one. In this case, we need to tell the node to
        // send out a verified ID message.
          {
            //  Serial.println("Sending VerifedNID");
            //((OLCB_CAN_Link*) _link)->sendVerifiedNID(_trains[i].NID);
            //_trains[i].verified = true;
          }
      }
  }
Ejemplo n.º 2
0
void OLCB_Event_Handler::update(void) //this method should be overridden to detect conditions for the production of events
{
	if(!isPermitted())
	{
		return;
	}
    // see if any replies are waiting to send
    //Serial.println("update===========");
    while (_sendEvent < _numEvents)
    {
    	//Serial.print("_sendEvent: ");
    	//Serial.println(_sendEvent);
    	//Serial.print("_numEvents: ");
    	//Serial.println(_numEvents);
        // OK to send, see if marked for some cause
        // ToDo: This only sends _either_ producer ID'd or consumer ID'd, not both
        if ( (_events[_sendEvent].flags & (IDENT_FLAG | OLCB_Event::CAN_PRODUCE_FLAG)) == (IDENT_FLAG | OLCB_Event::CAN_PRODUCE_FLAG))
        {
        	//Serial.println("identify produced events!");
            if(_link->sendProducerIdentified(NID, &_events[_sendEvent]))
            {
            	_events[_sendEvent].flags &= ~IDENT_FLAG;    // reset flag
            }
            break; // only send one from this loop
        }
        else if ( (_events[_sendEvent].flags & (IDENT_FLAG | OLCB_Event::CAN_CONSUME_FLAG)) == (IDENT_FLAG | OLCB_Event::CAN_CONSUME_FLAG))
        {
        	  //Serial.println("identify consumed events!");
            if(_link->sendConsumerIdentified(NID, &_events[_sendEvent]))
            {
            	_events[_sendEvent].flags &= ~IDENT_FLAG;    // reset flag
            }
            break; // only send one from this loop
        }
        else if (_events[_sendEvent].flags & PRODUCE_FLAG)
        {
	        //Serial.print("producing ");
	        //Serial.println(_sendEvent, DEC);
            if(_link->sendPCER(NID, &_events[_sendEvent]))
         		  _events[_sendEvent].flags &= ~PRODUCE_FLAG;    // reset flag   
            break; // only send one from this loop
        }
        else if (_events[_sendEvent].flags & TEACH_FLAG)
        {
			//Serial.println("ABOUT TO SEND TEACH MESSAGE");
			//Serial.println(_sendEvent, DEC);
			//Serial.println(_events[_sendEvent].val[6], HEX);
			//Serial.println(_events[_sendEvent].val[7], HEX);
            _link->sendLearnEvent(NID, &_events[_sendEvent]);
            	_events[_sendEvent].flags &= ~TEACH_FLAG;    // reset flag
            break; // only send one from this loop
        }
        else
        {
            // just skip
            ++_sendEvent;
        }
    }
}
Ejemplo n.º 3
0
void DCC_Proxy::update(void)
{
  if(!isPermitted())
    return;

  //check to see if we need to emit a producer identified event
  if (_producer_identified_flag)
  {
    OLCB_Event e(PROXY_SLOT_OCCUPIED);
    while (!_link->sendProducerIdentified(NID, &e));
    _producer_identified_flag = false;
  }

  uint32_t new_time = millis();
  if(_active)
  {
    if(_update_alias)
    {
      Serial.println("reacquiring alias");
      _update_alias = !_link->sendVerifyNID(NID, &DCC_NodeID);
      if(!_update_alias) //message has gone through
        _initial_blast = 10; //refresh status
      return;
    }

    //see if we need to send out any periodic updates
    if(_initial_blast)
    {
      Serial.print("Initial blast!! TRYING AGAIN! ");
      Serial.println(_initial_blast);
      _initial_blast--;
      //this is a hack to make sure the first commands get through while DCS Vnode is being allocated
      _dirty_speed = _dirty_FX = true; //send again!
    }

    if((new_time - _timer) >= 60000)
    {
      _timer = new_time;
      _dirty_speed = true;
      _dirty_FX = true;
    }
    if( _dirty_speed ) //if we are connected to CS, and either need to send an update or one minute has passed since last update:
    {
      sendSpeed();
    }
    if( _dirty_FX ) //if we are connected to CS, and either need to send an update or one minute has passed since last update:
    {
      sendFX();
    }
  }
  OLCB_Datagram_Handler::update();
}
Ejemplo n.º 4
0
/**
 * @brief OknoBazaru::wyswietlOpisDlaGracza	Wyświetla opis przedmiotu z listy posiadanych przez gracza
 * @param element	dane wpisu, który został wybrany.
 */
void MarketWindow::displayPlayerItem(const QModelIndex &index)
{
	wareList->setCurrentRow(-1);
	buyButton->setText(sellText);
	buyButton->setVisible(true);
	buyButton->setEnabled(true);

	const Item *item = player_->equipment()->backpack().at(index.row());
	equipButton->setVisible(true);
	if (isEquipped(item, player_))
		equipButton->setText(unequipText);
	else
		equipButton->setText(equipText);

	equipButton->setEnabled(isPermitted(item, player_));
	generateDescription(item, player_, itemDescriptionWidget);
}
/**
 * @brief wygenerujOpis		Generuje opis dla danego przedmiotu.
 * @param rzecz
 * @param gracz		Gracz, który miałby dany przedmiot nosić (do stwierdzenia czy może)
 * @param miejsce	QTextBrowser którego tekst ma być podmieniony na wygenerowany opis.
 */
void generateDescription(const Item *item, const Player *player, QTextBrowser *target)
{
	target->clear();

	QString equipped = isEquipped(item, player) ? "Tak" : "Nie";
	QString permitted = isPermitted(item, player) ? "Tak" : "Nie";
	QString minLevel = item->isStrong() ? QString::number(Player::MaxLevel) : "1";
	QString numberOfArtifacts = QString::number(player->equipment()->usedArtifacts().size());
	QString permittedClasses;
	for (int i = 0; i < PlayerRaceCount; ++i)
		if (isAllowedForClass(item, (PlayerClass)i))
			permittedClasses += PlayerClassString[i] + ". ";
	if (permittedClasses.size() > 2)
		permittedClasses.replace(permittedClasses.size() - 2, 2, "");

	//TODO color title acording to item quality
	target->setFontWeight(QFont::Bold);
	target->insertPlainText(item->name() + QString("\n\n"));
	target->setFontWeight(QFont::Normal);

	QString description;

	description += QString("typ: ") + RODZAJE_PRZEDMIOTOW[item->type()] + QString("\n");
	if (item->type() == artefakt)
		description += QString::fromUtf8("Założonych artefaktów: (") + numberOfArtifacts + QString("/") + QString::number(Item::ArtifactLimit) + QString(")\n");

	description += QString::fromUtf8("\ndozwolony od poziomu: ") + minLevel +  QString("\n");
	description += QString::fromUtf8("klasy zdolne używać przedmiotu: ") + permittedClasses +  QString("\n");
	description += QString::fromUtf8("czy dozwolony: ") + permitted +  QString("\n");
	description += QString::fromUtf8("czy założony: ") + equipped +  QString("\n\n");

	description += effectString(item->bonusMelee(), QString::fromUtf8("walka wręcz") );
	description += effectString(item->bonusRanged(), QString::fromUtf8("walka bronią dystansową") );
	description += effectString(item->bonusMagical(),  QString::fromUtf8("walka magiczna") );
	description += effectString(item->bonusDefence(), QString::fromUtf8("defence") );
	description += effectString(item->bonusPerception(), QString::fromUtf8("perception"));
	description += effectString(item->bonusHitPoints(), QString::fromUtf8("zdrowie"));
	description += effectString(item->bonusRegeneration(), QString::fromUtf8("regeneracja"));

	description += QString::fromUtf8("\nwartość kupna:  ") + QString::number(item->value());
	description += QString::fromUtf8("\nwartość sprzedaży:  ") + QString::number(item->value() / 2) + QString("\n");

	target->insertPlainText(description);
}
Ejemplo n.º 6
0
uint16_t DCC_Proxy::processDatagram(void)
{
  Serial.println("Got a datagram");

  if(!isPermitted()) // && (_rxDatagramBuffer->destination == *OLCB_Virtual_Node::NID))
    return DATAGRAM_REJECTED; // TODO NEED A WYA TO HANDLE THE UNPERMITTED CASE


  //make sure that it is a train control datagram, and handle that accordingly
  if(!_rxDatagramBuffer->length) //check for zeo length
      return DATAGRAM_REJECTED_DATAGRAM_TYPE_NOT_ACCEPTED;

  switch(_rxDatagramBuffer->data[0])
  {
  case DATAGRAM_MOTIVE:
    return handleTractionDatagram(_rxDatagramBuffer);
  case DATAGRAM_MEMCONFIG:
    return handleMemConfigDatagram(_rxDatagramBuffer);
  }		
  Serial.println("not a datagram we know"); //TODO HANDLE CONFIGURATION DATAGRAMS!!
  return DATAGRAM_REJECTED_DATAGRAM_TYPE_NOT_ACCEPTED;
}