Need coding help modifying ASCII protocol code

Hi all,
I am trying to make UART communication faster for high update counts by modifying the ASCII protocol file to accept one character for an instruction. I am using a Teensy 3.2 with HW serial. And using ODive v3.5

Say I want read the encoder position of axis 0.
Using the Arduino library provided, we use the commnd:

if (Serial.available()) {
char c = Serial.read();

if (c == 's') {
  odrive_serial << "r axis0.encoder.pos_estimate\n";
  odriveResponse();
}

This of course works, and it gives me the value I am looking for. The problem for me however, is that this command took 2.5ms to be sent.

A work around to this problem is to modify the ASCII file and add the following code:

if (cmd[0] == 's') { // status; position, velocity, current
    unsigned motor_number;
    int numscan = sscanf(cmd, "s %u", &motor_number);
    if (numscan < 1) {
        respond(response_channel, use_checksum, "invalid command format");
    } else if (motor_number >= AXIS_COUNT) {
        respond(response_channel, use_checksum, "invalid motor %u", motor_number);
    } else {
        respond(response_channel, use_checksum, "%f",
                (double)axes[motor_number]->encoder_.pos_estimate_);
    }

Now using the Teensy, I can send the following:

if (Serial.available()) {
char c = Serial.read();

if (c == 's') {
  odrive_serial << "s 0\n";
  odriveResponse();
}

This results in the command being sent in 370us, so about 7 times faster!!

Now that this works. I need help getting other reading and writing commands to work using the above mentioned method.

I need to be able to WRITE commands for:
1- axis0.requested_state = value
2- axis0.trap_traj.config.vel_limit = value
3- axis0.controller.input_pos = value (RazorsEdge firmware)
4- axis0.error = 0

I need to be able to READ the following values:
1- axis0.requested_state (I need to know what state the axis is in)
2- axis0.trap_traj.config.vel_limit
3- axis0.motor.config.current_lim
4- axis0.controller.trajectory_done (need to know if motion has ended (boolean))
5- axis.0.motor.is_calibrated (boolean)
6- axis0.error

I wanna thank @mike for helping me with the above code.
Thanks in advance to all that help.

Jamil

Here is what I tried so far:

1- Writing to axis0.requested_state

if (cmd[0] == 'n') { // change current limit
    unsigned motor_number;
    int32_t value;
    int numscan = sscanf(cmd, "n %u %i", &motor_number, &value);
    if (numscan < 1) {
        respond(response_channel, use_checksum, "invalid command format");
    } else if (motor_number >= AXIS_COUNT) {
        respond(response_channel, use_checksum, "invalid motor %u", motor_number);
    } else {
        //respond(response_channel, use_checksum, "%u %i", motor_number, value);
        axes[motor_number]->requested_state = value;
    }

2- Writing to axis0.trap_traj.config.vel_limit = value

if (cmd[0] == 'n') { // change current limit
    unsigned motor_number;
    int32_t value;
    int numscan = sscanf(cmd, "n %u %i", &motor_number, &value);
    if (numscan < 1) {
        respond(response_channel, use_checksum, "invalid command format");
    } else if (motor_number >= AXIS_COUNT) {
        respond(response_channel, use_checksum, "invalid motor %u", motor_number);
    } else {
        //respond(response_channel, use_checksum, "%u %i", motor_number, value);
        axes[motor_number]->trap_traj_.config_.vel_limit = value;
    }

Reading the value axis0.trap_traj.config.vel_limit

if (cmd[0] == 'n') { // change current limit
    unsigned motor_number;
    int numscan = sscanf(cmd, "n %u", &motor_number);
    if (numscan < 1) {
        respond(response_channel, use_checksum, "invalid command format");
    } else if (motor_number >= AXIS_COUNT) {
        respond(response_channel, use_checksum, "invalid motor %u", motor_number);
    } else {
        respond(response_channel, use_checksum, "%f", axes[motor_number]->trap_traj_.config_.vel_limit);
    }

Also Tried:

else if (cmd[0] == 'm') { // change current limit
    char name[MAX_LINE_LENGTH] = "axis0.requested_state";
    Endpoint* endpoint = application_endpoints_->get_by_name(name, sizeof(name));
    if (!endpoint) {
        respond(response_channel, use_checksum, "invalid property");
    } else {
        char response[10];
        bool success = endpoint->get_string(response, sizeof(response));
        if (!success)
            respond(response_channel, use_checksum, "not implemented");
        else
            respond(response_channel, use_checksum, response);
    }

None of the above worked for me. Hopefully someone with better coding abilities can help out.

Jamil