add property read/write functionality to ASCII protocol

Command examples:
r vbus_voltage
w axis0.config.enable_step_dir 1
This commit is contained in:
Samuel Sadok
2018-04-14 23:03:03 -07:00
parent bd292b4775
commit aee1a7343d
2 changed files with 141 additions and 4 deletions
+37 -3
View File
@@ -18,7 +18,9 @@
/* Global variables ----------------------------------------------------------*/
/* Private constant data -----------------------------------------------------*/
#define MAX_LINE_LENGTH 64
#define MAX_LINE_LENGTH 256
#define TO_STR_INNER(s) #s
#define TO_STR(s) TO_STR_INNER(s)
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
@@ -131,8 +133,40 @@ void ASCII_protocol_process_line(const uint8_t* buffer, size_t len, StreamSink&
respond(response_channel, use_checksum, "Flash Size: %#x KiB", STM_ID_GetFlashSize());
respond(response_channel, use_checksum, "Serial number: %s", serial_number_str);
// } else if (cmd[0] == 'r') { // read property
// } else if (cmd[0] == 'w') { // write property
} else if (cmd[0] == 'r') { // read property
char name[MAX_LINE_LENGTH];
int numscan = sscanf(cmd, "r %" TO_STR(MAX_LINE_LENGTH) "s", name);
if (numscan < 1) {
respond(response_channel, use_checksum, "invalid command format");
} else {
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);
}
}
} else if (cmd[0] == 'w') { // write property
char name[MAX_LINE_LENGTH];
char value[MAX_LINE_LENGTH];
int numscan = sscanf(cmd, "w %" TO_STR(MAX_LINE_LENGTH) "s %" TO_STR(MAX_LINE_LENGTH) "s", name, value);
if (numscan < 1) {
respond(response_channel, use_checksum, "invalid command format");
} else {
Endpoint* endpoint = application_endpoints->get_by_name(name, sizeof(name));
if (!endpoint) {
respond(response_channel, use_checksum, "invalid property");
} else {
bool success = endpoint->set_string(value, sizeof(value));
if (!success)
respond(response_channel, use_checksum, "not implemented");
}
}
} else if (cmd[0] == 'h') { // HALT
for(size_t i = 0; i < AXIS_COUNT; i++){