int writeCheckpoint(EvaluationState* es)
{
    FILE* f;

    /* Avoid corrupting the checkpoint file by writing to a temporary file, and moving that */
    f = mw_fopen(CHECKPOINT_FILE_TMP, "wb");
    if (!f)
    {
        mwPerror("Opening checkpoint '%s'", CHECKPOINT_FILE_TMP);
        return 1;
    }

    es->lastCheckpointNuStep = es->nu_step;
    writeState(f, es);
    fclose(f);

    if (mw_rename(CHECKPOINT_FILE_TMP, resolvedCheckpointPath))
    {
        mwPerror("Failed to update checkpoint file ('%s' to '%s')",
                 CHECKPOINT_FILE_TMP,
                 resolvedCheckpointPath
            );
        return 1;
    }

    return 0;
}
Exemplo n.º 2
0
void FLManagerModules::finish() {
  writeState();

  if ( dictKeyFiles ) {
    delete dictKeyFiles;
    dictKeyFiles = 0;
  }

  if ( listAllIdModules_ ) {
    delete listAllIdModules_;
    listAllIdModules_ = 0;
  }

  if ( listIdAreas_ ) {
    delete listIdAreas_;
    listIdAreas_ = 0;
  }

  if ( dictModFiles ) {
    delete dictModFiles;
    dictModFiles = 0;
  }

  if ( dictInfoMods ) {
    delete dictInfoMods;
    dictInfoMods = 0;
  }

  FLMemCache::clear();
}
Exemplo n.º 3
0
/**
 * @timef
 * NOTES:
 *     - Only the activity buffer covers the extended frame - this is the frame that
 * includes boundaries.
 *     - The membrane potential V covers the "real" or "restricted" frame.
 *     - In MPI runs, xLoc and yLoc refer to global coordinates.
 *     writeState is only called by the processor with (xLoc,yLoc) in its
 *     non-extended region.
 */
int PointProbe::outputState(double timef)
{
   getValues(timef);
   if (parent->columnId()==0) {
      return writeState(timef);
   }
   else{
      return PV_SUCCESS;
   }
}
Exemplo n.º 4
0
bool ompl::control::OpenDEStateSpace::evaluateCollision(const base::State *state) const
{
    if ((state->as<StateType>()->collision & (1 << STATE_COLLISION_KNOWN_BIT)) != 0)
        return (state->as<StateType>()->collision & (1 << STATE_COLLISION_VALUE_BIT)) != 0;
    env_->mutex_.lock();
    writeState(state);
    CallbackParam cp = {env_.get(), false};
    for (unsigned int i = 0; !cp.collision && i < env_->collisionSpaces_.size(); ++i)
        dSpaceCollide(env_->collisionSpaces_[i], &cp, &nearCallback);
    env_->mutex_.unlock();
    if (cp.collision)
        state->as<StateType>()->collision &= (1 << STATE_COLLISION_VALUE_BIT);
    state->as<StateType>()->collision &= (1 << STATE_COLLISION_KNOWN_BIT);
    return cp.collision;
}
Exemplo n.º 5
0
int LayerFunctionProbe::outputState(double timef) {
   for(int b = 0; b < getTargetLayer()->getParent()->getNBatch(); b++){
      pvdata_t val = function->evaluate(timef, getTargetLayer(), b);
#ifdef PV_USE_MPI
      if( getTargetLayer()->getParent()->icCommunicator()->commRank() != 0 ) return PV_SUCCESS;
#endif // PV_USE_MPI
      if( function ) {
         return writeState(timef, getTargetLayer(), b, val);
      }
      else {
         fprintf(stderr, "LayerFunctionProbe \"%s\" for layer %s: function has not been set\n", getMessage(), getTargetLayer()->getName());
         return PV_FAILURE;
      }
   }
   return PV_SUCCESS;
}  // end LayerFunctionProbe::outputState(float, HyPerLayer *)
Exemplo n.º 6
0
void HIDBridge_::task(void){
	//TODO implement Serialevent strong for this task?
#ifdef HIDBRIDGE_RX
	// if hid request timed out, send a new one
	// this is important if the main mcu gets a reset or misses an acknowledge
	uint32_t currentMillis = millis();
	if ((currentMillis - writeTimeout) > HIDBRIDGE_TX_TIMEOUT) {
		writeState();
		// do not write timeout value, will be written in the function above
#ifdef USB_DEBUG
		debug->println("ack 1s");
#endif
	}
#endif

	// read in new controls or data
	read();
}
Exemplo n.º 7
0
void rom_file::saveState(uint8_t *state, size_t length) {
    writeState(state, length);
}
Exemplo n.º 8
0
/* ========================================================================= */
static int writeHMM(xmlTextWriterPtr writer, ghmm_xmlfile* f, int number) {
#define CUR_PROC "writeHMM"
  int rc=0, i, N;
  int w_cos;
  double w_prior;
  char *w_name;
  char * w_type;

  /* start HMM */
  if (0 > xmlTextWriterStartElement(writer, BAD_CAST "HMM")) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterStartElement (HMM)");
    goto STOP;;
  }

  /* write HMM attributes applicable */
  switch (f->modelType & PTR_TYPE_MASK) {
  case GHMM_kDiscreteHMM:
    w_name  = f->model.d[number]->name;
    w_type  = strModeltype(f->model.d[number]->model_type);
    w_prior = f->model.d[number]->prior;
    N       = f->model.d[number]->N;
    w_cos   = 1;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses):
    w_name  = f->model.ds[number]->name;
    w_type  = strModeltype(f->model.ds[number]->model_type);
    w_prior = f->model.ds[number]->prior;
    N       = f->model.ds[number]->N;
    w_cos   = 0;
    break;
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM):
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses):
    /*
    w_name  = f->model.dp[number]->name;
    w_type  = strModeltype(f->model.dp[number]->model_type);
    w_prior = f->model.dp[number]->prior;
    N       = f->model.dp[number]->N;
    w_cos   = 0;
    */
    break;
  case GHMM_kContinuousHMM:
  case (GHMM_kContinuousHMM+GHMM_kMultivariate):
  case (GHMM_kContinuousHMM+GHMM_kTransitionClasses):
  case (GHMM_kContinuousHMM+GHMM_kMultivariate+GHMM_kTransitionClasses):
    w_name  = f->model.c[number]->name;
    if (f->model.c[number]->model_type)
      w_type  = strModeltype(f->model.c[number]->model_type);
    else
      w_type  = strModeltype(f->modelType);
    w_prior = f->model.c[number]->prior;
    N       = f->model.c[number]->N;
    w_cos   = f->model.c[number]->cos;
    break;
  default:
    GHMM_LOG(LERROR, "invalid modelType");
    goto STOP;}

  if (w_name) {
    if (xmlTextWriterWriteAttribute(writer, BAD_CAST "name", w_name))
      GHMM_LOG(LERROR, "writing HMM name failed");
  }
  if (xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST w_type))
    GHMM_LOG(LERROR, "writing HMM type failed");

  if (w_prior >= 0.0) {
    WRITE_DOUBLE_ATTRIBUTE(writer, "prior", w_prior);
  }

  if (w_cos > 1)
    if (0 > xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "transitionClasses",
                                              "%d", w_cos))
      GHMM_LOG(LERROR, "failed to write no of transitionClasses");
   

  /* write alphabet if applicable */
  switch (f->modelType & (GHMM_kDiscreteHMM + GHMM_kTransitionClasses
                          + GHMM_kPairHMM)) {
  case GHMM_kDiscreteHMM:
    rc = writeAlphabet(writer, f->model.d[number]->alphabet, kAlphabet);
    break;
  case (GHMM_kDiscreteHMM+GHMM_kTransitionClasses):
    /*rc = writeAlphabet(writer, f->model.ds[number]->alphabet, kAlphabet);*/
    break;
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM):
  case (GHMM_kDiscreteHMM+GHMM_kPairHMM+GHMM_kTransitionClasses):
    /*rc = writeAlphabet(writer, f->model.dp[number]->alphabets[0], kAlphabet);
    if (rc) {
      GHMM_LOG(LERROR, "writing first alphabet of discrete pair HMM failed");
      goto STOP;
    }
    rc = writeAlphabet(writer, f->model.dp[number]->alphabets[1], kAlphabet);*/
    break;
  }

  if (rc) {
      GHMM_LOG_PRINTF(LERROR, LOC, "writing alphabet for HMM %d (type %s) failed",
                      number, strModeltype(f->modelType));
      goto STOP;
  }

  /* write label alphabet if applicable */
  if ((f->modelType & PTR_TYPE_MASK) == GHMM_kDiscreteHMM
      && f->modelType & GHMM_kLabeledStates) {
    if (writeAlphabet(writer, f->model.d[number]->label_alphabet, kLabelAlphabet))
      GHMM_LOG(LERROR, "writing of label alphabet failed");
  }

  /* write background distributions if applicable */
  if ((f->modelType & PTR_TYPE_MASK) == GHMM_kDiscreteHMM
      && f->modelType & GHMM_kBackgroundDistributions) {
    if (writeBackground(writer, f->model.d[number]->bp))
      GHMM_LOG(LERROR, "writing of background distributions failed");
  }

  /* write all states */
  for (i=0; i<N; i++)
    if (writeState(writer, f, number, i)) {
      GHMM_LOG_PRINTF(LERROR, LOC, "writing of state %d in HMM %d failed", i, number);
      goto STOP;
    }

  /* write all outgoing transitions */
  for (i=0; i<N; i++)
    if (writeTransition(writer, f, number, i)) {
      GHMM_LOG_PRINTF(LERROR, LOC, "writing transitions of state %d in HMM %d failed",
                     i, number);
      goto STOP;
    }

  /*end HMM*/
  if (0 > xmlTextWriterEndElement(writer)) {
    GHMM_LOG(LERROR, "Error at xmlTextWriterEndElement (HMM)");
    goto STOP;
  }

  return 0;
STOP:
  return -1;
#undef CUR_PROC
}
Exemplo n.º 9
0
void HIDBridge_::proceedCommand(void){
#ifdef DEBUG
	debug->print("c");
	debug->println(nhp_read.command);
#endif

#ifdef HIDBRIDGE_RX
	// proceed a possible end flag
	if (nhp_read.command == HIDBRIDGE_COMMAND_END) {

		// we've got a correct USB protocol received. Write it to the host now.
		if (reportID && (recvLength == reportLength)) {
			rxReady = false; //TODO not needed?
#ifdef USB_DEBUG
			// debug print HID reports
			debug->print("USBk ");
			debug->print(reportID, DEC);
			for (uint8_t i = 0; i < reportLength; i++) {
				debug->print(", 0x");
				debug->print(hidReport[i], HEX);
			}
			debug->println();
#endif
			HID_SendReport(reportID, hidReport, reportLength);

			// acknowledge signal
			rxReady = true;
			writeState();
		}
		// log an error
		else
			err(HIDBRIDGE_ERR_CMD_END);

		// reset reportID in any case
		reportID = 0;
	}

	// proceed a possible new reportID lead
	else {
		// flag an error if we have a pending report
		if (reportID)
			err(HIDBRIDGE_ERR_CMD_RID);

		// determine the new report length
		switch (nhp_read.command) { //TODO progmem lookup table
#ifdef HID_MOUSE_ENABLE
		case HID_REPORTID_MOUSE:
			reportLength = sizeof(HID_MouseReport_Data_t);
			break;
#endif

#ifdef HID_MOUSE_ABSOLUTE_ENABLE
		case HID_REPORTID_MOUSE_ABSOLUTE:
			reportLength = sizeof(HID_MouseAbsoluteReport_Data_t);
			break;
#endif

#ifdef HID_KEYBOARD_ENABLE
		case HID_REPORTID_KEYBOARD:
			reportLength = sizeof(HID_KeyboardReport_Data_t);
			break;
#endif

#ifdef HID_CONSUMERCONTROL_ENABLE
		case HID_REPORTID_CONSUMERCONTROL:
			reportLength = sizeof(HID_ConsumerControlReport_Data_t);
			break;
#endif

#ifdef HID_SYSTEMCONTROL_ENABLE
		case HID_REPORTID_SYSTEMCONTROL:
			reportLength = sizeof(HID_SystemControlReport_Data_t);
			break;
#endif

#ifdef HID_GAMEPAD_ENABLE
		case HID_REPORTID_GAMEPAD:
			reportLength = sizeof(HID_GamepadReport_Data_t);
			break;
#endif

		default:
			// error
			reportLength = 0;
			break;
		}

		if (reportLength) {
			// save new report properties
			reportID = nhp_read.command;
			recvLength = 0;
		}
		else {
			// new reportID is not supported
			//TODO recv length =0?
			reportID = 0;
			err(HIDBRIDGE_ERR_COMMAND);
		}
	}
#else // ifdef HIDBRIDGE_RX
	err(HIDBRIDGE_ERR_COMMAND);
#endif
}
Exemplo n.º 10
0
void Radio::searchDown() {
   this->out.parsed.searchStopLevel = 3; // Strongest stations only
   this->out.parsed.searchUp = 0; // Going ... down!
   this->out.parsed.searchMode = 1;
   writeState();
}
Exemplo n.º 11
0
void Radio::searchUp() {
   this->out.parsed.searchStopLevel = 3; // Strongest stations only
   this->out.parsed.searchUp = 1;
   this->out.parsed.searchMode = 1;
   writeState();
}
Exemplo n.º 12
0
void Radio::tuneTo(double freq) {
  setFrequency(freq);
  this->out.parsed.searchMode = 0; // Turn search off.
  writeState();
}
Exemplo n.º 13
0
	void SkinExportSerializer::writeRegion(pugi::xml_node _parent, DataPtr _parentData, DataPtr _data, bool _text)
	{
		bool isVisible = MyGUI::utility::parseValue<bool>(_data->getPropertyValue("Visible")) &&
			MyGUI::utility::parseValue<bool>(_data->getPropertyValue("Enable"));

		if (!isVisible)
			return;

		MyGUI::IntCoord coord = MyGUI::IntCoord::parse(_data->getPropertyValue("Coord"));

		std::string type = _data->getPropertyValue("Type");
		bool tileVert = true;
		bool tileHorz = true;

		if (type == "TileRect Vert")
		{
			type = "TileRect";
			tileHorz = false;
		}
		else if (type == "TileRect Horz")
		{
			type = "TileRect";
			tileVert = false;
		}

		pugi::xml_node node = _parent.append_child("BasisSkin");
		node.append_attribute("type").set_value(type.c_str());
		node.append_attribute("offset").set_value(coord.print().c_str());
		node.append_attribute("align").set_value(convertEditorToExportAlign(_data->getPropertyValue("Name")).c_str());

		for (Data::VectorData::const_iterator child = _parentData->getChilds().begin(); child != _parentData->getChilds().end(); child ++)
		{
			if ((*child)->getType()->getName() != "State")
				continue;

			bool visible = MyGUI::utility::parseValue<bool>((*child)->getPropertyValue("Visible"));
			if (!visible)
				continue;

			if (_text)
			{
				writeStateText(node, (*child), coord);
			}
			else
			{
				pugi::xml_node stateNode = writeState(node, (*child), coord);
				if (type == "TileRect")
				{
					pugi::xml_node propertyNode = stateNode.append_child("Property");
					propertyNode.append_attribute("key").set_value("TileSize");
					propertyNode.append_attribute("value").set_value(coord.size().print().c_str());

					propertyNode = stateNode.append_child("Property");
					propertyNode.append_attribute("key").set_value("TileH");
					propertyNode.append_attribute("value").set_value(MyGUI::utility::toString(tileHorz).c_str());

					propertyNode = stateNode.append_child("Property");
					propertyNode.append_attribute("key").set_value("TileV");
					propertyNode.append_attribute("value").set_value(MyGUI::utility::toString(tileVert).c_str());
				}
			}
		}
	}
Exemplo n.º 14
0
void Unit::save(IO::StreamOut & stream)
{
	writeState(stream);
	controller->save(stream);
}