コード例 #1
0
void DTCGateway::processRadioMessage()
{
    if (process())
    {
        // A new message was received from one of the nodes
        DTCMessage message = getLastMessage();
        rxBlink(mGetCommand(message) == C_PRESENTATION ? 3 : 1);

        // pass the message to controller
        //char *json_String = aJson.print(jsonObject);
        serial(message);
    }
}
コード例 #2
0
ファイル: decodeIMDoc.cpp プロジェクト: paulhiggs/decode1
BOOL CDecodeIMDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	CUserInputDlg userInputDlg;
	userInputDlg.m_UserInput = getLastMessage();
	if (userInputDlg.DoModal() == IDOK)
		DecodeMessage(userInputDlg.m_UserInput);

	return TRUE;
}
コード例 #3
0
ファイル: MyGateway.cpp プロジェクト: rafaelbrasilia/Arduino
void MyGateway::processRadioMessage() {
	if (process()) {
	  // A new message was received from one of the sensors
	  MyMessage message = getLastMessage();
	  if (mGetCommand(message) == C_PRESENTATION && inclusionMode) {
		rxBlink(3);
	  } else {
		rxBlink(1);
	  }
	  // Pass along the message from sensors to serial line
	  serial(message);
	}

	checkButtonTriggeredInclusion();
	checkInclusionFinished();
}
コード例 #4
0
ファイル: qgtp.cpp プロジェクト: danhfan/qgo
int QGtp::openGtpSession(QString filename, int size, float komi, int handicap, int /*level*/)
{
	_cpt = 1000;
	
	programProcess = new QProcess();
    programProcess->setReadChannel(QProcess::StandardOutput);
	QStringList arguments;
	issueCmdNb = false;
	
	if(!filename.count())
	{
		_response = "No go engine path set";
		return FAIL;
	}

	if (filename.toLower().contains("gnugo"))
	{
		arguments << "--mode" << "gtp" << "--quiet" ;
		issueCmdNb = true;
	}

	if (filename.toLower().contains("mogo"))
	{
		arguments << "--19" << "--dontDisplay" << "1" ;

	}


	connect(programProcess, SIGNAL(readyRead()),
		this, SLOT(slot_readFromStdout()) );
	connect(programProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
		this, SLOT(slot_processExited(int , QProcess::ExitStatus )) );
	
    qDebug("starting Go engine : %s %s", filename.toLatin1().constData(), arguments.join(" ").toLatin1().constData());

	programProcess->start(filename, arguments);

	

	if (!programProcess->waitForStarted())
	{
		  _response="Could not start "+filename;
		  return FAIL ;
	}
	
	//?? never know ... otherwise, I get a segfault with sprint ...
	if ((outFile = (char *)malloc (100)) == NULL)
	{
		  _response="Yuck ! Could not allocate 100 bytes !!!"  ;
		  return FAIL ;
	}   
	
	if (protocolVersion()==OK)
	{
		if(getLastMessage().toInt() !=2)
		{
			qDebug("Protocol version problem???");
			//				quit();
			_response="Protocol version not supported";
			//				return FAIL;
		}
		if(setBoardsize(size)==FAIL)
		{
			return FAIL;
		}
		if(clearBoard()==FAIL)
		{
			// removed by frosla -> protocol changes...
			// return FAIL;
		}

/*
		if(knownCommand("level")==FAIL)
		{
			  return FAIL;
		}
	
		else if (getLastMessage().contains("true"))
        	{
        		if (setLevel(level)==FAIL)
			{
				return FAIL;
			}
        	}
*/ 
      
		if(setKomi(komi)==FAIL)
		{
			return FAIL;
		}

		if(fixedHandicap(handicap)==FAIL)
		{
			return FAIL;
		}
	}
	else
	{
		quit();
		_response="Protocol version error";
		return FAIL;
	}

    busy = false;
	return OK;
}
コード例 #5
0
ファイル: qgtp.cpp プロジェクト: EPeillard/qgo
int QGtp::openGtpSession(QString path, QString args, int size, float komi, int handicap)
{
	_cpt = 1000;
	
	programProcess = new QProcess();
    programProcess->setReadChannel(QProcess::StandardOutput);
    QStringList arguments = args.split(' ',QString::SkipEmptyParts);
    issueCmdNb = false;

    if (path.contains(QRegExp("gnugo$", Qt::CaseInsensitive)))
        issueCmdNb = true; // FIXME: are command numbers really gnugo-specific?

	connect(programProcess, SIGNAL(readyRead()),
		this, SLOT(slot_readFromStdout()) );
	connect(programProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
		this, SLOT(slot_processExited(int , QProcess::ExitStatus )) );
	
    qDebug() << "QGtp::openGtpSession(" << path << "," << args << ")";

    programProcess->start(path, arguments);
	

	if (!programProcess->waitForStarted())
	{
          _response="Could not start "+path;
		  return FAIL ;
	}
	
	//?? never know ... otherwise, I get a segfault with sprint ...
	if ((outFile = (char *)malloc (100)) == NULL)
	{
		  _response="Yuck ! Could not allocate 100 bytes !!!"  ;
		  return FAIL ;
	}   
	
	if (protocolVersion()==OK)
	{
		if(getLastMessage().toInt() !=2)
		{
			qDebug("Protocol version problem???");
			//				quit();
			_response="Protocol version not supported";
			//				return FAIL;
		}
		if(setBoardsize(size)==FAIL)
		{
			return FAIL;
		}
		if(clearBoard()==FAIL)
		{
			// removed by frosla -> protocol changes...
			// return FAIL;
		}

/*
		if(knownCommand("level")==FAIL)
		{
			  return FAIL;
		}
	
		else if (getLastMessage().contains("true"))
        	{
        		if (setLevel(level)==FAIL)
			{
				return FAIL;
			}
        	}
*/ 
      
		if(setKomi(komi)==FAIL)
		{
			return FAIL;
		}

		if(fixedHandicap(handicap)==FAIL)
		{
			return FAIL;
		}
	}
	else
	{
		quit();
		_response="Protocol version error";
		return FAIL;
	}

    busy = false;
	return OK;
}
コード例 #6
0
ファイル: serialcommunication.cpp プロジェクト: Oroles/AES
void bluetoothProcessReply(SoftwareSerial* bluetoothSerial, char *inputString)
{  
  char encryptedPassword[2 * PASSWORD_SIZE]; //make them more local
  char shortEncryptedPassword[PASSWORD_SIZE];
  char password[PASSWORD_SIZE];
  char message[MESSAGE_SIZE];
  
  memset(encryptedPassword, 0, 2 * PASSWORD_SIZE);
  memset(shortEncryptedPassword, 0, PASSWORD_SIZE);
  memset(password, 0, PASSWORD_SIZE);
  memset(message, 0, MESSAGE_SIZE);
  
  int typeCommand = getTypeCommand(inputString);
  
  switch (typeCommand)
  {
    case '0' + 1:
      { // add new entry
        getLastMessage(inputString, password);
        if (encryptPassword((const unsigned char*)password, (const unsigned char*)key, PASSWORD_CHUNCKS, (unsigned char*)encryptedPassword)) {
          generateBluetoothAddMessage(inputString, encryptedPassword, strlen(password), message);
          setMessageReceiver(Phone);
          storeInDataBuffer(message);
          memset(message, '\0', MESSAGE_SIZE);
          generateStoredInBuffer(message);
          sendToBluetooth(bluetoothSerial, message);
        }
        else {
          generateErrorMessage(message);
          sendToBluetooth(bluetoothSerial, message);
        }
      }
      break;
    case '0' + 2: //retrive password
    case '0' + 13: //retrive note 
      {
        getLastMessage(inputString, encryptedPassword);
        generateShortPassword(encryptedPassword, shortEncryptedPassword);
        byte l = getPasswordLength(inputString);
        if (decryptPassword((unsigned char*)shortEncryptedPassword, (unsigned char*)key, PASSWORD_CHUNCKS, l, (unsigned char*)password)) {
          generateSerialRetriveInfo(password, message);
          setMessageReceiver(Pc);
          storeInDataBuffer(message);
        }
        else {
          generateErrorMessage(message);
          sendToBluetooth(bluetoothSerial, message);
        }
      }
      break;
    case '0' + 5:
      { // get from message and store the hash value and close connection
        char hash[HASH_SIZE]; //input = "5:hash_value\n
        memset(hash, '\0', HASH_SIZE);
        getLastMessage(inputString, hash);
        writeHash(hash);
      }
      break;
    case '0' + 6:
      { //read hash from EERPOM and send back to bluetooth
        char hash[HASH_SIZE]; //input = 6:\n
        memset(hash, '\0', HASH_SIZE);
        readHash(hash);
        generateBluetoothRetrieveHash(hash, HASH_SIZE, message); //message = 6:hash_value\n
        storeInDataBuffer(message);
        setMessageReceiver(Phone);
        setEnableBluetoothOperations(true);
      }
      break;
     case '0' + 4:
      {
        char lastTimeUsed[LAST_TIME_USED_SIZE];
        memset(lastTimeUsed, '\0', LAST_TIME_USED_SIZE);
        readLastTimeUsed(lastTimeUsed);
        generateBluetoothLastTimeUsed(lastTimeUsed, LAST_TIME_USED_SIZE, message);
        //Serial.print(message);
        sendToBluetooth(bluetoothSerial, message);
      }
      break;
    case '0' + 10:
      {
        char lastTimeUsed[LAST_TIME_USED_SIZE];
        memset(lastTimeUsed, '\0', LAST_TIME_USED_SIZE);
        getLastMessage(inputString, lastTimeUsed);
        writeLastTimeUsed(lastTimeUsed);
      }
      break;
    
    case '0' + 7:
      { // generate password
        if ((generatePassword(inputString, password, PASSWORD_CHUNCKS)) &&
           (encryptPassword((const unsigned char*)password, (const unsigned char*)key, PASSWORD_CHUNCKS, (unsigned char*)encryptedPassword))) {
            generateBluetoothAddMessage(inputString, encryptedPassword, strlen(password), message);
            setMessageReceiver(Phone);
            storeInDataBuffer(message);
            memset(message, '\0', MESSAGE_SIZE);
            generateStoredInBuffer(message);
            sendToBluetooth(bluetoothSerial, message);
        } else {
          generateErrorMessage(message);
          sendToBluetooth(bluetoothSerial, message);
        }
      }
      break;
    case '0' + 8:
      { // get the salt
        char salt[SALT_SIZE];
        memset(salt, '\0', SALT_SIZE);
        getLastMessage(inputString, salt);
        readKey(key, KEY_SIZE, salt);
      }
      break;
    case '0' + 9:
      { // is alive message
        generateIsAliveMessage(message);
        sendToBluetooth(bluetoothSerial, message);
      }
      break;
    case '0' + 12:
      { //add note
        getLastMessage(inputString, password);//password = note text
        if (encryptPassword((const unsigned char*)password, (const unsigned char*)key, PASSWORD_CHUNCKS, (unsigned char*)encryptedPassword)) {
          generateBluetoothAddNote(inputString, encryptedPassword, strlen(password), message);
          setMessageReceiver(Phone);
          storeInDataBuffer(message);
          
          generateStoredInBuffer(message);
          sendToBluetooth(bluetoothSerial, message);
        }
        else {
          generateErrorMessage(message);
          sendToBluetooth(bluetoothSerial, message);
        }
      }
      break;
    default:
      {
        generateErrorMessage(message);
        sendToBluetooth(bluetoothSerial, message);
      }
      break;   
  }
}
コード例 #7
0
void CCopasiMessage::handler(const bool & /* _throw */)
{
  std::string Text = mText;

  switch (mType)
    {
    case RAW:
      mText = "";
      break;

    case TRACE:
      mText = ">TRACE ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case COMMANDLINE:
    case WARNING:
      mText = ">WARNING ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case ERROR:
      mText = ">ERROR ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case EXCEPTION:
      mText = ">EXCEPTION ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case RAW_FILTERED:
      mText = ">RAW(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case TRACE_FILTERED:
      mText = ">TRACE(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case COMMANDLINE_FILTERED:
      mText = ">COMMANDLINE(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case WARNING_FILTERED:
      mText = ">WARNING(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case ERROR_FILTERED:
      mText = ">ERROR(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;

    case EXCEPTION_FILTERED:
      mText = ">EXCEPTION(filtered) ";
      mText += LocalTimeStamp();
      mText += "<\n";
      break;
    }

  mText += Text;

  if (mType != RAW) lineBreak();

  // Remove the message: No more messages.
  if (mMessageDeque.size() == 1 &&
      mMessageDeque.back().getNumber() == MCCopasiMessage + 1)
    getLastMessage();

  mMessageDeque.push_back(*this);

  // All messages are printed to std::cerr
  if (COptions::compareValue("Verbose", true) &&
      mNumber != MCCopasiMessage + 1)
    {
      std::cerr << mText << std::endl;

#ifdef COPASI_DEBUG
      DebugFile << mText << std::endl;
#endif // COPASI_DEBUG
    }

  if (mType == EXCEPTION)
    throw CCopasiException(*this);
}