Skip to content

Commit

Permalink
Complain about undefined parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley committed Aug 13, 2024
1 parent 215a581 commit 019cef5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
4 changes: 2 additions & 2 deletions FluidNC/src/Job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ void Job::abort() {
}
}

float Job::get_param(const std::string& name) {
return job.top()->get_param(name);
bool Job::get_param(const std::string& name, float& value) {
return job.top()->get_param(name, value);
}
void Job::set_param(const std::string& name, float value) {
job.top()->set_param(name, value);
Expand Down
15 changes: 11 additions & 4 deletions FluidNC/src/Job.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ class JobSource {

public:
JobSource(Channel* channel) : _channel(channel) {}
float get_param(const std::string& name) { return _local_params[name]; }
void set_param(const std::string& name, float value) { _local_params[name] = value; }
bool param_exists(const std::string& name) { return _local_params.count(name) != 0; }
bool get_param(const std::string& name, float& value) {
auto it = _local_params.find(name);
if (it == _local_params.end()) {
return false;
}
value = it->second;
return true;
}
void set_param(const std::string& name, float value) { _local_params[name] = value; }
bool param_exists(const std::string& name) { return _local_params.count(name) != 0; }

void save() { _channel->save(); }
void restore() { _channel->restore(); }
Expand Down Expand Up @@ -41,7 +48,7 @@ class Job {
static void abort();
static JobSource* source();

static float get_param(const std::string& name);
static bool get_param(const std::string& name, float& value);
static void set_param(const std::string& name, float value);
static bool param_exists(const std::string& name);
static Channel* channel();
Expand Down
33 changes: 21 additions & 12 deletions FluidNC/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,25 +386,30 @@ bool named_param_exists(std::string& name) {
return global_named_params.count(search) != 0;
}

bool get_param(const param_ref_t& param_ref, float& result) {
bool get_global_named_param(const std::string& name, float& value) {
auto it = global_named_params.find(name);
if (it == global_named_params.end()) {
return false;
}
value = it->second;
return true;
}

bool get_param(const param_ref_t& param_ref, float& value) {
auto name = param_ref.name;
if (name.length()) {
if (name[0] == '/') {
return get_config_item(name, result);
return get_config_item(name, value);
}
bool got;
if (name[0] == '_') {
got = get_system_param(name, result);
if (got) {
if (get_system_param(name, value)) {
return true;
}
result = global_named_params[name];
return true;
return get_global_named_param(name, value);
}
result = Job::active() ? Job::get_param(name) : global_named_params[name];
return true;
return Job::active() ? Job::get_param(name, value) : get_global_named_param(name, value);
}
return get_numbered_param(param_ref.id, result);
return get_numbered_param(param_ref.id, value);
}

bool get_param_ref(const char* line, size_t& pos, param_ref_t& param_ref) {
Expand Down Expand Up @@ -462,7 +467,7 @@ bool get_param_ref(const char* line, size_t& pos, param_ref_t& param_ref) {
}
}

void set_named_param(const char* name, float value) {
void set_named_param(const std::string& name, float value) {
global_named_params[name] = value;
}

Expand All @@ -476,7 +481,7 @@ void set_param(const param_ref_t& param_ref, float value) {
if (name[0] != '_' && Job::active()) {
Job::set_param(name, value);
} else {
global_named_params[name] = value;
set_named_param(name, value);
}
return;
}
Expand All @@ -495,6 +500,10 @@ bool read_number(const char* line, size_t& pos, float& result, bool in_expressio
if (!get_param_ref(line, pos, param_ref)) {
return false;
}
if (get_param(param_ref, result)) {
return true;
}
log_debug("Undefined parameter " << param_ref.name);
return get_param(param_ref, result);
}
if (c == '[') {
Expand Down

0 comments on commit 019cef5

Please sign in to comment.