Beispiel #1
0
int
ctsimtext_main (int argc, char * argv[])
{
  int iReturn = 0;

  if (argc > 1 && (strcmp(s_szProgramName, fileBasename (argv[0])) == 0 || strcmp(s_szProgramName2, fileBasename (argv[0])) == 0 || strcmp(s_szProgramName3, fileBasename (argv[0])) == 0)) {
    argv++;
    argc--;
    iReturn = processCommand (argc, argv);
  } else if (argc >= 1 && ! (strcmp(s_szProgramName, fileBasename (argv[0])) == 0 || strcmp(s_szProgramName2, fileBasename (argv[0])) == 0 || strcmp(s_szProgramName3, fileBasename (argv[0])) == 0)) {
    iReturn = processCommand (argc, argv);
  } else {
    s_bInteractive = true;
    char szPrompt[] = "CTSim> ";
    std::cout << "CTSim Text Shell";
#ifdef VERSION
    std::cout << ", Version " << VERSION;
#endif
    std::cout << " (Type \"quit\" to end)\n\n";

    while (1) {
#ifdef HAVE_READLINE
      char* pszInputLine = readline (szPrompt);
      if (! pszInputLine)
        break;
      if (*pszInputLine != EOS)
        add_history (pszInputLine);

#else  // DONT_HAVE_READLINE

      static const int s_MaxLineLength = 1024;
      char* pszInputLine = new char [s_MaxLineLength+1];
      std::cout << szPrompt;
      std::cin.getline (pszInputLine, s_MaxLineLength);

#ifdef DEBUG
      std::cout << "#" << pszInputLine << "#\n";
#endif

      std::cout << std::flush;
      std::cout << "\n";
#endif  // DONT_HAVE_READLINE

      if (strncasecmp (pszInputLine, "quit", 4) == 0)
        break;

      convertStringToArgcv (pszInputLine, &argc, &argv);
#ifdef DEBUG
      for (int i = 0; i < argc; i++)
        std::cout << "Token " << i << ": " << argv[i] << "\n";
#endif
      iReturn = processCommand (argc, argv);

      delete pszInputLine;
    }
  }

  return iReturn;
}
Beispiel #2
0
void main (void)
{
	DDRB = 0xff;
	PORTB = 0;

	initUart(9600, 0);

#ifdef DEBUG
	printHelp(NULL);
#endif

	// initialize the 16-bit timer
	TCCR1A = _BV(COM1A1);
	TCCR1B |= TIMER1_CLOCKSOURCE;
	TIMSK = _BV (TOIE1);

	memset(info, 0, sizeof(struct LED_INFO) * 8);

	process = force = 0;

	sei ();
	while(1)
	{
		if(UCSRA & (1 << RXC))
			processCommand();
	}
}
Beispiel #3
0
int main(int argc, char** argv){
    GraphDiscription modelJets, bunchGraph, graphTemplate;
    ImageList *modelImages, *novelImages;
    JetMasks masks;
    Arguments args;

    srand(time(NULL));

    processCommand(argc, argv, &args);

    /* build masks */
    masks = readMasksFile(args.masksFile);
    modelImages = getImageNames(args.modelFile, NULL);
    novelImages = getImageNames(args.novelFile, NULL);
    graphTemplate = readGraphDiscription(makePath(args.graphDir,modelImages->filename));

    /* extract model jets */
    modelJets = extractModelJets(modelImages, args.imageDir, args.graphDir, masks);

    /* build jet bunch */
    /* bunchGraph = buildBunchGraph(modelJets, args.distance, args.bunchSize); */
    bunchGraph = modelJets;

    /* locate features in novel image */
    locateNovelFeatures(novelImages, graphTemplate, bunchGraph, masks, args.imageDir, args.outputDir, args.dispEst);

    return 0;
}
bool MeetAndroid::receive(){
	uint8_t lastByte;
	boolean timeout = false;
	while(!timeout)
	{
		while(Serial.available() > 0)
		{
			lastByte = Serial.read();
			
			if(lastByte == abord){
				flush();
			}
			else if(lastByte == ack){
				processCommand();
				flush();
			}
			else if(bufferCount < ByteBufferLenght){
				buffer[bufferCount] = lastByte;
				bufferCount++;
			}
			else return false;
		}
		
		if(Serial.available() <= 0 && !timeout){
			if(waitTime > 0) delayMicroseconds(waitTime);
			if(Serial.available() <= 0) timeout = true;
		}
	}
	return timeout;
}
Beispiel #5
0
/*usart code*/
void usart_gogo(){
	if(checkUSARTflag_up()){
		usart_data = receiveByte_up();
		usart_data &= 0x3F;	//Maska ut kommandot 
		processCommand(usart_data);
	}
}
int main( void ) {
	// initalise UART
	uart_init( UART_BAUD_RATE );
	
	statusLed_init( );
	
	// flash status LED for a bit
	statusLed_orange( );
	delay_ms( 500 );
	statusLed_green( );
	
	// uart_getc should block until data received
	uart_setBlocking( true );
	
	while ( 1 ) {
		// main loop of the programmer
		
		if ( uart_hasData( ) ) {
			unsigned char cmd = uart_getc( );
			
			processCommand( cmd );
		}
	}

	return 0;
}
Beispiel #7
0
std::string Transaction::processLine(const std::string& line) {
	const char* delims = " \t";
	bool last = false;
	// TODO Handle quotes. Double and single per bash?
	std::string::size_type pos = line.find_first_not_of(delims);
	if (pos == std::string::npos) {
		// Whitespace only.
		return "";
	}
	vector<std::string> args;
	while (!last) {
		std::string::size_type nextPos = line.find_first_of(delims, pos);
		if (nextPos == std::string::npos) {
			nextPos = line.length();
			last = true;
		}
		std::string part = line.substr(pos, nextPos - pos);
		args.push_back(part);
		if (!last) {
			pos = line.find_first_not_of(delims, nextPos);
			if (pos == std::string::npos) {
				last = true;
			}
		}
	}
	return processCommand(args);
}
Beispiel #8
0
/**
 * Parse one command line
 * @param context
 * @param data - complete command line
 * @param len - command line length
 * @return 1 if the last evaluated command was found
 */
int SCPI_Parse(scpi_t * context, char * data, size_t len) {
    int result = 0;
    const char * cmdline_end = data + len;
    char * cmdline_ptr = data;
    size_t cmd_len;
    size_t cmdline_len;
    char * cmdline_ptr_prev = NULL;
    size_t cmd_len_prev = 0;

    if (context == NULL) {
        return -1;
    }

    while (cmdline_ptr < cmdline_end) {
        result = 0;
        cmd_len = cmdTerminatorPos(cmdline_ptr, cmdline_end - cmdline_ptr);
        if (cmd_len > 0) {
            composeCompoundCommand(cmdline_ptr_prev, cmd_len_prev,
                                    &cmdline_ptr, &cmd_len);
            cmdline_len = cmdlineSeparatorPos(cmdline_ptr, cmdline_end - cmdline_ptr);
            if(findCommand(context, cmdline_ptr, cmdline_len, cmd_len)) {
                processCommand(context);
                result = 1;
                cmdline_ptr_prev = cmdline_ptr;
                cmd_len_prev = cmd_len;
            } else {
                SCPI_ErrorPush(context, SCPI_ERROR_UNDEFINED_HEADER);
            }
        }
        cmdline_ptr += skipCmdLine(cmdline_ptr, cmdline_end - cmdline_ptr);
        cmdline_ptr += skipWhitespace(cmdline_ptr, cmdline_end - cmdline_ptr);
    }
    return result;
}
Beispiel #9
0
int appendFileMotionStats(char * filename,struct motionStats *st,struct InputParserC * ipc,unsigned int startAtFrame)
{
 char line [512]={0};

 fprintf(stderr,"Opening file %s\n",filename);
 FILE * fp = fopen(filename,"r");
 if (fp == 0 ) { fprintf(stderr,"Cannot open stream %s \n",filename); return 0; }


   while (!feof(fp))
   {
   //We get a new line out of the file
   int readOpResult = (fgets(line,512,fp)!=0);
   if ( readOpResult != 0 )
    {
      //We tokenize it
      unsigned int words_count = InputParser_SeperateWords(ipc,line,0);
      if ( words_count > 0 )
         {
             processCommand(ipc,st,line,words_count,startAtFrame);
         } // End of line containing tokens
    } //End of getting a line while reading the file
  }


  fclose(fp);
  return 1;
}
Beispiel #10
0
int main(int argc, char *argv[]) 
{
initialize();
getCommandLineArgs(argc, argv);
processCommand(stdin);	
return 0;
}
Beispiel #11
0
void Programmanalisator::ProgramEinladen(QTextDocument* dok)

{
    LBL_lin.clear();
    LBL_rep.clear();
    LBL_call.clear();
    int Nstr = dok->lineCount();

    for (int i=0; i<(dok->lineCount()); i++ ) {

        QString* Kadr= new QString(dok->findBlockByLineNumber(i).text());

        int Res = processCommand(Kadr, i);

        if (Res<0) {
            QString str1=tr("Ошибка: Строка: ")+QString::number(i); // ошибка - выдадим сообщение
            errorMessage(str1);
        } else if (Res>0) {
            i=LBL_lin[I1];
            qDebug()<<"linie"<<I1;
        }

        int progress=(int)(((i+1)*100)/Nstr);
        qDebug()<<progress<<"%";
        emit Progress(progress);
        delete Kadr;
    }

    emit fertig();
}
Beispiel #12
0
/*******************************************************************************
 * TzCtrl
 *
 * Task for receiving commands from Tracealyzer and for recorder diagnostics.
 *
 ******************************************************************************/
static portTASK_FUNCTION( TzCtrl, pvParameters )
{
	TracealyzerCommandType msg;
	int bytes = 0;

	while (1)
	{
		bytes = 0;
		TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), &bytes);
		if (bytes != 0)
		{
			if (bytes == sizeof(TracealyzerCommandType))
			{
				if (isValidCommand(&msg))
				{
					processCommand(&msg); /* Start or Stop currently... */
				}
			}
		}

		do
		{
			bytes = 0;
			TRC_STREAM_PORT_PERIODIC_SEND_DATA(&bytes);
		}
		while (bytes != 0);

		CheckRecorderStatus();
		vTaskDelay(TRC_CTRL_TASK_DELAY);	/* 10ms */
	}
}
Beispiel #13
0
void checkReceive(char letter) {

    // Starts new received word when start character arrives
    if (letter == START) {
        rcvData.currentIndex = 0;
        rcvData.message[rcvData.currentIndex] = letter;
        rcvData.currentIndex++;
        return;
    }
    // More than 8 bytes without an end byte
    if (rcvData.currentIndex > 7) {
        rcvData.currentIndex = 0;
        return;
    }

    // Stores current letter in word
    rcvData.message[rcvData.currentIndex] = letter;

    // Indicates word has been properly assembled
    if (letter == END && rcvData.currentIndex == 7) {
        rcvData.currentIndex = 0;
        // Sends message out
        processCommand();
    }

    rcvData.currentIndex++;

}
Beispiel #14
0
bool StreamBase::checkCommandQueue() {
  if ( sd >= 0 ) {
    CmdMsg msg;
    memset(&msg, 0, sizeof(msg));
    int nbytes = recvfrom(sd, &msg, sizeof(msg), MSG_DONTWAIT, 0, 0);
    if ( nbytes < 0 ) {
      if ( errno != EAGAIN ) {
        Error("recvfrom(), errno = %d, error = %s", errno, strerror(errno));
        return false;
      }
    }
    //else if ( (nbytes != sizeof(msg)) )
    //{
      //Error( "Partial message received, expected %d bytes, got %d", sizeof(msg), nbytes );
    //}
    else {
      Debug(2, "Message length is (%d)", nbytes);
      processCommand(&msg);
      return true;
    }
  } else {
    Warning("No sd in checkCommandQueue, comms not open?");
  }
  return false;
}
Beispiel #15
0
/**
 * Parse one command line
 * @param context
 * @param data - complete command line
 * @param len - command line length
 * @return 1 if the last evaluated command was found
 */
int SCPI_Parse(scpi_t * context, const char * data, size_t len) {
    int result = 0;
    const char * cmdline_end = data + len;
    const char * cmdline_ptr = data;
    size_t cmd_len;
    size_t cmdline_len;

    if (context == NULL) {
        return -1;
    }

	
    while (cmdline_ptr < cmdline_end) {
        result = 0;
        cmd_len = cmdTerminatorPos(cmdline_ptr, cmdline_end - cmdline_ptr);
        cmdline_len = cmdlineSeparatorPos(cmdline_ptr, cmdline_end - cmdline_ptr);
        if (cmd_len > 0) {
            if(findCommand(context, cmdline_ptr, cmdline_len, cmd_len)) {
                processCommand(context);
                result = 1;
            } else {
                SCPI_ErrorPush(context, SCPI_ERROR_UNDEFINED_HEADER);
            }
        }
        cmdline_ptr = cmdlineNext(cmdline_ptr, cmdline_end - cmdline_ptr);
    }
    return result;
}
Beispiel #16
0
//---------------------------------------------------------------------
void loop()
{
    waitForIncomingConnection();
    
    while ( client_.connected() )
    {
        uint8_t cmd = 255;
        
        if ( checkTcpTimeout() )
        {
#ifdef DEBUG_SERIAL
            Serial.println( "ERROR: connection timeout!" );
#endif
            break;
        }
        
        cmd = getCommand();
        if ( cmd == COMMAND_INVALID_COMMAND )
        {
#ifdef DEBUG_SERIAL
            Serial.print( "ERROR: invalid command received: ");
            Serial.println( cmd );
#endif
            break;
        }
        
        processCommand( cmd );
    }
    terminateConnection();
}
  int readCommandFile(const char *path)
  {
    DEBUGMSG("reading command file " << path);

    QFile file(QFile::decodeName(path));
    if (!file.open(QFile::ReadOnly))
    {
      std::cout << "invalid" << std::endl;
      return ERR_INVALID;
    }

    LogCache cache;
    QVector<char*> argv;
    QTextStream stream(&file);
    while (!stream.atEnd())
    {
      QString line = stream.readLine();
      if (line.isEmpty())
        continue;
      auto args = line.toUtf8().split(' ');
      argv.resize(args.size() + 1);

      int argc = 0;
      for (auto &arg : args)
        argv[argc++] = arg.data();
      argv[argc] = nullptr;

      processCommand(argc, argv.data(), &cache);
    }

    qDeleteAll(cache); // clean up cached files
    return 0;
  }
int CommandExecutor::executorReceive(char recvChar)
{
	if (recvChar == 27) // ESC -> delete current commandLine
	{
		recvCommand.clear();
		if (commandHandler.getVerboseMode() == VERBOSE)
		{
			commandOutput->printf("\r\n%s",commandHandler.getCommandPrompt().c_str());
			commandOutput->flush();
		}
	}
	else if (recvChar == commandHandler.getCommandEOL())
	{
		processCommand(recvCommand);
		recvCommand.clear();
	}
	else
	{
		if (isprint(recvChar))
		{
			recvCommand.cmdString += recvChar;
		}
	}
	return 0;
}
Beispiel #19
0
void AdminConnection::processNormalFrame()
{
  InputFrame::Ptr frame( new InputFrame(version,paddingfilter) );
  if (readFrame(frame)) {
    try {
      switch (frame->getType()) {
        case ftad_CommandDesc_Get:
          processDescribeCommand(frame);
          break;
        case ftad_CommandTypes_Get:
          processGetCommandTypes(frame);
          break;
        case ftad_Command:
          processCommand(frame);
          break;
        default:
          WARNING("AdminConnection: Discarded frame, not processed, was type %d", frame->getType());
          throw FrameException( fec_ProtocolError, "Did not understand that frame type.");
          break;
      }
    } catch ( FrameException& exception ) {
      // This might be overkill later, but now let's log it
      DEBUG( "AdminConnection caught FrameException : %s", exception.what() );
      sendFail( frame, exception.getErrorCode(), exception.getErrorMessage() );
    }
  } else {
    DEBUG("noFrame :(");
    // client closed
  }
}
Beispiel #20
0
int  main(void){
    init();
    while(1){
        processCommand();
    }
    return 0;
}
Beispiel #21
0
/**
* Add a command which has already been broken up into its arguments.
*/
PointSegment* GcodeParser::addCommand(const QStringList &args)
{
    if (args.isEmpty()) {
        return NULL;
    }
    return processCommand(args);
}
		void ApiP2PExtensionHandler::run()
		{
			std::string buffer = "";
			_stream << ClientHandler::API_STATUS_OK << " SWITCHED TO P2P_EXTENSION" << std::endl;

			// run as long the stream is ok
			while (_stream.good())
			{
				getline(_stream, buffer);

				if (buffer.length() == 0) continue;

				// search for '\r\n' and remove the '\r'
				std::string::reverse_iterator iter = buffer.rbegin();
				if ( (*iter) == '\r' ) buffer = buffer.substr(0, buffer.length() - 1);

				std::vector<std::string> cmd = dtn::utils::Utils::tokenize(" ", buffer);
				if (cmd.empty()) continue;

				if (cmd[0] == "exit")
				{
					// return to previous level
					break;
				}
				else
				{
					// forward to standard command set
					processCommand(cmd);
				}
			}
		}
Beispiel #23
0
//PRIVATE SLOTS
void FtpHandler::managerFinished(QNetworkReply *reply)
{
    if(reply->error() != QNetworkReply::NetworkError::NoError)
        emit error(reply->errorString());

    FTPCommand *finishedCommand = cmdList.takeFirst();
    if(finishedCommand->getMode() == FTPCommand::Mode::DOWNLOAD)
        {
            QByteArray data = reply->readAll();
            QString downloadedFileName = QString("%1/%2").arg(finishedCommand->getDownloadLocation()).arg(finishedCommand->getFilename());
            QFile *file = new QFile(downloadedFileName);
            if(file->open(QIODevice::ReadWrite))
                {
                    file->write(data);
                    file->close();
                }
            else
                emit error(QString(tr("Could not save downloaded File: %1")).arg(finishedCommand->getFilename()));
        }

    if(!cmdList.isEmpty())
        processCommand();
    else
        state = State::IDLE;

    emit finished(finishedCommand->getFilename());
    reply->deleteLater();
    delete finishedCommand;
}
Beispiel #24
0
bool StreamBase::checkCommandQueue()
{
    if ( sd >= 0 )
    {
        CmdMsg msg;
        memset( &msg, 0, sizeof(msg) );
        int nbytes = recvfrom( sd, &msg, sizeof(msg), MSG_DONTWAIT, 0, 0 );
        if ( nbytes < 0 )
        {
            if ( errno != EAGAIN )
            {
                Fatal( "recvfrom(), errno = %d, error = %s", errno, strerror(errno) );
            }
        }
        //else if ( (nbytes != sizeof(msg)) )
        //{
            //Error( "Partial message received, expected %d bytes, got %d", sizeof(msg), nbytes );
        //}
        else
        {
            processCommand( &msg );
            return( true );
        }
    }
    return( false );
}
Beispiel #25
0
void processRspFile(FILE *rspfile, const char *filename)
{
    FILE    *localrsp = fopen(filename+1, "r");
    char    *buffer = malloc(BUFSIZE), *p;

    if (!buffer) {
        printf("Out of memory!\n");
        exit(-1);
        }
    if (!localrsp) {
        printf("Unable to open response file %s!\n", filename);
        exit(-1);
        }

    while (fgets(buffer, BUFSIZE, localrsp)) {
        p = strtok(buffer, " ");
        while (p) {
            processCommand(rspfile, p);
            p = strtok(NULL, " ");
            }
        }

    fclose(localrsp);
    free(buffer);
}
Beispiel #26
0
/*
-- FUNCTION: main
--
-- DATE: September 23, 2011
--
-- REVISIONS:
--
-- DESIGNER: Karl Castillo
--
-- PROGRAMMER: Karl Castillo
--
-- INTERFACE: int main(int argc, char** argv)
--				argc - number of arguments
--				argv - the arguments
--
-- RETURNS: int - 0
--
-- NOTES:
-- This is the main function where the arguments are parsed and proper 
-- preparations are done. These preparations include initializing sockets.
*/
int main(int argc, char** argv)
{
	char* ipAddr = 0;
	int option = 0;
	int controlSocket = 0;

	if(argc < 3) {
		fprintf(stderr, "Not Enough Arguments\n");
		fprintf(stderr, USAGE, argv[0]);
        exit(EXIT_FAILURE);
	}

	while((option = getopt(argc, argv, ":i:")) != -1)
    {
        switch(option)
        {
        case 'i':
            ipAddr = optarg;
            break;
        default:
            fprintf(stderr, USAGE, argv[0]);
            exit(EXIT_FAILURE);
        }
    }
    
	controlSocket = initConnection(DEF_PORT, ipAddr);
	processCommand(&controlSocket);

	return 0;
}
Beispiel #27
0
//lex method - lexes a string and returns a parse chain of its parts
LexNode* Lexer::lex(std::string stringToLex) {
	LexNode* apc = nullptr; //the parse chain
	std::string processStr = stringToLex; //get a local copy of the string
	processStr.append(" "); //workaround to prevent a segfault
	std::vector<char> text; //the destination area for the text to parse
	ParseToken t; //the token that is the parse result
	for (char& c : processStr) { //loop through the supplied string
		if (c == ' ' || c == '\n') { //if a space or newline is found
			text.push_back('\0'); //add a null
			char* str = &text[0]; //get the string
			text.clear(); //clear the vector
			t = processCommand(str); //handle the different commands
			if (apc == nullptr) { //if the parse chain doesn't exist
				apc = new LexNode(str, t); //start the parse chain
			} else { //if it does
				apc->addLexNode(str, t); //add a node
			}
			if (c == '\n') { //if a newline was found
				apc->addLexNode("\n", ParseToken::EOL); //add a line end token to the parse chain
			}

		} else { //if no space or newline was found
			text.push_back(c); //add the character to the vector
		}
	}
	return apc; //return the parse chain
}
Beispiel #28
0
int main (int argc, const char * argv[]) {
  int cnt;
  for (cnt = 1; cnt < argc; cnt++) {
    processCommand(argv[cnt]);
  }
  return 0;
}
Beispiel #29
0
int main() {
    int T;
    scanf("%d", &T);

    for (int i = 0; i < T; i++) {
        int N;
        scanf("%d", &N);

        double x = 0;
        double y = 0;
        double teta = 0;

        for (int j = 0; j < N; j++) {
            char command[3];
            double number;
            scanf("%s %lf", command, &number);
            processCommand(x, y, teta, command, number);
        }

        printf("%d\n", int(distance(x, y)));
    }


    return 0;
}
Beispiel #30
0
int processCommandIfExist(char* message, ClientInfo* ci) {
	if (message != NULL && strlen(message) > 0 && message[0] == '#') {
		processCommand(message, ci);
		return 1;
	} else
		return 0;
}