|
@@ -16,9 +16,14 @@
|
|
|
#include <notification/notification_messages.h>
|
|
#include <notification/notification_messages.h>
|
|
|
#include <flipper_format/flipper_format_i.h>
|
|
#include <flipper_format/flipper_format_i.h>
|
|
|
|
|
|
|
|
|
|
+#include <flipper.pb.h>
|
|
|
|
|
+#include <pb_decode.h>
|
|
|
|
|
+
|
|
|
#define SUBGHZ_FREQUENCY_RANGE_STR \
|
|
#define SUBGHZ_FREQUENCY_RANGE_STR \
|
|
|
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
|
|
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"
|
|
|
|
|
|
|
|
|
|
+#define SUBGHZ_REGION_FILENAME "/int/.region_data"
|
|
|
|
|
+
|
|
|
void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
|
|
void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
|
|
|
UNUSED(context);
|
|
UNUSED(context);
|
|
|
uint32_t frequency = 433920000;
|
|
uint32_t frequency = 433920000;
|
|
@@ -533,7 +538,7 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if(!furi_hal_subghz_is_tx_allowed(frequency)) {
|
|
|
|
|
|
|
+ if(!furi_hal_region_is_frequency_allowed(frequency)) {
|
|
|
printf(
|
|
printf(
|
|
|
"In your region, only reception on this frequency (%lu) is allowed,\r\n"
|
|
"In your region, only reception on this frequency (%lu) is allowed,\r\n"
|
|
|
"the actual operation of the application is not possible\r\n ",
|
|
"the actual operation of the application is not possible\r\n ",
|
|
@@ -756,6 +761,46 @@ static void subghz_cli_command(Cli* cli, string_t args, void* context) {
|
|
|
string_clear(cmd);
|
|
string_clear(cmd);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static bool
|
|
|
|
|
+ subghz_on_system_start_istream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) {
|
|
|
|
|
+ File* file = istream->state;
|
|
|
|
|
+ uint16_t ret = storage_file_read(file, buf, count);
|
|
|
|
|
+ return (count == ret);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static bool subghz_on_system_start_istream_decode_band(
|
|
|
|
|
+ pb_istream_t* stream,
|
|
|
|
|
+ const pb_field_t* field,
|
|
|
|
|
+ void** arg) {
|
|
|
|
|
+ (void)field;
|
|
|
|
|
+ FuriHalRegion* region = *arg;
|
|
|
|
|
+
|
|
|
|
|
+ PB_Region_Band band = {0};
|
|
|
|
|
+ if(!pb_decode(stream, PB_Region_Band_fields, &band)) {
|
|
|
|
|
+ FURI_LOG_E("SubGhzOnStart", "PB Region band decode error: %s", PB_GET_ERROR(stream));
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ region->bands_count += 1;
|
|
|
|
|
+ region =
|
|
|
|
|
+ realloc(region, sizeof(FuriHalRegion) + sizeof(FuriHalRegionBand) * region->bands_count);
|
|
|
|
|
+ size_t pos = region->bands_count - 1;
|
|
|
|
|
+ region->bands[pos].start = band.start;
|
|
|
|
|
+ region->bands[pos].end = band.end;
|
|
|
|
|
+ region->bands[pos].power_limit = band.power_limit;
|
|
|
|
|
+ region->bands[pos].duty_cycle = band.duty_cycle;
|
|
|
|
|
+ *arg = region;
|
|
|
|
|
+
|
|
|
|
|
+ FURI_LOG_I(
|
|
|
|
|
+ "SubGhzOnStart",
|
|
|
|
|
+ "Add allowed band: start %dHz, stop %dHz, power_limit %ddBm, duty_cycle %d%%",
|
|
|
|
|
+ band.start,
|
|
|
|
|
+ band.end,
|
|
|
|
|
+ band.power_limit,
|
|
|
|
|
+ band.duty_cycle);
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void subghz_on_system_start() {
|
|
void subghz_on_system_start() {
|
|
|
#ifdef SRV_CLI
|
|
#ifdef SRV_CLI
|
|
|
Cli* cli = furi_record_open(RECORD_CLI);
|
|
Cli* cli = furi_record_open(RECORD_CLI);
|
|
@@ -766,4 +811,52 @@ void subghz_on_system_start() {
|
|
|
#else
|
|
#else
|
|
|
UNUSED(subghz_cli_command);
|
|
UNUSED(subghz_cli_command);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
+
|
|
|
|
|
+#ifdef SRV_STORAGE
|
|
|
|
|
+ Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
|
|
+ File* file = storage_file_alloc(storage);
|
|
|
|
|
+ FileInfo fileinfo = {0};
|
|
|
|
|
+ PB_Region pb_region = {0};
|
|
|
|
|
+ pb_region.bands.funcs.decode = subghz_on_system_start_istream_decode_band;
|
|
|
|
|
+
|
|
|
|
|
+ do {
|
|
|
|
|
+ if(storage_common_stat(storage, SUBGHZ_REGION_FILENAME, &fileinfo) != FSE_OK ||
|
|
|
|
|
+ fileinfo.size == 0) {
|
|
|
|
|
+ FURI_LOG_W("SubGhzOnStart", "Region data is missing or empty");
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!storage_file_open(file, SUBGHZ_REGION_FILENAME, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
|
|
|
|
+ FURI_LOG_E("SubGhzOnStart", "Unable to open region data");
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ pb_istream_t istream = {
|
|
|
|
|
+ .callback = subghz_on_system_start_istream_read,
|
|
|
|
|
+ .state = file,
|
|
|
|
|
+ .errmsg = NULL,
|
|
|
|
|
+ .bytes_left = fileinfo.size,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ pb_region.bands.arg = malloc(sizeof(FuriHalRegion));
|
|
|
|
|
+ if(!pb_decode(&istream, PB_Region_fields, &pb_region)) {
|
|
|
|
|
+ FURI_LOG_E("SubGhzOnStart", "Invalid region data");
|
|
|
|
|
+ free(pb_region.bands.arg);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FuriHalRegion* region = pb_region.bands.arg;
|
|
|
|
|
+ memcpy(
|
|
|
|
|
+ region->country_code,
|
|
|
|
|
+ pb_region.country_code->bytes,
|
|
|
|
|
+ pb_region.country_code->size < 4 ? pb_region.country_code->size : 3);
|
|
|
|
|
+ furi_hal_region_set(region);
|
|
|
|
|
+ } while(0);
|
|
|
|
|
+
|
|
|
|
|
+ pb_release(PB_Region_fields, &pb_region);
|
|
|
|
|
+ storage_file_free(file);
|
|
|
|
|
+ furi_record_close(RECORD_STORAGE);
|
|
|
|
|
+#else
|
|
|
|
|
+ UNUSED(subghz_cli_command);
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|