mirror of https://github.com/PentHertz/srsLTE.git
fsm log macros, and utility methods to convert event callbacks to move tasks
This commit is contained in:
parent
9c5471b094
commit
36fc88d2e2
|
@ -31,6 +31,17 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
|
#define otherfsmDebug(f, fmt, ...) f->get_log()->debug("FSM \"%s\" - " fmt, get_type_name(*f).c_str(), ##__VA_ARGS__)
|
||||||
|
#define otherfsmInfo(f, fmt, ...) f->get_log()->info("FSM \"%s\" - " fmt, get_type_name(*f).c_str(), ##__VA_ARGS__)
|
||||||
|
#define otherfsmWarning(f, fmt, ...) \
|
||||||
|
f->get_log()->warning("FSM \"%s\" - " fmt, get_type_name(*f).c_str(), ##__VA_ARGS__)
|
||||||
|
#define otherfsmError(f, fmt, ...) f->get_log()->error("FSM \"%s\" - " fmt, get_type_name(*f).c_str(), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define fsmDebug(fmt, ...) otherfsmDebug(this, fmt, ##__VA_ARGS__)
|
||||||
|
#define fsmInfo(fmt, ...) otherfsmInfo(this, fmt, ##__VA_ARGS__)
|
||||||
|
#define fsmWarning(fmt, ...) otherfsmWarning(this, fmt, ##__VA_ARGS__)
|
||||||
|
#define fsmError(fmt, ...) otherfsmError(this, fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
namespace srslte {
|
namespace srslte {
|
||||||
|
|
||||||
//! Forward declarations
|
//! Forward declarations
|
||||||
|
@ -215,16 +226,16 @@ struct apply_first_guard_pass<FSM, type_list<First, Rows...> > {
|
||||||
if (triggered) {
|
if (triggered) {
|
||||||
// Log Transition
|
// Log Transition
|
||||||
if (std::is_same<src_state, dest_state>::value) {
|
if (std::is_same<src_state, dest_state>::value) {
|
||||||
f->log_fsm_activity("FSM \"%s\": Event \"%s\" updated state \"%s\"\n",
|
otherfsmInfo(static_cast<typename FSM::derived_t*>(f),
|
||||||
get_type_name<typename FSM::derived_t>().c_str(),
|
"Event \"%s\" triggered state \"%s\" update\n",
|
||||||
get_type_name<event_type>().c_str(),
|
get_type_name<event_type>().c_str(),
|
||||||
get_type_name<src_state>().c_str());
|
get_type_name<src_state>().c_str());
|
||||||
} else {
|
} else {
|
||||||
f->log_fsm_activity("FSM \"%s\": Transition detected - %s -> %s (cause: %s)",
|
otherfsmInfo(static_cast<typename FSM::derived_t*>(f),
|
||||||
get_type_name<typename FSM::derived_t>().c_str(),
|
"transition detected - %s -> %s (cause: %s)",
|
||||||
get_type_name<src_state>().c_str(),
|
get_type_name<src_state>().c_str(),
|
||||||
get_type_name<dest_state>().c_str(),
|
get_type_name<dest_state>().c_str(),
|
||||||
get_type_name<event_type>().c_str());
|
get_type_name<event_type>().c_str());
|
||||||
// Apply state change operations
|
// Apply state change operations
|
||||||
state_traits<FSM, src_state>::template transit_state<dest_state>(f, ev);
|
state_traits<FSM, src_state>::template transit_state<dest_state>(f, ev);
|
||||||
}
|
}
|
||||||
|
@ -239,9 +250,8 @@ struct apply_first_guard_pass<FSM, type_list<> > {
|
||||||
template <typename SrcState, typename Event>
|
template <typename SrcState, typename Event>
|
||||||
static bool trigger(FSM* f, SrcState& s, const Event& ev)
|
static bool trigger(FSM* f, SrcState& s, const Event& ev)
|
||||||
{
|
{
|
||||||
f->get_log()->debug("FSM \"%s\": Unhandled event caught: \"%s\"\n",
|
otherfsmDebug(
|
||||||
get_type_name<typename FSM::derived_t>().c_str(),
|
static_cast<typename FSM::derived_t*>(f), "unhandled event caught: \"%s\"\n", get_type_name<Event>().c_str());
|
||||||
get_type_name<Event>().c_str());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -681,6 +691,10 @@ private:
|
||||||
ProcFSM* proc_ptr = nullptr;
|
ProcFSM* proc_ptr = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**************************************
|
||||||
|
* Event Trigger Scheduling
|
||||||
|
*************************************/
|
||||||
|
|
||||||
template <typename Event>
|
template <typename Event>
|
||||||
struct event_callback {
|
struct event_callback {
|
||||||
event_callback() = default;
|
event_callback() = default;
|
||||||
|
@ -693,9 +707,34 @@ struct event_callback {
|
||||||
void operator()(const Event& ev) { callback(ev); }
|
void operator()(const Event& ev) { callback(ev); }
|
||||||
void operator()(const Event& ev) const { callback(ev); }
|
void operator()(const Event& ev) const { callback(ev); }
|
||||||
|
|
||||||
|
srslte::move_task_t to_move_task(const Event& ev)
|
||||||
|
{
|
||||||
|
auto& copied_callback = callback;
|
||||||
|
return [copied_callback, ev]() { copied_callback(ev); };
|
||||||
|
}
|
||||||
|
|
||||||
std::function<void(const Event&)> callback;
|
std::function<void(const Event&)> callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Event>
|
||||||
|
srslte::move_task_t make_move_task(const event_callback<Event>& callback, const Event& ev)
|
||||||
|
{
|
||||||
|
auto& copied_callback = callback;
|
||||||
|
return [copied_callback, ev]() { copied_callback(ev); };
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Event>
|
||||||
|
srslte::move_task_t make_move_task(std::vector<event_callback<Event> >&& callbacks, const Event& ev)
|
||||||
|
{
|
||||||
|
return std::bind(
|
||||||
|
[ev](const std::vector<event_callback<Event> >& callbacks) {
|
||||||
|
for (const auto& callback : callbacks) {
|
||||||
|
callback(ev);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
std::move(callbacks));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace srslte
|
} // namespace srslte
|
||||||
|
|
||||||
#endif // SRSLTE_FSM_H
|
#endif // SRSLTE_FSM_H
|
||||||
|
|
|
@ -71,10 +71,7 @@ void phy_controller::selecting_cell::enter(phy_controller* f, const cell_sel_cmd
|
||||||
csel_callback = ev.callback;
|
csel_callback = ev.callback;
|
||||||
csel_res.result = false;
|
csel_res.result = false;
|
||||||
|
|
||||||
f->log_h->info("Starting \"%s\" for pci=%d, earfcn=%d\n",
|
fsmInfo("Starting for pci=%d, earfcn=%d\n", target_cell.pci, target_cell.earfcn);
|
||||||
srslte::get_type_name(*this).c_str(),
|
|
||||||
target_cell.pci,
|
|
||||||
target_cell.earfcn);
|
|
||||||
f->stack->start_cell_select(&target_cell);
|
f->stack->start_cell_select(&target_cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,15 +80,13 @@ void phy_controller::selecting_cell::exit(phy_controller* f)
|
||||||
wait_in_sync_timer.stop();
|
wait_in_sync_timer.stop();
|
||||||
|
|
||||||
if (csel_res.result) {
|
if (csel_res.result) {
|
||||||
log_h->info("Cell %s successfully selected\n", to_string(target_cell).c_str());
|
fsmInfo("Cell %s successfully selected\n", to_string(target_cell).c_str());
|
||||||
} else {
|
} else {
|
||||||
log_h->warning("Failed to select cell %s\n", to_string(target_cell).c_str());
|
fsmWarning("Failed to select cell %s\n", to_string(target_cell).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal result back to FSM that called cell selection
|
// Signal result back to FSM that called cell selection
|
||||||
auto& copied_callback = csel_callback;
|
f->stack->defer_task(srslte::make_move_task(csel_callback, csel_res.result));
|
||||||
bool result = csel_res.result;
|
|
||||||
f->stack->defer_task([copied_callback, result]() { copied_callback(result); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void phy_controller::selecting_cell::wait_in_sync::enter(selecting_cell* f, const cell_sel_res& ev)
|
void phy_controller::selecting_cell::wait_in_sync::enter(selecting_cell* f, const cell_sel_res& ev)
|
||||||
|
@ -109,7 +104,7 @@ bool phy_controller::start_cell_search(const srslte::event_callback<cell_srch_re
|
||||||
{
|
{
|
||||||
trigger(cell_search_cmd{on_complete});
|
trigger(cell_search_cmd{on_complete});
|
||||||
if (not is_in_state<searching_cell>()) {
|
if (not is_in_state<searching_cell>()) {
|
||||||
log_h->warning("Failed to launch cell search\n");
|
fsmWarning("Failed to launch cell search\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -140,25 +135,18 @@ void phy_controller::handle_cell_search_res(searching_cell& s, const cell_srch_r
|
||||||
{
|
{
|
||||||
switch (result.cs_ret.found) {
|
switch (result.cs_ret.found) {
|
||||||
case cell_search_ret_t::CELL_FOUND:
|
case cell_search_ret_t::CELL_FOUND:
|
||||||
log_h->info("PHY cell search completed. Found cell %s\n", to_string(result.found_cell).c_str());
|
fsmInfo("PHY cell search completed. Found cell %s\n", to_string(result.found_cell).c_str());
|
||||||
break;
|
break;
|
||||||
case cell_search_ret_t::CELL_NOT_FOUND:
|
case cell_search_ret_t::CELL_NOT_FOUND:
|
||||||
log_h->warning("PHY cell search completed. No cells found.\n");
|
fsmWarning("PHY cell search completed. No cells found.\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log_h->error("Invalid cell search result\n");
|
fsmError("Invalid cell search result\n");
|
||||||
// TODO: check what errors can happen (currently not handled in our code)
|
// TODO: check what errors can happen (currently not handled in our code)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal result back to FSM that called cell search
|
// Signal result back to FSM that called cell search
|
||||||
auto& moved_callbacks = csearch_callbacks;
|
stack->defer_task(srslte::make_move_task(std::move(csearch_callbacks), result));
|
||||||
stack->defer_task(std::bind(
|
|
||||||
[result](std::vector<srslte::event_callback<cell_srch_res> >& callbacks) {
|
|
||||||
for (auto& f : callbacks) {
|
|
||||||
f(result);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
std::move(moved_callbacks)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void phy_controller::share_cell_search_res(searching_cell& s, const cell_search_cmd& cmd)
|
void phy_controller::share_cell_search_res(searching_cell& s, const cell_search_cmd& cmd)
|
||||||
|
|
Loading…
Reference in New Issue