Ejemplo n.º 1
0
void CSensorUSBMotionNodeAccel::closePort()
{
    if (getPort() > -1) {
        fprintf(stdout, "Closing %s sensor port...\n", getTypeStr());
    }
    if (m_node) {
        if (m_node->is_connected() && m_node->is_reading()) {
           m_node->stop();  // if started & reading
        }
        m_node->close();
        delete m_node;
        m_node = NULL;
        setPort();
        setType();
        if (getPort() > -1) {
           fprintf(stdout, "Port closed!\n");
           fflush(stdout);
        }
    }

    // close MN dll
    if (m_WinDLLHandle) {
#ifdef __USE_DLOPEN__
        if (dlclose(m_WinDLLHandle)) {
           fprintf(stderr, "%s: dlclose error %s\n", getTypeStr(), dlerror());
        }
#else // probably Windows - free library
   #ifdef _WIN32
        ::FreeLibrary(m_WinDLLHandle);
   #endif
#endif
	m_WinDLLHandle = NULL;
    }
}
Ejemplo n.º 2
0
void QXmppPresence::Status::toXml(QXmlStreamWriter *xmlWriter) const
{
    const QString show = getTypeStr();
    if (!show.isEmpty())
        helperToXmlAddTextElement(xmlWriter, "show", getTypeStr());
    if (!m_statusText.isEmpty())
        helperToXmlAddTextElement(xmlWriter, "status", m_statusText);
    if (m_priority != 0)
        helperToXmlAddNumberElement(xmlWriter, "priority", m_priority);
}
Ejemplo n.º 3
0
void
setPPstyle (ppOption pps, int i, const char *argv)
{
    static int setBy = 0;
    static const char *setArg = NULL;

	if (argv == NULL) {
		printf ("Set by arg %d (%-10s), PrettyPrint style = %s\n",
				setBy, setArg, getPPStyleStr());
		return;
	}
		
	// if the style has already been set, and is trying to be reset by default
	// rules, override the default  (i.e., don't make a change)
	if (setBy != 0 && i == 0)
		return;

	// If -long or -xml or -format are specified, do not reset to
	// "normal" style when followed by a flag such as -startd.
	if( ppStyle == PP_XML || ppStyle == PP_VERBOSE || ppStyle == PP_CUSTOM )
	{
		if( pps != PP_XML && pps != PP_VERBOSE && pps != PP_CUSTOM ) {
				// ignore this style setting and keep our existing setting
			return;
		}
	}

	// If setting a 'normal' output, check to see if there is a user-defined normal output
	if ( ! disable_user_print_files && ! explicit_format
		&& pps != PP_XML && pps != PP_VERBOSE && pps != PP_CUSTOM && pps != ppStyle) {
		MyString param_name("STATUS_DEFAULT_"); param_name += getTypeStr(); param_name += "_PRINT_FORMAT_FILE";
		char * pf_file = param(param_name.c_str());
		if (pf_file) {
			struct stat stat_buff;
			if (0 != stat(pf_file, &stat_buff)) {
				// do nothing, this is not an error.
			} else if (set_status_print_mask_from_stream(pf_file, true) < 0) {
				fprintf(stderr, "Warning: default %s select file '%s' is invalid\n", getTypeStr(), pf_file);
			} else {
				using_print_format = true;
			}
			free(pf_file);
		}
	}

    if ( (PP_XML == pps) || PP_VERBOSE == pps || (ppStyle <= pps || setBy == 0) ) {
        ppStyle = pps;
        setBy = i;
        setArg = argv;
    } else {
        fprintf (stderr, "Error:  arg %d (%s) contradicts arg %d (%s)\n",
                            i, argv, setBy, setArg);
        exit (1);
    }
}
Ejemplo n.º 4
0
void AreaNode::maybeRender()
{
    AVG_ASSERT(getState() == NS_CANRENDER);
    if (isVisible()) {
        if (getID() != "") {
            AVG_TRACE(Logger::BLTS, "Rendering " << getTypeStr() << 
                    " with ID " << getID());
        } else {
            AVG_TRACE(Logger::BLTS, "Rendering " << getTypeStr()); 
        }
        m_Transform = getParentTransform()*calcTransform();
        render();
    }
}
Ejemplo n.º 5
0
void CoeffsBase::checkCoeffsInfo(const std::string& msg_header, const std::string& coeffs_type_f, const unsigned int ndimensions_f, const size_t ncoeffs_total_f, const std::vector<unsigned int>& indices_shape_f) {

  if(coeffs_type_f != getTypeStr()) {
    std::string msg = msg_header + " coeffs type " + coeffs_type_f + " from file doesn't match the defined value " + getTypeStr();
    plumed_merror(msg);
  }
  if(ndimensions_f != numberOfDimensions() ) {
    std::string s1; Tools::convert(ndimensions_f,s1);
    std::string s2; Tools::convert(numberOfDimensions(),s2);
    std::string msg = msg_header + " the number of dimensions " + s1 + " in file doesn't match the defined value " + s2;
    plumed_merror(msg);
  }
  if(ncoeffs_total_f != numberOfCoeffs() ) {
    std::string s1; Tools::convert(ncoeffs_total_f,s1);
    std::string s2; Tools::convert(numberOfCoeffs(),s2);
    std::string msg = msg_header + " the number of coeffs " + s1 + " in file doesn't match the defined value " + s2;
    plumed_merror(msg);
  }
  for(unsigned int k=0; k<numberOfDimensions(); k++) {
    if(indices_shape_f[k] != shapeOfIndices(k) ) {
      std::string s1; Tools::convert(indices_shape_f[k],s1);
      std::string s2; Tools::convert(shapeOfIndices(k),s2);
      std::string msg = msg_header + " for dimension labeled " + getDimensionLabel(k) + " the shape of indices " + s1 + " in file doesn't match defined value " + s2;
      plumed_merror(msg);
    }
  }
}
Ejemplo n.º 6
0
void QXmppStanza::Error::toXml( QXmlStreamWriter *writer ) const
{
    QString cond = getConditionStr();
    QString type = getTypeStr();

    if(cond.isEmpty() && type.isEmpty())
        return;

    writer->writeStartElement("error");
    helperToXmlAddAttribute(writer, "type", type);

    if (m_code > 0)
        helperToXmlAddAttribute(writer, "code", QString::number(m_code));

    if(!cond.isEmpty())
    {
        writer->writeStartElement(cond);
        writer->writeAttribute("xmlns", ns_stanza);
        writer->writeEndElement();
    }
    if(!m_text.isEmpty())
    {
        writer->writeStartElement("text");
        writer->writeAttribute("xml:lang", "en");
        writer->writeAttribute("xmlns", ns_stanza);
        writer->writeCharacters(m_text);
        writer->writeEndElement();
    }

    writer->writeEndElement();
}
Ejemplo n.º 7
0
void LnkFsNode::printNodes()
{
    std::string pstr;
    
    // Print name of this node
    std::cout << getTypeStr() << " " << getPath(pstr) << "->" + lnk->getPath(pstr) + "\n";
}
Ejemplo n.º 8
0
void CSensorUSBPhidgets::closePort()
{
	if (m_handlePhidgetSpatial) {
		m_PtrCPhidget_close((CPhidgetHandle) m_handlePhidgetSpatial);
		m_PtrCPhidget_delete((CPhidgetHandle) m_handlePhidgetSpatial);
		m_handlePhidgetSpatial = NULL;
	}

	if (m_handleLibrary) {
#ifdef __USE_DLOPEN__
        if (dlclose(m_handleLibrary)) {
           fprintf(stderr, "%s: dlclose error %s\n", getTypeStr(), dlerror());
        }
#else // probably Windows - free library
   #ifdef _WIN32
        ::FreeLibrary(m_handleLibrary);
   #endif
#endif
		m_handleLibrary = NULL;
    }
	
	m_iSerialNum = 0;
	m_iVersion = 0;
	m_iNumAccelAxes = 0;
	m_iNumGyroAxes = 0;
	m_iNumCompassAxes = 0;
	m_iDataRateMax = 0;
	m_iDataRateMin = 0;
	
	setPort();
	setType();

}
Ejemplo n.º 9
0
void FileFsNode::printNodes()
{
    std::string pstr;
    
    // Print name of this node
    std::cout << getTypeStr() << " " << getPath(pstr) << "\n";
}
Ejemplo n.º 10
0
void CoeffsBase::writeCoeffsInfoToFile(OFile& ofile) const {
  ofile.addConstantField(field_type_).printField(field_type_,getTypeStr());
  ofile.addConstantField(field_ndimensions_).printField(field_ndimensions_,(int) numberOfDimensions());
  ofile.addConstantField(field_ncoeffs_total_).printField(field_ncoeffs_total_,(int) numberOfCoeffs());
  for(unsigned int k=0; k<numberOfDimensions(); k++) {
    ofile.addConstantField(field_shape_prefix_+getDimensionLabel(k));
    ofile.printField(field_shape_prefix_+getDimensionLabel(k),(int) shapeOfIndices(k));
  }
}
Ejemplo n.º 11
0
// Factory :
ElementContainer* ElementContainer::create(Type type)
{
	switch(type)
	{
	case ARRAY:
		return new ArrayElementContainer();
	default:
		logWarn("element container type \"", getTypeStr(type), "\" not implemented, will probably crash !");
		return NULL;
	}
}
Ejemplo n.º 12
0
string Field::getDefinition() const {
    string value = _name + " " + getTypeStr();

    if (isPrimaryKey())
        value += " PRIMARY KEY";

    if (isNotNull())
        value += " NOT NULL";

    return trim(value);
}
Ejemplo n.º 13
0
// Debug function to print all nodes recursively
void DirFsNode::printNodes()
{
    std::string pstr;
    
    // Print name of this node
    std::cout << getTypeStr() << " " << getPath(pstr) << "\n";
        
    // Print sub-nodes recursively    
    for (FsNode* x : nodeList) {
        x->printNodes();
    }
}
Ejemplo n.º 14
0
void QXmppPresence::toXml(QXmlStreamWriter *xmlWriter) const
{
    xmlWriter->writeStartElement("presence");
    helperToXmlAddAttribute(xmlWriter,"xml:lang", lang());
    helperToXmlAddAttribute(xmlWriter,"id", id());
    helperToXmlAddAttribute(xmlWriter,"to", to());
    helperToXmlAddAttribute(xmlWriter,"from", from());
    helperToXmlAddAttribute(xmlWriter,"type", getTypeStr());
    m_status.toXml(xmlWriter);

    error().toXml(xmlWriter);
    foreach (const QXmppElement &extension, extensions())
        extension.toXml(xmlWriter);
    
    xmlWriter->writeEndElement();
}
Ejemplo n.º 15
0
void DivNode::insertChild(NodePtr pChild, unsigned i)
{
    if (!pChild) {
        throw Exception(AVG_ERR_NO_NODE,
                getID()+"::insertChild called without a node.");
    }
    if (pChild->getState() == NS_CONNECTED || pChild->getState() == NS_CANRENDER) {
        throw(Exception(AVG_ERR_ALREADY_CONNECTED,
                "Can't connect node with id "+pChild->getID()+
                ": already connected."));
    }
    if (getState() == NS_CONNECTED || getState() == NS_CANRENDER) {
        getCanvas()->registerNode(pChild);
    }
    DivNodePtr ptr = dynamic_pointer_cast<DivNode>(shared_from_this());
    pChild->checkSetParentError(ptr); 
    if (!isChildTypeAllowed(pChild->getTypeStr())) {
        throw(Exception(AVG_ERR_ALREADY_CONNECTED,
                "Can't insert a node of type "+pChild->getTypeStr()+
                " into a node of type "+getTypeStr()+"."));
    }
    if (i > m_Children.size()) {
        throw(Exception(AVG_ERR_OUT_OF_RANGE,
                pChild->getID()+"::insertChild: index out of bounds."));
    }
    std::vector<NodePtr>::iterator pos = m_Children.begin()+i;
    m_Children.insert(pos, pChild);
    try {
        pChild->setParent(ptr, getState(), getCanvas());
    } catch (Exception&) {
        m_Children.erase(m_Children.begin()+i);
        throw;
    }
    if (getState() == NS_CANRENDER) {
        pChild->connectDisplay();
    }
}
Ejemplo n.º 16
0
// RTTI :
const char* ElementContainer::getTypeStr() const
{
	return getTypeStr(getType());
}
Ejemplo n.º 17
0
void OnLine::printInfo() const {
    std::cout<< " --- Nodal info --- " << std::endl;
    SEMBA::Source::Base::printInfo();
    std::cout<< "Type: " << getTypeStr() << std::endl;
    std::cout<< "Hardness: " << getHardnessStr() << std::endl;
}
Ejemplo n.º 18
0
void
setType (const char *dtype, int i, const char *argv)
{
    static int setBy = 0;
    static const char *setArg = NULL;

	if (argv == NULL) {
		printf ("Set by arg %d (%-10s), Query type = %s\n",
				setBy, setArg, getTypeStr());
		return;
	}

	// if the type has already been set, and is trying to be reset by default
	// rules, override the default  (i.e., don't make a change)
	if (setBy != 0 && i == 0)
		return;

    if (setArg == NULL) {
        if (strcmp (dtype, "STARTD") == 0) {
            type = STARTD_AD;
        } else
        if (strcmp (dtype, "LICENSE") == 0) {
            type = LICENSE_AD;
        } else

#ifdef HAVE_EXT_POSTGRESQL
        if (strcmp (dtype, "QUILL") == 0) {
            type = QUILL_AD;
        } else
#endif /* HAVE_EXT_POSTGRESQL */

        if (strcmp (dtype, "DEFRAG") == 0) {
            type = DEFRAG_AD;
        } else
        if (strcmp (dtype, "SCHEDD") == 0) {
            type = SCHEDD_AD;
        } else
		if (strcmp (dtype, "SUBMITTOR") == 0) {
			type = SUBMITTOR_AD;
		} else
        if (strcmp (dtype, "MASTER") == 0) {
            type = MASTER_AD;
        } else
        if (strcmp (dtype, "CKPT_SRVR") == 0) {
            type = CKPT_SRVR_AD;
        } else
        if (strcmp (dtype, "COLLECTOR") == 0) {
            type = COLLECTOR_AD;
		} else
        if (strcmp (dtype, "NEGOTIATOR") == 0) {
            type = NEGOTIATOR_AD;
        } else
        if (strcmp (dtype, "GATEWAYS") == 0) {
            type = GATEWAY_AD;
        } else
		if (strcmp(dtype, "GRID") == 0) {
			type = GRID_AD;
		} else
	    if (strcmp (dtype, "STORAGE") == 0) {
            type = STORAGE_AD;
        } else
        if (strcmp(dtype, "GENERIC") == 0) {
	        type = GENERIC_AD;
        } else
        if (strcmp(dtype, "ANY") == 0) {
	        type = ANY_AD;
        } else
        if (strcmp(dtype, "HAD") == 0) {
	        type = HAD_AD;
        } else {
            fprintf (stderr, "Error:  Unknown entity type: %s\n", dtype);
            exit (1);
        }
        setBy = i;
        setArg = argv;
    } else {
        fprintf (stderr,
        "Error:  Daemon type implied by arg %d (%s) contradicts arg %d (%s)\n",
        	i, argv, setBy, setArg);
    }
}
Ejemplo n.º 19
0
/**
 *	@brief Print out a discription of the event
 */
void Event::printStatus() const{
	printf("Event: Type = %s, Trigger Dir = %d, KillSim = %s\n", getTypeStr(), triggerDir, 
		bStop ? "YES" : "NO");
	printf("  Dist: %e Last Dist: %e\n", dist, lastDist);
}//====================================================
Ejemplo n.º 20
0
void MiniPS::scanf_dict(VALUE job, bool show_warnings, ...) {
  va_list ap;
  Dict *dict=RDICT(job);
  char *key;
  unsigned ty;
  char hex3[3];
  VALUE default_, *dst, got;
  if (getType(job)!=T_DICT) Error::sev(Error::EERROR) << "scanf_dict: dict expected" << (Error*)0;
  PTS_va_start(ap, show_warnings);
  //  "InputFile",  MiniPS::T_STRING, MiniPS::Qundef, &InputFile,
  //  "OutputFile", MiniPS::T_STRING, MiniPS::Qundef, &OutputFile,
  //  "Profile",    MiniPS::T_ARRAY,  MiniPS::Qundef, &Profiles,
  //  NULLP
  while (NULLP!=(key=va_arg(ap, char*))) {
    slen_t keylen=strlen(key);
    if (*key=='/') key++;
    ty=va_arg(ap, unsigned);
    default_=va_arg(ap, VALUE);
    dst=va_arg(ap, VALUE*);
    got=(show_warnings) ? dict->get1(key,keylen) : dict->get(key,keylen);
    if (got==Qundef) {
      got = (ty==S_SENUM) ? RDICT(default_)->get(" ",1) /* get the default value */
          : (ty==S_FUNC) ? ((VALUE(*)(VALUE))default_)(Qundef)
          : default_;
      if (got==Qundef) Error::sev(Error::EERROR) << "scanf_dict: required key missing: /" << key << (Error*)0;
      /* type of default value is unchecked deliberately */
    } else switch (ty) {
     case S_RGBSTR:
      /* Dat: red is: (\377\0\0), (#f00), (#ff0000) */
      if (getType(got)!=T_STRING || !(
             RSTRING(got)->getLength()==3 /* Imp: `transparent -red' shouldn't work */
          || (RSTRING(got)->getLength()==4 && RSTRING(got)->begin_()[0]=='#' && !toHex3(RSTRING(got)->begin_()+1, hex3) && (got=(VALUE)new String(hex3, 3), true))
          || (RSTRING(got)->getLength()==7 && RSTRING(got)->begin_()[0]=='#' && !toHex6(RSTRING(got)->begin_()+1, hex3) && (got=(VALUE)new String(hex3, 3), true))
          || (RSTRING(got)->getLength()==6 && !toHex6(RSTRING(got)->begin_(), hex3) && (got=(VALUE)new String(hex3, 3), true))
         )) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " must be an RGB color triplet" << (Error*)0;
      break;
     case S_SENUM:
      if (getType(got)!=T_SNAME) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " must be an enum value (name)" << (Error*)0;
      got=RDICT(default_)->get(RSNAME(got)->begin_(),RSNAME(got)->getLength());
      if (got==Qundef) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " must be a valid enum value" << (Error*)0;
      break;
     case S_FUNC:
      got=((VALUE(*)(VALUE))default_)(got);
      if (got==Qundef) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " has invalid value" << (Error*)0;
      break;
     case S_UINTEGER:
      if ((got&1)==0 || got<Qinteger(0)) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " must be a non-negative integer" << (Error*)0;
      break;
     case S_ANY:
      break;
     case S_PINTEGER:
      if ((got&1)==0 || got<=Qinteger(0)) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " must be a positive integer" << (Error*)0;
      break;
     case S_NUMBER:
      if ((got&1)==0 && getType(got)!=T_REAL) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " must be real or integer" << (Error*)0;
      break;
     case S_PNUMBER:
      if ((got&1)==0 && getType(got)!=T_REAL) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " must be real or integer" << (Error*)0;
      if (((got&1)!=0 && got<=Qinteger(0))
       || (getType(got)==T_REAL && RREAL(got)->getBp()<=0)
         ) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " must be positive" << (Error*)0;
      break;
     default:
      if (getType(got)!=ty) Error::sev(Error::EERROR) << "scanf_dict: key /" << key << " must have type " << getTypeStr(ty) << (Error*)0;
    }
    *dst=got;
  }
  va_end(ap);
  if (show_warnings) {
    // VALUE *keyy, *val;
    char const*const* keyy; slen_t keylen; VALUE *val;
    bool touched = false;  /* pacify gcc-4.2.1 by giving initial value */
    dict->getFirst(keyy, keylen, val, touched);
    // fprintf(stderr, "> %p\n", keyy);
    PTS_va_start(ap, show_warnings);
    while (keyy!=(char const*const*)NULLP) {
      // fprintf(stderr, "untouch len=%u\n", keylen);
      // fprintf(stderr, "untouching key=(%s)\n", *keyy);
      if (!touched) Error::sev(Error::WARNING) << "scanf_dict: ignoring unknown key /" << SimBuffer::Static(*keyy,keylen) << (Error*)0;
               else dict->untouch(*keyy, keylen); /* undo get1 */
      dict->getNext(keyy, keylen, val, touched);
    }
    va_end(ap);
  }
}
void TraceEventWriter::processEvent(const trace_event* event) {
	if (event->type == EventType::Complete) {
		if (event->duration < 1000) {
			// Discard events that are less than a millisecond long
			return;
		}
	}

	if (!_first_line) {
		_out << ",";
	}
	_out << "\n{\"tid\": " << event->tid << ",\"ts\":";

	writeTime(_out, event->timestamp);

	_out << ",\"pid\":";
	if (event->pid == GPU_PID) {
		_out << "\"GPU\"";
	}
	else {
		_out << event->pid;
	}

	if (event->scope != nullptr) {
		_out << ",\"cat\":\"" << event->scope->getName() << "\"";
		_out << ",\"id\":\"" << reinterpret_cast<const void*>(event->scope) << "\"";
	}

	_out << ",\"name\":\"" << event->category->getName() << "\",\"ph\":\"" << getTypeStr(event->type) << "\"";

	switch (event->type) {
		case EventType::Complete:
			writeCompleteEvent(_out, event);
			break;
		case EventType::Begin:
		case EventType::End:
			// Nothing to do here
			break;
		case EventType::AsyncBegin:
		case EventType::AsyncStep:
		case EventType::AsyncEnd:
			// Nothing to do here...
			break;
		case EventType::Counter: {
			auto flags = _out.flags();
			_out << std::fixed;

			_out << ",\"args\": {\"value\": " << event->value << "}";

			// and now restore it
			_out.flags(flags);
			break;
		}
		default:
			Assertion(false, "Unhandled enum value! This function should not have been called with this value!");
			break;
	}

	_out << "}";

	_first_line = false;
}
Ejemplo n.º 22
0
void Dispersive::printInfo() const {
    std::cout<< " --- Multiport Info --- " << std::endl;
    Multiport::printInfo();
    std::cout<< " Type: " << getTypeStr() << std::endl;
}
Ejemplo n.º 23
0
bool QXmppStanza::Error::isValid()
{
    return !(getTypeStr().isEmpty() && getConditionStr().isEmpty());
}
Ejemplo n.º 24
0
	std::string Exception::getMessage() const {
		std::stringstream str;
		str << "_[" << getTypeStr() << "]_ , " << m_message;
		return str.str();
	}
Ejemplo n.º 25
0
void Predefined::printInfo() const {
    std::cout<< " --- Multiport Info --- " << std::endl;
    Multiport::printInfo();
    std::cout<< " Type: " << getTypeStr() << std::endl;
}
Ejemplo n.º 26
0
bool CSensorUSBPhidgets::detect()
{
	int ret;
	float x,y,z; //test read_xyz


   setType();
   setPort();

   if (qcn_main::g_iStop) return false;

	// check for stop signal and function pointers
	if (qcn_main::g_iStop || ! setupFunctionPointers()) return false;

// log Linux
/*
#if !defined(__APPLE_CC__) && !defined(_WIN32)	
       if (!m_bLogging) {
          m_PtrCPhidget_enableLogging(PHIDGET_LOG_VERBOSE, "phidget.txt");
          m_bLogging = true;
       }
#endif
*/
	//Declare a spatial handle
	m_handlePhidgetSpatial = NULL;
	
	//create the spatial object
	m_PtrCPhidgetSpatial_create(&m_handlePhidgetSpatial);
	if (!m_handlePhidgetSpatial) return false; // can't create spatial handle
	
	//Set the handlers to be run when the device is plugged in or opened from software, unplugged or closed from software, or generates an error.
	//CPhidget_set_OnAttach_Handler((CPhidgetHandle) m_handlePhidgetSpatial, AttachHandler, NULL);
	//CPhidget_set_OnDetach_Handler((CPhidgetHandle) m_handlePhidgetSpatial, DetachHandler, NULL);
	//CPhidget_set_OnError_Handler((CPhidgetHandle) m_handlePhidgetSpatial, ErrorHandler, NULL);
	
	//Registers a callback that will run according to the set data rate that will return the spatial data changes
	//Requires the handle for the Spatial, the callback handler function that will be called, 
	//and an arbitrary pointer that will be supplied to the callback function (may be NULL)
	//CPhidgetSpatial_set_OnSpatialData_Handler(m_handlePhidgetSpatial, SpatialDataHandler, NULL);
	
	//open the spatial object for device connections
	if ((ret = m_PtrCPhidget_open((CPhidgetHandle) m_handlePhidgetSpatial, -1))) {
	        const char *err;
		m_PtrCPhidget_getErrorDescription(ret, &err);
		fprintf(stderr, "Phidgets error open handle %d = %s\n", ret, err);
		closePort();
		return false;
	}
	
	// try a second to open
	double dTime = dtime();

    if((ret = m_PtrCPhidget_waitForAttachment((CPhidgetHandle)m_handlePhidgetSpatial, 2000))) {
	        const char *err;
		m_PtrCPhidget_getErrorDescription(ret, &err);
//#if !defined(_WIN32) && !defined(__APPLE_CC__)
#ifdef _DEBUG
		fprintf(stderr, "Phidgets error waitForAttachment %d = %s\n", ret, err);
#endif
//#endif
		closePort();
		return false;
	}
	
	//Display the properties of the attached spatial device
	//display_properties((CPhidgetHandle)spatial);
	
	//Set the data rate for the spatial events
	// CPhidgetSpatial_setDataRate(spatial, 16);
	//Display the properties of the attached phidget to the screen.  
	//We will be displaying the name, serial number, version of the attached device, the number of accelerometer, gyro, and compass Axes, and the current data rate
	// of the attached Spatial.

	m_PtrCPhidget_getSerialNumber((CPhidgetHandle) m_handlePhidgetSpatial, &m_iSerialNum);
	m_PtrCPhidget_getDeviceVersion((CPhidgetHandle) m_handlePhidgetSpatial, &m_iVersion);
	m_PtrCPhidgetSpatial_getAccelerationAxisCount(m_handlePhidgetSpatial, &m_iNumAccelAxes);
	m_PtrCPhidgetSpatial_getGyroAxisCount(m_handlePhidgetSpatial, &m_iNumGyroAxes);
	m_PtrCPhidgetSpatial_getCompassAxisCount(m_handlePhidgetSpatial, &m_iNumCompassAxes);
	m_PtrCPhidgetSpatial_getDataRateMax(m_handlePhidgetSpatial, &m_iDataRateMax);
	m_PtrCPhidgetSpatial_getDataRateMin(m_handlePhidgetSpatial, &m_iDataRateMin);
	m_PtrCPhidget_getDeviceName((CPhidgetHandle) m_handlePhidgetSpatial, &m_cstrDeviceName);
	m_PtrCPhidget_getDeviceType((CPhidgetHandle) m_handlePhidgetSpatial, &m_cstrDeviceType); 
	m_PtrCPhidget_getDeviceLabel((CPhidgetHandle) m_handlePhidgetSpatial, &m_cstrDeviceLabel); 
	m_PtrCPhidget_getDeviceID((CPhidgetHandle) m_handlePhidgetSpatial, &m_enumPhidgetDeviceID);

	if (m_iNumAccelAxes < 1) { // error as we should have 1 - 3 axes
		fprintf(stderr, "Error - Phidgets Accel with %d axes\n", m_iNumAccelAxes);
		closePort();
		return false;
	}

/*  per Phidgets forum re version # :
- with gyro & compass
1056 is <300
1042 is 300 - <400
1044 is 400 - <500

- no gyro or compass
1041 is <300
1043 is <400

*/

   if (m_iNumGyroAxes == 0 && m_iNumCompassAxes == 0) {
            if (m_iVersion < 300)
              setType(SENSOR_USB_PHIDGETS_1041);
            else if (m_iVersion >= 300 && m_iVersion < 400)
              setType(SENSOR_USB_PHIDGETS_1043);
            else {
              fprintf(stderr, "Error - Unknown Phidgets Accel with %d axes - Version %d\n", m_iNumAccelAxes, m_iVersion);
              closePort();
               return false;
            }
    }
    else {
            if (m_iVersion < 300)
              setType(SENSOR_USB_PHIDGETS_1056);
            else if (m_iVersion >= 300 && m_iVersion < 400)
              setType(SENSOR_USB_PHIDGETS_1042);
            else
              setType(SENSOR_USB_PHIDGETS_1044);
    }
    setPort(getTypeEnum());

	char *strSensor = new char[256];

	sprintf(strSensor, "%s (Serial # %d)", getTypeStr(), m_iSerialNum);
	setSensorStr(strSensor);
	delete [] strSensor;
	fprintf(stdout, "%s detected in %f milliseconds\n", getSensorStr(), (dtime() - dTime) * 1000.0);

   // OK, at this point we should be connected, so from here on out can just read_xyz until closePort()
   // set as a single sample per point
   setSingleSampleDT(false);  // mn samples itself

   // NB: closePort resets the type & port, so have to set again 
	
   // one last sanity check, test the xyz reading
   if (!read_xyz(x,y,z)) {
	   closePort();
	   return false;
   }

   // last setup a detach callback function if device is removed
   m_PtrCPhidget_set_OnAttach_Handler((CPhidgetHandle) m_handlePhidgetSpatial, PhidgetsAttachHandler, NULL);
   m_PtrCPhidget_set_OnDetach_Handler((CPhidgetHandle) m_handlePhidgetSpatial, PhidgetsDetachHandler, NULL);
	
#if !defined(__APPLE_CC__) && !defined(_WIN32)	
       if (m_bLogging) {
           m_PtrCPhidget_disableLogging();
           m_bLogging = false;
       }
#endif

   return true;
}
Ejemplo n.º 27
0
void
Generator::printInfo() const {
    std::cout<< " --- Generator info --- " << std::endl;
    SEMBA::Source::Base::printInfo();
    std::cout<< "Type: " << getTypeStr() << std::endl;
}
Ejemplo n.º 28
0
// As per the tiny compiler. Probably the most ugly way to do a print statement.
void printTree(TreeNode *tree, int sibCount, bool annotated, bool scoped) {
    bool flag = false;
    if(sibCount == -1) {
        sibCount++;
        flag = true;
    } else {
        spaces += 4;
    }
    for(TreeNode *t = tree; t != NULL; t = t->sibling) {
        printSpaces();
        if(sibCount > 0) {
            printf("|Sibling: %i ", sibCount);
        } else if(sibCount == 0 && flag == false) {
            printf("Child: %i ", chiCount);
        }
        sibCount++;

        if(t->nodekind == StmtK) {
            switch(t->kind.stmt) {
            case IfK:
                printf("If ");
                break;
            case ForK:
                printf("Foreach ");
                break;
            case WhileK:
                printf("While ");
                break;
            case CompK:
                printf("Compound ");
                if(scoped) {
                    printf("with size %i at end of it's declarations ", t->memSize);
                }
                break;
            case ReturnK:
                printf("Return ");
                break;
            case BreakK:
                printf("Break ");
                break;
            }
        } else if(t->nodekind == ExprK) {
            switch(t->kind.expr) {
            case ConstK:
                printf("Const: ");
                switch(t->declType) {
                case Int:
                    printf("%i ", t->attr.ivalue);
                    break;
                case Bool:
                    if(t->attr.ivalue == 0) {
                        printf("false ");
                    } else {
                        printf("true ");
                    }
                    break;
                case Char:
                    if(t->isArray) {
                        printf("\"%s\" ", t->attr.svalue);
                    } else printf("'%c' ", t->attr.cvalue);
                    break;
                default:
                    break;
                }

                break;
            case IdK:
                printf("Id: %s ", t->attr.name);
                break;
            case OpK:
                printf("Op: %s ", t->attr.name);
                break;
            case AssignK:
                printf("Assign: %s ", t->attr.name);
                break;
            case CallK:
                printf("Call: %s ", t->attr.name);
                break;
            }
        } else if(t->nodekind == DeclK) {
            switch(t->kind.decl) {
            case FuncK:
                printf("Func %s returns type ", t->attr.name);
                break;
            case VarK:
                if(t->isArray == true) {
                    printf("Var %s is array of ", t->attr.name);
                } else {
                    printf("Var %s ", t->attr.name);
                }
                break;
            case ParamK:
                if(t->isArray == true) {
                    printf("Param %s is array of ", t->attr.name);
                } else {
                    printf("Param %s ", t->attr.name);
                }
                break;
            default:
                break;
            }
            switch(t->declType) {
            case Void:
                printf("void ");
                break;
            case Int:
                printf("int ");
                break;
            case Bool:
                printf("bool ");
                break;
            case Char:
                printf("char ");
                break;
            default:
                break;
            }
            if(scoped) {
                switch(t->kind.decl) {
                case FuncK:
                    printf("allocated as Global%s of size %i and exec location %i ", t->isStatic ? "Static" : "", t->memSize, t->memOffset);
                    break;
                case VarK:
                    printf("allocated as %s%s of size %i and data location %i ", t->isGlobal ? "Global" : "Local", t->isStatic ? "Static" : "", t->memSize, t->memOffset);
                    break;
                case ParamK:
                    printf("allocated as Parameter of size %i and data location %i ", t->memSize, t->memOffset);
                    break;
                default:
                    break;
                }
            }
        } else {
            printf("Unknown node kind.\n");
        }
        if(annotated && t->nodekind == ExprK) {
            if(t->isArray && t->child[0] == NULL) {
                printf("Type: is array of %s ", getTypeStr(t->declType));
            } else printf("Type: %s ", getTypeStr(t->declType));
        }
        printf("[line: %d]\n", t->lineno);
        for(int i = 0; i < MAXCHILDREN; i++) {
            chiCount = i;
            printTree(t->child[i], 0, annotated, scoped);
            chiCount = 0;
        }
    }
    siblingIndex--;
    spaces -= 4;
}
Ejemplo n.º 29
0
void Base::printInfo() const {
    std::cout<< "Name: " << name_.c_str() << std::endl;
    std::cout<< "Type: " << getTypeStr() << std::endl;
    Domain::printInfo();
}