ibutton: fix cli command reading (#449)

Co-authored-by: SG <who.just.the.doctor@gmail.com>
This commit is contained in:
gornekich 2021-05-07 03:37:28 +03:00 committed by GitHub
parent fb73d3bd52
commit 19637c6fc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,7 +76,7 @@ void iButtonApp::cli_cmd_callback(string_t args, void* context) {
// Parse write / emulate commands // Parse write / emulate commands
size_t ws = string_search_char(args, ' '); size_t ws = string_search_char(args, ' ');
if(ws == STRING_FAILURE) { if(ws == STRING_FAILURE) {
printf("Incorrect input. Try tm <read | write | emulate> [key_type] [key_data]\r\n"); printf("Incorrect input. Try tm <read | write | emulate> [key_type] [key_data]");
string_clear(cmd); string_clear(cmd);
return; return;
} else { } else {
@ -89,7 +89,7 @@ void iButtonApp::cli_cmd_callback(string_t args, void* context) {
} else if(!string_cmp_str(cmd, "emulate")) { } else if(!string_cmp_str(cmd, "emulate")) {
scene = iButtonApp::Scene::SceneCliEmulate; scene = iButtonApp::Scene::SceneCliEmulate;
} else { } else {
printf("Incorrect input. Try tm <write | emulate> <key_type> <key_data>\r\n"); printf("Incorrect input. Try tm <write | emulate> <key_type> <key_data>");
string_clear(cmd); string_clear(cmd);
return; return;
} }
@ -125,7 +125,7 @@ void iButtonApp::cli_cmd_callback(string_t args, void* context) {
ret = read_hex_byte(args, &key_data[i++]); ret = read_hex_byte(args, &key_data[i++]);
} }
if(i != bytes_to_read) { if(i != bytes_to_read) {
printf("Incorrect key data\r\n"); printf("Incorrect key data. Type %d key data hex digits", bytes_to_read);
return; return;
} }
key.set_data(key_data, bytes_to_read); key.set_data(key_data, bytes_to_read);
@ -140,30 +140,32 @@ void iButtonApp::cli_cmd_callback(string_t args, void* context) {
// Wait return event // Wait return event
iButtonApp::CliEvent result; iButtonApp::CliEvent result;
if(osMessageQueueGet(cli_event_result, &result, NULL, osWaitForever) != osOK) { if(osMessageQueueGet(cli_event_result, &result, NULL, osWaitForever) != osOK) {
printf("Command execution error\r\n"); printf("Command execution error");
return; return;
} }
// Process return event // Process return event
switch(result) { switch(result) {
case iButtonApp::CliEvent::CliReadSuccess: case iButtonApp::CliEvent::CliReadSuccess:
print_key_data();
case iButtonApp::CliEvent::CliReadCRCError: case iButtonApp::CliEvent::CliReadCRCError:
printf("Read error: invalid CRC\r\n"); print_key_data();
if(result == iButtonApp::CliEvent::CliReadCRCError) {
printf("Warning: invalid CRC");
}
break; break;
case iButtonApp::CliEvent::CliReadNotKeyError: case iButtonApp::CliEvent::CliReadNotKeyError:
printf("Read error: not a key\r\n"); printf("Read error: not a key");
break; break;
case iButtonApp::CliEvent::CliTimeout: case iButtonApp::CliEvent::CliTimeout:
printf("Timeout error\r\n"); printf("Timeout error");
break; break;
case iButtonApp::CliEvent::CliInterrupt: case iButtonApp::CliEvent::CliInterrupt:
printf("Command interrupted\r\n"); printf("Command interrupted");
break; break;
case iButtonApp::CliEvent::CliWriteSuccess: case iButtonApp::CliEvent::CliWriteSuccess:
printf("Write success\r\n"); printf("Write success");
break; break;
case iButtonApp::CliEvent::CliWriteFail: case iButtonApp::CliEvent::CliWriteFail:
printf("Write fail\r\n"); printf("Write fail");
break; break;
default: default:
break; break;