This is what I think you were going for. I fixed the warning messages and added the conversion from ascii to integer. It seems to be parsing commands correctly:
Device ready.
> help
Available commands:
help
passthrough
bind
read
write
Use "help <command> " for further details on a command.
Note: use of certain functions may take longer to process.
> help passthrough
Sets the state of controller passthrough.
On: Controller passthrough enabled.
Off: controller passthrough disabled.
On by default
> passthrough on
Passthrough on.
> passthrough off
Passthrough off.
> read 0
0
> read 1
0
> read 2
0
> write 0
0
> write 0 512
512
> write 1 256
256
> write 2 99
99
>
const byte RecieverPins[] = {2, 4, 7}; //Set what pins have been used to connect to the reciever in order of channel.
const byte OutputPins[] = {6, 3, 5}; //Set what pins to use to communicate to rc car.
const byte bindpin = 8;
boolean passthrough = true;
#define LINE_BUF_SIZE 128
#define ARG_BUF_SIZE 64
#define MAX_NUM_ARGS 3
bool error_flag = false;
char line[LINE_BUF_SIZE];
char args[MAX_NUM_ARGS][ARG_BUF_SIZE];
//FUNCTIONS
void cmd_help(); //List the 5 commands
void cmd_passthrough(); //Enable passthrough
void cmd_bind(); //Toggle BIND mode on the reciever.
void cmd_read();
void cmd_write();
//List of functions for each command.
void (*commands_func[])()
{
cmd_help, cmd_passthrough, cmd_bind, cmd_read, cmd_write
};
//COMMANDS
const char *commands_str[] =
{
"help", "passthrough", "bind", "read", "write"
};
//APPLICATION ARGUMENTS
const char *passthrough_args[] =
{
"on", "off"
};
const char *bind_args[] =
{
"on", "off"
};
const int num_commands = sizeof commands_str / sizeof commands_str[0];
//
// SETUP LOOP
void setup()
{
for (int i = 0; i < 3; i++)
{
pinMode(RecieverPins[i], INPUT); //set reciever side pins as input to read PWM goodness.
}
pinMode(bindpin, OUTPUT);
digitalWrite(bindpin, LOW);
Serial.begin(115200);
cli_init();
}
//
//
//
//
//MAIN LOOP
void loop()
{
RCcli();
}
//
//
//
//
//
//
//
void cli_init()
{
Serial.println("Device ready.");
}
void RCcli()
{
Serial.print("> ");
read_line();
if (!error_flag)
{
parse_line();
}
if (!error_flag)
{
execute();
}
memset(line, 0, LINE_BUF_SIZE);
memset(args, 0, sizeof(args[0][0]) * MAX_NUM_ARGS * ARG_BUF_SIZE);
error_flag = false;
}
void read_line()
{
String line_string;
while (!Serial.available());
if (Serial.available())
{
line_string = Serial.readStringUntil('\n');
if (line_string.length() < LINE_BUF_SIZE)
{
line_string.toCharArray(line, LINE_BUF_SIZE);
Serial.println(line_string);
}
else
{
Serial.println("Invalid data.");
error_flag = true;
}
}
}
void parse_line()
{
char *argument;
int counter = 0;
argument = strtok(line, " ");
while ((argument != NULL))
{
if (counter < MAX_NUM_ARGS)
{
if (strlen(argument) < ARG_BUF_SIZE)
{
strcpy(args[counter], argument);
argument = strtok(NULL, " ");
counter++;
}
else
{
Serial.println("Invalid data.");
error_flag = true;
break;
}
}
else
{
break;
}
}
}
void execute()
{
for (int i = 0; i < num_commands; i++)
{
if (strcmp(args[0], commands_str[i]) == 0)
{
(*commands_func[i])();
return;
}
}
Serial.println("Invalid command.");
return;
}
void cmd_help()
{
if (args[1] == NULL)
{
help_help();
}
else if (strcmp(args[1], commands_str[0]) == 0)
{
help_help();
}
else if (strcmp(args[1], commands_str[1]) == 0)
{
help_passthrough();
}
else if (strcmp(args[1], commands_str[2]) == 0)
{
help_bind();
}
else if (strcmp(args[1], commands_str[3]) == 0)
{
help_dataFunct();
}
else
{
help_help();
}
}
void help_help()
{
Serial.println("Available commands:");
for (int i = 0; i < num_commands; i++)
{
Serial.print(" ");
Serial.println(commands_str[i]);
}
Serial.println("");
Serial.println("Use \"help <command> \" for further details on a command.");
Serial.println("Note: use of certain functions may take longer to process.");
}
void help_passthrough()
{
Serial.print("Sets the state of controller passthrough.\n");
Serial.println("On: Controller passthrough enabled.\n");
Serial.println("Off: controller passthrough disabled.\n");
Serial.println("On by default\n");
}
void help_bind()
{
Serial.print("Sets BIND mode on or off.\n");
Serial.println("On: sets BIND mode on.\n");
Serial.println("Off: sets BIND mode off.\n");
}
void help_dataFunct()
{
Serial.print("Data command that allows read and writes on PWM channels.\n");
Serial.println("read <channel> <PWM Value>\n");
Serial.println("write <channel> <PWM Value>\n");
}
void cmd_passthrough()
{
if (strcmp(args[1], passthrough_args[0]) == 0)
{
Serial.println("Passthrough on.");
passthrough = true;
}
else if (strcmp(args[1], passthrough_args[1]) == 0)
{
Serial.println("Passthrough off.");
passthrough = false;
}
}
void cmd_bind()
{
if (strcmp(args[1], bind_args[0]) == 0)
{
Serial.println("Bind mode on");
digitalWrite(bindpin, HIGH);
}
else if (strcmp(args[1], bind_args[1]) == 0)
{
Serial.println("Bind mode off");
digitalWrite(bindpin, LOW);
}
}
void cmd_read()
{
int channel = atoi(args[1]);
unsigned long pwm_value = pulseIn(RecieverPins[channel], HIGH, 20000);
Serial.println(pwm_value);
}
void cmd_write()
{
int channel = atoi(args[1]);
int pwm_value = atoi(args[2]);
analogWrite(OutputPins[channel], pwm_value);
Serial.println(pwm_value);
}