-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Build results | ||
build/ | ||
|
||
# VSCode | ||
.vscode |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Check notice on line 1 in src/finite_state_machine.c
|
||
* MIT License | ||
* | ||
* Copyright (c) 2022 Volodymyr Pavlusha | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#include "finite_state_machine.h" | ||
Check failure on line 25 in src/finite_state_machine.c
|
||
|
||
#include <stddef.h> | ||
|
||
FSM_ReturnCode_t FSM_Kernel(FSM_t *const fsm) | ||
{ | ||
if (fsm == NULL) { | ||
return FSM_ARGUMENT_NOT_VALID; | ||
} | ||
|
||
for (size_t row = 0; row < fsm->fsm_table_size / sizeof(FSM_TableRow_t); ++row) { | ||
if (fsm->fsm_table[row].present_state == fsm->current_state) { | ||
if (fsm->fsm_table[row].event != NULL) { | ||
if (fsm->fsm_table[row].event()) { | ||
if (fsm->fsm_table[row].action != NULL) { | ||
fsm->fsm_table[row].action(); | ||
} | ||
fsm->current_state = fsm->fsm_table[row].next_state; | ||
break; | ||
} | ||
} else { | ||
return FSM_ARGUMENT_NOT_VALID; | ||
} | ||
} | ||
} | ||
return FSM_SUCCESS; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Check notice on line 1 in src/finite_state_machine.cpp
|
||
* MIT License | ||
* | ||
* Copyright (c) 2022 Volodymyr Pavlusha | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#include <finite_state_machine.hpp> | ||
Check failure on line 25 in src/finite_state_machine.cpp
|
||
|
||
#include <cstddef> | ||
|
||
namespace fsm { | ||
|
||
FSM_State_t FSM::FSM_GetCurrentState() const noexcept | ||
{ | ||
return current_state_; | ||
} | ||
|
||
FSM_ReturnCode_t FSM::FSM_Kernel() noexcept | ||
{ | ||
for (size_t row = 0; row < fsm_table_size_ / sizeof(FSM_TableRow_t); ++row) { | ||
if (fsm_table_[row].present_state == current_state_) { | ||
if (fsm_table_[row].event != nullptr) { | ||
if (fsm_table_[row].event()) { | ||
if (fsm_table_[row].action != nullptr) { | ||
fsm_table_[row].action(); | ||
} | ||
current_state_ = fsm_table_[row].next_state; | ||
break; | ||
} | ||
} else { | ||
return FSM_ReturnCode_t::FSM_ARGUMENT_NOT_VALID; | ||
} | ||
} | ||
} | ||
return FSM_ReturnCode_t::FSM_SUCCESS; | ||
} | ||
|
||
} // namespace fsm |