Пример #1
0
bool
SerialPort::open(int mode)
{
    // Always open as raw so no input/output buffering
    if (!QFile::open(mode | IO_Raw))
	return false;

    // Save current state and set raw
    if (tcgetattr(handle(),&_p->state) < 0) {
	qWarning("Saving termios state failed: %d", errno);
	close();
	return false;
    } else {
	struct termios state = _p->state;
	cfmakeraw(&state);
	state.c_cflag |= CLOCAL;
	state.c_cflag &= ~CRTSCTS;
	if (tcsetattr(handle(), TCSANOW, &state) < 0) {
	    qWarning("Setting raw state failed: %d", errno);
	    close();
	    return false;
	}
    }

    // Set serial port to current characteristics
    setSerial(_baud, _dataBits, _parity, _stopBits);
    setHandshake(_handshake);
    setTimeout(_timeout);

    return true;
}
Пример #2
0
// Sets all data automatically
void cUOTxConfirmLogin::fromChar( P_CHAR pChar )
{
	setSerial( pChar->serial );
	setBody( pChar->id() );
	setDirection( pChar->dir );
	setX( pChar->pos.x );
	setY( pChar->pos.y );
	setZ( pChar->pos.z );
}
Пример #3
0
// Simple setting and getting of properties for scripts and the set command.
stError* cUObject::setProperty( const QString& name, const cVariant& value )
{
	changed( TOOLTIP );
	changed_ = true;
	// \rproperty object.serial This integer property contains the serial for this object.
	if ( name == "serial" )
	{
		if ( !value.canCast( cVariant::IntType ) )
		{
			PROPERTY_ERROR( -3, QString( "Invalid integer value: '%1'" ).arg( value.toString() ) );
		}
		setSerial( value.toInt() );
		return 0;
	}

	// \property object.free This boolean property indicates that the object has been freed and is awaiting deletion.
	else
		SET_BOOL_PROPERTY( "free", free )
		// \property object.name This string property contains the name of the object.
	else
		SET_STR_PROPERTY( "name", this->name_ )
		// \property object.pos This property is a <object id="coord">coord</object> object (Python) or a string representation (Show/Set) of the objects position.
	else if ( name == "pos" )
	{
		Coord pos;
		if ( !parseCoordinates( value.toString(), pos ) )
			PROPERTY_ERROR( -3, QString( "Invalid coordinate value: '%1'" ).arg( value.toString() ) )
			moveTo( pos );
		return 0;
	}

	// \property object.eventlist This string property contains a comma separated list of the names of the scripts that are assigned to this object.
	else if ( name == "scriptlist" )
	{
		clearScripts();
		QStringList list = value.toString().split( "," );
		for ( QStringList::const_iterator it( list.begin() ); it != list.end(); ++it )
		{
			cPythonScript* script = ScriptManager::instance()->find( ( *it ).toLatin1() );
			if ( script )
				addScript( script );
			else
				PROPERTY_ERROR( -3, QString( "Script not found: '%1'" ).arg( *it ) )
		}
		return 0;
	}
Пример #4
0
int main(int argc, char *argv[]) {
        char *s_device = "\0";
	char ch;
	char *optstr = "d:0:1:2:3:s:";

	while( -1 != (ch=getopt(argc,argv,optstr))) {
		switch(ch) {
			case 's':           
				s_device = optarg;
				printf("option: -s : %s\n", s_device); 
				break;
			case 'd':
				debug = atoi(optarg);
				printf("option: -d : %d\n", debug); 
				break;
			case '?':
				printf("unrecognized option: %c\n",optopt);
				break;
			default:
				printf("error?  condition unaccounted for?\n");
				break;

		}
	}

	if (debug > 1) {
		printf("\nEPSPD version 1.5 (2009-0m-dd)");
		printf("\nDebug level: %d", debug);
	}
	setSerial(s_device);
	
	/*
	 *	Up.. time to go (Clunk, ..(wait), Clunk, Clunk)
	 */
	 
	printf("\nEPSPD: Starting EPSP disk services on %s", s_device);
	printf("\n");
	
	while(1) {
		blk_read(epsp_port, dataMsg, 256);
	}
	
	return(1);
}
Пример #5
0
/****************************************************************
* Main
****************************************************************/
int main(){	
	// Set the signal callback for Ctrl-C
	signal(SIGINT, signal_handler);

	initUART();
	setSerial();
	while(keepgoing){
		cwrotate(800);
		ccwrotate(800);
		burstout(1000);
		burstin(1000);
		starburstout(600);
		starburstin(600);
		spiralin(400);
		spiralout(400);
		flashon_off(800);
		snake(200);
	}
	return 0;
}
Пример #6
0
Файл: mw.c Проект: coder03/ldd
main(){
	int fd;
	struct termios *oldser,*newser,*oldter,*newter;
	oldser=(struct termios *)malloc(sizeof(struct termios));
	newser=(struct termios *)malloc(sizeof(struct termios));
	oldter=(struct termios *)malloc(sizeof(struct termios));
	newter=(struct termios *)malloc(sizeof(struct termios));
	fd=openSerial("/dev/ttyS1");
	setSerial(fd,oldser,newser);
	/* next stop echo and buffering for stdin */
 	tcgetattr(0,oldter);
 	tcgetattr(0,newter); /* get working stdtio */
 	newter->c_lflag &= ~(ICANON | ECHO);
 	tcsetattr(0,TCSANOW,newter);
	writeToSerial(fd,'x');
   	tcsetattr(fd,TCSANOW,oldser); /* restore old serial setings */
	close(fd);
   	tcsetattr(0,TCSANOW,oldter); /* restore old tty setings */
	exit(0);
}
Пример #7
0
StreamSerialProtocol::StreamSerialProtocol(int serial, uint8_t* payload, uint8_t payloadSize)
    :SerialProtocol(payload, payloadSize)
{
    setSerial(serial);
}
Пример #8
0
NewhavenDisplay::NewhavenDisplay(HardwareSerial &serial) :
  row_count_(ROW_COUNT_DEFAULT),
  col_count_(COL_COUNT_DEFAULT)
{
  setSerial(serial);
}
Пример #9
0
NewhavenDisplay::NewhavenDisplay(HardwareSerial &serial, const int row_count, const int col_count) :
  row_count_(row_count),
  col_count_(col_count)
{
  setSerial(serial);
}
Пример #10
0
/*----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);

  a.addLibraryPath(a.applicationDirPath() + "/plugins");

  config = new DDAConfig(&a);
  if(config->fileExists() && config->isError())
  {
    QMessageBox::critical(NULL, QObject::tr("Error load config"), config->message());
  }

  translator = new Translator(&a);
  QString locale;
  locale = config->settings().localeName;
  if(locale.isEmpty())
    locale = QLocale::system().name();

  if(!translator->load("dda-messages.xml")
     && !translator->load("dda-messages.xml", QDir::currentPath())
     && !translator->load("dda-messages.xml", QLibraryInfo::location(QLibraryInfo::TranslationsPath))
     && locale != "C")
  {
    QString error = QString("Error load language file '%1': %2").arg("dda-messages.xml").arg(translator->errorString());
    QMessageBox::critical(NULL, "Error translation", error);
    if(config->settings().localeName.isEmpty())
    {
      DDASettings s = config->settings();
      s.localeName = "C";
      config->setSettings(s);
    }
  }
  else
  {
    if(!translator->setLang(locale))
    {
      QString error = QString("Error set language: %1").arg(translator->errorString());
      QMessageBox::critical(NULL, "Error translation", error);
      if(config->settings().localeName.isEmpty())
      {
        DDASettings s = config->settings();
        s.localeName = "C";
        config->setSettings(s);
      }
    }
    else
    if(config->settings().localeName.isEmpty())
    {
      DDASettings s = config->settings();
      s.localeName = QLocale::system().name();
      config->setSettings(s);
    }
  }

  a.installTranslator(translator);


  database = new DDADatabase(&a);
  if(database->isError())
  {
    QMessageBox::critical(NULL, QObject::tr("Error open database"), database->message());
  }



  QStringList profiles = config->profileList();
/*
  if(profiles.size() > 1)
  {
    ProfileSelectDialog dlg;
    if(dlg.exec() != QDialog::Accepted || dlg.selectedProfile() < 0 || dlg.selectedProfile() > profiles.size())
      return 1;
    config->setProfileIndex(dlg.selectedProfile());
  }
  else */
  if(profiles.isEmpty())
  {
    DDAProfile profile;
    config->defaultProfle(&profile);
    EditProfileDialog dlg;
    dlg.setProfile(profile);
    if(dlg.exec() != QDialog::Accepted)
      return 1;
    config->addProfile(dlg.profile());
    config->setProfileIndex(0);
  }

  int defaultProfile = getOptValue("profile", 'p', -1).toInt();
  if(defaultProfile > 0)
    config->setProfileIndex(defaultProfile - 1);


  session = new DDAMeasureSession(&a);

  if(getOptSwitch("demo", 'd') || getOptSwitch("demo-mode", 'D'))
    controller = new DemoController(&a);
  else
    controller = new DDAController(&a);

  QObject::connect(controller, SIGNAL(measure(double,double,int)), session, SLOT(addMeasure(double,double,int)));
  QObject::connect(controller, SIGNAL(serialReceived(QString)), session, SLOT(setSerial(QString)));
  QObject::connect(controller, SIGNAL(endOfMeasuring()), session, SLOT(onEndOfMeasuring()));
  QObject::connect(controller, SIGNAL(noParticle()), session, SLOT(onNoParticle()));

  QObject::connect(controller, SIGNAL(measure(double,double,int)), database, SLOT(measure(double,double,int)));
  QObject::connect(controller, SIGNAL(serialReceived(QString)), database, SLOT(setSerial(QString)));
  QObject::connect(controller, SIGNAL(endOfMeasuring()), database, SLOT(onEndOfMeasuring()));
  QObject::connect(controller, SIGNAL(noParticle()), database, SLOT(onNoParticle()));

  MeasureWindow w;
  w.show();
  //w.showMaximized();
  return a.exec();
}