Beispiel #1
0
void shellPrompt()
{
    	while(1)
    	{
    		char order[ORDER_LEN];
    	
    		printf("myshell$");//提示符
    		scanf("%s", order); 			
    
    		if (strcmp(order, "doit") == 0)
		{
			commandExecute();
		}
		else
		{
			if (strcmp(order, "exit") == 0)
			{
				return;
			}
			else
			{
				continue;
			}
		}
	}
}
Beispiel #2
0
static void commandCharIn(unsigned char ch) {
    switch (commandData.state) {
    case COMMAND_WAIT_SYNC1:
        if (ch == COMMAND_SYNC1)
            commandData.state = COMMAND_WAIT_SYNC2;
        break;

    case COMMAND_WAIT_SYNC2:
        if (ch == COMMAND_SYNC2)
            commandData.state = COMMAND_WAIT_SYNC3;
        else
            commandData.state = COMMAND_WAIT_SYNC1;
        break;

    case COMMAND_WAIT_SYNC3:
        if (ch == COMMAND_COMMAND) {
            commandData.checkA = commandData.checkB = 0;
            commandData.state = COMMAND_WAIT_RQID1;
        }
        else if (ch == COMMAND_FLOAT_DUMP) {
            commandData.buf.commandId = COMMAND_ACC_IN;
            commandData.bufPoint = 1;
            commandData.checkA = commandData.checkB = 0;
            commandData.state = COMMAND_WAIT_ROWS;
        }
        else
            commandData.state = COMMAND_WAIT_SYNC1;
        break;

    case COMMAND_WAIT_RQID1:
        commandChecksum(ch);
        commandData.requestId[0] = ch;
        commandData.state = COMMAND_WAIT_RQID2;
        break;

    case COMMAND_WAIT_RQID2:
        commandChecksum(ch);
        commandData.requestId[1] = ch;
        commandData.state = COMMAND_WAIT_RQID3;
        break;

    case COMMAND_WAIT_RQID3:
        commandChecksum(ch);
        commandData.requestId[2] = ch;
        commandData.state = COMMAND_WAIT_RQID4;
        break;

    case COMMAND_WAIT_RQID4:
        commandChecksum(ch);
        commandData.requestId[3] = ch;
        commandData.state = COMMAND_WAIT_LEN;
        break;

    case COMMAND_WAIT_LEN:
        commandChecksum(ch);
        commandData.len = ch;
        commandData.bufPoint = 0;
        commandData.state = COMMAND_PAYLOAD;
        break;

    case COMMAND_WAIT_ROWS:
        commandChecksum(ch);
        *((char *)&commandData.buf + commandData.bufPoint++) = ch;
        commandData.len = ch;
        commandData.state = COMMAND_WAIT_FLOATS;
        break;

    case COMMAND_WAIT_FLOATS:
        commandChecksum(ch);
        *((char *)&commandData.buf + commandData.bufPoint++) = ch;
        commandData.len = commandData.bufPoint + commandData.len * ch * sizeof(float);
        commandData.state = COMMAND_PAYLOAD;
        break;

    case COMMAND_PAYLOAD:
        commandChecksum(ch);
        *((char *)&commandData.buf + commandData.bufPoint++) = ch;
        if (commandData.bufPoint == commandData.len)
            commandData.state = COMMAND_CHECK1;
        break;

    case COMMAND_CHECK1:
        if (ch == commandData.checkA) {
            commandData.state = COMMAND_CHECK2;
        }
        else {
            commandData.state = COMMAND_WAIT_SYNC1;
            commandData.checksumErrors++;
        }
        break;

    case COMMAND_CHECK2:
        commandData.state = COMMAND_WAIT_SYNC1;
        if (ch == commandData.checkB)
            commandExecute(&commandData.buf);
        else
            commandData.checksumErrors++;
        break;
    }
}