Вопрос

I am trying to write a command interface in C for telosb, the rule is: "shift+:" to start a new command, and "Esc" to end a command. So how should I tell a combination of "shift" and ":"? Thank you very much.

Это было полезно?

Решение

Keep interfaces simple on the MSP430. You do not have unlimited resources like you do on a PC. If you were looking to use a combination of characters to represent a command, you will need to perform string comparisons (which will be much easier than checking each individual character coming in with an if-else structure). I used to develop these interfaces using the following type of command structure:

struct command
{
    char *command;
    char *params;
    int numOfParams;
};

struct command commandList[] = 
{
    { "help", null, 0 },
    { "reset", "%x", 1 }
};

Then I would have my UART handler look for valid commands - a command that came in with a valid delimiter (for instance, a newline). Once a newline is read, then you can begin parsing the command and verifying it (by strcmp) with the commandList entries. The commandList contains the command, the type of parameters that are expected (use sscanf to validate parameters) and the number of parameters to expect.

This process can be extended to compare byte arrays as well (in your case using special characters such as ESC in hex).

I hope that helps you get started.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top