mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-01-13 17:23:39 +00:00
Added new file format funcs
This commit is contained in:
parent
223cd7c20d
commit
a7370ee95d
@ -23,166 +23,574 @@
|
|||||||
#include "freqman.hpp"
|
#include "freqman.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
using option_t = std::pair<std::string, int32_t>;
|
||||||
|
using options_t = std::vector<option_t>;
|
||||||
|
|
||||||
|
options_t freqman_entry_modulations = {
|
||||||
|
{ "AM", 0 },
|
||||||
|
{ "NFM", 1 },
|
||||||
|
{ "WFM", 2 }
|
||||||
|
};
|
||||||
|
|
||||||
|
options_t freqman_entry_bandwidths[ 4 ] = {
|
||||||
|
{ //AM
|
||||||
|
{ "DSB", 0 },
|
||||||
|
{ "USB", 1 },
|
||||||
|
{ "LSB", 2 },
|
||||||
|
{ "CW" , 3 }
|
||||||
|
},
|
||||||
|
{ //NFM
|
||||||
|
{ "8k5" , 0 },
|
||||||
|
{ "11k" , 1 },
|
||||||
|
{ "16k" , 2 }
|
||||||
|
},
|
||||||
|
{ //WFM
|
||||||
|
{ "16k" , 0 },
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
options_t freqman_entry_steps = {
|
||||||
|
{ "5KHz (SA AM)" , 5000 },
|
||||||
|
{ "6.25KHz(NFM)" , 6250 },
|
||||||
|
{ "8.33KHz(AIR)" , 8330 },
|
||||||
|
{ "9KHz (EU AM)" , 9000 },
|
||||||
|
{ "10KHz(US AM)" , 10000 },
|
||||||
|
{ "12.5KHz(NFM)" , 12500 },
|
||||||
|
{ "15KHz (HFM)" , 15000 },
|
||||||
|
{ "25KHz (N1)" , 25000 },
|
||||||
|
{ "50KHz (FM1)" , 50000 },
|
||||||
|
{ "100KHz (FM2)" , 100000 },
|
||||||
|
{ "250KHz (N2)" , 250000 },
|
||||||
|
{ "500KHz " , 500000 },
|
||||||
|
{ "1MHz " , 1000000 }
|
||||||
|
};
|
||||||
|
|
||||||
|
options_t freqman_entry_steps_short = {
|
||||||
|
{ "5KHz" , 5000 },
|
||||||
|
{ "6.25KHz" , 6250 },
|
||||||
|
{ "8.33KHz" , 8330 },
|
||||||
|
{ "9KHz" , 9000 },
|
||||||
|
{ "10KHz" , 10000 },
|
||||||
|
{ "12.5KHz" , 12500 },
|
||||||
|
{ "15KHz" , 15000 },
|
||||||
|
{ "25KHz" , 25000 },
|
||||||
|
{ "50KHz" , 50000 },
|
||||||
|
{ "100KHz" , 100000 },
|
||||||
|
{ "250KHz" , 250000 },
|
||||||
|
{ "500KHz" , 500000 },
|
||||||
|
{ "1MHz" , 1000000 }
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<std::string> get_freqman_files() {
|
std::vector<std::string> get_freqman_files() {
|
||||||
std::vector<std::string> file_list;
|
std::vector<std::string> file_list;
|
||||||
|
|
||||||
auto files = scan_root_files(u"FREQMAN", u"*.TXT");
|
auto files = scan_root_files(u"FREQMAN", u"*.TXT");
|
||||||
|
|
||||||
for (auto file : files) {
|
for (auto file : files) {
|
||||||
std::string file_name = file.stem().string();
|
std::string file_name = file.stem().string();
|
||||||
// don't propose tmp / hidden files in freqman's list
|
// don't propose tmp / hidden files in freqman's list
|
||||||
if (file_name.length() && file_name[0] != '.') {
|
if (file_name.length() && file_name[0] != '.') {
|
||||||
file_list.emplace_back(file_name);
|
file_list.emplace_back(file_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return file_list;
|
return file_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool load_freqman_file(std::string& file_stem, freqman_db &db) {
|
bool load_freqman_file(std::string& file_stem, freqman_db &db) {
|
||||||
File freqman_file;
|
return load_freqman_file_ex( file_stem , db , true , true , true );
|
||||||
size_t length, n = 0, file_position = 0;
|
/* File freqman_file;
|
||||||
char * pos;
|
size_t length, n = 0, file_position = 0;
|
||||||
char * line_start;
|
char * pos;
|
||||||
char * line_end;
|
char * line_start;
|
||||||
std::string description;
|
char * line_end;
|
||||||
rf::Frequency frequency_a, frequency_b;
|
std::string description;
|
||||||
char file_data[257];
|
rf::Frequency frequency_a, frequency_b;
|
||||||
freqman_entry_type type;
|
char file_data[257];
|
||||||
|
freqman_entry_type type;
|
||||||
|
|
||||||
db.clear();
|
db.clear();
|
||||||
|
|
||||||
auto result = freqman_file.open("FREQMAN/" + file_stem + ".TXT");
|
auto result = freqman_file.open("FREQMAN/" + file_stem + ".TXT");
|
||||||
if (result.is_valid())
|
if (result.is_valid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// Read a 256 bytes block from file
|
// Read a 256 bytes block from file
|
||||||
freqman_file.seek(file_position);
|
freqman_file.seek(file_position);
|
||||||
|
|
||||||
memset(file_data, 0, 257);
|
memset(file_data, 0, 257);
|
||||||
auto read_size = freqman_file.read(file_data, 256);
|
auto read_size = freqman_file.read(file_data, 256);
|
||||||
if (read_size.is_error())
|
if (read_size.is_error())
|
||||||
return false; // Read error
|
return false; // Read error
|
||||||
|
|
||||||
file_position += 256;
|
file_position += 256;
|
||||||
|
|
||||||
// Reset line_start to beginning of buffer
|
// Reset line_start to beginning of buffer
|
||||||
line_start = file_data;
|
line_start = file_data;
|
||||||
|
|
||||||
if (!strstr(file_data, "f=") && !strstr(file_data, "a="))
|
if (!strstr(file_data, "f=") && !strstr(file_data, "a="))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Look for complete lines in buffer
|
// Look for complete lines in buffer
|
||||||
while ((line_end = strstr(line_start, "\x0A"))) {
|
while ((line_end = strstr(line_start, "\x0A"))) {
|
||||||
// Read frequency
|
// Read frequency
|
||||||
pos = strstr(line_start, "f=");
|
pos = strstr(line_start, "f=");
|
||||||
frequency_b = 0;
|
frequency_b = 0;
|
||||||
type = SINGLE;
|
type = SINGLE;
|
||||||
if (pos) {
|
if (pos) {
|
||||||
pos += 2;
|
pos += 2;
|
||||||
frequency_a = strtoll(pos, nullptr, 10);
|
frequency_a = strtoll(pos, nullptr, 10);
|
||||||
} else {
|
} else {
|
||||||
// ...or range
|
// ...or range
|
||||||
pos = strstr(line_start, "a=");
|
pos = strstr(line_start, "a=");
|
||||||
if (pos) {
|
if (pos) {
|
||||||
pos += 2;
|
pos += 2;
|
||||||
frequency_a = strtoll(pos, nullptr, 10);
|
frequency_a = strtoll(pos, nullptr, 10);
|
||||||
type = RANGE;
|
type = RANGE;
|
||||||
pos = strstr(line_start, "b=");
|
pos = strstr(line_start, "b=");
|
||||||
if (pos) {
|
if (pos) {
|
||||||
pos += 2;
|
pos += 2;
|
||||||
frequency_b = strtoll(pos, nullptr, 10);
|
frequency_b = strtoll(pos, nullptr, 10);
|
||||||
} else
|
} else
|
||||||
frequency_b = 0;
|
frequency_b = 0;
|
||||||
} else
|
} else
|
||||||
frequency_a = 0;
|
frequency_a = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read description until , or LF
|
// Read description until , or LF
|
||||||
pos = strstr(line_start, "d=");
|
pos = strstr(line_start, "d=");
|
||||||
if (pos) {
|
if (pos) {
|
||||||
pos += 2;
|
pos += 2;
|
||||||
length = std::min(strcspn(pos, ",\x0A"), (size_t)FREQMAN_DESC_MAX_LEN);
|
length = std::min(strcspn(pos, ",\x0A"), (size_t)FREQMAN_DESC_MAX_LEN);
|
||||||
description = string(pos, length);
|
description = string(pos, length);
|
||||||
} else
|
} else
|
||||||
description = "-";
|
description = "-";
|
||||||
|
|
||||||
db.push_back({ frequency_a, frequency_b, description, type });
|
db.push_back({ frequency_a, frequency_b, description, type , -1 , -1 , -1 , -1 });
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
if (n >= FREQMAN_MAX_PER_FILE) return true;
|
if (n >= FREQMAN_MAX_PER_FILE) return true;
|
||||||
|
|
||||||
line_start = line_end + 1;
|
line_start = line_end + 1;
|
||||||
if (line_start - file_data >= 256) break;
|
if (line_start - file_data >= 256) break;
|
||||||
}
|
|
||||||
|
|
||||||
if (read_size.value() != 256)
|
|
||||||
break; // End of file
|
|
||||||
|
|
||||||
// Restart at beginning of last incomplete line
|
|
||||||
file_position -= (file_data + 256 - line_start);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool save_freqman_file(std::string& file_stem, freqman_db &db) {
|
if (read_size.value() != 256)
|
||||||
File freqman_file;
|
break; // End of file
|
||||||
std::string item_string;
|
|
||||||
rf::Frequency frequency_a, frequency_b;
|
|
||||||
|
|
||||||
if (!create_freqman_file(file_stem, freqman_file))
|
// Restart at beginning of last incomplete line
|
||||||
return false;
|
file_position -= (file_data + 256 - line_start);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t n = 0; n < db.size(); n++) {
|
bool load_freqman_file_ex(std::string& file_stem, freqman_db& db, bool load_freqs , bool load_ranges , bool load_hamradios ) {
|
||||||
auto& entry = db[n];
|
File freqman_file;
|
||||||
|
size_t length, n = 0, file_position = 0;
|
||||||
|
char * pos;
|
||||||
|
char * line_start;
|
||||||
|
char * line_end;
|
||||||
|
std::string description;
|
||||||
|
rf::Frequency frequency_a, frequency_b;
|
||||||
|
char file_data[257];
|
||||||
|
freqman_entry_type type;
|
||||||
|
freqman_index_t modulation = 0 ;
|
||||||
|
freqman_index_t bandwidth = 0 ;
|
||||||
|
freqman_index_t step = 0 ;
|
||||||
|
freqman_index_t tone = 0 ;
|
||||||
|
|
||||||
frequency_a = entry.frequency_a;
|
|
||||||
|
|
||||||
if (entry.type == SINGLE) {
|
db.clear();
|
||||||
// Single
|
|
||||||
|
|
||||||
// TODO: Make to_string_dec_uint be able to return uint64_t's
|
auto result = freqman_file.open("FREQMAN/" + file_stem + ".TXT");
|
||||||
// Please forgive me...
|
if (result.is_valid())
|
||||||
item_string = "f=" + to_string_dec_uint(frequency_a / 1000) + to_string_dec_uint(frequency_a % 1000UL, 3, '0');
|
return false;
|
||||||
|
|
||||||
} else {
|
while (1) {
|
||||||
// Range
|
// Read a 256 bytes block from file
|
||||||
frequency_b = entry.frequency_b;
|
freqman_file.seek(file_position);
|
||||||
|
|
||||||
item_string = "a=" + to_string_dec_uint(frequency_a / 1000) + to_string_dec_uint(frequency_a % 1000UL, 3, '0');
|
memset(file_data, 0, 257);
|
||||||
item_string += ",b=" + to_string_dec_uint(frequency_b / 1000) + to_string_dec_uint(frequency_b % 1000UL, 3, '0');
|
auto read_size = freqman_file.read(file_data, 256);
|
||||||
}
|
if (read_size.is_error())
|
||||||
|
return false; // Read error
|
||||||
|
|
||||||
if (entry.description.size())
|
file_position += 256;
|
||||||
item_string += ",d=" + entry.description;
|
|
||||||
|
|
||||||
freqman_file.write_line(item_string);
|
// Reset line_start to beginning of buffer
|
||||||
}
|
line_start = file_data;
|
||||||
|
|
||||||
return true;
|
if (!strstr(file_data, "f=") && !strstr(file_data, "a=") && !strstr(file_data, "r=") )
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Look for complete lines in buffer
|
||||||
|
while ((line_end = strstr(line_start, "\x0A"))) {
|
||||||
|
|
||||||
|
modulation = -1 ;
|
||||||
|
bandwidth = -1 ;
|
||||||
|
step = -1 ;
|
||||||
|
tone = -1 ;
|
||||||
|
type=SINGLE ;
|
||||||
|
|
||||||
|
frequency_a = frequency_b = 0;
|
||||||
|
// Read frequency
|
||||||
|
pos = strstr(line_start, "f=");
|
||||||
|
if(pos) {
|
||||||
|
pos += 2;
|
||||||
|
frequency_a = strtoll(pos, nullptr, 10);
|
||||||
|
} else {
|
||||||
|
// ...or range
|
||||||
|
pos = strstr(line_start, "a=");
|
||||||
|
if (pos) {
|
||||||
|
pos += 2;
|
||||||
|
frequency_a = strtoll(pos, nullptr, 10);
|
||||||
|
type = RANGE;
|
||||||
|
pos = strstr(line_start, "b=");
|
||||||
|
if (pos) {
|
||||||
|
pos += 2;
|
||||||
|
frequency_b = strtoll(pos, nullptr, 10);
|
||||||
|
} else
|
||||||
|
frequency_b = 0;
|
||||||
|
}else {
|
||||||
|
// ... or hamradio
|
||||||
|
pos = strstr(line_start, "r=");
|
||||||
|
if (pos) {
|
||||||
|
pos += 2;
|
||||||
|
frequency_a = strtoll(pos, nullptr, 10);
|
||||||
|
type = HAMRADIO;
|
||||||
|
pos = strstr(line_start, "t=");
|
||||||
|
if (pos) {
|
||||||
|
pos += 2;
|
||||||
|
frequency_b = strtoll(pos, nullptr, 10);
|
||||||
|
} else
|
||||||
|
frequency_b = frequency_a ;
|
||||||
|
} else
|
||||||
|
frequency_a = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// modulation if any
|
||||||
|
pos = strstr(line_start, "m=");
|
||||||
|
if (pos) {
|
||||||
|
pos += 2;
|
||||||
|
modulation = freqman_entry_get_modulation_from_str( pos );
|
||||||
|
}
|
||||||
|
// bandwidth if any
|
||||||
|
pos = strstr(line_start, "bw=");
|
||||||
|
if (pos) {
|
||||||
|
pos += 3;
|
||||||
|
bandwidth = freqman_entry_get_bandwidth_from_str( modulation , pos );
|
||||||
|
}
|
||||||
|
// step if any
|
||||||
|
pos = strstr(line_start, "s=");
|
||||||
|
if (pos) {
|
||||||
|
pos += 2;
|
||||||
|
step = freqman_entry_get_step_from_str_short( pos );
|
||||||
|
}
|
||||||
|
// ctcss tone if any
|
||||||
|
/* disabled until better form
|
||||||
|
pos = strstr(line_start, "c=");
|
||||||
|
if (pos) {
|
||||||
|
pos += 2;
|
||||||
|
tone = tone_key_index_by_value( strtoll( pos , nullptr , 10 ) );
|
||||||
|
} */
|
||||||
|
// Read description until , or LF
|
||||||
|
pos = strstr(line_start, "d=");
|
||||||
|
if (pos) {
|
||||||
|
pos += 2;
|
||||||
|
length = std::min(strcspn(pos, ",\x0A"), (size_t)FREQMAN_DESC_MAX_LEN);
|
||||||
|
description = string(pos, length);
|
||||||
|
} else
|
||||||
|
description = "-";
|
||||||
|
if( (type == SINGLE && load_freqs) || (type == RANGE && load_ranges) || (type == HAMRADIO && load_hamradios) )
|
||||||
|
{
|
||||||
|
db.push_back({ frequency_a, frequency_b, description, type , modulation , bandwidth , step , tone });
|
||||||
|
n++;
|
||||||
|
if (n >= FREQMAN_MAX_PER_FILE) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
line_start = line_end + 1;
|
||||||
|
if (line_start - file_data >= 256) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (read_size.value() != 256)
|
||||||
|
break; // End of file
|
||||||
|
|
||||||
|
// Restart at beginning of last incomplete line
|
||||||
|
file_position -= (file_data + 256 - line_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* populate implicitly specified modulation / bandwidth */
|
||||||
|
if( db.size() > 2 )
|
||||||
|
{
|
||||||
|
modulation = db[ 0 ] . modulation;
|
||||||
|
bandwidth = db[ 0 ] . bandwidth;
|
||||||
|
|
||||||
|
for( unsigned int it = 1 ; it < db.size() ; it ++ )
|
||||||
|
{
|
||||||
|
if( db[ it ] . modulation < 0 )
|
||||||
|
{
|
||||||
|
db[ it ] . modulation = modulation ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
modulation = db[ it ] . modulation ;
|
||||||
|
}
|
||||||
|
if( db[ it ] . bandwidth < 0 )
|
||||||
|
{
|
||||||
|
db[ it ] . bandwidth = bandwidth ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
modulation = db[ it ] . bandwidth ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get_freq_string( freqman_entry &entry , std::string &item_string )
|
||||||
|
{
|
||||||
|
rf::Frequency frequency_a, frequency_b;
|
||||||
|
|
||||||
|
frequency_a = entry.frequency_a;
|
||||||
|
if (entry.type == SINGLE) {
|
||||||
|
// Single
|
||||||
|
item_string = "f=" + to_string_dec_uint(frequency_a / 1000) + to_string_dec_uint(frequency_a % 1000UL, 3, '0');
|
||||||
|
} else if( entry.type == RANGE ) {
|
||||||
|
// Range
|
||||||
|
frequency_b = entry.frequency_b;
|
||||||
|
item_string = "a=" + to_string_dec_uint(frequency_a / 1000) + to_string_dec_uint(frequency_a % 1000UL, 3, '0');
|
||||||
|
item_string += ",b=" + to_string_dec_uint(frequency_b / 1000) + to_string_dec_uint(frequency_b % 1000UL, 3, '0');
|
||||||
|
if( entry.step >= 0 )
|
||||||
|
{
|
||||||
|
item_string += ",s=" + freqman_entry_get_step_string_short( entry.step );
|
||||||
|
}
|
||||||
|
} else if( entry.type == HAMRADIO ) {
|
||||||
|
frequency_b = entry.frequency_b;
|
||||||
|
item_string = "r=" + to_string_dec_uint(frequency_a / 1000) + to_string_dec_uint(frequency_a % 1000UL, 3, '0');
|
||||||
|
item_string += ",t=" + to_string_dec_uint(frequency_b / 1000) + to_string_dec_uint(frequency_b % 1000UL, 3, '0');
|
||||||
|
if( entry.tone >= 0 )
|
||||||
|
{
|
||||||
|
item_string += ",c=" + tone_key_string( entry.tone );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( entry.modulation >= 0 && (unsigned)entry.modulation < freqman_entry_modulations . size() )
|
||||||
|
{
|
||||||
|
item_string += ",m=" + freqman_entry_get_modulation_string( entry.modulation );
|
||||||
|
if( entry.bandwidth >= 0 && (unsigned)entry.bandwidth < freqman_entry_bandwidths[ entry.modulation ] . size() )
|
||||||
|
{
|
||||||
|
item_string += ",bw=" + freqman_entry_get_bandwidth_string( entry.modulation , entry.bandwidth );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (entry.description.size())
|
||||||
|
item_string += ",d=" + entry.description;
|
||||||
|
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool save_freqman_file(std::string &file_stem, freqman_db &db) {
|
||||||
|
|
||||||
|
File freqman_file;
|
||||||
|
|
||||||
|
std::string freq_file_path = "FREQMAN/" + file_stem + ".TXT";
|
||||||
|
std::string tmp_freq_file_path = "FREQMAN/" + file_stem + ".TXT.TMP";
|
||||||
|
|
||||||
|
if( !db.size() )
|
||||||
|
{
|
||||||
|
delete_file( "FREQMAN/"+file_stem+".TXT" );
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_file( tmp_freq_file_path );
|
||||||
|
auto result = freqman_file.open( tmp_freq_file_path );
|
||||||
|
if ( !result.is_valid() ) {
|
||||||
|
for (size_t n = 0; n < db.size(); n++) {
|
||||||
|
std::string item_string;
|
||||||
|
auto& entry = db[n];
|
||||||
|
get_freq_string( entry , item_string );
|
||||||
|
freqman_file.write_line( item_string );
|
||||||
|
delete &item_string;
|
||||||
|
}
|
||||||
|
delete_file( freq_file_path );
|
||||||
|
rename_file( tmp_freq_file_path , freq_file_path );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool create_freqman_file(std::string& file_stem, File& freqman_file) {
|
bool create_freqman_file(std::string& file_stem, File& freqman_file) {
|
||||||
auto result = freqman_file.create("FREQMAN/" + file_stem + ".TXT");
|
|
||||||
if (result.is_valid())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
auto result = freqman_file.create( "FREQMAN/" + file_stem + ".TXT" );
|
||||||
|
|
||||||
|
if (result.is_valid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string freqman_item_string(freqman_entry &entry, size_t max_length) {
|
std::string freqman_item_string(freqman_entry &entry, size_t max_length) {
|
||||||
std::string item_string;
|
std::string item_string;
|
||||||
|
|
||||||
if (entry.type == SINGLE) {
|
switch( entry.type ){
|
||||||
item_string = to_string_short_freq(entry.frequency_a) + "M: " + entry.description;
|
case SINGLE:
|
||||||
} else {
|
item_string = to_string_short_freq(entry.frequency_a) + "M: " + entry.description;
|
||||||
item_string = "Range: " + entry.description;
|
break;
|
||||||
}
|
case RANGE:
|
||||||
|
item_string = "R: " + entry.description;
|
||||||
|
break;
|
||||||
|
case HAMRADIO:
|
||||||
|
item_string = "H: " + entry.description;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
item_string = "!UNKNOW TYPE " + entry.description;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (item_string.size() > max_length)
|
if (item_string.size() > max_length)
|
||||||
return item_string.substr(0, max_length - 3) + "...";
|
return item_string.substr(0, max_length - 3) + "...";
|
||||||
|
|
||||||
return item_string;
|
return item_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
void freqman_set_modulation_option( OptionsField &option )
|
||||||
|
{
|
||||||
|
option.set_options( freqman_entry_modulations );
|
||||||
|
}
|
||||||
|
|
||||||
|
void freqman_set_bandwidth_option( freqman_index_t modulation , OptionsField &option )
|
||||||
|
{
|
||||||
|
option.set_options( freqman_entry_bandwidths[ modulation ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
void freqman_set_step_option( OptionsField &option )
|
||||||
|
{
|
||||||
|
option.set_options( freqman_entry_steps );
|
||||||
|
}
|
||||||
|
|
||||||
|
void freqman_set_step_option_short( OptionsField &option )
|
||||||
|
{
|
||||||
|
option.set_options( freqman_entry_steps_short );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string freqman_entry_get_modulation_string( freqman_index_t modulation )
|
||||||
|
{
|
||||||
|
if( modulation < 0 || (unsigned)modulation >= freqman_entry_modulations . size() )
|
||||||
|
{
|
||||||
|
return std::string( "" ); // unknown modulation
|
||||||
|
}
|
||||||
|
return freqman_entry_modulations[ modulation ] . first ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string freqman_entry_get_bandwidth_string( freqman_index_t modulation , freqman_index_t bandwidth )
|
||||||
|
{
|
||||||
|
if( modulation < 0 || (unsigned)modulation >= freqman_entry_modulations . size() )
|
||||||
|
{
|
||||||
|
return std::string( "" ); // unknown modulation
|
||||||
|
}
|
||||||
|
if( bandwidth < 0 || (unsigned)bandwidth > freqman_entry_bandwidths[ modulation ] . size() )
|
||||||
|
{
|
||||||
|
return std::string( "" ); // unknown modulation
|
||||||
|
}
|
||||||
|
return freqman_entry_bandwidths[ modulation ][ bandwidth ] . first ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string freqman_entry_get_step_string( freqman_index_t step )
|
||||||
|
{
|
||||||
|
if( step < 0 || (unsigned)step >= freqman_entry_steps . size() )
|
||||||
|
{
|
||||||
|
return std::string( "" ); // unknown modulation
|
||||||
|
}
|
||||||
|
return freqman_entry_steps[ step ] . first ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string freqman_entry_get_step_string_short( freqman_index_t step )
|
||||||
|
{
|
||||||
|
if( step < 0 || (unsigned)step >= freqman_entry_steps_short . size() )
|
||||||
|
{
|
||||||
|
return std::string( "" ); // unknown modulation
|
||||||
|
}
|
||||||
|
return freqman_entry_steps_short[ step ] . first ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t freqman_entry_get_modulation_value( freqman_index_t modulation )
|
||||||
|
{
|
||||||
|
if( modulation < 0 || (unsigned)modulation >= freqman_entry_modulations . size() )
|
||||||
|
{
|
||||||
|
return -1 ; // unknown modulation
|
||||||
|
}
|
||||||
|
return freqman_entry_modulations[ modulation ] . second ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t freqman_entry_get_bandwidth_value( freqman_index_t modulation , freqman_index_t bandwidth )
|
||||||
|
{
|
||||||
|
if( modulation < 0 || (unsigned)modulation >= freqman_entry_modulations . size() )
|
||||||
|
{
|
||||||
|
return -1 ; // unknown modulation
|
||||||
|
}
|
||||||
|
if( bandwidth < 0 || (unsigned)bandwidth > freqman_entry_bandwidths[ modulation ] . size() )
|
||||||
|
{
|
||||||
|
return -1 ; // unknown bandwidth for modulation
|
||||||
|
}
|
||||||
|
return freqman_entry_bandwidths[ modulation ][ bandwidth ] . second ;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t freqman_entry_get_step_value( freqman_index_t step )
|
||||||
|
{
|
||||||
|
if( step < 0 || (unsigned)step >= freqman_entry_steps . size() )
|
||||||
|
{
|
||||||
|
return -1 ; // unknown modulation
|
||||||
|
}
|
||||||
|
return freqman_entry_steps[ step ] . second ;
|
||||||
|
}
|
||||||
|
|
||||||
|
freqman_index_t freqman_entry_get_modulation_from_str( char *str )
|
||||||
|
{
|
||||||
|
if( !str )
|
||||||
|
return -1 ;
|
||||||
|
for( freqman_index_t index = 0 ; (unsigned)index < freqman_entry_modulations . size() ; index ++ )
|
||||||
|
{
|
||||||
|
if( strncmp( freqman_entry_modulations[ index ] . first . c_str() , str , freqman_entry_modulations[ index ] . first . size() ) == 0 )
|
||||||
|
return index ;
|
||||||
|
}
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
freqman_index_t freqman_entry_get_bandwidth_from_str( freqman_index_t modulation , char *str )
|
||||||
|
{
|
||||||
|
if( !str )
|
||||||
|
return -1 ;
|
||||||
|
if( modulation < 0 || (unsigned)modulation >= freqman_entry_modulations . size() )
|
||||||
|
return -1 ;
|
||||||
|
for( freqman_index_t index = 0 ; (unsigned)index < freqman_entry_bandwidths[ modulation ] . size() ; index ++ )
|
||||||
|
{
|
||||||
|
if( strncmp( freqman_entry_bandwidths[ modulation ][ index ] . first . c_str() , str , freqman_entry_bandwidths[ modulation ][ index ] . first . size() ) == 0 )
|
||||||
|
return index ;
|
||||||
|
}
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
freqman_index_t freqman_entry_get_step_from_str( char *str )
|
||||||
|
{
|
||||||
|
if( !str )
|
||||||
|
return -1 ;
|
||||||
|
for( freqman_index_t index = 0 ; (unsigned)index < freqman_entry_steps . size() ; index ++ )
|
||||||
|
{
|
||||||
|
if( strncmp( freqman_entry_steps[ index ] . first . c_str() , str , freqman_entry_steps[ index ] . first . size() ) == 0 )
|
||||||
|
return index ;
|
||||||
|
}
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
freqman_index_t freqman_entry_get_step_from_str_short( char *str )
|
||||||
|
{
|
||||||
|
if( !str )
|
||||||
|
return -1 ;
|
||||||
|
for( freqman_index_t index = 0 ; (unsigned)index < freqman_entry_steps_short . size() ; index ++ )
|
||||||
|
{
|
||||||
|
if( strncmp( freqman_entry_steps_short[ index ] . first . c_str() , str , freqman_entry_steps_short[ index ] . first . size() ) == 0 )
|
||||||
|
return index ;
|
||||||
|
}
|
||||||
|
return -1 ;
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,16 @@
|
|||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __FREQMAN_H__
|
||||||
|
#define __FREQMAN_H__
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "file.hpp"
|
#include "file.hpp"
|
||||||
#include "ui_receiver.hpp"
|
#include "ui_receiver.hpp"
|
||||||
|
#include "tone_key.hpp"
|
||||||
#include "string_format.hpp"
|
#include "string_format.hpp"
|
||||||
|
#include "ui_widget.hpp"
|
||||||
#ifndef __FREQMAN_H__
|
|
||||||
#define __FREQMAN_H__
|
|
||||||
|
|
||||||
#define FREQMAN_DESC_MAX_LEN 30
|
#define FREQMAN_DESC_MAX_LEN 30
|
||||||
#define FREQMAN_MAX_PER_FILE 99
|
#define FREQMAN_MAX_PER_FILE 99
|
||||||
@ -35,6 +37,10 @@
|
|||||||
|
|
||||||
using namespace ui;
|
using namespace ui;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace tonekey;
|
||||||
|
|
||||||
|
// needs to be signed as -1 means not set
|
||||||
|
typedef int8_t freqman_index_t ;
|
||||||
|
|
||||||
enum freqman_error {
|
enum freqman_error {
|
||||||
NO_ERROR = 0,
|
NO_ERROR = 0,
|
||||||
@ -44,13 +50,23 @@ enum freqman_error {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum freqman_entry_type {
|
enum freqman_entry_type {
|
||||||
SINGLE = 0,
|
SINGLE = 0, //f=
|
||||||
RANGE
|
RANGE, //a=,b=
|
||||||
|
HAMRADIO, //r=,t=
|
||||||
|
ERROR_TYPE
|
||||||
|
};
|
||||||
|
|
||||||
|
enum freqman_entry_modulation {
|
||||||
|
AM_MODULATION = 0 ,
|
||||||
|
NFM_MODULATION ,
|
||||||
|
WFM_MODULATION ,
|
||||||
|
MODULATION_DEF ,
|
||||||
|
ERROR_MODULATION
|
||||||
};
|
};
|
||||||
|
|
||||||
//Entry step placed for AlainD freqman version (or any other enhanced version)
|
//Entry step placed for AlainD freqman version (or any other enhanced version)
|
||||||
enum freqman_entry_step {
|
enum freqman_entry_step {
|
||||||
STEP_DEF = 0, // default
|
STEP_DEF = -1, // default
|
||||||
AM_US, // 10 kHz AM/CB
|
AM_US, // 10 kHz AM/CB
|
||||||
AM_EUR, // 9 kHz LW/MW
|
AM_EUR, // 9 kHz LW/MW
|
||||||
NFM_1, // 12,5 kHz (Analogic PMR 446)
|
NFM_1, // 12,5 kHz (Analogic PMR 446)
|
||||||
@ -63,21 +79,46 @@ enum freqman_entry_step {
|
|||||||
ERROR_STEP
|
ERROR_STEP
|
||||||
};
|
};
|
||||||
|
|
||||||
// freqman_entry_step step added, as above, to provide compatibility / future enhancement.
|
|
||||||
struct freqman_entry {
|
struct freqman_entry {
|
||||||
rf::Frequency frequency_a { 0 };
|
rf::Frequency frequency_a { 0 }; // 'f=freq' or 'a=freq_start' or 'r=recv_freq'
|
||||||
rf::Frequency frequency_b { 0 };
|
rf::Frequency frequency_b { 0 }; // 'b=freq_end' or 't=tx_freq'
|
||||||
std::string description { };
|
std::string description { }; // 'd=desc'
|
||||||
freqman_entry_type type { };
|
freqman_entry_type type { }; // SINGLE,RANGE,HAMRADIO
|
||||||
freqman_entry_step step { };
|
freqman_index_t modulation { }; // AM,NFM,WFM
|
||||||
|
freqman_index_t bandwidth { }; // AM_DSB, ...
|
||||||
|
freqman_index_t step { }; // 5Khz (SA AM,...
|
||||||
|
tone_index tone { }; // 0XZ, 11 1ZB,...
|
||||||
};
|
};
|
||||||
|
|
||||||
using freqman_db = std::vector<freqman_entry>;
|
using freqman_db = std::vector<freqman_entry>;
|
||||||
|
|
||||||
std::vector<std::string> get_freqman_files();
|
std::vector<std::string> get_freqman_files();
|
||||||
bool load_freqman_file(std::string& file_stem, freqman_db& db);
|
bool load_freqman_file(std::string& file_stem, freqman_db& db);
|
||||||
|
bool load_freqman_file_ex(std::string& file_stem, freqman_db& db, bool load_freqs , bool load_ranges , bool load_hamradios );
|
||||||
|
bool get_freq_string( freqman_entry &entry , std::string &item_string );
|
||||||
bool save_freqman_file(std::string& file_stem, freqman_db& db);
|
bool save_freqman_file(std::string& file_stem, freqman_db& db);
|
||||||
bool create_freqman_file(std::string& file_stem, File& freqman_file);
|
bool create_freqman_file(std::string& file_stem, File& freqman_file);
|
||||||
|
|
||||||
std::string freqman_item_string(freqman_entry &item, size_t max_length);
|
std::string freqman_item_string(freqman_entry &item, size_t max_length);
|
||||||
|
|
||||||
|
void freqman_set_bandwidth_option( freqman_index_t modulation , OptionsField &option );
|
||||||
|
void freqman_set_modulation_option( OptionsField &option );
|
||||||
|
void freqman_set_step_option( OptionsField &option );
|
||||||
|
void freqman_set_step_option_short( OptionsField &option );
|
||||||
|
void freqman_set_tone_option( OptionsField &option );
|
||||||
|
|
||||||
|
std::string freqman_entry_get_modulation_string( freqman_index_t modulation );
|
||||||
|
std::string freqman_entry_get_bandwidth_string( freqman_index_t modulation , freqman_index_t bandwidth );
|
||||||
|
std::string freqman_entry_get_step_string( freqman_index_t step );
|
||||||
|
std::string freqman_entry_get_step_string_short( freqman_index_t step );
|
||||||
|
|
||||||
|
int32_t freqman_entry_get_modulation_value( freqman_index_t modulation );
|
||||||
|
int32_t freqman_entry_get_bandwidth_value( freqman_index_t modulation , freqman_index_t bandwidth );
|
||||||
|
int32_t freqman_entry_get_step_value( freqman_index_t step );
|
||||||
|
|
||||||
|
freqman_index_t freqman_entry_get_modulation_from_str( char *str );
|
||||||
|
freqman_index_t freqman_entry_get_bandwidth_from_str( freqman_index_t modulation , char *str );
|
||||||
|
freqman_index_t freqman_entry_get_step_from_str( char *str );
|
||||||
|
freqman_index_t freqman_entry_get_step_from_str_short( char *str );
|
||||||
|
|
||||||
#endif/*__FREQMAN_H__*/
|
#endif/*__FREQMAN_H__*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user