mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-28 01:58:11 -07:00
cc1101 modem configurable preset introduced.
Available to configure: datarate, bandwidth and manchester decoding flag log ability added to unit_test app (it's very helpful when writing a unit_tests)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <lib/subghz/subghz_keystore.h>
|
||||
#include <lib/subghz/subghz_file_encoder_worker.h>
|
||||
#include <lib/subghz/protocols/protocol_items.h>
|
||||
#include <lib/subghz/helpers/subghz_config_preset_custom.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
|
||||
#define TAG "SubGhz TEST"
|
||||
@@ -203,6 +204,132 @@ static bool subghz_encoder_test(const char* path) {
|
||||
return subghz_test_decoder_count ? true : false;
|
||||
}
|
||||
|
||||
static bool subghz_custom_preset_test(void) {
|
||||
static const uint8_t preset_data[][2] = {
|
||||
{CC1101_MDMCFG0, 0},
|
||||
{CC1101_MDMCFG1, 0},
|
||||
{CC1101_MDMCFG2, 0},
|
||||
{CC1101_MDMCFG3, 0},
|
||||
{CC1101_MDMCFG4, 0},
|
||||
};
|
||||
|
||||
static uint8_t test_data[sizeof(preset_data)] = {0};
|
||||
memcpy(test_data, preset_data, sizeof(preset_data));
|
||||
|
||||
uint8_t* test_data_ptr = &test_data[0];
|
||||
|
||||
{ // CHEKING BANDWIDTH SET
|
||||
for(uint32_t i = 0; i < CH_BANDWIDTH_NUM; ++i) {
|
||||
uint8_t bw_value = subghz_preset_custom_bandwidth_values[i];
|
||||
|
||||
bool result =
|
||||
subghz_preset_custom_set_bandwidth(test_data_ptr, sizeof(test_data), bw_value);
|
||||
if(!result) {
|
||||
FURI_LOG_E(TAG, "Failed to set BW value: %hhu", bw_value);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t get_bw_value =
|
||||
subghz_preset_custom_get_bandwidth(test_data_ptr, sizeof(test_data));
|
||||
if(get_bw_value != bw_value) {
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"BW value from preset: %hhu is not equal expected value: %hhu",
|
||||
get_bw_value,
|
||||
bw_value);
|
||||
return false;
|
||||
}
|
||||
|
||||
FURI_LOG_T(TAG, "Bandwidth check OK: %hhu", bw_value);
|
||||
}
|
||||
}
|
||||
|
||||
{ // CHEKING MACHESTER SET
|
||||
bool result =
|
||||
subghz_preset_custom_set_machester_enable(test_data_ptr, sizeof(test_data), false);
|
||||
if(!result) {
|
||||
FURI_LOG_E(TAG, "Failed to set manchester enable flag");
|
||||
return false;
|
||||
}
|
||||
bool flag = subghz_preset_custom_get_machester_enable(test_data_ptr, sizeof(test_data));
|
||||
if(flag != false) {
|
||||
FURI_LOG_E(TAG, "Manchester disable flag setup failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
subghz_preset_custom_set_machester_enable(test_data_ptr, sizeof(test_data), true);
|
||||
flag = subghz_preset_custom_get_machester_enable(test_data_ptr, sizeof(test_data));
|
||||
if(flag != true) {
|
||||
FURI_LOG_E(TAG, "Manchester enable flag setup failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
FURI_LOG_T(TAG, "Manchester flag check OK");
|
||||
}
|
||||
{ // CHEKING DATARATE SET
|
||||
const float datarateRoughMax = 1600000.0f; // bauds
|
||||
const float datarateRoughStep = 5000.0f;
|
||||
|
||||
const float datarateFineMax = 30000.0f;
|
||||
const float datarateFineStep = 50.0f;
|
||||
|
||||
bool result = false;
|
||||
char datarate_set_str[16] = {0};
|
||||
char datarate_get_str[16] = {0};
|
||||
|
||||
float datarate_set = datarateRoughMax;
|
||||
float datarate_get = -1.0f;
|
||||
while(datarate_set > 0) {
|
||||
subghz_preset_custom_printf_datarate(
|
||||
datarate_set, datarate_set_str, sizeof(datarate_set_str));
|
||||
|
||||
result =
|
||||
subghz_preset_custom_set_datarate(test_data_ptr, sizeof(test_data), datarate_set);
|
||||
if(!result) {
|
||||
FURI_LOG_E(TAG, "Failed to set datarate: %s!", datarate_set_str);
|
||||
return false;
|
||||
}
|
||||
|
||||
datarate_get = subghz_preset_custom_get_datarate(test_data_ptr, sizeof(test_data));
|
||||
subghz_preset_custom_printf_datarate(
|
||||
datarate_get, datarate_get_str, sizeof(datarate_get_str));
|
||||
|
||||
if(datarate_get < 0) {
|
||||
FURI_LOG_E(TAG, "Failed to get datarate!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(datarate_set > datarateFineMax) {
|
||||
result = fabsf(datarate_get - datarate_set) <= datarateRoughStep;
|
||||
datarate_set -= datarateRoughStep;
|
||||
} else {
|
||||
result = fabsf(datarate_get - datarate_set) <= datarateFineStep;
|
||||
datarate_set -= datarateFineStep;
|
||||
}
|
||||
|
||||
if(result) {
|
||||
FURI_LOG_T(
|
||||
TAG,
|
||||
"Datarate check OK: Set: %s - Get: %s",
|
||||
datarate_set_str,
|
||||
datarate_get_str);
|
||||
} else {
|
||||
FURI_LOG_E(
|
||||
TAG,
|
||||
"Datarate check failed!: %s is way to diff %s! DRATE_E: %hhu DRATE_M: %hhu",
|
||||
datarate_set_str,
|
||||
datarate_get_str,
|
||||
test_data[4 * 2 + 1] & 0b00001111,
|
||||
test_data[3 * 2 + 1]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "Sub GHz custom preset test: OK");
|
||||
return true;
|
||||
}
|
||||
|
||||
MU_TEST(subghz_keystore_test) {
|
||||
mu_assert(
|
||||
subghz_environment_load_keystore(environment_handler, KEYSTORE_DIR_NAME),
|
||||
@@ -734,6 +861,10 @@ MU_TEST(subghz_random_test) {
|
||||
mu_assert(subghz_decode_random_test(TEST_RANDOM_DIR_NAME), "Random test error\r\n");
|
||||
}
|
||||
|
||||
MU_TEST(subghz_preset_test) {
|
||||
mu_assert(subghz_custom_preset_test(), "Custom preset logic error\r\n");
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(subghz) {
|
||||
subghz_test_init();
|
||||
MU_RUN_TEST(subghz_keystore_test);
|
||||
@@ -802,7 +933,16 @@ MU_TEST_SUITE(subghz) {
|
||||
subghz_test_deinit();
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(subghz_app) {
|
||||
MU_RUN_TEST(subghz_preset_test);
|
||||
}
|
||||
|
||||
int run_minunit_test_subghz() {
|
||||
MU_RUN_SUITE(subghz);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
||||
|
||||
int run_minunit_test_subghz_app() {
|
||||
MU_RUN_SUITE(subghz_app);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <notification/notification_messages.h>
|
||||
#include <cli/cli.h>
|
||||
#include <loader/loader.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
|
||||
#define TAG "UnitTests"
|
||||
|
||||
@@ -18,6 +19,7 @@ int run_minunit_test_flipper_format_string();
|
||||
int run_minunit_test_stream();
|
||||
int run_minunit_test_storage();
|
||||
int run_minunit_test_subghz();
|
||||
int run_minunit_test_subghz_app();
|
||||
int run_minunit_test_dirwalk();
|
||||
int run_minunit_test_power();
|
||||
int run_minunit_test_protocol_dict();
|
||||
@@ -45,6 +47,7 @@ const UnitTest unit_tests[] = {
|
||||
{.name = "flipper_format_string", .entry = run_minunit_test_flipper_format_string},
|
||||
{.name = "rpc", .entry = run_minunit_test_rpc},
|
||||
{.name = "subghz", .entry = run_minunit_test_subghz},
|
||||
{.name = "subghz_app", .entry = run_minunit_test_subghz_app},
|
||||
{.name = "infrared", .entry = run_minunit_test_infrared},
|
||||
{.name = "nfc", .entry = run_minunit_test_nfc},
|
||||
{.name = "power", .entry = run_minunit_test_power},
|
||||
@@ -71,6 +74,72 @@ void minunit_print_fail(const char* str) {
|
||||
printf(FURI_LOG_CLR_E "%s\r\n" FURI_LOG_CLR_RESET, str);
|
||||
}
|
||||
|
||||
void unit_tests_cli_logs_puts(const char* str) {
|
||||
printf(str);
|
||||
}
|
||||
|
||||
// by default there is no output from unit tests
|
||||
// you have to enable them with this function
|
||||
void unit_tests_cli_enable_logs(FuriLogLevel logLevel) {
|
||||
furi_log_init();
|
||||
furi_log_set_level(logLevel);
|
||||
furi_log_set_puts(unit_tests_cli_logs_puts);
|
||||
}
|
||||
|
||||
void unit_tests_cli_print_help() {
|
||||
printf(
|
||||
"Usage:\r\n"
|
||||
" unit_tests [log level] [test_suit_name]\r\n"
|
||||
" Arguments:\r\n"
|
||||
" [log level]: optional, enables printing output from FURI_LOG_* macro in unit_tests\r\n"
|
||||
" [test_suit_name]: a specific test suit to run. If not specified runs all tests\r\n"
|
||||
" Warning: supports only 1 test suit to launch\r\n"
|
||||
" Example:\r\n"
|
||||
" unit_tests - run ALL tests wihtout log printing\r\n"
|
||||
" unit_tests bt - run bt tests wihtout log printing\r\n"
|
||||
" unit_tests log debug subghz - run subghz tests with logs at debug level abd above\r\n\r\n"
|
||||
" unit_tests help [?]\r\n"
|
||||
" prints this help\r\n");
|
||||
}
|
||||
|
||||
bool unit_tests_cli_parse_log_level(FuriString* args) {
|
||||
bool result = true;
|
||||
FuriString* level = furi_string_alloc();
|
||||
if(args_read_string_and_trim(args, level)) {
|
||||
if(furi_string_cmpi_str(level, "default") == 0) {
|
||||
unit_tests_cli_enable_logs(FuriLogLevelDefault);
|
||||
} else if(furi_string_cmpi_str(level, "none") == 0) {
|
||||
unit_tests_cli_enable_logs(FuriLogLevelNone);
|
||||
} else if(furi_string_cmpi_str(level, "error") == 0) {
|
||||
unit_tests_cli_enable_logs(FuriLogLevelError);
|
||||
} else if(furi_string_cmpi_str(level, "warn") == 0) {
|
||||
unit_tests_cli_enable_logs(FuriLogLevelWarn);
|
||||
} else if(furi_string_cmpi_str(level, "info") == 0) {
|
||||
unit_tests_cli_enable_logs(FuriLogLevelInfo);
|
||||
} else if(furi_string_cmpi_str(level, "debug") == 0) {
|
||||
unit_tests_cli_enable_logs(FuriLogLevelDebug);
|
||||
} else if(furi_string_cmpi_str(level, "trace") == 0) {
|
||||
unit_tests_cli_enable_logs(FuriLogLevelTrace);
|
||||
} else {
|
||||
printf("Error: Invalid log level: %s\r\n", furi_string_get_cstr(level));
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
furi_string_free(level);
|
||||
return result;
|
||||
}
|
||||
|
||||
FuriString* unit_tests_cli_parse_test_suit(FuriString* args) {
|
||||
FuriString* test_suit = furi_string_alloc();
|
||||
|
||||
if(!args_read_string_and_trim(args, test_suit)) {
|
||||
furi_string_free(test_suit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return test_suit;
|
||||
}
|
||||
|
||||
void unit_tests_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(cli);
|
||||
UNUSED(args);
|
||||
@@ -80,6 +149,34 @@ void unit_tests_cli(Cli* cli, FuriString* args, void* context) {
|
||||
minunit_fail = 0;
|
||||
minunit_status = 0;
|
||||
|
||||
if(furi_string_cmp_str(args, "help") == 0 || furi_string_cmp_str(args, "?") == 0) {
|
||||
unit_tests_cli_print_help();
|
||||
return;
|
||||
}
|
||||
|
||||
FuriString* test_suit_to_run = NULL;
|
||||
|
||||
if(furi_string_size(args)) {
|
||||
FuriString* arg = furi_string_alloc();
|
||||
if(args_read_string_and_trim(args, arg)) {
|
||||
if(furi_string_cmp_str(arg, "log") == 0) {
|
||||
// read next argument - log level, if fail - show help and return
|
||||
if(!unit_tests_cli_parse_log_level(args)) {
|
||||
unit_tests_cli_print_help();
|
||||
furi_string_free(arg);
|
||||
return;
|
||||
}
|
||||
|
||||
// next argument might be test suit
|
||||
test_suit_to_run = unit_tests_cli_parse_test_suit(args);
|
||||
} else {
|
||||
// if first argument wasn't log - it was exact test suit to run
|
||||
test_suit_to_run = unit_tests_cli_parse_test_suit(arg);
|
||||
}
|
||||
}
|
||||
furi_string_free(arg);
|
||||
}
|
||||
|
||||
Loader* loader = furi_record_open(RECORD_LOADER);
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
|
||||
@@ -98,8 +195,8 @@ void unit_tests_cli(Cli* cli, FuriString* args, void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(furi_string_size(args)) {
|
||||
if(furi_string_cmp_str(args, unit_tests[i].name) == 0) {
|
||||
if(test_suit_to_run) {
|
||||
if(furi_string_cmp_str(test_suit_to_run, unit_tests[i].name) == 0) {
|
||||
unit_tests[i].entry();
|
||||
} else {
|
||||
printf("Skipping %s\r\n", unit_tests[i].name);
|
||||
@@ -132,6 +229,10 @@ void unit_tests_cli(Cli* cli, FuriString* args, void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
if(test_suit_to_run) {
|
||||
furi_string_free(test_suit_to_run);
|
||||
}
|
||||
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
furi_record_close(RECORD_LOADER);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user