-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add irts file module, and test file #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
samuelbravi11
wants to merge
9
commits into
dev
Choose a base branch
from
feature/irts
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0b238b7
feat: add irts file module, and test file
samuelbravi11 d9df8ab
fix: moved from double to float, cleaned code
samuelbravi11 233b767
Update Core/Src/das/irts-api.c
samuelbravi11 dd96afa
fix: add array for irts temperature
samuelbravi11 5b86a68
Update Core/Src/das/irts-api.c
samuelbravi11 ce10fab
Update Core/Src/das/irts-api.c
samuelbravi11 fbc2f6a
fix: test
samuelbravi11 26a010d
Update test/test_irts_api/test_irts_api.c
samuelbravi11 7e85267
Merge branch 'dev' into feature/irts
samuelbravi11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #include "irts.h" | ||
|
|
||
| #include "eagletrt.h" | ||
| #include <stdlib.h> | ||
| #include <stdint.h> | ||
|
|
||
| /*! | ||
| * \brief Initializes the module | ||
| * | ||
| * \retval IRTS_RC_OK if successful | ||
| * \retval IRTS_RC_ERROR if fail | ||
| */ | ||
| enum IrtsReturnCode irts_api_init(void); | ||
|
|
||
| /*! | ||
| * \brief Get the current state of a irts line | ||
| * | ||
| * \param irts The irts to query | ||
| * | ||
| * \retval int16_t temperature of \p irts | ||
| */ | ||
| float irts_api_get_temperature(enum IrtsName irts); | ||
|
|
||
| /*! | ||
| * \brief Set the current state of a irts line | ||
| * | ||
| * \param irts The irts to be set | ||
| * \param temperature The temperature to set \p irts to | ||
| * | ||
| * \retval IRTS_RC_OK if successful | ||
| * \retval IRTS_RC_ERROR if \p irts or \p temperature are out of bounds | ||
| */ | ||
| enum IrtsReturnCode irts_api_set_temperature(enum IrtsName irts, float temperature); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #ifndef IRTS_H | ||
| #define IRTS_H | ||
|
|
||
| #include "eagletrt.h" | ||
| #include <stdint.h> | ||
|
|
||
| /*! | ||
| * \brief Names for checked irts | ||
| */ | ||
| enum IrtsName : uint8_t { | ||
| IRTS_NAME_LEFT, /*!< Irts LEFT */ | ||
| IRTS_NAME_RIGHT, /*!< Irts RIGHT */ | ||
| IRTS_NAME_COUNT /*!< Total number of irts */ | ||
| }; | ||
|
|
||
| /*! | ||
| * \brief Possible return codes for irts initialization function | ||
| */ | ||
| enum IrtsReturnCode : uint8_t { | ||
| IRTS_RC_OK, /*!< Initialization successful */ | ||
| IRTS_RC_ERROR /*!< Error during initialization */ | ||
| }; | ||
|
|
||
| /*! | ||
| * \brief Struct that handles all temperature from irts | ||
| */ | ||
| struct IrtsHandler { | ||
| float left_temperature; | ||
| float right_temperature; | ||
|
samuelbravi11 marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| #endif // IRTS_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include "irts-api.h" | ||
| #include <string.h> | ||
|
|
||
| EAGLETRT_STATIC struct IrtsHandler irts_api_handler; | ||
|
|
||
| enum IrtsReturnCode irts_api_init(void) { | ||
| // Initialize irts temperature to 0 to indicate no data | ||
| memset(&irts_api_handler, 0, sizeof(irts_api_handler)); | ||
|
|
||
| return IRTS_RC_OK; | ||
| } | ||
|
|
||
| float irts_api_get_temperature(enum IrtsName irts) { | ||
| switch (irts) { | ||
| case IRTS_NAME_LEFT: | ||
| return (float)irts_api_handler.left_temperature; | ||
| case IRTS_NAME_RIGHT: | ||
| return (float)irts_api_handler.right_temperature; | ||
| default: | ||
| return -1; | ||
| } | ||
|
samuelbravi11 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| enum IrtsReturnCode irts_api_set_temperature(enum IrtsName irts, float temperature) { | ||
| if (irts >= IRTS_NAME_COUNT) { | ||
| return IRTS_RC_ERROR; | ||
| } | ||
|
|
||
| if (irts == IRTS_NAME_LEFT) { | ||
| irts_api_handler.left_temperature = temperature; | ||
| } else if (irts == IRTS_NAME_RIGHT) { | ||
| irts_api_handler.right_temperature = temperature; | ||
| } | ||
|
|
||
| return IRTS_RC_OK; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| #include "unity.h" | ||
|
|
||
| #include "irts.h" | ||
| #include "irts-api.h" | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| extern struct IrtsHandler irts_api_handler; | ||
|
|
||
| void setUp(void) { | ||
| (void)irts_api_init(); | ||
| } | ||
|
|
||
| void tearDown(void) { | ||
| } | ||
|
|
||
| void test_irts_api_init_should_return_ok_and_set_all_irts_to_zero(void) { | ||
| float expected_temperature_left; | ||
| float expected_temperature_right; | ||
|
|
||
| irts_api_handler.left_temperature = 1; | ||
| irts_api_handler.right_temperature = 1; | ||
|
|
||
| expected_temperature_left = 0U; | ||
| expected_temperature_right = 0U; | ||
|
|
||
| enum IrtsReturnCode rc = irts_api_init(); | ||
|
|
||
| TEST_ASSERT_EQUAL_UINT8_MESSAGE( | ||
| IRTS_RC_OK, | ||
| rc, | ||
| "irts_api_init() should return IRTS_RC_OK"); | ||
|
|
||
| TEST_ASSERT_EQUAL_FLOAT_MESSAGE( | ||
| expected_temperature_left, | ||
| irts_api_handler.left_temperature, | ||
| "irts_api_init() should return IRTS_RC_OK"); | ||
|
|
||
| TEST_ASSERT_EQUAL_FLOAT_MESSAGE( | ||
| expected_temperature_right, | ||
| irts_api_handler.right_temperature, | ||
| "irts_api_init() should return IRTS_RC_OK"); | ||
| } | ||
|
|
||
| void test_irts_api_get_temperature_should_return_saved_temperature(void) { | ||
| enum IrtsName irts = IRTS_NAME_LEFT; | ||
|
|
||
| irts_api_handler.left_temperature = 1; | ||
|
|
||
| TEST_ASSERT_EQUAL_FLOAT_MESSAGE( | ||
| 1, | ||
| irts_api_get_temperature(irts), | ||
| "irts_api_get_temperature() should return the saved temperature for each valid irts"); | ||
| } | ||
|
|
||
| void test_irts_api_get_temperature_should_return_minus_one_for_invalid_irts_count(void) { | ||
| float temperature = irts_api_get_temperature(IRTS_NAME_COUNT); | ||
|
|
||
| TEST_ASSERT_EQUAL_FLOAT_MESSAGE( | ||
| -1, | ||
| temperature, | ||
| "irts_api_get_temperature(IRTS_NAME_COUNT) should return -1"); | ||
| } | ||
|
|
||
| void test_irts_api_set_temperature_should_update_temperature_for_valid_input(void) { | ||
| enum IrtsName irts = IRTS_NAME_LEFT; | ||
|
|
||
| enum IrtsReturnCode rc = irts_api_set_temperature( | ||
| irts, | ||
| 1000U); | ||
|
|
||
| TEST_ASSERT_EQUAL_UINT8_MESSAGE( | ||
| IRTS_RC_OK, | ||
| rc, | ||
| "feedback_api_set_state() should return FEEDBACK_RC_OK for valid input"); | ||
|
|
||
| TEST_ASSERT_EQUAL_FLOAT_MESSAGE( | ||
| 1000U, | ||
| irts_api_handler.left_temperature, | ||
| "irts_api_set_temperature() should update the requested irts temperature"); | ||
| } | ||
|
|
||
| void test_irts_api_set_temperature_should_return_error_and_reject_invalid_irts_count(void) { | ||
| float expected_temperatures[IRTS_NAME_COUNT]; | ||
| float temperature = 1; | ||
|
|
||
| for (enum IrtsName irts = 0; irts < IRTS_NAME_COUNT; ++irts) { | ||
| expected_temperatures[irts] = temperature; | ||
| } | ||
| irts_api_handler.left_temperature = temperature; | ||
| irts_api_handler.right_temperature = temperature; | ||
|
|
||
| enum IrtsReturnCode rc = irts_api_set_temperature( | ||
| IRTS_NAME_COUNT, | ||
| 1000U); | ||
|
|
||
| TEST_ASSERT_EQUAL_UINT8_MESSAGE( | ||
| IRTS_RC_ERROR, | ||
| rc, | ||
| "irts_api_set_temperature(IRTS_NAME_COUNT, ...) should return IRTS_RC_ERROR"); | ||
|
|
||
| TEST_ASSERT_EQUAL_FLOAT_MESSAGE( | ||
| temperature, | ||
| irts_api_handler.left_temperature, | ||
| "Invalid irts should not modify any valid irts temperature"); | ||
|
|
||
| TEST_ASSERT_EQUAL_FLOAT_MESSAGE( | ||
| temperature, | ||
| irts_api_handler.right_temperature, | ||
| "Invalid irts should not modify any valid irts temperature"); | ||
| } | ||
|
|
||
| int main(void) { | ||
| UNITY_BEGIN(); | ||
|
|
||
| RUN_TEST(test_irts_api_init_should_return_ok_and_set_all_irts_to_zero); | ||
| RUN_TEST(test_irts_api_get_temperature_should_return_saved_temperature); | ||
| RUN_TEST(test_irts_api_get_temperature_should_return_minus_one_for_invalid_irts_count); | ||
| RUN_TEST(test_irts_api_set_temperature_should_update_temperature_for_valid_input); | ||
| RUN_TEST(test_irts_api_set_temperature_should_return_error_and_reject_invalid_irts_count); | ||
|
|
||
| return UNITY_END(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.